Karl
Karl

Reputation: 5723

Is there a more efficient way to deal with 2^n pixels size requirement for OpenGL ES texture?

Sorry if my question is uncleared. Let me elaborate.

I have a rectangle of size 100 x 200, and I have a graphic size 100 x 200 which fits with the rectangle. Since OpenGL requires all textures to have 2^n width and height, I basically put the 100 x 200 graphic right into a 128 x 256 image for this. It works fine for OpenGL because I simply requested it to draw only a portion of the texture that I need on the rectangle. However, what nags me is that in the 128 x 256 texture, there are a lot of unused spaces.

Is there a better way to deal with these unused spaces in this case? Or is this supposed to be the way to go?

Upvotes: 2

Views: 331

Answers (3)

shouston
shouston

Reputation: 641

If you must reduce padding to save memory you could split the image into multiple pow2 textures, e.g. split 100 pixels horizontally into 64, 32, 4 and 200 pixels vertically into 128, 64, 8. You'll also need to split the rectangle you're texturing into multiple corresponding rectangles (quads).

In this example you will be rendering 9 quads/textures instead of 1 so you will need to measure if there is a performance hit in your application.

You won't be able to use this technique if you're using bilinear interpolation as you'd require a texture border which I don't think is supported by OpenGL ES.

Upvotes: 1

Henry
Henry

Reputation: 423

Resize your image to fit better. You don't get anything for nothing in this world.

Upvotes: 0

Jim Buck
Jim Buck

Reputation: 20726

Pack multiple textures into one "sheet".

Upvotes: 5

Related Questions