diff --git a/libraries/gpu/src/gpu/GLBackendShared.h b/libraries/gpu/src/gpu/GLBackendShared.h index d6aab6034d..aef670e6b0 100644 --- a/libraries/gpu/src/gpu/GLBackendShared.h +++ b/libraries/gpu/src/gpu/GLBackendShared.h @@ -54,6 +54,8 @@ public: static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat) { return evalGLTexelFormat(dstFormat, dstFormat); } + static GLTexelFormat evalGLTexelFormatInternal(const gpu::Element& dstFormat); + static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat, const gpu::Element& srcFormat); }; diff --git a/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp b/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp index 3f64f373d6..1a7b969e13 100644 --- a/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexelFormat.cpp @@ -10,6 +10,11 @@ using namespace gpu; +GLTexelFormat GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { + GLTexelFormat texel = { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE }; + return texel; +} + GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const Element& srcFormat) { if (dstFormat != srcFormat) { GLTexelFormat texel = { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE }; @@ -118,6 +123,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E break; case gpu::COMPRESSED_SRGBA: texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA; + break; // FIXME: WE will want to support this later @@ -156,6 +162,10 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E texel.type = _elementTypeToGLType[dstFormat.getType()]; switch (dstFormat.getSemantic()) { + case gpu::COMPRESSED_R: { + texel.internalFormat = GL_COMPRESSED_RED_RGTC1; + break; + } case gpu::RGB: case gpu::RGBA: case gpu::SRGB: @@ -312,6 +322,12 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E case gpu::SRGBA: texel.internalFormat = GL_SRGB8; // standard 2.2 gamma correction color break; + case gpu::COMPRESSED_RGB: + texel.internalFormat = GL_COMPRESSED_RGB; + break; + case gpu::COMPRESSED_SRGB: + texel.internalFormat = GL_COMPRESSED_SRGB; + break; default: qCDebug(gpulogging) << "Unknown combination of texel format"; } @@ -383,11 +399,19 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E } break; case gpu::SRGB: + texel.format = GL_RGB; texel.internalFormat = GL_SRGB8; break; case gpu::SRGBA: + texel.format = GL_RGBA; texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color break; + case gpu::COMPRESSED_RGBA: + texel.internalFormat = GL_COMPRESSED_RGBA; + break; + case gpu::COMPRESSED_SRGBA: + texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA; + break; default: qCDebug(gpulogging) << "Unknown combination of texel format"; } diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 35c8666292..1e68dd1453 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -72,20 +72,41 @@ GLBackend::GLTexture::GLTexture(const Texture& texture) : } GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat()); - withPreservedTexture(_target, [&] { - glBindTexture(_target, _texture); - (void)CHECK_GL_ERROR(); - // GO through the process of allocating the correct storage - if (GLEW_VERSION_4_2) { - glTexStorage2D(_target, levels, texelFormat.internalFormat, width, height); - } else { - glTexImage2D(_target, 0, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, 0); - } - (void)CHECK_GL_ERROR(); - syncSampler(texture.getSampler(), texture.getType(), this); - (void)CHECK_GL_ERROR(); - updateSize((GLuint)texture.evalTotalSize()); - }); + + GLint boundTex = -1; + switch (_target) { + case GL_TEXTURE_2D: + glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex); + break; + + case GL_TEXTURE_CUBE_MAP: + glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &boundTex); + break; + + default: + qFatal("Unsupported texture type"); + } + (void)CHECK_GL_ERROR(); + + glBindTexture(_target, _texture); + + (void)CHECK_GL_ERROR(); + // GO through the process of allocating the correct storage + if (GLEW_VERSION_4_2) { + glTexStorage2D(_target, levels, texelFormat.internalFormat, width, height); + } else { + glTexImage2D(_target, 0, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, 0); + } + (void)CHECK_GL_ERROR(); + + syncSampler(texture.getSampler(), texture.getType(), this); + (void)CHECK_GL_ERROR(); + + updateSize((GLuint)texture.evalTotalSize()); + (void)CHECK_GL_ERROR(); + + glBindTexture(_target, boundTex); + (void)CHECK_GL_ERROR(); } GLBackend::GLTexture::~GLTexture() {