1

This is my 1st question here. I m new to Android development and i build now a live wallpaper (LiveSpace) I allready uploaded the lite version , you can find it here. https://market.android.com/details?id=thedavincode.alienland&feature=search_result#?t=W251bGwsMSwyLDEsInRoZWRhdmluY29kZS5hbGllbmxhbmQiXQ..

i tested it with Xperia phones and Lg P990 , and it seems to work fine , but there is a weird problem with Galaxy S2. (2.3.4. android) My app has 11 objects(classes) with a texture for each object, and every object has its own program and shaders. galaxy wont render more than 8 textures. it goes from id 0 to 7 and then rest objects apear black. no matter what i ve tried nothing changes. ive read that there is a limit for 8 textures but per shader , not total. Any help would be valueable.. thanks.

DavinCode
  • 51
  • 2
  • 5

1 Answers1

1

SGS2(Mali400MP) have a limit of a max. 8 texture units. If you are using only single texture in shader, then you could use only one unit. For example:

  1. When you are doing some setup with shader, then bind your texture uniform to first texture unit (0) like: glUniform1i(uTexture, 0); - do it for all of your objects
  2. Before rendering each object bind texture which belongs to it: glBindTexture(GL_TEXTURE_2D , m_texture); - you are binding texture to active texture unit.
  3. As in this case there is used only one texture unit, you can omit glActiveTexture call, as by default first texture unit activated (GL_TEXTURE0)

You should always keep in specification limits if possible, to be compatible with most devices.

Using one texture unit per object/texture is not a way to go.

Krystian Bigaj
  • 1,295
  • 8
  • 14
  • Thanks for your reply kibab. well i think i do all these see my code. – DavinCode Mar 05 '12 at 18:54
  • Thanks for your reply kibab. well i think i do all these see my code. this is onDraw of every object class GLES20.glUseProgram(GroundProgram); //checkGlError("glUseProgram"); int grtextureLoc = GLES20.glGetUniformLocation(GroundProgram, "sTexture"); GrTextureID = Commons.Mytextures[11]; GLES20.glActiveTexture(GLES20.GL_TEXTURE11); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, GrTextureID); and after setting my shaders and other stuff and before drawing GLES20.glUniform1i(grtextureLoc,GrTextureID); do i miss something???? – DavinCode Mar 05 '12 at 19:03
  • You don't pass texture id to uniforms. You pass texture unit index. Read here: http://www.opengl.org/wiki/GLSL_Sampler#Binding_textures_to_samplers And do you really need to read 12 textures simultaneously in shader? – Mārtiņš Možeiko Mar 05 '12 at 19:45
  • If your fragment shader have only one texture uniform (like one `uniform sampler2D uTexture`), then you don't need to use `glActivateTexture`. You can do all texture stuff with just one texture unit. So after creating shader set first texture unit to your shader by `glUniform1i(grtextureLoc, 0)` (you don't need to do it every draw call). But before each object draw call just `glBindTexture(GL_TEXTURE_2D, GrTextureID)`. PS. And you do not do anything that I wrote in your code ;) – Krystian Bigaj Mar 05 '12 at 21:19
  • Ok.. thanks guys.. solved The error was that i was passing texture id to glUniform1i I was doing this because textureid and texture slot had the same num textureid 0 bind to texture slot 0 etc. and also didnt know that i m able to bind all to one slot. (as i said my first android app) Thanks again! – DavinCode Mar 05 '12 at 22:11
  • Hi Kibab, Here i am facing some problem while using Samsung Galaxy note II like GPU Mali400MP, for run opengl es2.0 auto cad app in android. I cant draw multiple lines or circles, when I draw line again, it erased previous line or circle dawned already. Please see this link and understand my problem clearly and see my sample code also. please help me to solve this issue.. http://stackoverflow.com/questions/17187032/why-my-opengl-output-differs-for-various-devices – harikrishnan Jun 20 '13 at 06:10