Weird Texture Creation Failure

Im creating textures of different sizes in my application. Which doesn’t seem to be a problem most of the time(which you would expect).

However I have a case where when i once create a texture with the size 720x576, I can no longer create texture with the size 1280x720. In order to get around this I have to create all my 1280x720 first. This is a somewhat weird problem.

I have not tested with other texture sizes.

I get the error code 1282, invalid operation i believe it is?


glGenTextures(1, &texture_);	
GL_CHECK();

glBindTexture(GL_TEXTURE_2D, texture_);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
GL_CHECK(); // 1282

What might be causing this?

if you dont use texture rectangle. your texture width and height must be power of two
512512
1024
1024…

Memory fragmentation ?
Compare an estimate of the vram used by your texture to the actual vram. If it is near, then creation/destruction order may well be relevant. Create largest textures first, if you can.
Do you destroy textures also ?

@glsl09 : 3 wrongs in your post :

  1. nothing to do with texture rectangle, but with Non Power Of Two (NPOT) textures. Rectangle is a much more limited form of NPOT, without mipmaps and non-normalized texture coordinates
  2. as the original poster said, it works with a different creation order, so this is not about “must” or “must not”, as the hardware clearly supports NPOT textures
  3. Power Of Two does not mean that width and height must be the same. Your confusion is due to rectangle texture, which is a misnomer. Ie 2048*1024 is perfectly legal POT even for GL 1.x

No I do not destroy textures. They are pooled.

I guess I will have to fill the pools with enough texture in size order, and simply disallow any more texture creations.

EDIT:

I only create these 2 rather small textures in the entire application when i get the error… so I don’t see how vram memory could affect it?

My problem is that some texture are create at runtime with sizes I cannot know beforehand.

How could I solve this?

Please provide the answer to my second question, about memory usage.

Put GL_CHECK() after each GL call, to be sure to catch the good one.
Then read the relevant section in the man page, example for glTexImage2D :
http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml

“Is it between glbegin/glEnd” etc

Sounds like a driver bug. Here are approaches I have used.

Solution 1: Create the simplest example that reproduces the problem and submit it to your driver vendor and wait for a fix.

Solution 2: Experiment and hope to find a way around the driver bug.

I often try both approaches. Occasionally you may find your own mistake in the process.

Have you tried using GL_CLAMP_TO_EDGE instead of GL_CLAMP?

Update your video drivers. This ensures that you using the latest GL version for your current card. I’ve noticed that drivers can mess up if you run opengl apps vigorously during testing. Reinstalling them fixed the problems for me.

What is the specs of your system?

Will try all suggestions as soon as i get time. It is not between glBegin, glEnd

My specs are:

Nvidia Quadro FX1700M

Driver Version: nv_4disp 6.14.12.5896 (Forceware 258.96) / XP

EDIT:

Should I maybe also ask this question on NVIDIAs forums?

I suppose you mean

Compare an estimate of the vram used by your texture to the actual vram. If it is near, then creation/destruction order may well be relevant.

Not sure how I would do this. Could you please explain how vram can affect this issue? Ive got 512mb video memory, soo creating two small texture shouldn’t be a problem?

2 small textures is not a problem, but a load of textures + 2 small textures may be.
So, how much “load of textures” do you have ?

No other textures loaded. Only the small first and then the large and then it crashes.

Driver update solved the problem.

You had pretty recent drivers, I am really surprised such a simple case had a bug.

Good to know.

I’ve had problems with that driver. It seems to mess up after running an OpenGL app countless times. My fix was to reinstall the exact same driver and it was fixed.