CodeFlakes
CodeFlakes

Reputation: 3711

Blank texture when disabling mipmaping?

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);

Upvotes: 0

Views: 344

Answers (2)

rotoglup
rotoglup

Reputation: 5273

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

Upvotes: 2

Tommy
Tommy

Reputation: 100642

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%.

Upvotes: 1

Related Questions