GRIM: Cleanup pixel formats for textures

This commit is contained in:
Paweł Kołodziejski 2021-12-04 22:21:12 +01:00
parent 31421a4504
commit 66bc1955e8
No known key found for this signature in database
GPG Key ID: 0BDADC9E74440FF7
7 changed files with 21 additions and 109 deletions

View File

@ -1620,32 +1620,7 @@ void GfxOpenGL::createTexture(Texture *texture, const uint8 *data, const CMap *c
}
}
} else {
#ifdef SCUMM_BIG_ENDIAN
// Copy and swap
for (int y = 0; y < texture->_height; y++) {
for (int x = 0; x < texture->_width; x++) {
uint32 pixel = (y * texture->_width + x) * texture->_bpp;
for (int b = 0; b < texture->_bpp; b++) {
texdata[pixel + b] = data[pixel + (texture->_bpp - 1) - b];
}
}
}
#else
memcpy(texdata, data, texture->_width * texture->_height * texture->_bpp);
#endif
}
GLuint format = 0;
GLuint internalFormat = 0;
if (texture->_colorFormat == BM_RGBA) {
format = GL_RGBA;
internalFormat = GL_RGBA;
} else if (texture->_colorFormat == BM_BGRA) {
format = GL_BGRA;
internalFormat = GL_RGBA;
} else { // The only other colorFormat we load right now is BGR
format = GL_BGR;
internalFormat = GL_RGB;
}
GLuint *textures = (GLuint *)texture->_texture;
@ -1662,7 +1637,7 @@ void GfxOpenGL::createTexture(Texture *texture, const uint8 *data, const CMap *c
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, texture->_width, texture->_height, 0, format, GL_UNSIGNED_BYTE, texdata);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->_width, texture->_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texdata);
delete[] texdata;
}

View File

@ -1015,8 +1015,7 @@ void GfxOpenGLS::drawEMIModelFace(const EMIModel* model, const EMIMeshFace* face
actorShader->use();
bool textured = face->_hasTexture && !_currentShadowArray;
actorShader->setUniform("textured", textured ? GL_TRUE : GL_FALSE);
actorShader->setUniform("swapRandB", _selectedTexture->_colorFormat == BM_BGRA || _selectedTexture->_colorFormat == BM_BGR888);
actorShader->setUniform("useVertexAlpha", _selectedTexture->_colorFormat == BM_BGRA);
actorShader->setUniform("useVertexAlpha", _selectedTexture->_hasAlpha);
actorShader->setUniform1f("meshAlpha", (model->_meshAlphaMode == Actor::AlphaReplace) ? model->_meshAlpha : 1.0f);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, face->_indicesEBO);
@ -1119,7 +1118,6 @@ void GfxOpenGLS::drawSprite(const Sprite *sprite) {
extraMatrix.transpose();
_spriteProgram->setUniform("extraMatrix", extraMatrix);
_spriteProgram->setUniform("textured", GL_TRUE);
_spriteProgram->setUniform("swapRandB", _selectedTexture->_colorFormat == BM_BGRA || _selectedTexture->_colorFormat == BM_BGR888);
if (g_grim->getGameType() == GType_GRIM) {
_spriteProgram->setUniform1f("alphaRef", 0.5f);
} else if (sprite->_flags2 & Sprite::AlphaTest) {
@ -1230,29 +1228,6 @@ void GfxOpenGLS::createTexture(Texture *texture, const uint8 *data, const CMap *
memcpy(texdata, data, texture->_width * texture->_height * texture->_bpp);
}
GLuint format = 0;
GLuint internalFormat = 0;
if (texture->_colorFormat == BM_RGBA) {
format = GL_RGBA;
internalFormat = GL_RGBA;
} else if (texture->_colorFormat == BM_BGRA) {
#ifdef USE_GLES2
format = GL_RGBA;
internalFormat = GL_RGBA;
#else
format = GL_BGRA;
internalFormat = GL_RGBA;
#endif
} else { // The only other colorFormat we load right now is BGR
#ifdef USE_GLES2
format = GL_RGB;
internalFormat = GL_RGB;
#else
format = GL_BGR;
internalFormat = GL_RGBA;
#endif
}
GLuint *textures = (GLuint *)texture->_texture;
glBindTexture(GL_TEXTURE_2D, textures[0]);
@ -1267,7 +1242,7 @@ void GfxOpenGLS::createTexture(Texture *texture, const uint8 *data, const CMap *
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, texture->_width, texture->_height, 0, format, GL_UNSIGNED_BYTE, texdata);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->_width, texture->_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texdata);
delete[] texdata;
}

View File

