0

I do not master all the subtlety of OpenGL so sorry if my question is not precise enough

On iPhone I load a texture (png image) like this

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTextureSize.width, iTextureSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_FILTER, GL_NEAREST);

Which works well but I noticed that this allocate exactly twice the size of textureData. I've read in forums that this could be caused by mipmaping so I tried to turn it off by commenting the glTexParameteri lines but then my textures is blank.

Is this a problem is my texture loading parameter on in my display code ? My display code is like this

glTexCoordPointer(2, GL_FLOAT, 0, texture);
glVertexPointer(DIMENSION,  GL_SHORT,  0, iVertex);
glBindTexture(GL_TEXTURE_2D, (GLuint)textureID);
glDrawArrays(GL_TRIANGLE_FAN,  0, iVertexCount);
genpfault
  • 51,148
  • 11
  • 85
  • 139
CodeFlakes
  • 3,671
  • 3
  • 25
  • 28
  • What do you mean by 'allocate exactly twice the size of textureData'? Also you can free the memory textureData points to after uploading the texture. glTexImage creates a full copy. – datenwolf Feb 23 '11 at 18:12
  • I already free textureData nonetheless glTexImage2D allocate twice the size of textureData – CodeFlakes Feb 23 '11 at 18:17

2 Answers2

2

Now that you have mipmaps disabled alright, have you tried to disable the texture repeat ?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

If your texture width or height is a value that is not a power of two, you fall into the 'non-power-of-two texture' (NPOT), which is handled with limitations on iPhone, see :

Rendering to non-power-of-two texture on iPhone

Community
  • 1
  • 1
rotoglup
  • 5,223
  • 25
  • 37
1

Commenting out the two texture parameter lines enables MIP mapping. Since you upload only one level of texture, all the other levels are blank. That's why you subsequently don't see anything.

By what means are you concluding that you're causing twice the size of textureData to be allocated and how do you reach the conclusion that this is an error? It's up to the GL driver how it allocates memory internally and where it caches what it wants. There's no reason to assume that double is incorrect, especially if you're adding video RAM to main RAM.

Furthermore, storing MIP maps adds one third to your overall storage requirements, not 100%.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • Yes I know I should have 1/3 more but in my case I have twice. I'm trying to minimize the memory used by my app that is why I'm interested in glTextImage2D behavior. I just display fullscreen png so I guess I don't need mipmap right ? – CodeFlakes Feb 23 '11 at 18:18
  • No, you're right — mip mapping is simultaneously to reduce aliasing and memory bandwidth requirements when you'll often be scaling the texture down. I'm still unclear on where you're getting double from, but it could just be a RAM copy + a VRAM copy, the VRAM being for the GPU and the duplicate in RAM being e.g. kept for quick access unless and until a low memory warning occurs. The iPhone partitions the same physical RAM between the two devices according to their needs, so you could end up with both stores being counted towards your total. – Tommy Feb 23 '11 at 18:34