diff --git a/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfile.cpp b/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfile.cpp index a3b2b557af..6db9d89024 100644 --- a/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfile.cpp +++ b/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfile.cpp @@ -49,18 +49,6 @@ GLint GetMaxViewports() return value; } -void GetTexParameterInternalFormat(GLenum target, GLint* params) -{ - glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, params); -} - -void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params) -{ - #ifdef GL_ARB_internalformat_query - glGetInternalformativ(target, internalformat, pname, bufsize, params); - #endif -} - void DepthRange(GLclamp_t nearVal, GLclamp_t farVal) { glDepthRange(nearVal, farVal); diff --git a/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp b/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp index 9dc16f51f7..8fbd5694eb 100644 --- a/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp +++ b/sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp @@ -139,7 +139,7 @@ static void GLGetSupportedTextureFormats(std::vector& textureFormats) { textureFormats = GetDefaultSupportedGLTextureFormats(); - #if defined GL_ARB_internalformat_query && defined GL_ARB_internalformat_query2 + #if GL_ARB_internalformat_query && GL_ARB_internalformat_query2 if (HasExtension(GLExt::ARB_internalformat_query) && HasExtension(GLExt::ARB_internalformat_query2)) { @@ -160,7 +160,7 @@ static void GLGetSupportedTextureFormats(std::vector& textureFormats) #endif - #ifdef GL_EXT_texture_compression_s3tc + #if GL_EXT_texture_compression_s3tc const std::uint32_t numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS); diff --git a/sources/Renderer/OpenGL/GLESProfile/GLESProfile.cpp b/sources/Renderer/OpenGL/GLESProfile/GLESProfile.cpp index 30ba40c891..e99b5a6197 100644 --- a/sources/Renderer/OpenGL/GLESProfile/GLESProfile.cpp +++ b/sources/Renderer/OpenGL/GLESProfile/GLESProfile.cpp @@ -49,20 +49,6 @@ GLint GetMaxViewports() return 1; } -void GetTexParameterInternalFormat(GLenum target, GLint* params) -{ - #ifdef GL_ES_VERSION_3_1 - glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, params); - #else - LLGL_TRAP_NOT_IMPLEMENTED(); //TODO - #endif -} - -void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params) -{ - LLGL_TRAP_NOT_IMPLEMENTED(); //TODO -} - void DepthRange(GLclamp_t nearVal, GLclamp_t farVal) { glDepthRangef(nearVal, farVal); diff --git a/sources/Renderer/OpenGL/GLESProfile/GLESProfileCaps.cpp b/sources/Renderer/OpenGL/GLESProfile/GLESProfileCaps.cpp index 9f4704a0c6..aa73f0acd5 100644 --- a/sources/Renderer/OpenGL/GLESProfile/GLESProfileCaps.cpp +++ b/sources/Renderer/OpenGL/GLESProfile/GLESProfileCaps.cpp @@ -105,19 +105,19 @@ static void GLGetSupportedTextureFormats(std::vector& textureFormats) { textureFormats = GetDefaultSupportedGLTextureFormats(); - RemoveAllFromListIf( + /*RemoveAllFromListIf( textureFormats, [](Format format) -> bool { if (auto internalformat = GLTypes::MapOrZero(format)) { GLint supported = 0; - GLProfile::GetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported); + glGetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported); return (supported == GL_FALSE); } return true; } - ); + );*/ const auto numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS); diff --git a/sources/Renderer/OpenGL/GLProfile.h b/sources/Renderer/OpenGL/GLProfile.h index f0cda0203d..478560e812 100644 --- a/sources/Renderer/OpenGL/GLProfile.h +++ b/sources/Renderer/OpenGL/GLProfile.h @@ -46,12 +46,6 @@ const char* GetShadingLanguageName(); // Returns the maximum number of viewports (GL_MAX_VIEWPORT for GL, 1 for GLES). GLint GetMaxViewports(); -// Returns the internal format of the first texture level for the specified bound texture target. -void GetTexParameterInternalFormat(GLenum target, GLint* params); - -// Wrapper for glGetInternalformativ with special case for GLES. -void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params); - // Wrapper for glDepthRange/glDepthRangef. void DepthRange(GLclamp_t nearVal, GLclamp_t farVal); diff --git a/sources/Renderer/OpenGL/Texture/GLTexSubImage.cpp b/sources/Renderer/OpenGL/Texture/GLTexSubImage.cpp index 6a5ff47200..db746fd7a9 100644 --- a/sources/Renderer/OpenGL/Texture/GLTexSubImage.cpp +++ b/sources/Renderer/OpenGL/Texture/GLTexSubImage.cpp @@ -19,17 +19,6 @@ namespace LLGL { -static void QueryGLInternalFormat(GLenum target, GLenum& internalFormat) -{ - if (internalFormat == 0) - { - GLint format = 0; - GLProfile::GetTexParameterInternalFormat(target, &format); - LLGL_ASSERT(format != 0); - internalFormat = static_cast(format); - } -} - #ifdef LLGL_OPENGL static void GLTexSubImage1DBase( @@ -40,7 +29,7 @@ static void GLTexSubImage1DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(target, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTexSubImage1D( @@ -79,7 +68,7 @@ static void GLTexSubImage2DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(target, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTexSubImage2D( @@ -122,7 +111,7 @@ static void GLTexSubImage3DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(target, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTexSubImage3D( diff --git a/sources/Renderer/OpenGL/Texture/GLTexSubImage.h b/sources/Renderer/OpenGL/Texture/GLTexSubImage.h index 52759352f9..8d96bbce96 100644 --- a/sources/Renderer/OpenGL/Texture/GLTexSubImage.h +++ b/sources/Renderer/OpenGL/Texture/GLTexSubImage.h @@ -23,7 +23,7 @@ bool GLTexSubImage( const TextureType type, const TextureRegion& region, const ImageView& imageView, - GLenum internalFormat = 0 + GLenum internalFormat ); diff --git a/sources/Renderer/OpenGL/Texture/GLTexture.cpp b/sources/Renderer/OpenGL/Texture/GLTexture.cpp index 50e893527a..a50ccad6b6 100644 --- a/sources/Renderer/OpenGL/Texture/GLTexture.cpp +++ b/sources/Renderer/OpenGL/Texture/GLTexture.cpp @@ -1011,6 +1011,34 @@ static ImageFormat MapSwizzleImageFormat(const ImageFormat format) } } +// Binds the specified GL texture temporarily. Only used to gather texture information, not to bind texture for the graphics or compute pipeline. +static void BindGLTextureNonPersistent(const GLTexture& textureGL) +{ + GLStateManager::Get().BindTexture(GLStateManager::GetTextureTarget(textureGL.GetType()), textureGL.GetID()); +} + +#if LLGL_OPENGL || GL_ES_VERSION_3_1 + +static GLenum GLGetTextureInternalFormat(const GLTexture& tex) +{ + /* Bind texture and query attributes */ + GLint format = 0; + BindGLTextureNonPersistent(tex); + glGetTexLevelParameteriv(tex.GetGLTexLevelTarget(), 0, GL_TEXTURE_INTERNAL_FORMAT, &format); + return static_cast(format); +} + +#endif + +static GLenum GLGetRenderbufferInternalFormat(const GLTexture& tex) +{ + /* Bind renderbuffer and query qttributes */ + GLint format = 0; + GLStateManager::Get().BindRenderbuffer(tex.GetID()); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &format); + return static_cast(format); +} + void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const ImageView* initialImage) { /* Bind texture */ @@ -1030,8 +1058,12 @@ void GLTexture::AllocTextureStorage(const TextureDescriptor& textureDesc, const //GLStateManager::Get().BindBuffer(GLBufferTarget::PIXEL_UNPACK_BUFFER, 0); GLTexImage(textureDesc, initialImage); - /* Store internal GL format */ - //internalFormat_ = GetTextureInternalFormat(); + /* Store internal GL format. Only desktop OpenGL can query the actual internal format. For GLES 3.0 and WebGL 2.0 we have to rely on the input format. */ + #if LLGL_OPENGL || GL_ES_VERSION_3_1 + internalFormat_ = GLGetTextureInternalFormat(*this); + #else + internalFormat_ = GLTypes::Map(textureDesc.format); + #endif /* Initialize texture parameters for the first time (sampler states not supported for multisample textures) */ if (!IsMultiSampleTexture(textureDesc.type)) @@ -1063,31 +1095,7 @@ void GLTexture::AllocRenderbufferStorage(const TextureDescriptor& textureDesc) ); /* Store internal GL format */ - internalFormat_ = GetRenderbufferInternalFormat(); -} - -// Binds the specified GL texture temporarily. Only used to gather texture information, not to bind texture for the graphics or compute pipeline. -static void BindGLTextureNonPersistent(const GLTexture& textureGL) -{ - GLStateManager::Get().BindTexture(GLStateManager::GetTextureTarget(textureGL.GetType()), textureGL.GetID()); -} - -GLenum GLTexture::GetTextureInternalFormat() const -{ - /* Bind texture and query attributes */ - GLint format = 0; - BindGLTextureNonPersistent(*this); - GLProfile::GetTexParameterInternalFormat(GetGLTexLevelTarget(), &format); - return static_cast(format); -} - -GLenum GLTexture::GetRenderbufferInternalFormat() const -{ - /* Bind renderbuffer and query qttributes */ - GLint format = 0; - GLStateManager::Get().BindRenderbuffer(GetID()); - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_INTERNAL_FORMAT, &format); - return static_cast(format); + internalFormat_ = GLGetRenderbufferInternalFormat(*this); } void GLTexture::GetTextureParams(GLint* extent, GLint* samples) const diff --git a/sources/Renderer/OpenGL/Texture/GLTexture.h b/sources/Renderer/OpenGL/Texture/GLTexture.h index efbc0c8dd5..deeab3f2de 100644 --- a/sources/Renderer/OpenGL/Texture/GLTexture.h +++ b/sources/Renderer/OpenGL/Texture/GLTexture.h @@ -145,9 +145,6 @@ class GLTexture final : public Texture void AllocTextureStorage(const TextureDescriptor& textureDesc, const ImageView* initialImage); void AllocRenderbufferStorage(const TextureDescriptor& textureDesc); - GLenum GetTextureInternalFormat() const; - GLenum GetRenderbufferInternalFormat() const; - void GetTextureParams(GLint* extent, GLint* samples) const; void GetRenderbufferParams(GLint* extent, GLint* samples) const; diff --git a/sources/Renderer/OpenGL/Texture/GLTextureSubImage.cpp b/sources/Renderer/OpenGL/Texture/GLTextureSubImage.cpp index d265d63849..bac5c1d165 100644 --- a/sources/Renderer/OpenGL/Texture/GLTextureSubImage.cpp +++ b/sources/Renderer/OpenGL/Texture/GLTextureSubImage.cpp @@ -8,6 +8,7 @@ #include "GLTextureSubImage.h" #include "../GLTypes.h" #include "../Ext/GLExtensions.h" +#include "../../../Core/Assertion.h" #include #include @@ -18,16 +19,6 @@ namespace LLGL #if defined GL_ARB_direct_state_access && defined LLGL_GL_ENABLE_DSA_EXT -static void QueryGLInternalFormat(GLuint texID, GLenum& internalFormat) -{ - if (internalFormat == 0) - { - GLint format = 0; - glGetTextureLevelParameteriv(texID, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); - internalFormat = static_cast(format); - } -} - static void GLTextureSubImage1DBase( GLuint texID, std::uint32_t mipLevel, @@ -36,7 +27,7 @@ static void GLTextureSubImage1DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(texID, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTextureSubImage1D( @@ -73,7 +64,7 @@ static void GLTextureSubImage2DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(texID, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTextureSubImage2D( @@ -116,7 +107,7 @@ static void GLTextureSubImage3DBase( const ImageView& imageView, GLenum internalFormat) { - QueryGLInternalFormat(texID, internalFormat); + LLGL_ASSERT(internalFormat != 0); if (IsCompressedFormat(imageView.format)) { glCompressedTextureSubImage3D( diff --git a/sources/Renderer/OpenGL/Texture/GLTextureSubImage.h b/sources/Renderer/OpenGL/Texture/GLTextureSubImage.h index a1ae338bac..33683fcbe4 100644 --- a/sources/Renderer/OpenGL/Texture/GLTextureSubImage.h +++ b/sources/Renderer/OpenGL/Texture/GLTextureSubImage.h @@ -24,7 +24,7 @@ void GLTextureSubImage( const TextureType type, const TextureRegion& region, const ImageView& imageView, - GLenum internalFormat = 0 + GLenum internalFormat ); diff --git a/sources/Renderer/OpenGL/WebGLProfile/WebGLProfile.cpp b/sources/Renderer/OpenGL/WebGLProfile/WebGLProfile.cpp index 3c3dfb5652..34d15c601c 100644 --- a/sources/Renderer/OpenGL/WebGLProfile/WebGLProfile.cpp +++ b/sources/Renderer/OpenGL/WebGLProfile/WebGLProfile.cpp @@ -51,16 +51,6 @@ GLint GetMaxViewports() return 1; } -void GetTexParameterInternalFormat(GLenum target, GLint* params) -{ - LLGL_TRAP_NOT_IMPLEMENTED(); //TODO -} - -void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufsize, GLint* params) -{ - LLGL_TRAP_NOT_IMPLEMENTED(); //TODO -} - void DepthRange(GLclamp_t nearVal, GLclamp_t farVal) { glDepthRangef(nearVal, farVal); diff --git a/sources/Renderer/OpenGL/WebGLProfile/WebGLProfileCaps.cpp b/sources/Renderer/OpenGL/WebGLProfile/WebGLProfileCaps.cpp index 6b84464afc..4a44f92f51 100644 --- a/sources/Renderer/OpenGL/WebGLProfile/WebGLProfileCaps.cpp +++ b/sources/Renderer/OpenGL/WebGLProfile/WebGLProfileCaps.cpp @@ -105,19 +105,19 @@ static void GLGetSupportedTextureFormats(std::vector& textureFormats) { textureFormats = GetDefaultSupportedGLTextureFormats(); - RemoveAllFromListIf( + /*RemoveAllFromListIf( textureFormats, [](Format format) -> bool { if (auto internalformat = GLTypes::MapOrZero(format)) { GLint supported = 0; - GLProfile::GetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported); + glGetInternalformativ(GL_TEXTURE_2D, internalformat, GL_INTERNALFORMAT_SUPPORTED, 1, &supported); return (supported == GL_FALSE); } return true; } - ); + );*/ const auto numCompressedTexFormats = GLGetUInt(GL_NUM_COMPRESSED_TEXTURE_FORMATS);