Hi guys,
I recently switched to using an array texture to load all my textures into the one array...
Before, I was passing each texture (diffuse, normal, displacement) to separate samplers in my shader, and I had mip maps enabled. The thing is, since switching to using an array texture, mip mapping no longer works. This is my code:
// I pass in 3 strings to this method, which are the 3 texture names
private static int loadPNGTexture(String ... filenames) {
ByteBuffer buf = null;
int tWidth = 1024;
int tHeight = 1024;
int texId = GL11.glGenTextures();
GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, texId);
GL42.glTexStorage3D(GL30.GL_TEXTURE_2D_ARRAY, 1, GL11.GL_RGBA8, 1024, 1024, 3); //last 3 params are image size and array size
for (int i = 0; i < filenames.length; i++){
try {
// Open the PNG file as an InputStream
InputStream in = new FileInputStream(filenames[i]);
// Link the PNG decoder to this stream
PNGDecoder decoder = new PNGDecoder(in);
// Get the width and height of the texture
tWidth = decoder.getWidth();
tHeight = decoder.getHeight();
// Decode the PNG file in a ByteBuffer
buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
buf.flip();
in.close();
GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, tWidth, tHeight, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
return texId;
}
I cleaned out the old mip mapping code, since I don't think it will apply to a 2D texture array...how do I modify the above code to have mip mapping working on all 3 textures?
Thanks