Hello JOGL users!
I have problems with monochrome (1-bit) textures.
My question is: how to load it fast into GPU memory and use it without reformatting it to grayscale (or RGB) with CPU?
I need it because I’m developing earth map viewer and a lot of maps in large scales are monochome (1-bit, black & white) images.
I’ve looked into JOGL TextureData source code and I saw that BufferedImage with image type of TYPE_BYTE_BINARY is reformatted to TYPE_CUSTOM with RGB color palette. This is very slow operation. Loading 4096x4096 monochrome image takes 8 seconds. The same image in grayscale loads in 1,5 sec.
I’ve experimented with GL_COLOR_INDEX pixel format and GL_BITMAP pixel type operators with glTexImage2D, but all tests have failed.
I’ve started to add some code to Texture.java and it also gave me nothig. This is a piece of the code:
int[] map = new int[256];
IntBuffer palette = IntBuffer.allocate(256);
for(int i=0; i<map.length; i++) {
if(i<128)
map[i] = 0;
else
map[i] = 255;
}
palette.put(map);
palette.rewind();
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, GL.GL_TRUE);
gl.glPixelStorei(GL.GL_UNPACK_ROW_LENGTH, data.getWidth());
gl.glPixelTransferi(GL.GL_MAP_COLOR, GL.GL_TRUE);
gl.glPixelMapuiv(GL.GL_PIXEL_MAP_I_TO_R, 256, palette);
gl.glTexImage2D(newTarget, 0, GL.GL_LUMINANCE,
texWidth, texHeight, 0,
data.getPixelFormat(), data.getPixelType(), null);
updateSubImageImpl(data, newTarget, 0, 0, 0);
gl.glPixelTransferi(GL.GL_MAP_COLOR, GL.GL_FALSE);
System.out.println(gl.glGetError());
The result is a completly black texture in OpenGL window. ???
As I mentioned above, my BufferedImage type is TYPE_BYTE_BINARY. data.getPixelFormat() returns GL.GL_COLOR_INDEX and data.getPixelType() returns GL.GL_BITMAP. Pixel alignment is set to 1. gl.glGetError() returns 0.
I didn’t found any useful things in Google. OpenGL docs also don’t explain this issue.
I’ve been sitting with this for days, so please help me!!!
Greetings
Latek