[Scummvm-git-logs] scummvm master -> 66bc1955e876636dc12611b6a574bbd1204f6d82
aquadran
noreply at scummvm.org
Sat Dec 4 21:21:18 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
66bc1955e8 GRIM: Cleanup pixel formats for textures
Commit: 66bc1955e876636dc12611b6a574bbd1204f6d82
https://github.com/scummvm/scummvm/commit/66bc1955e876636dc12611b6a574bbd1204f6d82
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-12-04T22:21:12+01:00
Commit Message:
GRIM: Cleanup pixel formats for textures
Changed paths:
engines/grim/gfx_opengl.cpp
engines/grim/gfx_opengl_shaders.cpp
engines/grim/gfx_tinygl.cpp
engines/grim/material.cpp
engines/grim/shaders/emi_actor.fragment
engines/grim/shaders/emi_actorlights.fragment
engines/grim/shaders/emi_sprite.fragment
diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp
index 0a76ce0f8b..e5300b660d 100644
--- a/engines/grim/gfx_opengl.cpp
+++ b/engines/grim/gfx_opengl.cpp
@@ -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;
}
diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp
index b54ce431cf..af3a218e8c 100644
--- a/engines/grim/gfx_opengl_shaders.cpp
+++ b/engines/grim/gfx_opengl_shaders.cpp
@@ -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;
}
diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp
index cda5ec2438..390f7bcfa4 100644
--- a/engines/grim/gfx_tinygl.cpp
+++ b/engines/grim/gfx_tinygl.cpp
@@ -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;
}
diff --git a/engines/grim/material.cpp b/engines/grim/material.cpp
index c62969d07d..11a6d0a70d 100644
--- a/engines/grim/material.cpp
+++ b/engines/grim/material.cpp
@@ -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;
+ assert(bpp == 3 || bpp == 4); // Assure we have 24/32 bpp
+
+ // Allocate room for the texture.
+ t->_data = new uint8[t->_width * t->_height * 4];
+ t->_colorFormat = BM_RGBA;
+ t->_bpp = 4;
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));
-
+#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;
}
diff --git a/engines/grim/shaders/emi_actor.fragment b/engines/grim/shaders/emi_actor.fragment
index fc4e957e34..7616331a0e 100644
--- a/engines/grim/shaders/emi_actor.fragment
+++ b/engines/grim/shaders/emi_actor.fragment
@@ -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)
diff --git a/engines/grim/shaders/emi_actorlights.fragment b/engines/grim/shaders/emi_actorlights.fragment
index fc4e957e34..7616331a0e 100644
--- a/engines/grim/shaders/emi_actorlights.fragment
+++ b/engines/grim/shaders/emi_actorlights.fragment
@@ -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)
diff --git a/engines/grim/shaders/emi_sprite.fragment b/engines/grim/shaders/emi_sprite.fragment
index fc4e957e34..7616331a0e 100644
--- a/engines/grim/shaders/emi_sprite.fragment
+++ b/engines/grim/shaders/emi_sprite.fragment
@@ -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)
More information about the Scummvm-git-logs
mailing list