eskimo9
eskimo9

Reputation: 753

android opengl es 2.0 texture switching

I have the following code that loads and binds 3 textures:

 // Load the texture
 mTextureDataHandle[0] = TextureHelper.loadTexture(mActivityContext, R.drawable.bricks);

 mTextureDataHandle[1] = TextureHelper.loadTexture(mActivityContext, R.drawable.grass);

 mTextureDataHandle[2] = TextureHelper.loadTexture(mActivityContext, R.drawable.steel);

 // Set the active texture unit to texture unit 0 and bind to the texture data.
 GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle[0]);

 GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle[1]);

 GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle[2]);

I then want to use each texture independently:

GLES20.glUseProgram(mPerVertexTexturedProgramHandle);

GLES20.glUniform1f(mTextureUniformHandle, 2);
drawStuff();

GLES20.glUseProgram(mPerVertexProgramHandle);

//Draw some smooth shapes

GLES20.glUseProgram(mPerVertexTexturedProgramHandle);

GLES20.glUniform1f(mTextureUniformHandle, 3);

drawOtherStuff();

GLES20.glUseProgram(mPerVertexProgramHandle);

I would have expected that Stuff would be drawn in grass, and OtherStuff in steel, but I find that both shapes are drawn in steel. If I change the indices of the textures at bind time (glActiveTexture with TEXTURE0, TEXTURE1, TEXTURE2 instead of 1, 2, 3) both shapes are drawn in bricks. It doesn't seem to matter what values are passed to glUniform1f.

I'm at a loss here, I was following a method from Android OpenGL ES2.0 Texture Swapping , but aside from not using uniform normal handles that he is using (as far as I know they aren't necessary?), I'm not sure why it wouldn't be working. Thoughts?

Upvotes: 1

Views: 1988

Answers (1)

Tim
Tim

Reputation: 35923

I see you're calling glUniform1f for your samplers instead of glUniform1i. I don't know if that would cause an error necessarily, but it does seem a bit strange and I'm not sure what happens if you try to set a sampler with a float.

Also do you have glGetError anywhere?

Upvotes: 2

Related Questions