[Scummvm-git-logs] scummvm master -> 13fb62eb2593bc6ac801ad3de24fbbf136385a17

somaen noreply at scummvm.org
Mon Nov 30 23:55:31 UTC 2026


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
82459b0747 WATCHMAKER: Revert state changes after renderTexture()
5b8ca7e055 WATCHMAKER: Set initial state to match rSetAllStates
a590bef19b WATCHMAKER: Apply texture wrap modes on load, and match original behaviour
496a3afeec WATCHMAKER: Avoid sharing normals between mesh and body.
13fb62eb25 WATCHMAKER: Ignore the orientation during TGA load


Commit: 82459b07474ed970191ca790c4ec39db491eb3cd
    https://github.com/scummvm/scummvm/commit/82459b07474ed970191ca790c4ec39db491eb3cd
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2026-12-01T00:55:15+01:00

Commit Message:
WATCHMAKER: Revert state changes after renderTexture()

Otherwise this state change would leak into the 3D rendering,
and lead to scenes without sky being rendered with depth disabled.

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    engines/watchmaker/3d/render/opengl_2d.cpp


diff --git a/engines/watchmaker/3d/render/opengl_2d.cpp b/engines/watchmaker/3d/render/opengl_2d.cpp
index 37a82fb91a4..a90616d018c 100644
--- a/engines/watchmaker/3d/render/opengl_2d.cpp
+++ b/engines/watchmaker/3d/render/opengl_2d.cpp
@@ -143,6 +143,9 @@ bool gClipToBlitterViewport(int *sposx, int *sposy, int *sdimx, int *sdimy,
 
 void renderTexture(WGame &game, gTexture &bitmap, Common::Rect srcRect, Common::Rect dstRect) {
 	checkGlError("Entering renderTexture");
+	glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT);
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
 	glEnable(GL_TEXTURE_2D);
 	glEnable(GL_ALPHA_TEST);
 	glDisable(GL_DEPTH_TEST);
@@ -182,6 +185,8 @@ void renderTexture(WGame &game, gTexture &bitmap, Common::Rect srcRect, Common::
 
 	glEnd();
 	glFlush();
+	glPopMatrix();
+	glPopAttrib();
 	checkGlError("Exiting renderTexture");
 }
 


Commit: 5b8ca7e055bf5f0f86b712dd1a63bb2760b7d2fa
    https://github.com/scummvm/scummvm/commit/5b8ca7e055bf5f0f86b712dd1a63bb2760b7d2fa
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2026-12-01T00:55:15+01:00

Commit Message:
WATCHMAKER: Set initial state to match rSetAllStates

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    engines/watchmaker/renderer.cpp


diff --git a/engines/watchmaker/renderer.cpp b/engines/watchmaker/renderer.cpp
index ff89f3a999d..8cc0cf0a138 100644
--- a/engines/watchmaker/renderer.cpp
+++ b/engines/watchmaker/renderer.cpp
@@ -61,6 +61,14 @@ void Renderer::initGL() {
 	glFrontFace(GL_CCW);
 	//glEnable(GL_CULL_FACE); // TODO
 
+	// Default states, as set by rSetAllStates() in the original
+	glEnable(GL_DEPTH_TEST);
+	glDepthFunc(GL_LEQUAL);
+	glDepthMask(GL_TRUE);
+
+	glEnable(GL_ALPHA_TEST);
+	glAlphaFunc(GL_GREATER, 0.0f);
+
 	glClearColor(0, 0, 0, 0);
 	glViewport(0, 0, windowInfo.width, windowInfo.height);
 


Commit: a590bef19bc32498b824f32112627c2571397785
    https://github.com/scummvm/scummvm/commit/a590bef19bc32498b824f32112627c2571397785
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2026-12-01T00:55:16+01:00

Commit Message:
WATCHMAKER: Apply texture wrap modes on load, and match original behaviour

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    engines/watchmaker/3d/dds_header.h
    engines/watchmaker/3d/render/opengl_2d.cpp
    engines/watchmaker/3d/render/opengl_renderer.cpp
    engines/watchmaker/3d/render/opengl_renderer.h
    engines/watchmaker/3d/render/opengl_texture.cpp
    engines/watchmaker/3d/render/render.cpp
    engines/watchmaker/3d/t3d_body.cpp


diff --git a/engines/watchmaker/3d/dds_header.h b/engines/watchmaker/3d/dds_header.h
index 89c67b0c69c..14891531cf8 100644
--- a/engines/watchmaker/3d/dds_header.h
+++ b/engines/watchmaker/3d/dds_header.h
@@ -47,11 +47,17 @@ public:
 	virtual const void *getData() const = 0;
 };
 
+enum class TextureWrapMode {
+	WRAP,
+	CLAMP
+};
+
 class Texture {
 public:
 	virtual ~Texture() {}
 	virtual void assignData(const TextureData &data) = 0;
 	virtual void bind() = 0;
+	virtual void setWrapMode(TextureWrapMode mode) = 0;
 };
 
 
diff --git a/engines/watchmaker/3d/render/opengl_2d.cpp b/engines/watchmaker/3d/render/opengl_2d.cpp
index a90616d018c..56584df72ec 100644
--- a/engines/watchmaker/3d/render/opengl_2d.cpp
+++ b/engines/watchmaker/3d/render/opengl_2d.cpp
@@ -341,6 +341,7 @@ int rLoadBitmapImage(WGame &game, const char *TextName, unsigned char flags) {
 	applyColorKey(*surface, 0, 0, 0, false);
 	auto texData = createTextureFromSurface(*surface, GL_RGBA);
 	Texture->_texture = createGLTexture();
+	Texture->_texture->setWrapMode(TextureWrapMode::CLAMP);
 	Texture->_texture->assignData(*texData);
 	Texture->name = TextName;
 
diff --git a/engines/watchmaker/3d/render/opengl_renderer.cpp b/engines/watchmaker/3d/render/opengl_renderer.cpp
index 548c68ca8a8..d1c0f0ce392 100644
--- a/engines/watchmaker/3d/render/opengl_renderer.cpp
+++ b/engines/watchmaker/3d/render/opengl_renderer.cpp
@@ -150,22 +150,6 @@ void OpenGLRenderer::popModelView() {
 	glMatrixMode(oldMatrixMode);
 }
 
-void OpenGLRenderer::setTextureWrapMode(int index, TextureWrapMode mode) {
-	GLint openGlWrapMode = 0;
-	switch (mode) {
-	case TextureWrapMode::WRAP:
-		openGlWrapMode = GL_REPEAT;
-		break;
-	case TextureWrapMode::CLAMP:
-		openGlWrapMode = GL_CLAMP;
-		break;
-	default:
-		assert(0);
-	}
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, openGlWrapMode);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, openGlWrapMode);
-}
-
 void OpenGLRenderer::setTexture(int stage, void *texture) {
 	if (texture == nullptr) {
 		glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/engines/watchmaker/3d/render/opengl_renderer.h b/engines/watchmaker/3d/render/opengl_renderer.h
index 69d967cbe46..f76542f196f 100644
--- a/engines/watchmaker/3d/render/opengl_renderer.h
+++ b/engines/watchmaker/3d/render/opengl_renderer.h
@@ -57,11 +57,6 @@ enum class BlendFactor {
 	INVDESTCOLOR
 };
 
-enum class TextureWrapMode {
-	WRAP,
-	CLAMP
-};
-
 enum class PrimitiveType {
 	LINE,
 	TRIANGLE
@@ -92,7 +87,6 @@ public:
 	// TODO: This just maps to the D3D way to setting textures
 	void setTexture(int stage, void *texture);
 	void setTexture(int stage, const gTexture &texture);
-	void setTextureWrapMode(int index, TextureWrapMode mode);
 
 	void drawPrimitives(PrimitiveType primitiveType, Vertex *vertices, int numPrimitives);
 	void drawIndexedPrimitivesVBO(PrimitiveType primitiveType, int VBO, int firstVertex, int numVertices, uint16 *faces, uint32 numFaces);
diff --git a/engines/watchmaker/3d/render/opengl_texture.cpp b/engines/watchmaker/3d/render/opengl_texture.cpp
index c99760c64d0..5b73fb63277 100644
--- a/engines/watchmaker/3d/render/opengl_texture.cpp
+++ b/engines/watchmaker/3d/render/opengl_texture.cpp
@@ -50,16 +50,27 @@ GLuint dxtCompressionToTextureFormat(DxtCompression compression) {
 class OpenGLTexture : public Texture {
 public:
 	unsigned int _texId;
+	TextureWrapMode _wrapMode = TextureWrapMode::WRAP;
 	OpenGLTexture() {
 		glGenTextures(1, &_texId);
 	}
 	OpenGLTexture(unsigned int texId) : _texId(texId) {}
+	void applyWrapMode() {
+		GLint glWrapMode = (_wrapMode == TextureWrapMode::CLAMP) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glWrapMode);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glWrapMode);
+	}
+	void setWrapMode(TextureWrapMode mode) override {
+		_wrapMode = mode;
+		glBindTexture(GL_TEXTURE_2D, _texId);
+		applyWrapMode();
+		checkGlError("OpenGLTexture::setWrapMode");
+	}
 	void assignData(const TextureData &data) override {
 		glBindTexture(GL_TEXTURE_2D, _texId);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+		applyWrapMode();
 
 		// TODO: Check both compiletime and runtime for the existence of EXT_texture_compression_s3tc
 		GLuint texFormat = dxtCompressionToTextureFormat(data._compression);
diff --git a/engines/watchmaker/3d/render/render.cpp b/engines/watchmaker/3d/render/render.cpp
index e08dcbf5711..e0b13434e2b 100644
--- a/engines/watchmaker/3d/render/render.cpp
+++ b/engines/watchmaker/3d/render/render.cpp
@@ -135,7 +135,7 @@ void RenderGeometry() {
 	g_renderer->SetTextureStageState(1, D3DTSS_COLOROP,   D3DTOP_DISABLE);
 	g_renderer->SetTextureStageState(1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE);
 #endif
-	g_renderer->setTextureWrapMode(1, TextureWrapMode::CLAMP);
+	// Stage 1 (lightmaps) uses clamping, which is set on the lightmap textures in LoadLightmaps()
 
 	g_renderer->setRenderState(RenderState::TEXTUREFACTOR, 0xFFFFFFFF);
 	g_renderer->setRenderState(RenderState::ALPHAREF, 0x00000000);
@@ -173,7 +173,6 @@ void RenderGeometry() {
 					g_renderer->SetTextureStageState(1, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG2);
 					g_renderer->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
 #endif
-					g_renderer->setTextureWrapMode(1, TextureWrapMode::CLAMP);
 				}
 				g_renderer->setTexture(1, gTextureList[bb->Texture2]);
 			} else if (LastTexture2 > 0) {
diff --git a/engines/watchmaker/3d/t3d_body.cpp b/engines/watchmaker/3d/t3d_body.cpp
index e13263e4f33..7d10314d05c 100644
--- a/engines/watchmaker/3d/t3d_body.cpp
+++ b/engines/watchmaker/3d/t3d_body.cpp
@@ -337,6 +337,8 @@ void LoadLightmaps(WGame &game, t3dBODY *b) {
 		b->LightmapTable.push_back(mat);
 		if (!game._renderer->addMaterial(*b->LightmapTable[i], Appo, 0, 0))
 			return;
+		// The original clamps texture stage 1, which is only used for lightmaps
+		b->LightmapTable[i]->Texture->_texture->setWrapMode(TextureWrapMode::CLAMP);
 
 		b->LightmapTable[i]->clear();
 	}


Commit: 496a3afeec41da1737fad490d0c6e18fb2c30f40
    https://github.com/scummvm/scummvm/commit/496a3afeec41da1737fad490d0c6e18fb2c30f40
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2026-12-01T00:55:16+01:00

Commit Message:
WATCHMAKER: Avoid sharing normals between mesh and body.

The existing code led to adding the new objects at the wrong position,
since we didn't clear the buffer, which in turn meant that the copying
would go into the body's normals, which wasn't the intention.
The original allocates an entirely new buffer here, so this should match better.

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    engines/watchmaker/3d/t3d_body.cpp


diff --git a/engines/watchmaker/3d/t3d_body.cpp b/engines/watchmaker/3d/t3d_body.cpp
index 7d10314d05c..8efe5ae5a33 100644
--- a/engines/watchmaker/3d/t3d_body.cpp
+++ b/engines/watchmaker/3d/t3d_body.cpp
@@ -135,6 +135,8 @@ void t3dBODY::initNormals(Common::SeekableReadStream &stream) {
 #ifndef WMGEN
 		Mesh.VBptr = Mesh.VertexBuffer;
 #endif
+		// Avoid sharing normals between mesh and body
+		Mesh.NList.clear();
 		Mesh.NList.reserve(Mesh.NumVerts); // Alloca normali mesh
 		for (int k = 0; k < Mesh.NumVerts; k++) {
 			Mesh.NList.push_back(Common::SharedPtr<t3dNORMAL>(new t3dNORMAL()));


Commit: 13fb62eb2593bc6ac801ad3de24fbbf136385a17
    https://github.com/scummvm/scummvm/commit/13fb62eb2593bc6ac801ad3de24fbbf136385a17
Author: Einar Johan Trøan Sømåen (somaen at scummvm.org)
Date: 2026-12-01T00:55:16+01:00

Commit Message:
WATCHMAKER: Ignore the orientation during TGA load

The original TGA loader did not respect the TGA header's
orientation flag, instead always reading the file in the same
way. So we patch the header before passing it to the loader.

Assisted-by: Claude:claude-opus-5-5

Changed paths:
    engines/watchmaker/3d/render/opengl_2d.cpp
    engines/watchmaker/tga_util.cpp


diff --git a/engines/watchmaker/3d/render/opengl_2d.cpp b/engines/watchmaker/3d/render/opengl_2d.cpp
index 56584df72ec..460e32391b1 100644
--- a/engines/watchmaker/3d/render/opengl_2d.cpp
+++ b/engines/watchmaker/3d/render/opengl_2d.cpp
@@ -337,7 +337,7 @@ int rLoadBitmapImage(WGame &game, const char *TextName, unsigned char flags) {
 	gTexture *Texture = &game._renderer->_bitmapList.bitmaps[pos];
 	*Texture = gTexture();
 	Texture->Flags = CurLoaderFlags;
-	auto surface = ReadTgaImage(TextName, *stream, RGBA32, Texture->Flags);
+	auto surface = ReadTgaImage(TextName, *stream, RGBA32, flags & rSURFACEFLIP);
 	applyColorKey(*surface, 0, 0, 0, false);
 	auto texData = createTextureFromSurface(*surface, GL_RGBA);
 	Texture->_texture = createGLTexture();
diff --git a/engines/watchmaker/tga_util.cpp b/engines/watchmaker/tga_util.cpp
index c0684ae4581..6d30eb49747 100644
--- a/engines/watchmaker/tga_util.cpp
+++ b/engines/watchmaker/tga_util.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "watchmaker/tga_util.h"
+#include "common/memstream.h"
 #include "image/tga.h"
 #include "watchmaker/types.h"
 #include "watchmaker/render.h"
@@ -28,18 +29,27 @@
 namespace Watchmaker {
 
 Graphics::Surface *ReadTgaImage(const char *Name, Common::SeekableReadStream &stream, Graphics::PixelFormat format, unsigned int flag) {
+	const uint32 kDescriptorOffset = 17;
+	uint32 size = stream.size() - stream.pos();
+	if (size <= kDescriptorOffset) {
+		error("TGA too small: %s", Name);
+	}
+	Common::Array<byte> data(size);
+	stream.read(data.data(), size);
+	// The original ignores the origin bits and keeps the rows in file order,
+	// so mark the image as top-left origin to make the decoder do the same.
+	data[kDescriptorOffset] = (data[kDescriptorOffset] | 0x20) & ~0x10;
+	Common::MemoryReadStream patchedStream(data.data(), size);
+
 	Image::TGADecoder tgaDecoder;
-	if (!tgaDecoder.loadStream(stream)) {
+	if (!tgaDecoder.loadStream(patchedStream)) {
 		error("Failed to load TGA: %s", Name);
 	}
-	auto surface = tgaDecoder.getSurface();
-	return surface->convertTo(format);
-#if 0
-	if (flag & 1)                                                                                // read alpa byte?
-		bAlpha = 1;
-	if (flag & rSURFACEFLIP)                                                                    // flip tga orientation?
-		bFlip = 1;
-#endif
+	Graphics::Surface *surface = tgaDecoder.getSurface()->convertTo(format);
+	if (flag & rSURFACEFLIP) {
+		surface->flipVertical(Common::Rect(surface->w, surface->h));
+	}
+	return surface;
 }
 
 } // End of namespace Watchmaker




More information about the Scummvm-git-logs mailing list