Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating texture using glTexImage2D(..) in OpenglES2 [Android]

Initialization code creates one RGB one-color texture with 128x128 pixels:

GLES20.glGenTextures ( 1, textureId, 0 );
GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, textureId[0] );
GLES20.glTexImage2D ( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, bitmap.getWidth(), bitmap.getHeight(), 0,GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, byteBuffer );|
GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, 0 );

after initialization I have the proper texture and everything works ok. At some poin I have to make some changes in my texture or even replace it completelly with other image:

GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, textureId[0] );
GLES20.glTexImage2D ( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, bitmap.getWidth(), bitmap.getHeight(), 0,GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, byteBuffer );|
GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, 0 );

But glTexImage2D dosen't make any changes to the texture and returns no error. But this code works correctly in my iOS project, but in case of android it doesn't. It looks like I can't use glTexImage2D(..) twice with same texture, in other words, the only way to modify my texture is to create new one and delete old one, but why it's works correctly in iOS? What's wrong with my code?

like image 664
Tutankhamen Avatar asked Jul 23 '12 05:07

Tutankhamen


1 Answers

Sorry, that was my fault. I tried to call glTexImage2D function from other thread (not from GL thread). Now everything works perfect.

like image 137
Tutankhamen Avatar answered Sep 19 '22 03:09

Tutankhamen