Trying to ge5t the proper behavior for the Compression texture and textures in genral...

This commit is contained in:
samcake 2016-04-05 19:13:24 -07:00
parent 710c4a1b8f
commit d9bc06d92d
3 changed files with 61 additions and 14 deletions

View file

@ -54,6 +54,8 @@ public:
static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat) { static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat) {
return evalGLTexelFormat(dstFormat, dstFormat); return evalGLTexelFormat(dstFormat, dstFormat);
} }
static GLTexelFormat evalGLTexelFormatInternal(const gpu::Element& dstFormat);
static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat, const gpu::Element& srcFormat); static GLTexelFormat evalGLTexelFormat(const gpu::Element& dstFormat, const gpu::Element& srcFormat);
}; };

View file

@ -10,6 +10,11 @@
using namespace gpu; 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) { GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const Element& srcFormat) {
if (dstFormat != srcFormat) { if (dstFormat != srcFormat) {
GLTexelFormat texel = { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE }; GLTexelFormat texel = { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE };
@ -118,6 +123,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
break; break;
case gpu::COMPRESSED_SRGBA: case gpu::COMPRESSED_SRGBA:
texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA; texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA;
break; break;
// FIXME: WE will want to support this later // 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()]; texel.type = _elementTypeToGLType[dstFormat.getType()];
switch (dstFormat.getSemantic()) { switch (dstFormat.getSemantic()) {
case gpu::COMPRESSED_R: {
texel.internalFormat = GL_COMPRESSED_RED_RGTC1;
break;
}
case gpu::RGB: case gpu::RGB:
case gpu::RGBA: case gpu::RGBA:
case gpu::SRGB: case gpu::SRGB:
@ -312,6 +322,12 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
case gpu::SRGBA: case gpu::SRGBA:
texel.internalFormat = GL_SRGB8; // standard 2.2 gamma correction color texel.internalFormat = GL_SRGB8; // standard 2.2 gamma correction color
break; break;
case gpu::COMPRESSED_RGB:
texel.internalFormat = GL_COMPRESSED_RGB;
break;
case gpu::COMPRESSED_SRGB:
texel.internalFormat = GL_COMPRESSED_SRGB;
break;
default: default:
qCDebug(gpulogging) << "Unknown combination of texel format"; qCDebug(gpulogging) << "Unknown combination of texel format";
} }
@ -383,11 +399,19 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E
} }
break; break;
case gpu::SRGB: case gpu::SRGB:
texel.format = GL_RGB;
texel.internalFormat = GL_SRGB8; texel.internalFormat = GL_SRGB8;
break; break;
case gpu::SRGBA: case gpu::SRGBA:
texel.format = GL_RGBA;
texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color texel.internalFormat = GL_SRGB8_ALPHA8; // standard 2.2 gamma correction color
break; break;
case gpu::COMPRESSED_RGBA:
texel.internalFormat = GL_COMPRESSED_RGBA;
break;
case gpu::COMPRESSED_SRGBA:
texel.internalFormat = GL_COMPRESSED_SRGB_ALPHA;
break;
default: default:
qCDebug(gpulogging) << "Unknown combination of texel format"; qCDebug(gpulogging) << "Unknown combination of texel format";
} }

View file

@ -72,20 +72,41 @@ GLBackend::GLTexture::GLTexture(const Texture& texture) :
} }
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat()); GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat());
withPreservedTexture(_target, [&] {
glBindTexture(_target, _texture); GLint boundTex = -1;
(void)CHECK_GL_ERROR(); switch (_target) {
// GO through the process of allocating the correct storage case GL_TEXTURE_2D:
if (GLEW_VERSION_4_2) { glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex);
glTexStorage2D(_target, levels, texelFormat.internalFormat, width, height); break;
} else {
glTexImage2D(_target, 0, texelFormat.internalFormat, width, height, 0, texelFormat.format, texelFormat.type, 0); case GL_TEXTURE_CUBE_MAP:
} glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &boundTex);
(void)CHECK_GL_ERROR(); break;
syncSampler(texture.getSampler(), texture.getType(), this);
(void)CHECK_GL_ERROR(); default:
updateSize((GLuint)texture.evalTotalSize()); 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() { GLBackend::GLTexture::~GLTexture() {