texture performance

I had a question about the texture performance demo on apple’s developer site. It uses the:

glBindTextures( target, &texID);
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image_ptr);

Update the texture with:

glTexSubImage2D(target, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image_ptr);

Anyhow, I use mipmaps. I could not get it to work. They claim a 70% performance increase because it uses dma transfers. Anyone used this with mipmaps? Also, if the texture is simply rgb and not rgba what to pass to glTexImage2D and glTexSubImage2D?

There are four things you have to do to get optimal texture upload:

  • Use client storage. This eliminates copying from your buffer to GL.
  • Use texture range. This maps your buffer into AGP space, so it is possible for the GPU to DMA directly, eliminating another copy.
  • Match your texture data to a native hardware format-- rectangle target and BGRA, UNSIGNED_INT_8_8_8_8_REV.
  • Make sure the rowbytes of your texture is a multiple of 32.

If either of the two latter points aren’t met, the DMA probably won’t be enabled.

Rectangle textures don’t allow mipmaps, so you won’t get optimal performance if you require mipmaps and use TEXTURE_2D. But you can still get a 70% boost by doing only the first point, client storage.

The thing to watch out for with client storage is that you must retain your buffer for the entire lifetime of the texture. That means you can not use gluBuild*Mipmaps, because the buffers those functions internally create during mipmap upload are immediately discarded. Just submit each mip level yourself with TexImage and keep the buffers around.

You should also make sure to use a native format; if you use RGB it will probably go through a transform to BGRA first, and of course this slows things down.

Thanks for the suggestions. Unfortunately, I’m only getting color through. I read in the image with quicktime just like the demo program from the apple dev site. Though, I had to port the snippet to c++. But it works fine with the TEXTURE_2D and mip maps.

Here is a code snippet … maybe I just dont see the error:

----load in texture----

//does this once per texture when program is loading models.
//image data in mdata variable and not deleted until
//program exit.
//do not use mip maps.

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, mid); glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
//glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE ,GL_STORAGE_CACHED_APPLE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA8, mWidth,mHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mData);
glDisable(GL_TEXTURE_RECTANGLE_EXT);

-----enable texture for use with a display list…called every frame draw----

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, mid);
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, mWidth, mHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mData);

//draw the display list

glDisable(GL_TEXTURE_RECTANGLE_EXT);

So, this only sends color through and no texture. :frowning: The demo program works and I can see the improvement. Using Radion 9800XT. Program uses glut and c++.

I simply draw the display list for most of the program. The display list remembers all my texture calls when I created the list. Correction, when I created the display list I called:

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, mid);
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, mWidth, mHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mData);

//draw the model

glDisable(GL_TEXTURE_RECTANGLE_EXT);

I’d assume the display list would execute the previous code when I call glCallList(listID) ?

Got it to work. Seems faster now. :cool:

After a little digging I found that the problem was with the u,v texture coordinates. If your using GL_TEXTURE_RECTANGLE_EXT then you have to multiply u/v by the height/width respectively.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.