From 675ee4915b73d9f3be7fb365c2d7bf56571eb15b Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Thu, 14 Aug 2025 18:32:37 +0800 Subject: [PATCH] [Feat|Fix] (MG_Impl/Texture): Implement TexImage2D & related stuff. --- CMakeLists.txt | 3 + .../MG_Impl/GLImpl/Texture/GL_Texture.cpp | 53 ++++- .../MG_Impl/GLImpl/Texture/Validators.cpp | 207 +++++++++++++++++- MobileGL/MG_Impl/GLImpl/Texture/Validators.h | 14 +- .../GLState/TextureState/TextureObject.cpp | 4 +- .../GLState/TextureState/TextureObject.h | 34 ++- .../GLToMG/TextureEnumConverter.cpp | 158 +++++++------ .../Converters/GLToMG/TextureEnumConverter.h | 2 +- .../MGToGL/TextureEnumConverter.cpp | 158 +++++++------ .../Converters/MGToGL/TextureEnumConverter.h | 2 +- .../MGToMG/TextureEnumConverter.cpp | 32 +++ .../Converters/MGToMG/TextureEnumConverter.h | 9 + .../MGToStr/TextureEnumConverter.cpp | 164 ++++++++------ .../Converters/MGToStr/TextureEnumConverter.h | 2 +- MobileGL/MG_Util/Metrics/TextureMetrics.cpp | 158 ++++++++----- MobileGL/MG_Util/Metrics/TextureMetrics.h | 7 +- 16 files changed, 744 insertions(+), 263 deletions(-) create mode 100644 MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp create mode 100644 MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f46823eb..b2fef458 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ set(SOURCE_FILES MobileGL/MG_Util/Debug/Log.cpp + MobileGL/MG_Util/Metrics/TextureMetrics.cpp + MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp MobileGL/MG_Util/Converters/MGToStr/DataTypeConverter.cpp MobileGL/MG_Util/Converters/MGToStr/GLExtensionConverter.cpp @@ -30,6 +32,7 @@ set(SOURCE_FILES MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp + MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 7f096abd..739b668a 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -1,10 +1,14 @@ #include "GL_Texture.h" +#include "MG_State/GLState/TextureState/TextureObject.h" +#include "MG_Util/Types.h" #include "Validators.h" #include +#include #include #include #include #include +#include namespace MobileGL { namespace MG_Impl::GLImpl { @@ -48,7 +52,52 @@ namespace MobileGL { void TexImage2D_State(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) { - // TODO: implement + // ====================== Converting ================================= + TextureUploadTarget textureUploadingTarget = MG_Util::ConvertGLEnumToTextureUploadTarget(target); + TextureTarget textureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadingTarget); + TextureInputFormat textureInputFormat = MG_Util::ConvertGLEnumToTextureInputFormat(format); + TexturePixelDataType texturePixelDataType = MG_Util::ConvertGLEnumToTexturePixelDataType(type); + TextureInternalFormat textureInternalFormat = MG_Util::ConvertGLEnumToTextureInternalFormat(format); + + // ==================== Error Checking =============================== + if (!TextureImpl::ValidateTexturePixelDataType(texturePixelDataType)) return; + if (!TextureImpl::ValidateTextureInputFormat(textureInputFormat)) return; + if (!TextureImpl::ValidateTextureUploadTarget(textureUploadingTarget)) return; + if (!TextureImpl::ValidateTextureLevelNumber(level)) return; + if (!TextureImpl::ValidateTextureSizeWithTextureUploadTarget(textureUploadingTarget, width, height)) return; + if (!TextureImpl::ValidateTextureSizeRange(width, height)) return; + if (!TextureImpl::ValidateTextureInternalFormat(textureInternalFormat)) return; + if (!TextureImpl::ValidateTextureBorderNumber(border)) return; + if (!TextureImpl::ValidateTextureFormatWithType(textureInputFormat, textureInternalFormat, + texturePixelDataType)) + return; + if (!TextureImpl::ValidateTextureLevelWithUploadTarget(textureUploadingTarget, level)) return; + + // TODO: GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the + // GL_PIXEL_UNPACK_BUFFER target and the buffer object's data store is currently mapped. + // GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER + // target and the data would be unpacked from the buffer object such that the memory reads required would + // exceed the data store size. + // GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER + // target and data is not evenly divisible into the number of bytes needed to store in memory a datum + // indicated by type. + + // ======================= Processing ================================ + auto activeUnit = MG_State::pGLContext->GetTextureUnitObject(MG_State::pGLContext->GetActiveTextureUnit()); + auto& bindingSlot = activeUnit.GetBindingSlot(textureTarget); + auto textureObject = bindingSlot.GetBoundObject(); + + // ==================== Error Checking =============================== + if (!TextureImpl::ValidateTextureObject(textureObject)) return; + + // ======================= Processing ================================ + SizeT imageSize = + MG_Util::CalculateTextureImageSize(textureInternalFormat, texturePixelDataType, {width, height, 1}); + + textureObject->SetInternalFormat(textureInternalFormat); + MG_State::GLState::MipmapLevelInput mipmap = MG_State::GLState::MipmapLevelInput( + {width, height, 1}, level, false, 0, {const_cast(pixels), imageSize}); + textureObject->SetMipmapLevel(mipmap); } void TexImage1D_State(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, @@ -216,7 +265,7 @@ namespace MobileGL { MG_State::pGLContext->RecordError( ErrorCode::InvalidEnum, MakeShared( - "MG_Impl/GLImpl", "ActiveTexture_State", + "MG_Impl/GLI mpl", "ActiveTexture_State", "Texture must be one of GL_TEXTUREi, where i is in the range 0 to 31.")); return; } diff --git a/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp b/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp index 160d5dd9..ca41f29e 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp @@ -1,4 +1,6 @@ #include "Validators.h" +#include "MG_State/GLState/TextureState/TextureObject.h" +#include "MG_Util/Types.h" #include #include #include @@ -18,7 +20,18 @@ namespace MobileGL::MG_Impl::GLImpl { return true; } - Bool ValidateTextureName(GLuint texture, Bool allowZero) { + Bool ValidateTextureUploadTarget(TextureUploadTarget textureUploadTarget) { + if (textureUploadTarget == TextureUploadTarget::Unknown) { + MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum, + MakeShared("MG_Impl/GLImpl", + "ValidateTextureUploadTarget", + "Invalid texture upload target")); + return false; + } + return true; + } + + Bool ValidateTextureName(Uint texture, Bool allowZero) { if (texture == 0) { if (allowZero) return true; @@ -36,5 +49,197 @@ namespace MobileGL::MG_Impl::GLImpl { } return true; } + + Bool ValidateTextureInputFormat(TextureInputFormat format) { + if (format == TextureInputFormat::Unknown) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidEnum, MakeShared("MG_Impl/GLImpl", "ValidateTextureInputFormat", + "Invalid texture input format")); + return false; + } + return true; + } + + Bool ValidateTexturePixelDataType(TexturePixelDataType texturePixelDataType) { + if (texturePixelDataType == TexturePixelDataType::Unknown) { + MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum, + MakeShared("MG_Impl/GLImpl", + "ValidateTexturePixelDataType", + "Invalid texture pixel data type")); + return false; + } + return true; + } + + Bool ValidateTextureLevelNumber(GLint level) { + if (level < 0) { + MG_State::pGLContext->RecordError(ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", + "ValidateTextureLevelNumber", + "Texture level must be non-negative")); + return false; + } + + // TODO: GL_INVALID_VALUE may be generated if level is greater than log2(max), where max is the returned + // value of GL_MAX_TEXTURE_SIZE. + + return true; + } + + Bool ValidateTextureSizeWithTextureUploadTarget(TextureUploadTarget target, GLsizei width, GLsizei height) { + if (target == TextureUploadTarget::CubeMapPositiveX || target == TextureUploadTarget::CubeMapNegativeX || + target == TextureUploadTarget::CubeMapPositiveY || target == TextureUploadTarget::CubeMapNegativeY || + target == TextureUploadTarget::CubeMapPositiveZ || target == TextureUploadTarget::CubeMapNegativeZ) { + if (width != height) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureSizeWithTarget", + "Width and height must be equal for cube map textures")); + return false; + } + } + + if (!(target == TextureUploadTarget::Texture1DArray || + target == TextureUploadTarget::ProxyTexture1DArray)) { + if (height < 0) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureSizeWithTarget", + "Height must be greater than or equal to zero")); + return false; + } + // TODO: GL_INVALID_VALUE is generated if target is not GL_TEXTURE_1D_ARRAY or GL_PROXY_TEXTURE_1D_ARRAY + // and height is greater than GL_MAX_TEXTURE_SIZE. + } + + if (target == TextureUploadTarget::Texture1DArray || target == TextureUploadTarget::ProxyTexture1DArray) { + if (height < 0) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureSizeWithTarget", + "Height must be greater than or equal to zero")); + return false; + } + // TODO: GL_INVALID_VALUE is generated if target is GL_TEXTURE_1D_ARRAY or GL_PROXY_TEXTURE_1D_ARRAY and + // height is greater than GL_MAX_ARRAY_TEXTURE_LAYERS. + } + + return true; + } + + Bool ValidateTextureSizeRange(SizeT width, SizeT height) { + if (width < 0 || height < 0) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureSizeRange", + "Width and height must be greater than zero")); + return false; + } + + // TODO: GL_INVALID_VALUE is generated if width is greater than GL_MAX_TEXTURE_SIZE. + + return true; + } + + Bool ValidateTextureInternalFormat(TextureInternalFormat format) { + if (format == TextureInternalFormat::Unknown) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidEnum, + MakeShared("MG_Impl/GLImpl", "ValidateTextureInternalFormat", + "Invalid texture sized internal format")); + return false; + } + return true; + } + + Bool ValidateTextureBorderNumber(Int border) { + if (border != 0) { + MG_State::pGLContext->RecordError(ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", + "ValidateTextureBorderNumber", + "Border must be zero")); + return false; + } + return true; + } + Bool ValidateTextureFormatWithType(TextureInputFormat format, TextureInternalFormat internalFormat, + TexturePixelDataType type) { + if (type == TexturePixelDataType::UnsignedByte332 || type == TexturePixelDataType::UnsignedByte233Rev || + type == TexturePixelDataType::UnsignedShort565 || type == TexturePixelDataType::UnsignedShort565Rev || + type == TexturePixelDataType::UnsignedInt101111Rev) { + if (format != TextureInputFormat::RGB) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", "ValidateTextureFormatWithType", + "Invalid format for the given type")); + return false; + } + } + + if (type == TexturePixelDataType::UnsignedShort4444 || type == TexturePixelDataType::UnsignedShort4444Rev || + type == TexturePixelDataType::UnsignedShort5551 || type == TexturePixelDataType::UnsignedShort1555Rev || + type == TexturePixelDataType::UnsignedInt8888 || type == TexturePixelDataType::UnsignedInt8888Rev || + type == TexturePixelDataType::UnsignedInt1010102 || + type == TexturePixelDataType::UnsignedInt2101010Rev || + type == TexturePixelDataType::UnsignedInt5999Rev) { + if (format != TextureInputFormat::RGBA && format != TextureInputFormat::BGRA) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", "ValidateTextureFormatWithType", + "Invalid format for the given type")); + return false; + } + } + + if (internalFormat == TextureInternalFormat::DepthComponent || + internalFormat == TextureInternalFormat::DepthComponent16 || + internalFormat == TextureInternalFormat::DepthComponent24 || + internalFormat == TextureInternalFormat::DepthComponent32F) { + if (format != TextureInputFormat::DepthComponent) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", "ValidateTextureFormatWithType", + "Invalid format for depth component internal format")); + return false; + } + } + + if (format == TextureInputFormat::DepthComponent && + (internalFormat != TextureInternalFormat::DepthComponent && + internalFormat != TextureInternalFormat::DepthComponent16 && + internalFormat != TextureInternalFormat::DepthComponent24 && + internalFormat != TextureInternalFormat::DepthComponent32F)) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", "ValidateTextureFormatWithType", + "Invalid internal format for depth component format")); + return false; + } + return true; + } + + Bool ValidateTextureLevelWithUploadTarget(TextureUploadTarget target, Int level) { + if (target == TextureUploadTarget::TextureRectangle || + target == TextureUploadTarget::ProxyTextureRectangle) { + if (level != 0) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureLevelWithUploadTarget", + "Level must be zero for rectangle textures")); + return false; + } + } + } + + Bool ValidateTextureObject(SharedPtr textureObject) { + if (!textureObject) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeShared("MG_Impl/GLImpl", "ValidateTextureObject", "Texture object is null")); + return false; + } + + return true; + } } // namespace TextureImpl } // namespace MobileGL::MG_Impl::GLImpl diff --git a/MobileGL/MG_Impl/GLImpl/Texture/Validators.h b/MobileGL/MG_Impl/GLImpl/Texture/Validators.h index 573e6a1c..074022eb 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/Validators.h +++ b/MobileGL/MG_Impl/GLImpl/Texture/Validators.h @@ -6,6 +6,18 @@ namespace MobileGL::MG_Impl::GLImpl { namespace TextureImpl { Bool ValidateTextureTarget(TextureTarget target); - Bool ValidateTextureName(GLuint texture, Bool allowZero = false); + Bool ValidateTextureUploadTarget(TextureUploadTarget textureUploadTarget); + Bool ValidateTextureName(Uint texture, Bool allowZero = false); + Bool ValidateTextureInputFormat(TextureInputFormat format); + Bool ValidateTexturePixelDataType(TexturePixelDataType texturePixelDataType); + Bool ValidateTextureLevelNumber(Int level); + Bool ValidateTextureSizeWithTextureUploadTarget(TextureUploadTarget target, GLsizei width, GLsizei height); + Bool ValidateTextureSizeRange(SizeT width, SizeT height); + Bool ValidateTextureInternalFormat(TextureInternalFormat format); + Bool ValidateTextureBorderNumber(Int border); + Bool ValidateTextureFormatWithType(TextureInputFormat format, TextureInternalFormat internalFormat, + TexturePixelDataType type); + Bool ValidateTextureLevelWithUploadTarget(TextureUploadTarget target, Int level); + Bool ValidateTextureObject(SharedPtr textureObject); } // namespace TextureImpl } // namespace MobileGL::MG_Impl::GLImpl \ No newline at end of file diff --git a/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp b/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp index da610d42..7da5a935 100644 --- a/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp +++ b/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp @@ -11,7 +11,7 @@ namespace MobileGL { SetMipmapImpl(level); } - TextureSizedInternalFormat TextureObjectBase::GetFormat() const { + TextureInternalFormat TextureObjectBase::GetFormat() const { return m_internalFormat; } @@ -34,7 +34,7 @@ namespace MobileGL { return m_mipmaps; } - void TextureObjectBase::SetInternalFormat(TextureSizedInternalFormat format) { + void TextureObjectBase::SetInternalFormat(TextureInternalFormat format) { m_internalFormat = format; } diff --git a/MobileGL/MG_State/GLState/TextureState/TextureObject.h b/MobileGL/MG_State/GLState/TextureState/TextureObject.h index 909f5621..0b5a2178 100644 --- a/MobileGL/MG_State/GLState/TextureState/TextureObject.h +++ b/MobileGL/MG_State/GLState/TextureState/TextureObject.h @@ -35,6 +35,8 @@ namespace MobileGL { CubeMapPositiveZ, CubeMapNegativeZ, ProxyCubeMap, + Texture2DMultisample, + ProxyTexture2DMultisample, TextureUploadTargetCount, Unknown = -1 }; @@ -60,7 +62,7 @@ namespace MobileGL { Unknown = -1 }; - enum class TextureSizedInternalFormat { + enum class TextureInternalFormat { R8, R8Snorm, R16, @@ -122,8 +124,21 @@ namespace MobileGL { RGBA16UI, RGBA32I, RGBA32UI, + DepthComponent16, + DepthComponent24, + DepthComponent32, // not a standard format in OpenGL core profile + DepthComponent32F, + Depth24Stencil8, + Depth32FStencil8, - TextureSizedInternalFormatCount, + DepthComponent, + DepthStencil, + Red, + RG, + RGB, + RGBA, + + TextureInternalFormatCount, Unknown = -1 }; @@ -147,6 +162,8 @@ namespace MobileGL { UnsignedInt8888Rev, UnsignedInt1010102, UnsignedInt2101010Rev, + UnsignedInt101111Rev, // not a standard type in OpenGL core profile + UnsignedInt5999Rev, // not a standard type in OpenGL core profile TypeCount, Unknown = -1 @@ -163,6 +180,9 @@ namespace MobileGL { struct MipmapLevelInput : MipmapLevelBase { DataPtr inputData = {nullptr, 0}; + + MipmapLevelInput(IntVec3 size, Int level, Bool compressed, Int compressedSize, DataPtr data) + : MipmapLevelBase{size, level, compressed, compressedSize}, inputData(data) {} }; struct MipmapLevelInternal : MipmapLevelBase { @@ -182,12 +202,12 @@ namespace MobileGL { virtual ~ITextureObject() = default; virtual void SetMipmapLevel(const MipmapLevelInput& level) = 0; - virtual TextureSizedInternalFormat GetFormat() const = 0; + virtual TextureInternalFormat GetFormat() const = 0; virtual TextureTarget GetTarget() const = 0; virtual IntVec3 GetBaseSize() const = 0; virtual SharedPtr GetSamplerObject() const = 0; virtual const Vector& GetMipmaps() const = 0; - virtual void SetInternalFormat(TextureSizedInternalFormat format) = 0; + virtual void SetInternalFormat(TextureInternalFormat format) = 0; }; class TextureObjectBase : public ITextureObject { @@ -196,18 +216,18 @@ namespace MobileGL { virtual ~TextureObjectBase() = default; void SetMipmapLevel(const MipmapLevelInput& level) override; - TextureSizedInternalFormat GetFormat() const override; + TextureInternalFormat GetFormat() const override; TextureTarget GetTarget() const override; IntVec3 GetBaseSize() const override; SharedPtr GetSamplerObject() const override; const Vector& GetMipmaps() const override; - void SetInternalFormat(TextureSizedInternalFormat format) override; + void SetInternalFormat(TextureInternalFormat format) override; protected: virtual void SetMipmapImpl(const MipmapLevelInput& level) = 0; const TextureTarget m_target = TextureTarget::Unknown; - TextureSizedInternalFormat m_internalFormat = TextureSizedInternalFormat::Unknown; + TextureInternalFormat m_internalFormat = TextureInternalFormat::Unknown; Vector m_mipmaps = {}; SharedPtr m_sampler = nullptr; }; diff --git a/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp b/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp index 7b249e1d..8e2cc1a6 100644 --- a/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp +++ b/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp @@ -68,132 +68,156 @@ namespace MobileGL { } } - TextureSizedInternalFormat ConvertGLEnumToTextureSizedInternalFormat(GLenum internalformat) { + TextureInternalFormat ConvertGLEnumToTextureInternalFormat(GLenum internalformat) { switch (internalformat) { case GL_R8: - return TextureSizedInternalFormat::R8; + return TextureInternalFormat::R8; case GL_R8_SNORM: - return TextureSizedInternalFormat::R8Snorm; + return TextureInternalFormat::R8Snorm; case GL_R16: - return TextureSizedInternalFormat::R16; + return TextureInternalFormat::R16; case GL_R16_SNORM: - return TextureSizedInternalFormat::R16Snorm; + return TextureInternalFormat::R16Snorm; case GL_RG8: - return TextureSizedInternalFormat::RG8; + return TextureInternalFormat::RG8; case GL_RG8_SNORM: - return TextureSizedInternalFormat::RG8Snorm; + return TextureInternalFormat::RG8Snorm; case GL_RG16: - return TextureSizedInternalFormat::RG16; + return TextureInternalFormat::RG16; case GL_RG16_SNORM: - return TextureSizedInternalFormat::RG16Snorm; + return TextureInternalFormat::RG16Snorm; case GL_R3_G3_B2: - return TextureSizedInternalFormat::R3G3B2; + return TextureInternalFormat::R3G3B2; case GL_RGB4: - return TextureSizedInternalFormat::RGB4; + return TextureInternalFormat::RGB4; case GL_RGB5: - return TextureSizedInternalFormat::RGB5; + return TextureInternalFormat::RGB5; case GL_RGB8: - return TextureSizedInternalFormat::RGB8; + return TextureInternalFormat::RGB8; case GL_RGB8_SNORM: - return TextureSizedInternalFormat::RGB8Snorm; + return TextureInternalFormat::RGB8Snorm; case GL_RGB10: - return TextureSizedInternalFormat::RGB10; + return TextureInternalFormat::RGB10; case GL_RGB12: - return TextureSizedInternalFormat::RGB12; + return TextureInternalFormat::RGB12; case GL_RGB16_SNORM: - return TextureSizedInternalFormat::RGB16Snorm; + return TextureInternalFormat::RGB16Snorm; case GL_RGBA2: - return TextureSizedInternalFormat::RGBA2; + return TextureInternalFormat::RGBA2; case GL_RGBA4: - return TextureSizedInternalFormat::RGBA4; + return TextureInternalFormat::RGBA4; case GL_RGB5_A1: - return TextureSizedInternalFormat::RGB5A1; + return TextureInternalFormat::RGB5A1; case GL_RGBA8: - return TextureSizedInternalFormat::RGBA8; + return TextureInternalFormat::RGBA8; case GL_RGBA8_SNORM: - return TextureSizedInternalFormat::RGBA8Snorm; + return TextureInternalFormat::RGBA8Snorm; case GL_RGB10_A2: - return TextureSizedInternalFormat::RGB10A2; + return TextureInternalFormat::RGB10A2; case GL_RGB10_A2UI: - return TextureSizedInternalFormat::RGB10A2UI; + return TextureInternalFormat::RGB10A2UI; case GL_RGBA12: - return TextureSizedInternalFormat::RGBA12; + return TextureInternalFormat::RGBA12; case GL_RGBA16: - return TextureSizedInternalFormat::RGBA16; + return TextureInternalFormat::RGBA16; case GL_SRGB8: - return TextureSizedInternalFormat::SRGB8; + return TextureInternalFormat::SRGB8; case GL_SRGB8_ALPHA8: - return TextureSizedInternalFormat::SRGB8Alpha8; + return TextureInternalFormat::SRGB8Alpha8; case GL_R16F: - return TextureSizedInternalFormat::R16F; + return TextureInternalFormat::R16F; case GL_RG16F: - return TextureSizedInternalFormat::RG16F; + return TextureInternalFormat::RG16F; case GL_RGB16F: - return TextureSizedInternalFormat::RGB16F; + return TextureInternalFormat::RGB16F; case GL_RGBA16F: - return TextureSizedInternalFormat::RGBA16F; + return TextureInternalFormat::RGBA16F; case GL_R32F: - return TextureSizedInternalFormat::R32F; + return TextureInternalFormat::R32F; case GL_RG32F: - return TextureSizedInternalFormat::RG32F; + return TextureInternalFormat::RG32F; case GL_RGB32F: - return TextureSizedInternalFormat::RGB32F; + return TextureInternalFormat::RGB32F; case GL_RGBA32F: - return TextureSizedInternalFormat::RGBA32F; + return TextureInternalFormat::RGBA32F; case GL_R11F_G11F_B10F: - return TextureSizedInternalFormat::R11FG11FB10F; + return TextureInternalFormat::R11FG11FB10F; case GL_RGB9_E5: - return TextureSizedInternalFormat::RGB9E5; + return TextureInternalFormat::RGB9E5; case GL_R8I: - return TextureSizedInternalFormat::R8I; + return TextureInternalFormat::R8I; case GL_R8UI: - return TextureSizedInternalFormat::R8UI; + return TextureInternalFormat::R8UI; case GL_R16I: - return TextureSizedInternalFormat::R16I; + return TextureInternalFormat::R16I; case GL_R16UI: - return TextureSizedInternalFormat::R16UI; + return TextureInternalFormat::R16UI; case GL_R32I: - return TextureSizedInternalFormat::R32I; + return TextureInternalFormat::R32I; case GL_R32UI: - return TextureSizedInternalFormat::R32UI; + return TextureInternalFormat::R32UI; case GL_RG8I: - return TextureSizedInternalFormat::RG8I; + return TextureInternalFormat::RG8I; case GL_RG8UI: - return TextureSizedInternalFormat::RG8UI; + return TextureInternalFormat::RG8UI; case GL_RG16I: - return TextureSizedInternalFormat::RG16I; + return TextureInternalFormat::RG16I; case GL_RG16UI: - return TextureSizedInternalFormat::RG16UI; + return TextureInternalFormat::RG16UI; case GL_RG32I: - return TextureSizedInternalFormat::RG32I; + return TextureInternalFormat::RG32I; case GL_RG32UI: - return TextureSizedInternalFormat::RG32UI; + return TextureInternalFormat::RG32UI; case GL_RGB8I: - return TextureSizedInternalFormat::RGB8I; + return TextureInternalFormat::RGB8I; case GL_RGB8UI: - return TextureSizedInternalFormat::RGB8UI; + return TextureInternalFormat::RGB8UI; case GL_RGB16I: - return TextureSizedInternalFormat::RGB16I; + return TextureInternalFormat::RGB16I; case GL_RGB16UI: - return TextureSizedInternalFormat::RGB16UI; + return TextureInternalFormat::RGB16UI; case GL_RGB32I: - return TextureSizedInternalFormat::RGB32I; + return TextureInternalFormat::RGB32I; case GL_RGB32UI: - return TextureSizedInternalFormat::RGB32UI; + return TextureInternalFormat::RGB32UI; case GL_RGBA8I: - return TextureSizedInternalFormat::RGBA8I; + return TextureInternalFormat::RGBA8I; case GL_RGBA8UI: - return TextureSizedInternalFormat::RGBA8UI; + return TextureInternalFormat::RGBA8UI; case GL_RGBA16I: - return TextureSizedInternalFormat::RGBA16I; + return TextureInternalFormat::RGBA16I; case GL_RGBA16UI: - return TextureSizedInternalFormat::RGBA16UI; + return TextureInternalFormat::RGBA16UI; case GL_RGBA32I: - return TextureSizedInternalFormat::RGBA32I; + return TextureInternalFormat::RGBA32I; case GL_RGBA32UI: - return TextureSizedInternalFormat::RGBA32UI; + return TextureInternalFormat::RGBA32UI; + case GL_DEPTH_COMPONENT16: + return TextureInternalFormat::DepthComponent16; + case GL_DEPTH_COMPONENT24: + return TextureInternalFormat::DepthComponent24; + case GL_DEPTH_COMPONENT32: + return TextureInternalFormat::DepthComponent32; + case GL_DEPTH_COMPONENT32F: + return TextureInternalFormat::DepthComponent32F; + case GL_DEPTH24_STENCIL8: + return TextureInternalFormat::Depth24Stencil8; + case GL_DEPTH32F_STENCIL8: + return TextureInternalFormat::Depth32FStencil8; + case GL_DEPTH_COMPONENT: + return TextureInternalFormat::DepthComponent; + case GL_DEPTH_STENCIL: + return TextureInternalFormat::DepthStencil; + case GL_RED: + return TextureInternalFormat::Red; + case GL_RG: + return TextureInternalFormat::RG; + case GL_RGB: + return TextureInternalFormat::RGB; + case GL_RGBA: + return TextureInternalFormat::RGBA; default: - return TextureSizedInternalFormat::Unknown; + return TextureInternalFormat::Unknown; } } @@ -234,9 +258,11 @@ namespace MobileGL { case GL_UNSIGNED_INT_8_8_8_8_REV: return TexturePixelDataType::UnsignedInt8888Rev; case GL_UNSIGNED_INT_10F_11F_11F_REV: - return TexturePixelDataType::UnsignedInt1010102; + return TexturePixelDataType::UnsignedInt101111Rev; case GL_UNSIGNED_INT_2_10_10_10_REV: return TexturePixelDataType::UnsignedInt2101010Rev; + case GL_UNSIGNED_INT_5_9_9_9_REV: + return TexturePixelDataType::UnsignedInt5999Rev; default: return TexturePixelDataType::Unknown; } @@ -270,6 +296,10 @@ namespace MobileGL { return TextureUploadTarget::CubeMapNegativeZ; case GL_PROXY_TEXTURE_CUBE_MAP: return TextureUploadTarget::ProxyCubeMap; + case GL_TEXTURE_2D_MULTISAMPLE: + return TextureUploadTarget::Texture2DMultisample; + case GL_PROXY_TEXTURE_2D_MULTISAMPLE: + return TextureUploadTarget::ProxyTexture2DMultisample; default: return TextureUploadTarget::Unknown; } diff --git a/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.h b/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.h index e23caf7b..777b0504 100644 --- a/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.h +++ b/MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.h @@ -6,7 +6,7 @@ namespace MobileGL { namespace MG_Util { TextureTarget ConvertGLEnumToTextureTarget(GLenum target); TextureInputFormat ConvertGLEnumToTextureInputFormat(GLenum format); - TextureSizedInternalFormat ConvertGLEnumToTextureSizedInternalFormat(GLenum internalformat); + TextureInternalFormat ConvertGLEnumToTextureInternalFormat(GLenum internalformat); TexturePixelDataType ConvertGLEnumToTexturePixelDataType(GLenum type); TextureUploadTarget ConvertGLEnumToTextureUploadTarget(GLenum target); } // namespace MG_Util diff --git a/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.cpp b/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.cpp index bf4b332c..5581fe28 100644 --- a/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.cpp +++ b/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.cpp @@ -68,130 +68,154 @@ namespace MobileGL { } } - GLenum ConvertTextureSizedInternalFormatToGLEnum(TextureSizedInternalFormat format) { + GLenum ConvertTextureInternalFormatToGLEnum(TextureInternalFormat format) { switch (format) { - case TextureSizedInternalFormat::R8: + case TextureInternalFormat::R8: return GL_R8; - case TextureSizedInternalFormat::R8Snorm: + case TextureInternalFormat::R8Snorm: return GL_R8_SNORM; - case TextureSizedInternalFormat::R16: + case TextureInternalFormat::R16: return GL_R16; - case TextureSizedInternalFormat::R16Snorm: + case TextureInternalFormat::R16Snorm: return GL_R16_SNORM; - case TextureSizedInternalFormat::RG8: + case TextureInternalFormat::RG8: return GL_RG8; - case TextureSizedInternalFormat::RG8Snorm: + case TextureInternalFormat::RG8Snorm: return GL_RG8_SNORM; - case TextureSizedInternalFormat::RG16: + case TextureInternalFormat::RG16: return GL_RG16; - case TextureSizedInternalFormat::RG16Snorm: + case TextureInternalFormat::RG16Snorm: return GL_RG16_SNORM; - case TextureSizedInternalFormat::R3G3B2: + case TextureInternalFormat::R3G3B2: return GL_R3_G3_B2; - case TextureSizedInternalFormat::RGB4: + case TextureInternalFormat::RGB4: return GL_RGB4; - case TextureSizedInternalFormat::RGB5: + case TextureInternalFormat::RGB5: return GL_RGB5; - case TextureSizedInternalFormat::RGB8: + case TextureInternalFormat::RGB8: return GL_RGB8; - case TextureSizedInternalFormat::RGB8Snorm: + case TextureInternalFormat::RGB8Snorm: return GL_RGB8_SNORM; - case TextureSizedInternalFormat::RGB10: + case TextureInternalFormat::RGB10: return GL_RGB10; - case TextureSizedInternalFormat::RGB12: + case TextureInternalFormat::RGB12: return GL_RGB12; - case TextureSizedInternalFormat::RGB16Snorm: + case TextureInternalFormat::RGB16Snorm: return GL_RGB16_SNORM; - case TextureSizedInternalFormat::RGBA2: + case TextureInternalFormat::RGBA2: return GL_RGBA2; - case TextureSizedInternalFormat::RGBA4: + case TextureInternalFormat::RGBA4: return GL_RGBA4; - case TextureSizedInternalFormat::RGB5A1: + case TextureInternalFormat::RGB5A1: return GL_RGB5_A1; - case TextureSizedInternalFormat::RGBA8: + case TextureInternalFormat::RGBA8: return GL_RGBA8; - case TextureSizedInternalFormat::RGBA8Snorm: + case TextureInternalFormat::RGBA8Snorm: return GL_RGBA8_SNORM; - case TextureSizedInternalFormat::RGB10A2: + case TextureInternalFormat::RGB10A2: return GL_RGB10_A2; - case TextureSizedInternalFormat::RGB10A2UI: + case TextureInternalFormat::RGB10A2UI: return GL_RGB10_A2UI; - case TextureSizedInternalFormat::RGBA12: + case TextureInternalFormat::RGBA12: return GL_RGBA12; - case TextureSizedInternalFormat::RGBA16: + case TextureInternalFormat::RGBA16: return GL_RGBA16; - case TextureSizedInternalFormat::SRGB8: + case TextureInternalFormat::SRGB8: return GL_SRGB8; - case TextureSizedInternalFormat::SRGB8Alpha8: + case TextureInternalFormat::SRGB8Alpha8: return GL_SRGB8_ALPHA8; - case TextureSizedInternalFormat::R16F: + case TextureInternalFormat::R16F: return GL_R16F; - case TextureSizedInternalFormat::RG16F: + case TextureInternalFormat::RG16F: return GL_RG16F; - case TextureSizedInternalFormat::RGB16F: + case TextureInternalFormat::RGB16F: return GL_RGB16F; - case TextureSizedInternalFormat::RGBA16F: + case TextureInternalFormat::RGBA16F: return GL_RGBA16F; - case TextureSizedInternalFormat::R32F: + case TextureInternalFormat::R32F: return GL_R32F; - case TextureSizedInternalFormat::RG32F: + case TextureInternalFormat::RG32F: return GL_RG32F; - case TextureSizedInternalFormat::RGB32F: + case TextureInternalFormat::RGB32F: return GL_RGB32F; - case TextureSizedInternalFormat::RGBA32F: + case TextureInternalFormat::RGBA32F: return GL_RGBA32F; - case TextureSizedInternalFormat::R11FG11FB10F: + case TextureInternalFormat::R11FG11FB10F: return GL_R11F_G11F_B10F; - case TextureSizedInternalFormat::RGB9E5: + case TextureInternalFormat::RGB9E5: return GL_RGB9_E5; - case TextureSizedInternalFormat::R8I: + case TextureInternalFormat::R8I: return GL_R8I; - case TextureSizedInternalFormat::R8UI: + case TextureInternalFormat::R8UI: return GL_R8UI; - case TextureSizedInternalFormat::R16I: + case TextureInternalFormat::R16I: return GL_R16I; - case TextureSizedInternalFormat::R16UI: + case TextureInternalFormat::R16UI: return GL_R16UI; - case TextureSizedInternalFormat::R32I: + case TextureInternalFormat::R32I: return GL_R32I; - case TextureSizedInternalFormat::R32UI: + case TextureInternalFormat::R32UI: return GL_R32UI; - case TextureSizedInternalFormat::RG8I: + case TextureInternalFormat::RG8I: return GL_RG8I; - case TextureSizedInternalFormat::RG8UI: + case TextureInternalFormat::RG8UI: return GL_RG8UI; - case TextureSizedInternalFormat::RG16I: + case TextureInternalFormat::RG16I: return GL_RG16I; - case TextureSizedInternalFormat::RG16UI: + case TextureInternalFormat::RG16UI: return GL_RG16UI; - case TextureSizedInternalFormat::RG32I: + case TextureInternalFormat::RG32I: return GL_RG32I; - case TextureSizedInternalFormat::RG32UI: + case TextureInternalFormat::RG32UI: return GL_RG32UI; - case TextureSizedInternalFormat::RGB8I: + case TextureInternalFormat::RGB8I: return GL_RGB8I; - case TextureSizedInternalFormat::RGB8UI: + case TextureInternalFormat::RGB8UI: return GL_RGB8UI; - case TextureSizedInternalFormat::RGB16I: + case TextureInternalFormat::RGB16I: return GL_RGB16I; - case TextureSizedInternalFormat::RGB16UI: + case TextureInternalFormat::RGB16UI: return GL_RGB16UI; - case TextureSizedInternalFormat::RGB32I: + case TextureInternalFormat::RGB32I: return GL_RGB32I; - case TextureSizedInternalFormat::RGB32UI: + case TextureInternalFormat::RGB32UI: return GL_RGB32UI; - case TextureSizedInternalFormat::RGBA8I: + case TextureInternalFormat::RGBA8I: return GL_RGBA8I; - case TextureSizedInternalFormat::RGBA8UI: + case TextureInternalFormat::RGBA8UI: return GL_RGBA8UI; - case TextureSizedInternalFormat::RGBA16I: + case TextureInternalFormat::RGBA16I: return GL_RGBA16I; - case TextureSizedInternalFormat::RGBA16UI: + case TextureInternalFormat::RGBA16UI: return GL_RGBA16UI; - case TextureSizedInternalFormat::RGBA32I: + case TextureInternalFormat::RGBA32I: return GL_RGBA32I; - case TextureSizedInternalFormat::RGBA32UI: + case TextureInternalFormat::RGBA32UI: return GL_RGBA32UI; + case TextureInternalFormat::DepthComponent: + return GL_DEPTH_COMPONENT; + case TextureInternalFormat::DepthComponent16: + return GL_DEPTH_COMPONENT16; + case TextureInternalFormat::DepthComponent24: + return GL_DEPTH_COMPONENT24; + case TextureInternalFormat::DepthComponent32F: + return GL_DEPTH_COMPONENT32F; + case TextureInternalFormat::Depth24Stencil8: + return GL_DEPTH24_STENCIL8; + case TextureInternalFormat::Depth32FStencil8: + return GL_DEPTH32F_STENCIL8; + case TextureInternalFormat::DepthComponent32: + return GL_DEPTH_COMPONENT32; + case TextureInternalFormat::DepthStencil: + return GL_DEPTH_STENCIL; + case TextureInternalFormat::Red: + return GL_RED; + case TextureInternalFormat::RG: + return GL_RG; + case TextureInternalFormat::RGB: + return GL_RGB; + case TextureInternalFormat::RGBA: + return GL_RGBA; default: return GL_UNKNOWN_MGL; } @@ -233,6 +257,12 @@ namespace MobileGL { return GL_UNSIGNED_INT_8_8_8_8_REV; case TexturePixelDataType::UnsignedInt1010102: return GL_UNSIGNED_INT_10_10_10_2; + case TexturePixelDataType::UnsignedInt2101010Rev: + return GL_UNSIGNED_INT_2_10_10_10_REV; + case TexturePixelDataType::UnsignedInt101111Rev: + return GL_UNSIGNED_INT_10F_11F_11F_REV; + case TexturePixelDataType::UnsignedInt5999Rev: + return GL_UNSIGNED_INT_5_9_9_9_REV; default: return GL_UNKNOWN_MGL; } @@ -266,6 +296,10 @@ namespace MobileGL { return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; case TextureUploadTarget::ProxyCubeMap: return GL_PROXY_TEXTURE_CUBE_MAP; + case TextureUploadTarget::Texture2DMultisample: + return GL_TEXTURE_2D_MULTISAMPLE; + case TextureUploadTarget::ProxyTexture2DMultisample: + return GL_PROXY_TEXTURE_2D_MULTISAMPLE; default: return GL_UNKNOWN_MGL; } diff --git a/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.h b/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.h index f0c694cd..777fa306 100644 --- a/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.h +++ b/MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.h @@ -6,7 +6,7 @@ namespace MobileGL { namespace MG_Util { GLenum ConvertTextureTargetToGLEnum(TextureTarget target); GLenum ConvertTextureInputFormatToGLEnum(TextureInputFormat format); - GLenum ConvertTextureSizedInternalFormatToGLEnum(TextureSizedInternalFormat internalformat); + GLenum ConvertTextureInternalFormatToGLEnum(TextureInternalFormat internalformat); GLenum ConvertTexturePixelDataTypeToGLEnum(TexturePixelDataType type); GLenum ConvertTextureUploadTargetToGLEnum(TextureUploadTarget target); } // namespace MG_Util diff --git a/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp b/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp new file mode 100644 index 00000000..2e5d1e93 --- /dev/null +++ b/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp @@ -0,0 +1,32 @@ +#include "TextureEnumConverter.h" + +namespace MobileGL { + namespace MG_Util { + TextureTarget ConvertTextureUploadTargetToTextureTarget(TextureUploadTarget target) { + switch (target) { + case TextureUploadTarget::Texture2D: + case TextureUploadTarget::ProxyTexture2D: + return TextureTarget::Texture2D; + case TextureUploadTarget::Texture1DArray: + case TextureUploadTarget::ProxyTexture1DArray: + return TextureTarget::Texture1DArray; + case TextureUploadTarget::TextureRectangle: + case TextureUploadTarget::ProxyTextureRectangle: + return TextureTarget::TextureRectangle; + case TextureUploadTarget::CubeMapPositiveX: + case TextureUploadTarget::CubeMapNegativeX: + case TextureUploadTarget::CubeMapPositiveY: + case TextureUploadTarget::CubeMapNegativeY: + case TextureUploadTarget::CubeMapPositiveZ: + case TextureUploadTarget::CubeMapNegativeZ: + case TextureUploadTarget::ProxyCubeMap: + return TextureTarget::TextureCubeMap; + case TextureUploadTarget::Texture2DMultisample: + case TextureUploadTarget::ProxyTexture2DMultisample: + return TextureTarget::Texture2DMultisample; + default: + return TextureTarget::Unknown; + } + } + } // namespace MG_Util +} // namespace MobileGL \ No newline at end of file diff --git a/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.h b/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.h new file mode 100644 index 00000000..c745fc3c --- /dev/null +++ b/MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.h @@ -0,0 +1,9 @@ +#pragma once +#include +#include + +namespace MobileGL { + namespace MG_Util { + TextureTarget ConvertTextureUploadTargetToTextureTarget(TextureUploadTarget target); + } // namespace MG_Util +} // namespace MobileGL \ No newline at end of file diff --git a/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.cpp b/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.cpp index 50c08c49..04c78954 100644 --- a/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.cpp +++ b/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.cpp @@ -62,130 +62,154 @@ namespace MobileGL { } } - String ConvertTextureSizedInternalFormatToString(TextureSizedInternalFormat format) { + String ConvertTextureInternalFormatToString(TextureInternalFormat format) { switch (format) { - case TextureSizedInternalFormat::R8: + case TextureInternalFormat::R8: return "R8"; - case TextureSizedInternalFormat::R8Snorm: + case TextureInternalFormat::R8Snorm: return "R8Snorm"; - case TextureSizedInternalFormat::R16: + case TextureInternalFormat::R16: return "R16"; - case TextureSizedInternalFormat::R16Snorm: + case TextureInternalFormat::R16Snorm: return "R16Snorm"; - case TextureSizedInternalFormat::RG8: + case TextureInternalFormat::RG8: return "RG8"; - case TextureSizedInternalFormat::RG8Snorm: + case TextureInternalFormat::RG8Snorm: return "RG8Snorm"; - case TextureSizedInternalFormat::RG16: + case TextureInternalFormat::RG16: return "RG16"; - case TextureSizedInternalFormat::RG16Snorm: + case TextureInternalFormat::RG16Snorm: return "RG16Snorm"; - case TextureSizedInternalFormat::R3G3B2: + case TextureInternalFormat::R3G3B2: return "R3G3B2"; - case TextureSizedInternalFormat::RGB4: + case TextureInternalFormat::RGB4: return "RGB4"; - case TextureSizedInternalFormat::RGB5: + case TextureInternalFormat::RGB5: return "RGB5"; - case TextureSizedInternalFormat::RGB8: + case TextureInternalFormat::RGB8: return "RGB8"; - case TextureSizedInternalFormat::RGB8Snorm: + case TextureInternalFormat::RGB8Snorm: return "RGB8Snorm"; - case TextureSizedInternalFormat::RGB10: + case TextureInternalFormat::RGB10: return "RGB10"; - case TextureSizedInternalFormat::RGB12: + case TextureInternalFormat::RGB12: return "RGB12"; - case TextureSizedInternalFormat::RGB16Snorm: + case TextureInternalFormat::RGB16Snorm: return "RGB16Snorm"; - case TextureSizedInternalFormat::RGBA2: + case TextureInternalFormat::RGBA2: return "RGBA2"; - case TextureSizedInternalFormat::RGBA4: + case TextureInternalFormat::RGBA4: return "RGBA4"; - case TextureSizedInternalFormat::RGB5A1: + case TextureInternalFormat::RGB5A1: return "RGB5A1"; - case TextureSizedInternalFormat::RGBA8: + case TextureInternalFormat::RGBA8: return "RGBA8"; - case TextureSizedInternalFormat::RGBA8Snorm: + case TextureInternalFormat::RGBA8Snorm: return "RGBA8Snorm"; - case TextureSizedInternalFormat::RGB10A2: + case TextureInternalFormat::RGB10A2: return "RGB10A2"; - case TextureSizedInternalFormat::RGB10A2UI: + case TextureInternalFormat::RGB10A2UI: return "RGB10A2UI"; - case TextureSizedInternalFormat::RGBA12: + case TextureInternalFormat::RGBA12: return "RGBA12"; - case TextureSizedInternalFormat::RGBA16: + case TextureInternalFormat::RGBA16: return "RGBA16"; - case TextureSizedInternalFormat::SRGB8: + case TextureInternalFormat::SRGB8: return "SRGB8"; - case TextureSizedInternalFormat::SRGB8Alpha8: + case TextureInternalFormat::SRGB8Alpha8: return "SRGB8Alpha8"; - case TextureSizedInternalFormat::R16F: + case TextureInternalFormat::R16F: return "R16F"; - case TextureSizedInternalFormat::RG16F: + case TextureInternalFormat::RG16F: return "RG16F"; - case TextureSizedInternalFormat::RGB16F: + case TextureInternalFormat::RGB16F: return "RGB16F"; - case TextureSizedInternalFormat::RGBA16F: + case TextureInternalFormat::RGBA16F: return "RGBA16F"; - case TextureSizedInternalFormat::R32F: + case TextureInternalFormat::R32F: return "R32F"; - case TextureSizedInternalFormat::RG32F: + case TextureInternalFormat::RG32F: return "RG32F"; - case TextureSizedInternalFormat::RGB32F: + case TextureInternalFormat::RGB32F: return "RGB32F"; - case TextureSizedInternalFormat::RGBA32F: + case TextureInternalFormat::RGBA32F: return "RGBA32F"; - case TextureSizedInternalFormat::R11FG11FB10F: + case TextureInternalFormat::R11FG11FB10F: return "R11FG11FB10F"; - case TextureSizedInternalFormat::RGB9E5: + case TextureInternalFormat::RGB9E5: return "RGB9E5"; - case TextureSizedInternalFormat::R8I: + case TextureInternalFormat::R8I: return "R8I"; - case TextureSizedInternalFormat::R8UI: + case TextureInternalFormat::R8UI: return "R8UI"; - case TextureSizedInternalFormat::R16I: + case TextureInternalFormat::R16I: return "R16I"; - case TextureSizedInternalFormat::R16UI: + case TextureInternalFormat::R16UI: return "R16UI"; - case TextureSizedInternalFormat::R32I: + case TextureInternalFormat::R32I: return "R32I"; - case TextureSizedInternalFormat::R32UI: + case TextureInternalFormat::R32UI: return "R32UI"; - case TextureSizedInternalFormat::RG8I: + case TextureInternalFormat::RG8I: return "RG8I"; - case TextureSizedInternalFormat::RG8UI: + case TextureInternalFormat::RG8UI: return "RG8UI"; - case TextureSizedInternalFormat::RG16I: + case TextureInternalFormat::RG16I: return "RG16I"; - case TextureSizedInternalFormat::RG16UI: + case TextureInternalFormat::RG16UI: return "RG16UI"; - case TextureSizedInternalFormat::RG32I: + case TextureInternalFormat::RG32I: return "RG32I"; - case TextureSizedInternalFormat::RG32UI: + case TextureInternalFormat::RG32UI: return "RG32UI"; - case TextureSizedInternalFormat::RGB8I: + case TextureInternalFormat::RGB8I: return "RGB8I"; - case TextureSizedInternalFormat::RGB8UI: + case TextureInternalFormat::RGB8UI: return "RGB8UI"; - case TextureSizedInternalFormat::RGB16I: + case TextureInternalFormat::RGB16I: return "RGB16I"; - case TextureSizedInternalFormat::RGB16UI: + case TextureInternalFormat::RGB16UI: return "RGB16UI"; - case TextureSizedInternalFormat::RGB32I: + case TextureInternalFormat::RGB32I: return "RGB32I"; - case TextureSizedInternalFormat::RGB32UI: + case TextureInternalFormat::RGB32UI: return "RGB32UI"; - case TextureSizedInternalFormat::RGBA8I: + case TextureInternalFormat::RGBA8I: return "RGBA8I"; - case TextureSizedInternalFormat::RGBA8UI: + case TextureInternalFormat::RGBA8UI: return "RGBA8UI"; - case TextureSizedInternalFormat::RGBA16I: + case TextureInternalFormat::RGBA16I: return "RGBA16I"; - case TextureSizedInternalFormat::RGBA16UI: + case TextureInternalFormat::RGBA16UI: return "RGBA16UI"; - case TextureSizedInternalFormat::RGBA32I: + case TextureInternalFormat::RGBA32I: return "RGBA32I"; - case TextureSizedInternalFormat::RGBA32UI: + case TextureInternalFormat::RGBA32UI: return "RGBA32UI"; + case TextureInternalFormat::DepthComponent: + return "DepthComponent"; + case TextureInternalFormat::DepthComponent16: + return "DepthComponent16"; + case TextureInternalFormat::DepthComponent24: + return "DepthComponent24"; + case TextureInternalFormat::DepthComponent32: + return "DepthComponent32"; + case TextureInternalFormat::DepthComponent32F: + return "DepthComponent32F"; + case TextureInternalFormat::DepthStencil: + return "DepthStencil"; + case TextureInternalFormat::Depth24Stencil8: + return "Depth24Stencil8"; + case TextureInternalFormat::Depth32FStencil8: + return "Depth32FStencil8"; + case TextureInternalFormat::Red: + return "Red"; + case TextureInternalFormat::RG: + return "RG"; + case TextureInternalFormat::RGB: + return "RGB"; + case TextureInternalFormat::RGBA: + return "RGBA"; default: return "Unknown"; } @@ -223,6 +247,18 @@ namespace MobileGL { return "UnsignedShort5551"; case TexturePixelDataType::UnsignedShort1555Rev: return "UnsignedShort1555Rev"; + case TexturePixelDataType::UnsignedInt8888: + return "UnsignedInt8888"; + case TexturePixelDataType::UnsignedInt8888Rev: + return "UnsignedInt8888Rev"; + case TexturePixelDataType::UnsignedInt1010102: + return "UnsignedInt1010102"; + case TexturePixelDataType::UnsignedInt2101010Rev: + return "UnsignedInt2101010Rev"; + case TexturePixelDataType::UnsignedInt101111Rev: + return "UnsignedInt101111Rev"; + case TexturePixelDataType::UnsignedInt5999Rev: + return "UnsignedInt5999Rev"; default: return "Unknown"; } @@ -256,6 +292,10 @@ namespace MobileGL { return "CubeMapNegativeZ"; case TextureUploadTarget::ProxyCubeMap: return "ProxyCubeMap"; + case TextureUploadTarget::Texture2DMultisample: + return "Texture2DMultisample"; + case TextureUploadTarget::ProxyTexture2DMultisample: + return "ProxyTexture2DMultisample"; default: return "Unknown"; } diff --git a/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.h b/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.h index fb97e56d..0f764331 100644 --- a/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.h +++ b/MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.h @@ -6,7 +6,7 @@ namespace MobileGL { namespace MG_Util { String ConvertTextureTargetToString(TextureTarget target); String ConvertTextureInputFormatToString(TextureInputFormat format); - String ConvertTextureSizedInternalFormatToString(TextureSizedInternalFormat internalformat); + String ConvertTextureInternalFormatToString(TextureInternalFormat internalformat); String ConvertTexturePixelDataTypeToString(TexturePixelDataType type); String ConvertTextureUploadTargetToString(TextureUploadTarget target); } // namespace MG_Util diff --git a/MobileGL/MG_Util/Metrics/TextureMetrics.cpp b/MobileGL/MG_Util/Metrics/TextureMetrics.cpp index 9910d772..32cf838b 100644 --- a/MobileGL/MG_Util/Metrics/TextureMetrics.cpp +++ b/MobileGL/MG_Util/Metrics/TextureMetrics.cpp @@ -1,85 +1,129 @@ #include "TextureMetrics.h" +#include "MG_Util/Math/VectorTypes.h" namespace MobileGL { namespace MG_Util { - SizeT GetTexturePixelSize(TextureSizedInternalFormat internal) { + SizeT GetTexturePixelSize(TextureInternalFormat internal) { switch (internal) { - case TextureSizedInternalFormat::R8: - case TextureSizedInternalFormat::R8Snorm: - case TextureSizedInternalFormat::R8I: - case TextureSizedInternalFormat::R8UI: + case TextureInternalFormat::R8: + case TextureInternalFormat::R8Snorm: + case TextureInternalFormat::R8I: + case TextureInternalFormat::R8UI: return 1; - case TextureSizedInternalFormat::R16: - case TextureSizedInternalFormat::R16Snorm: - case TextureSizedInternalFormat::R16I: - case TextureSizedInternalFormat::R16UI: - case TextureSizedInternalFormat::R16F: - case TextureSizedInternalFormat::RG8: - case TextureSizedInternalFormat::RG8Snorm: - case TextureSizedInternalFormat::RG8I: - case TextureSizedInternalFormat::RG8UI: + case TextureInternalFormat::R16: + case TextureInternalFormat::R16Snorm: + case TextureInternalFormat::R16I: + case TextureInternalFormat::R16UI: + case TextureInternalFormat::R16F: + case TextureInternalFormat::RG8: + case TextureInternalFormat::RG8Snorm: + case TextureInternalFormat::RG8I: + case TextureInternalFormat::RG8UI: return 2; - case TextureSizedInternalFormat::R3G3B2: - case TextureSizedInternalFormat::RGB4: - case TextureSizedInternalFormat::RGB5: - case TextureSizedInternalFormat::RGB8: - case TextureSizedInternalFormat::RGB8Snorm: - case TextureSizedInternalFormat::SRGB8: - case TextureSizedInternalFormat::RGB8I: - case TextureSizedInternalFormat::RGB8UI: + case TextureInternalFormat::R3G3B2: + case TextureInternalFormat::RGB4: + case TextureInternalFormat::RGB5: + case TextureInternalFormat::RGB8: + case TextureInternalFormat::RGB8Snorm: + case TextureInternalFormat::SRGB8: + case TextureInternalFormat::RGB8I: + case TextureInternalFormat::RGB8UI: return 3; - case TextureSizedInternalFormat::RGBA2: - case TextureSizedInternalFormat::RGBA4: - case TextureSizedInternalFormat::RGB5A1: - case TextureSizedInternalFormat::RGBA8: - case TextureSizedInternalFormat::RGBA8Snorm: - case TextureSizedInternalFormat::RGBA8I: - case TextureSizedInternalFormat::RGBA8UI: - case TextureSizedInternalFormat::SRGB8Alpha8: - case TextureSizedInternalFormat::RGB10A2: - case TextureSizedInternalFormat::RGB10A2UI: - case TextureSizedInternalFormat::R32F: + case TextureInternalFormat::RGBA2: + case TextureInternalFormat::RGBA4: + case TextureInternalFormat::RGB5A1: + case TextureInternalFormat::RGBA8: + case TextureInternalFormat::RGBA8Snorm: + case TextureInternalFormat::RGBA8I: + case TextureInternalFormat::RGBA8UI: + case TextureInternalFormat::SRGB8Alpha8: + case TextureInternalFormat::RGB10A2: + case TextureInternalFormat::RGB10A2UI: + case TextureInternalFormat::R32F: - case TextureSizedInternalFormat::RG16: - case TextureSizedInternalFormat::RG16Snorm: - case TextureSizedInternalFormat::RG16I: - case TextureSizedInternalFormat::RG16UI: - case TextureSizedInternalFormat::RG16F: + case TextureInternalFormat::RG16: + case TextureInternalFormat::RG16Snorm: + case TextureInternalFormat::RG16I: + case TextureInternalFormat::RG16UI: + case TextureInternalFormat::RG16F: return 4; - case TextureSizedInternalFormat::RGBA12: - case TextureSizedInternalFormat::RGBA16: - case TextureSizedInternalFormat::RGBA16I: - case TextureSizedInternalFormat::RGBA16UI: - case TextureSizedInternalFormat::RGBA16F: - case TextureSizedInternalFormat::RG32F: - case TextureSizedInternalFormat::RG32I: - case TextureSizedInternalFormat::RG32UI: + case TextureInternalFormat::RGBA12: + case TextureInternalFormat::RGBA16: + case TextureInternalFormat::RGBA16I: + case TextureInternalFormat::RGBA16UI: + case TextureInternalFormat::RGBA16F: + case TextureInternalFormat::RG32F: + case TextureInternalFormat::RG32I: + case TextureInternalFormat::RG32UI: return 8; - case TextureSizedInternalFormat::RGB16F: - case TextureSizedInternalFormat::RGB32F: - case TextureSizedInternalFormat::RGB16I: - case TextureSizedInternalFormat::RGB16UI: - case TextureSizedInternalFormat::RGB32I: - case TextureSizedInternalFormat::RGB32UI: + case TextureInternalFormat::RGB16F: + case TextureInternalFormat::RGB32F: + case TextureInternalFormat::RGB16I: + case TextureInternalFormat::RGB16UI: + case TextureInternalFormat::RGB32I: + case TextureInternalFormat::RGB32UI: return 12; - case TextureSizedInternalFormat::RGBA32F: - case TextureSizedInternalFormat::RGBA32I: - case TextureSizedInternalFormat::RGBA32UI: + case TextureInternalFormat::RGBA32F: + case TextureInternalFormat::RGBA32I: + case TextureInternalFormat::RGBA32UI: return 16; - case TextureSizedInternalFormat::R11FG11FB10F: - case TextureSizedInternalFormat::RGB9E5: + case TextureInternalFormat::R11FG11FB10F: + case TextureInternalFormat::RGB9E5: return 4; default: return 0; } } + + SizeT GetTexturePixelDataTypeSize(TexturePixelDataType type) { + switch (type) { + case TexturePixelDataType::UnsignedByte: + case TexturePixelDataType::Byte: + case TexturePixelDataType::UnsignedByte332: + case TexturePixelDataType::UnsignedByte233Rev: + return 1; + case TexturePixelDataType::UnsignedShort: + case TexturePixelDataType::Short: + case TexturePixelDataType::UnsignedShort565: + case TexturePixelDataType::UnsignedShort565Rev: + case TexturePixelDataType::UnsignedShort4444: + case TexturePixelDataType::UnsignedShort4444Rev: + case TexturePixelDataType::UnsignedShort5551: + case TexturePixelDataType::UnsignedShort1555Rev: + return 2; + case TexturePixelDataType::UnsignedInt: + case TexturePixelDataType::Int: + case TexturePixelDataType::Float: + case TexturePixelDataType::UnsignedInt8888: + case TexturePixelDataType::UnsignedInt8888Rev: + case TexturePixelDataType::UnsignedInt1010102: + case TexturePixelDataType::UnsignedInt2101010Rev: + case TexturePixelDataType::UnsignedInt101111Rev: + case TexturePixelDataType::UnsignedInt5999Rev: + return 4; + default: + return 0; + } + } + + SizeT CalculateTextureImageSize(TextureInternalFormat internalFormat, TexturePixelDataType pixelDataType, + IntVec3 size) { + SizeT pixelSize = GetTexturePixelSize(internalFormat); + if (pixelSize == 0) return 0; + + SizeT dataTypeSize = GetTexturePixelDataTypeSize(pixelDataType); + if (dataTypeSize == 0) return 0; + + return pixelSize * dataTypeSize * size.x() * size.y() * size.z(); + } + } // namespace MG_Util } // namespace MobileGL diff --git a/MobileGL/MG_Util/Metrics/TextureMetrics.h b/MobileGL/MG_Util/Metrics/TextureMetrics.h index e61296ab..0b609c06 100644 --- a/MobileGL/MG_Util/Metrics/TextureMetrics.h +++ b/MobileGL/MG_Util/Metrics/TextureMetrics.h @@ -4,6 +4,9 @@ namespace MobileGL { namespace MG_Util { - SizeT GetTexturePixelSize(TextureSizedInternalFormat internal); - } + SizeT GetTexturePixelSize(TextureInternalFormat internal); + SizeT GetTexturePixelDataTypeSize(TexturePixelDataType type); + SizeT CalculateTextureImageSize(TextureInternalFormat internalFormat, TexturePixelDataType pixelDataType, + IntVec3 size); + } // namespace MG_Util } // namespace MobileGL