diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 85ce1d462..6bbb433f3 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -218,7 +218,7 @@ std::unique_ptr Context::createTextureResource( texture[0] = static_cast(*resource).texture; // Creates an empty texture with the specified size and format. - MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, Enum::to(format), + MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, Enum::sizedFor(format, type), size.width, size.height, 0, Enum::to(format), Enum::to(type), nullptr)); diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp index b63331391..899fb496c 100644 --- a/src/mbgl/gl/enum.cpp +++ b/src/mbgl/gl/enum.cpp @@ -265,6 +265,26 @@ platform::GLenum Enum::to(const gfx::TexturePixelType val return GL_INVALID_ENUM; } +template <> template<> +platform::GLenum Enum::sizedFor<>(const gfx::TexturePixelType value, + gfx::TextureChannelDataType type) +{ + switch (type) { + case gfx::TextureChannelDataType::UnsignedByte: { + return Enum::to(value); + } + case gfx::TextureChannelDataType::HalfFloat: { + switch (value) { + case gfx::TexturePixelType::RGBA: + return GL_RGBA16F; + default: break; + } + } + } + + return GL_INVALID_ENUM; +} + template <> gfx::TextureChannelDataType Enum::from(const platform::GLint value) { switch (value) { diff --git a/src/mbgl/gl/enum.hpp b/src/mbgl/gl/enum.hpp index 70243d646..d4ef3eea3 100644 --- a/src/mbgl/gl/enum.hpp +++ b/src/mbgl/gl/enum.hpp @@ -15,6 +15,9 @@ public: static T from(InType); static OutType to(T); + + template + static OutType sizedFor(T, U type); }; } // namespace gl