@ -1152,31 +1152,7 @@ void GfxTinyGL::createTexture(Texture *texture, const uint8 *data, const CMap *c
}
}
} else {
#ifdef SCUMM_BIG_ENDIAN
// Copy and swap
for (int y = 0; y < texture->_height; y++) {
for (int x = 0; x < texture->_width; x++) {
uint32 pixel = (y * texture->_width + x) * texture->_bpp;
for (int b = 0; b < texture->_bpp; b++) {
texdata[pixel + b] = data[pixel + (texture->_bpp - 1) - b];
}
}
}
#else
memcpy(texdata, data, texture->_width * texture->_height * texture->_bpp);
#endif
}
TGLuint format = 0;
// TGLuint internalFormat = 0;
if (texture->_colorFormat == BM_RGBA) {
format = TGL_RGBA;
// internalFormat = TGL_RGBA;
} else if (texture->_colorFormat == BM_BGRA) {
format = TGL_BGRA;
} else { // The only other colorFormat we load right now is BGR
format = TGL_BGR;
// internalFormat = TGL_RGB;
}
TGLuint *textures = (TGLuint *)texture->_texture;
@ -1188,7 +1164,7 @@ void GfxTinyGL::createTexture(Texture *texture, const uint8 *data, const CMap *c
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MAG_FILTER, TGL_LINEAR);
tglTexParameteri(TGL_TEXTURE_2D, TGL_TEXTURE_MIN_FILTER, TGL_LINEAR);
tglTexImage2D(TGL_TEXTURE_2D, 0, 3, texture->_width, texture->_height, 0, format, TGL_UNSIGNED_BYTE, texdata);
tglTexImage2D(TGL_TEXTURE_2D, 0, TGL_RGBA, texture->_width, texture->_height, 0, TGL_RGBA, TGL_UNSIGNED_BYTE, texdata);
delete[] texdata;
}

View File

@ -123,7 +123,7 @@ void MaterialData::initGrim(Common::SeekableReadStream *data) {
}
}
void loadTGA(Common::SeekableReadStream *data, Texture *t) {
static void loadTGA(Common::SeekableReadStream *data, Texture *t) {
Image::TGADecoder *tgaDecoder = new Image::TGADecoder();
tgaDecoder->loadStream(*data);
const Graphics::Surface *tgaSurface = tgaDecoder->getSurface();
@ -133,24 +133,25 @@ void loadTGA(Common::SeekableReadStream *data, Texture *t) {
t->_texture = nullptr;
int bpp = tgaSurface->format.bytesPerPixel;
if (bpp == 4) {
t->_colorFormat = BM_BGRA;
t->_bpp = 4;
t->_hasAlpha = true;
} else {
t->_colorFormat = BM_BGR888;
t->_bpp = 3;
t->_hasAlpha = false;
}
assert(bpp == 3 || bpp == 4); // Assure we have 24/32 bpp
// Allocate room for the texture.
t->_data = new uint8[t->_width * t->_height * (bpp)];
// Copy the texture data, as the decoder owns the current copy.
memcpy(t->_data, tgaSurface->getPixels(), t->_width * t->_height * (bpp));
t->_data = new uint8[t->_width * t->_height * 4];
t->_colorFormat = BM_RGBA;
t->_bpp = 4;
if (bpp == 4) {
t->_hasAlpha = true;
} else {
t->_hasAlpha = false;
}
#ifdef SCUMM_BIG_ENDIAN
auto newSurface = tgaSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
#else
auto newSurface = tgaSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
#endif
memcpy(t->_data, newSurface->getPixels(), t->_width * t->_height * (t->_bpp));
newSurface->free();
delete newSurface;
delete tgaDecoder;
}

View File

@ -3,7 +3,6 @@ in vec4 Color;
uniform sampler2D tex;
uniform bool textured;
uniform bool swapRandB;
uniform float alphaRef;
uniform float meshAlpha;
@ -14,10 +13,6 @@ void main()
outColor = Color;
if (textured) {
vec4 texColor = texture(tex, Texcoord);
#ifdef GL_ES
if (swapRandB)
texColor.rb = texColor.br;
#endif
outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha;
if (outColor.a < alphaRef)

View File

@ -3,7 +3,6 @@ in vec4 Color;
uniform sampler2D tex;
uniform bool textured;
uniform bool swapRandB;
uniform float alphaRef;
uniform float meshAlpha;
@ -14,10 +13,6 @@ void main()
outColor = Color;
if (textured) {
vec4 texColor = texture(tex, Texcoord);
#ifdef GL_ES
if (swapRandB)
texColor.rb = texColor.br;
#endif
outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha;
if (outColor.a < alphaRef)

View File

@ -3,7 +3,6 @@ in vec4 Color;
uniform sampler2D tex;
uniform bool textured;
uniform bool swapRandB;
uniform float alphaRef;
uniform float meshAlpha;
@ -14,10 +13,6 @@ void main()
outColor = Color;
if (textured) {
vec4 texColor = texture(tex, Texcoord);
#ifdef GL_ES
if (swapRandB)
texColor.rb = texColor.br;
#endif
outColor.rgba *= texColor.rgba;
outColor.a *= meshAlpha;
if (outColor.a < alphaRef)