PDA

View Full Version : Using a DXT5 Texture



CornyKorn21
12-30-2015, 10:30 PM
I'm attempting to set up and use a DXT5 texture but my call to glCompressedTextureSubImage2D comes back with the following:
GL_INVALID_ENUM error generated. <target> enum is invalid.



GLuint texture;
glCreateTextures( GL_TEXTURE_2D, 1, &texture );
glTextureStorage2D( texture, 1, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height );
glCompressedTextureSubImage2D( texture, 0, 0, 0, width, height, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, size, data ); // Error occurs when attempting to make this call


Any thoughts on what would cause this error?

For kicks I tried using the bind method and everything seems to work fine with that version. Although I would like to understand why my original version doesn't work.


GLuint texture;
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexStorage2D( GL_TEXTURE_2D, 1, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height );
glCompressedTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, width, height, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, size, data );
glBindTexture( GL_TEXTURE_2D, 0 );

GClements
12-31-2015, 06:37 AM
I'm attempting to set up and use a DXT5 texture but my call to glCompressedTextureSubImage2D comes back with the following:
GL_INVALID_ENUM error generated. <target> enum is invalid.

GL_COMPRESSED_RGBA_S3TC_DXT5_EXT is not one of the compressed formats listed in the OpenGL 4.5 specification.



For kicks I tried using the bind method and everything seems to work fine with that version.

That version is valid according to the EXT_texture_compression_s3tc extension. But that doesn't apply to the original version, because EXT_texture_compression_s3tc is written against OpenGL 1.2.1 and ARB_texture_compression, and neither of those define glCompressedTextureSubImage2D (as opposed to glCompressedTexSubImage2D).

CornyKorn21
12-31-2015, 06:43 AM
Then what is the proper format to use in that case? Or should I no longer use DXT5 when using OpenGL 4.5?

GClements
12-31-2015, 07:03 AM
Then what is the proper format to use in that case? Or should I no longer use DXT5 when using OpenGL 4.5?

You can use S3TC (provided that the extension is supported) or you can use DSA (either the extension or the functions in 4.5 core). But currently there doesn't appears to be any combination of extensions which will allow you to create S3TC textures with the DSA texture functions. It's possible that the existing S3TC extensions will be superseded by something which supports DSA.

S3TC isn't in core (and probably never will be) due to some patent issues. EXT_texture_compression_s3tc specifically says:


WARNING: Vendors able to support S3TC texture compression in Direct3D drivers do not necessarily have the right to use the same functionality in OpenGL.

In light of that, using one of the compressions schemes which are part of the core standard (RGTC, BPTC, ETC or EAC) would probably have fewer issues going forward.

CornyKorn21
12-31-2015, 07:36 AM
The issue seems to persist even if I utilize any of the core specified compression formats. Although using DXT5 may be unsupported it doesn't seem to be the cause of the issue I am having.

Osbios
12-31-2015, 07:50 AM
Considering glTextureStorage2D is fine with the value but glCompressedTextureSubImage2D is not, this looks like a driver fuck up to me...

Alfonse Reinheart
12-31-2015, 08:25 AM
You can use S3TC (provided that the extension is supported) or you can use DSA (either the extension or the functions in 4.5 core). But currently there doesn't appears to be any combination of extensions which will allow you to create S3TC textures with the DSA texture functions. It's possible that the existing S3TC extensions will be superseded by something which supports DSA.


If it works with glCompressedTexSubImage, it ought to work with glCompressedTextureSubImage. The OpenGL specification permits no difference in their behavior. So if the driver's interpretation permits S3TC formats with glCompressedTexSubImage, then it permits them with glCompressedTextureSubImage too.

This is clearly a driver bug.

CornyKorn21
12-31-2015, 09:15 AM
Ended up being an issue on my end. I didn't cross all of my T's and dot all of my I's. Sorry for taking your time and thank you for all of the help.

Solution: Copy/paste mapped glCompressedTexSubImage to glCompressedTextureSubImage when I loaded the functions.
Lesson learned: Verify everything... or use something like GLEW.

Also, thank you GClements for pointing out that the DXT compression is not part of the core system. I'm going to consider the core supported formats in the long run, or at least supporting them as a backup.