How to test if OpenGL support textures of non power of 2?

Started by
10 comments, last by 21st Century Moose 11 years, 5 months ago
I need a code (that works under OpenGL 1.5+) that checks if textures of non power of 2 are supported (via some extension maybe?)

Or maybe I should just check if OpenGL 2.0 is present and older versions would never be able to support it anyway?

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

Advertisement
Check the extension string for ARB_texture_non_power_of_two. For OpenGL 2.0 and later you don't have to check anything since its in the core already.
Do I need to test for extension AND for OpenGL version 2.0+

OR

OpenGL 2.0+ has ARB_texture_non_power_of_two extension always present? So the check for extension presence alone is enough?

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

OpenGL 2.0 or later alone is enough, you don't need to check the extension if the version is OK. If the version is pre-2.0, then you need to check the extension. But note that 2.0 does not mean that the extension will be listed so you cannot rely on the extension alone. You have to check both if you want to cover for earlier versions, but passing one of the tests is enough.
Thanks

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

Beware that OpenGL makes no promise to hardware-accelerate non-power-of-two textures. And you can't check for that.

In general if your GL_VERSION is 3.0 or better you're absolutely guaranteed to have them, and to have them be hardware accelerated. In the rare event that you encounter a really really really old card with a lower version, you may or may not have them be accelerated (GeForce FX was an offender here, despite claiming 2.0). You might be aware to get away with GL_ARB_texture_rectangle instead, if your usage meets it's restrictions: http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

For simplicity's sake:

[source lang="cpp"]#include <GL/glew.h>

glewInit();

if (GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two)
{
/* I can haz teh supportz? */
}[/source]

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

OK, maybe I will explain in details.

I use glDrawPixels for 2D stuff, that are my requirements. Because it's slow I rewrote it to standard textured quads (ortho perspective, etc). But since power of two textures are sometimes not supported I need to fallback to glDrawPixels in some cases (that's why I need the detection part). I can do it any other way of course, as long as compatibility and performance is OK since this is my goal. Again, I don't need anything fancy here, it's just a replacement for glDrawPixels.

Is the GL_ARB_texture_rectangle extension significantly more supported? Or other extensions/tricks?

How to do it best? How you would do it?

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

Just because you're using textures doesn't mean you have to draw the whole texture. Another option is to use a texture the size of the next larger power of two and then stick your image in a part of the larger texture. You can even pack multiple images in in the same texture if you want.
OK, maybe I will explain in details.

I use glDrawPixels for 2D stuff, that are my requirements. Because it's slow I rewrote it to standard textured quads (ortho perspective, etc). But since power of two textures are sometimes not supported I need to fallback to glDrawPixels in some cases (that's why I need the detection part). I can do it any other way of course, as long as compatibility and performance is OK since this is my goal. Again, I don't need anything fancy here, it's just a replacement for glDrawPixels.


glDrawPixels can be fast if you use the right params. Since you've observed slowness I'm guessing that you're using dear old GL_RGB/GL_UNSIGNED_BYTE, which is a slow path nearly everywhere; you need these parameters to match the native format of your backbuffer otherwise GL is going to send the data through intermediate conversion steps, so try it with GL_BGRA/GL_UNSIGNED_INT_8_8_8_8_REV for starters and you should see a very noticeable performance increase (at the cost of an extra byte per pixel - fair tradeoff) - that just requires GL1.2 support. Also be sure, if you're using glDrawPixels, to switch off texturing and lighting, as OpenGL will texture and light individual pixels otherwise.

Is the GL_ARB_texture_rectangle extension significantly more supported? Or other extensions/tricks?


The definition of "significant" nowadays is that you can rely on full general non-power-of-two support being available absolutely everywhere, aside from some 6-year-old laptops or business-class PCs with integrated Intels. But since you're aiming for an extremely downlevel minimum GL_VERSION it's fair to say that GL_ARB_texture_rectangle is more likely to be supported on that class of lower paleolithic hardware.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement