[ad_1]
I’m programming an app with OpenGL ES on Android in Java. The app uses 9 textures during a render loop pass. A depth, position, normal, albedo, noise, SSAO, SSAO blur and two image textures for the models I draw. The problem is that 9/10 times, the image textures fail to load. I get no GL error during or after loading the texture. I get an error 1282 when I bind the texture 8 and 9 during the draw call. But only when they don’t load/show up. When they load and show up I get no error and they are displayed correctly on the primitives.
According to the documentation of glBindTexture
, the method generates the error code 1282 (GL_INVALID_OPERATION
) if texture was previously created with a target that doesn’t match that of the target. The only target I use in the whole application is GL_TEXTURE_2D
, so I don’t understand why I get this error.
Since I’m using a deferred rendering pipeline, I thought that maybe the albedo buffer is messed up, but I could rule that out by setting constant colors for the whole scene directly in the fragment shader of the geometry pass, and that is working fine every time.
I managed to take GPU-snapshots of both cases using snapdragon profiler to debug the app/profile the GPU (Adreno 630). I could verify that all the uniforms are correct, the attribute arrays are also correct and the correct units are active in both cases. The difference I could notice in the error case is that both image textures are missing, the rest is there.
These are all the textures on the GPU when they load:
Here, in the other snapshot they are missing, even though it is the exact same code that loads the textures. In both cases I get valid handles/indexes when I call glGenTexture
.
It just seems that somehow the textures aren’t loaded anymore during the draw call.
The image textures are being loaded like this:
AssetManager assetManager = context.getAssets();
InputStream stream = assetManager.open(id.getResourceName());
int[] textureHandle = new int[1];
BitmapFactory.Options option = new BitmapFactory.Options();
option.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, option);
//GLES30.glActiveTexture(GLES30.GL_TEXTURE5);
GLES30.glGenTextures(1, textureHandle, 0);
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureHandle[0]);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_MIRRORED_REPEAT);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_MIRRORED_REPEAT);
if (bitmap != null) {
Log.d(TextureLoader.class.getSimpleName(), "Texture format: " + GLUtils.getInternalFormat(bitmap));
GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
ShaderUtil.checkGLError(TextureLoader.class.getSimpleName(), "Failed to load texture");
Log.d("Texture id", String.valueOf(textureHandle[0]));
return textureHandle[0];
- The code above is executed during the
onSurfaceCreated
invocation, so I have a valid OpenGL context. - The code above is executed two times, once per image texture in sequential order.
- Both textures are of type 32 bit RGBA (PNG) 512px x 512px
The code below is executed in the render loop. I have multiple models, some are using one texture and some the other one.
GLES30.glActiveTexture(GLES30.GL_TEXTURE5);
GLES30.glUniform1i(shaderHandles.getTextureMapHandle(), 5);
ShaderUtil.checkGLError("Render loop", "Activate unit");
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureDataHandle);
ShaderUtil.checkGLError("Render loop", "Activate " + textureDataHandle);
I’ve been debugging for multiple days now, so I appreciate any help. Thank you
[ad_2]