[Plib-devel] No longer blocking non power-of-two textures
Brought to you by:
sjbaker
From: Paolo L. <p.l...@ci...> - 2007-09-28 13:35:49
|
Dear friends, As most of you probably know the GL_ARB_texture_non_power_of_two OpenGL extension, when supported, allows to overcome the subject limit at the = only implementation effort of checking if such extension is supported by the hardware (http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of= _tw o.txt). GL_ARB_texture_non_power_of_two has no relevant limitation, and is much better than GL_EXT_texture_rectangle in which, e.g., texture coordinates were addressed non-parametrically [0..w],[0..h]. Such check could be done in ssgMakeMipMaps at the very beginning just = before the power-of-two test. So in our case, in ssgLoadTexture.cxx: ssgMakeMipMaps ( GLubyte *image, int xsize, int ysize, int zsize ) { bool non_power_of_two_tex_supported =3D ssgIsExtensionSupported( "GL_ARB_texture_non_power_of_two" ); =20 if ( !non_power_of_two_tex_supported && (! ((xsize & (xsize-1))=3D=3D0) || ! ((ysize & (ysize-1))=3D=3D0)) ) { ulSetError ( UL_WARNING, "Map is not a power-of-two in size!" ) ; return false ; } ... Checking for such extension could be done, in this and future cases, by = the following code (code by C=E9sar Blecua Ud=EDas sent me by Roman = Grigoriev when testing VBOs): static bool ssgSearchExtensionString(char *extString, char *extName) { // Returns GL_TRUE if the *extName string appears in the *extString string, // surrounded by white spaces, or GL_FALSE otherwise. char *p, *end; int n, extNameLen; if ((extString =3D=3D NULL) || (extName =3D=3D NULL)) return false; extNameLen =3D strlen(extName); p=3DextString; end =3D p + strlen(p); while (p < end) { n =3D strcspn(p, " "); if ((extNameLen =3D=3D n) && (strncmp(extName, p, n) =3D=3D 0)) return GL_TRUE; p +=3D (n + 1); } return GL_FALSE; } bool ssgIsExtensionSupported(char *extName) { // Returns GL_TRUE if the OpenGL Extension whose name is *extName // is supported by the system, or GL_FALSE otherwise. // // The *extName string must follow the OpenGL extensions naming = scheme // (ie: "GL_type_extension", like GL_EXT_convolution) return ssgSearchExtensionString((char *)glGetString(GL_EXTENSIONS), extName); } Waiting for reactions - Paolo Leoncini |