Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Acharis   Crossbones+   -  Reputation: 3972

Like
0Likes
Like

Posted 23 October 2012 - 03:27 PM

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?

Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)

PocketSpaceEmpire - turn based 4X with no micromanagement FB


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8575

Like
1Likes
Like

Posted 23 October 2012 - 03:37 PM

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.

#3 Acharis   Crossbones+   -  Reputation: 3972

Like
0Likes
Like

Posted 23 October 2012 - 04:34 PM

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?

Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)

PocketSpaceEmpire - turn based 4X with no micromanagement FB


#4 Brother Bob   Moderators   -  Reputation: 8575

Like
1Likes
Like

Posted 23 October 2012 - 04:45 PM

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.

#5 Acharis   Crossbones+   -  Reputation: 3972

Like
0Likes
Like

Posted 23 October 2012 - 05:46 PM

Thanks

Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)

PocketSpaceEmpire - turn based 4X with no micromanagement FB


#6 mhagain   Crossbones+   -  Reputation: 8275

Like
1Likes
Like

Posted 23 October 2012 - 07:09 PM

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

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 swiftcoder   Senior Moderators   -  Reputation: 10363

Like
2Likes
Like

Posted 23 October 2012 - 08:49 PM

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 - Software Engineer @Amazon - [swiftcoding]


#8 Acharis   Crossbones+   -  Reputation: 3972

Like
0Likes
Like

Posted 24 October 2012 - 01:27 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?

Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)

PocketSpaceEmpire - turn based 4X with no micromanagement FB


#9 Brother Bob   Moderators   -  Reputation: 8575

Like
1Likes
Like

Posted 24 October 2012 - 03:30 AM

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.

#10 mhagain   Crossbones+   -  Reputation: 8275

Like
1Likes
Like

Posted 24 October 2012 - 04:57 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.


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.

Edited by mhagain, 24 October 2012 - 11:14 AM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#11 Acharis   Crossbones+   -  Reputation: 3972

Like
0Likes
Like

Posted 12 November 2012 - 05:31 AM

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.

Can I use GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV instead? Or it must be BGRA?

Europe1300.eu - Historical Realistic Medieval Sim (RELEASED!)

PocketSpaceEmpire - turn based 4X with no micromanagement FB


#12 mhagain   Crossbones+   -  Reputation: 8275

Like
1Likes
Like

Posted 12 November 2012 - 06:01 AM


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.

Can I use GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV instead? Or it must be BGRA?


It depends on the layout of your underlying framebuffer, and that's going to be decided by your hardware. If your hardware likes data in BGRA order, then BGRA order is what you must use to get the fast path.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS