0
\$\begingroup\$

I read everywhere that you have to use a power of two size for your texture width and height, like 16, 32 or 64, but right now my sprite drawing is based on Grid.java from SpriteMethodTest, and I set the Vertex array "quad" to the pixel size, 20 X 28, and and apply the texture, the same pixel size, to that, and I'm not using any scaling information, and it's drawing them fine and I don't seem to be getting any errors.

Is it actually scaling it behind the scenes?

When I process each Bitmap I use:

gl.glBindTexture(GL10.GL_TEXTURE_2D, iTextureName);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,    GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

So if I start doing sprite batching instead, the image I grab out of the bigger image has to be a power of two width and height, if I want it drawn without any scaling?

Thanks!

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

While it is always recommended that you stick to power of two textures, whether or not it is required is dependent on platform implementation and content pipeline features. OpenGL itself does not require the textures to be square, or powers of two.

See this link for more specifics on OpenGL Textures. https://www.opengl.org/wiki/Texture

To add in some of the details from the comments, there are performance and portability issues that affect your choice of texture dimensions. While it is indeed often not necessary for your artists to produce textures in powers of two, placing this restriction on them can provide benefits over the lifetime of the project.

Performance

This is something that could be overlooked, especially with the latest generation of gaming consoles and high end PC hardware, but the topic of performance is always relevant in gaming.

Power of two texture dimensions allow for assumptions to be made with various post processing and computer vision applications. This becomes even more true when your textures become square, though this is not always an option for various reasons. Whenever you can place constraints that enable your engineers to make assumptions, you can likely facilitate performance games.

Another performance gain can be made in the realm of memory management when building a texture atlas, or a simple decal/sprite sheet. When your textures are composed of random dimensions, it becomes increasingly difficult to pack them together, and you will require additional texture atlas'. While this may sound insignificant if you are developing for the PC, or the current generation of consoles, hand held devices such as the 3DS, the Vita, and the world of mobile devices are very concerned with texture size and memory footprint.

Finally, compression algorithms are always best when they are applied to a very specific type of data, and textures are no exception. These techniques can not only be better at compressing, but also faster at it. Many hardware platforms today have support for texture decompression as a part of the graphics pipeline. This is best supported via very specific texture formats.

Portability

A more overlooked benefit would be platform portability. Not all platforms support the same texture formats, and while you can guarantee that any platform will support powers of two, not all platforms support random dimensions. This leads to the logical conclusion that producing all your texture assets in power of two dimensions increases the cross platform support that your project has. This also might sound insignificant, but we are seeing more big name games being ported to these limited platforms. Such a project the designers likely thought was as far fetched as a trip to the moon once was.

\$\endgroup\$
0
\$\begingroup\$

Arbitrary texture sizes became fully supported in OpenGL 2.0, but GPU's nowadays support them anyway, so there's no need to worry unless you plan to support ancient devices.

\$\endgroup\$
4
  • \$\begingroup\$ Not necessarily. There can be performance issues associated with using non power of two textures in certain situations. Computer vision algorithms, and various post processing effects can often make performance related assumptions when your textures conform to certain dimensions. In addition to that, construction of a texture atlas would generate significantly more wasted space if your textures are random dimensions, as opposed to powers of two. Finally, some high performance compression formats require powers of two dimensions. \$\endgroup\$
    – Evan
    Feb 17, 2014 at 22:32
  • \$\begingroup\$ Oh, and another major benefit, is cross platform support. Any platform your game is targeting is guaranteed to support power of two textures (assuming it was made here on earth). While on the other hand, it is very common (especially with mobile and hand held platforms) to see restrictions that require powers of two. \$\endgroup\$
    – Evan
    Feb 17, 2014 at 22:34
  • \$\begingroup\$ I agree with both of you. Using power of two textures always offers advantages. You avoid possible mipmap interpolation artifacts, improve performance, reduce RAM overload. But this is stuff you usually don't have to worry about in 2014, and judging by the nature of the question, I thought a simply "don't worry about it" suffices at that level, there are more fun things to worry about :) \$\endgroup\$
    – Terje
    Feb 17, 2014 at 22:39
  • \$\begingroup\$ It might be good to edit some of these details into the answer. \$\endgroup\$ Feb 17, 2014 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .