From 7a782f5b24fe8b618ac582edc41deeda6689435d Mon Sep 17 00:00:00 2001 From: Matthew Duggan Date: Sat, 4 Feb 2023 16:33:35 +0900 Subject: [PATCH] TETRAEDGE: Fixes for TinyGL rendering, almost works --- engines/tetraedge/te/te_3d_texture_opengl.cpp | 4 +- engines/tetraedge/te/te_3d_texture_tinygl.cpp | 14 +++--- engines/tetraedge/te/te_mesh_tinygl.cpp | 20 ++++---- engines/tetraedge/te/te_renderer.h | 1 + engines/tetraedge/te/te_renderer_opengl.cpp | 8 +++- engines/tetraedge/te/te_renderer_opengl.h | 1 + engines/tetraedge/te/te_renderer_tinygl.cpp | 48 +++++++++++++------ engines/tetraedge/te/te_renderer_tinygl.h | 1 + 8 files changed, 63 insertions(+), 34 deletions(-) diff --git a/engines/tetraedge/te/te_3d_texture_opengl.cpp b/engines/tetraedge/te/te_3d_texture_opengl.cpp index efb352aa3c8..004baa8e471 100644 --- a/engines/tetraedge/te/te_3d_texture_opengl.cpp +++ b/engines/tetraedge/te/te_3d_texture_opengl.cpp @@ -195,8 +195,8 @@ void Te3DTextureOpenGL::update(const TeImage &img, uint xoff, uint yoff) { setAccessName(img.getAccessName().append(".3dtex")); glBindTexture(GL_TEXTURE_2D, _glTexture); - glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); - glPixelStorei(GL_UNPACK_LSB_FIRST, 0); + glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); diff --git a/engines/tetraedge/te/te_3d_texture_tinygl.cpp b/engines/tetraedge/te/te_3d_texture_tinygl.cpp index 4b00e9f5b29..71116ecb606 100644 --- a/engines/tetraedge/te/te_3d_texture_tinygl.cpp +++ b/engines/tetraedge/te/te_3d_texture_tinygl.cpp @@ -132,12 +132,13 @@ bool Te3DTextureTinyGL::load(const TeImage &img) { _texHeight = _height; tglBindTexture(TGL_TEXTURE_2D, _glTexture); + // Note: these are unsupported in TGL but should be the defaults? //tglPixelStorei(TGL_UNPACK_SWAP_BYTES, TGL_FALSE); //tglPixelStorei(TGL_UNPACK_LSB_FIRST, TGL_FALSE); //tglPixelStorei(TGL_UNPACK_ROW_LENGTH, 0); //tglPixelStorei(TGL_UNPACK_SKIP_ROWS, 0); //tglPixelStorei(TGL_UNPACK_SKIP_PIXELS, 0); - //tglPixelStorei(TGL_UNPACK_ALIGNMENT, 1); + tglPixelStorei(TGL_UNPACK_ALIGNMENT, 1); const void *imgdata = img.getPixels(); if (_format == TeImage::RGB8) { @@ -185,11 +186,12 @@ void Te3DTextureTinyGL::update(const TeImage &img, uint xoff, uint yoff) { setAccessName(img.getAccessName().append(".3dtex")); tglBindTexture(TGL_TEXTURE_2D, _glTexture); - tglPixelStorei(TGL_UNPACK_SWAP_BYTES, 0); - tglPixelStorei(TGL_UNPACK_LSB_FIRST, 0); - tglPixelStorei(TGL_UNPACK_ROW_LENGTH, 0); - tglPixelStorei(TGL_UNPACK_SKIP_ROWS, 0); - tglPixelStorei(TGL_UNPACK_SKIP_PIXELS, 0); + // Note: these are unsupported in TGL but should be the defaults? + //tglPixelStorei(TGL_UNPACK_SWAP_BYTES, TGL_FALSE); + //tglPixelStorei(TGL_UNPACK_LSB_FIRST, TGL_FALSE); + //tglPixelStorei(TGL_UNPACK_ROW_LENGTH, 0); + //tglPixelStorei(TGL_UNPACK_SKIP_ROWS, 0); + //tglPixelStorei(TGL_UNPACK_SKIP_PIXELS, 0); tglPixelStorei(TGL_UNPACK_ALIGNMENT, 1); //const void *imgdata = img.getPixels(); diff --git a/engines/tetraedge/te/te_mesh_tinygl.cpp b/engines/tetraedge/te/te_mesh_tinygl.cpp index 3f9db8ea0ca..f100363eebe 100644 --- a/engines/tetraedge/te/te_mesh_tinygl.cpp +++ b/engines/tetraedge/te/te_mesh_tinygl.cpp @@ -28,7 +28,7 @@ namespace Tetraedge { -TeMeshTinyGL::TeMeshTinyGL() : _glMeshMode(TGL_POINTS), _gltexEnvMode(TGL_MODULATE) { +TeMeshTinyGL::TeMeshTinyGL() : _glMeshMode(TGL_POINTS), _gltexEnvMode(TGL_DECAL) { } void TeMeshTinyGL::draw() { @@ -141,8 +141,8 @@ void TeMeshTinyGL::draw() { if (!renderer->scissorEnabled()) tglDisable(TGL_SCISSOR_TEST); - // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + // TODO: GL_MODULATE not supported in TGL + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); tglDisableClientState(TGL_VERTEX_ARRAY); tglDisableClientState(TGL_NORMAL_ARRAY); tglDisableClientState(TGL_COLOR_ARRAY); @@ -151,19 +151,19 @@ void TeMeshTinyGL::draw() { if (_drawWires && !normals.empty()) { renderer->disableAllLights(); - error("TODO: Properly implement _drawWires case in TeMesh::draw"); - /* + //error("TODO: Properly implement _drawWires case in TeMesh::draw"); + ///* // TODO: Reimplement without glBegin/glEnd - glBegin(TGL_LINES); + tglBegin(TGL_LINES); renderer->setCurrentColor(TeColor(255, 255, 255, 255)); for (uint i = 0; i < verticies.size(); i++) { - glVertex3f(verticies[i].x(), verticies[i].y(), verticies[i].z()); - glVertex3f(verticies[i].x() + normals[i].x(), + tglVertex3f(verticies[i].x(), verticies[i].y(), verticies[i].z()); + tglVertex3f(verticies[i].x() + normals[i].x(), verticies[i].y() + normals[i].y(), verticies[i].z() + normals[i].z()); } - glEnd(); - */ + tglEnd(); + //*/ } renderer->setMatrixMode(TeRenderer::MM_GL_MODELVIEW); diff --git a/engines/tetraedge/te/te_renderer.h b/engines/tetraedge/te/te_renderer.h index 4b72f6e6ca1..edb46d14c5d 100644 --- a/engines/tetraedge/te/te_renderer.h +++ b/engines/tetraedge/te/te_renderer.h @@ -134,6 +134,7 @@ public: void dumpTransparentMeshData() const; const TeColor ¤tColor() const { return _currentColor; } + virtual void updateScreen() = 0; virtual void updateGlobalLight() = 0; virtual void applyMaterial(const TeMaterial &m) = 0; diff --git a/engines/tetraedge/te/te_renderer_opengl.cpp b/engines/tetraedge/te/te_renderer_opengl.cpp index a4be743d8c0..4a14b3dc2f2 100644 --- a/engines/tetraedge/te/te_renderer_opengl.cpp +++ b/engines/tetraedge/te/te_renderer_opengl.cpp @@ -21,6 +21,7 @@ #include "common/textconsole.h" #include "common/debug.h" +#include "common/system.h" #include "graphics/opengl/system_headers.h" @@ -99,7 +100,8 @@ void TeRendererOpenGL::init(uint width, uint height) { // Note: original doesn't separate but blends are nicer that way. glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE); + // Original does this, probably not needed? + //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE); glClearDepth(1.0); glClearStencil(0); _clearColor = TeColor(0, 0, 0, 255); @@ -382,6 +384,10 @@ void TeRendererOpenGL::updateGlobalLight() { TeLightOpenGL::updateGlobal(); } +void TeRendererOpenGL::updateScreen() { + g_system->updateScreen(); +} + Common::String TeRendererOpenGL::vendor() { return Common::String((const char *)glGetString(GL_VENDOR)); } diff --git a/engines/tetraedge/te/te_renderer_opengl.h b/engines/tetraedge/te/te_renderer_opengl.h index 7bdd43ab1c2..128bce82663 100644 --- a/engines/tetraedge/te/te_renderer_opengl.h +++ b/engines/tetraedge/te/te_renderer_opengl.h @@ -54,6 +54,7 @@ public: Common::String vendor() override; void applyMaterial(const TeMaterial &m) override; void updateGlobalLight() override; + void updateScreen() override; protected: diff --git a/engines/tetraedge/te/te_renderer_tinygl.cpp b/engines/tetraedge/te/te_renderer_tinygl.cpp index 8bd830f305c..a82b25a1055 100644 --- a/engines/tetraedge/te/te_renderer_tinygl.cpp +++ b/engines/tetraedge/te/te_renderer_tinygl.cpp @@ -90,9 +90,9 @@ void TeRendererTinyGL::enableZBuffer() { } void TeRendererTinyGL::init(uint width, uint height) { - Graphics::PixelFormat pixelFormat = g_system->getScreenFormat(); - initGraphics(width, height, &pixelFormat); + initGraphics(width, height, nullptr); + const Graphics::PixelFormat pixelFormat = g_system->getScreenFormat(); debug(2, "INFO: TinyGL front buffer pixel format: %s", pixelFormat.toString().c_str()); TinyGL::createContext(width, height, pixelFormat, 256, true, ConfMan.getBool("dirtyrects")); @@ -107,9 +107,10 @@ void TeRendererTinyGL::init(uint width, uint height) { tglEnable(TGL_BLEND); tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA); tglDepthFunc(TGL_LEQUAL); - tglHint(TGL_PERSPECTIVE_CORRECTION_HINT, TGL_DONT_CARE); + // Original does this, probably not needed? + //tglHint(TGL_PERSPECTIVE_CORRECTION_HINT, TGL_DONT_CARE); tglClearDepth(1.0); - tglClearStencil(0); + //tglClearStencil(0); _clearColor = TeColor(0, 0, 0, 255); tglClearColor(0, 0, 0, 1.0); //TeOpenGLExtensions::loadExtensions(); // this does nothing in the game? @@ -196,7 +197,7 @@ void TeRendererTinyGL::renderTransparentMeshes() { if (meshProperties._scissorEnabled) { tglEnable(TGL_SCISSOR_TEST); - // No scissoring in TGL.. + // TODO: No scissoring in TGL.. /* tglScissor(meshProperties._scissorX, meshProperties._scissorY, @@ -204,7 +205,7 @@ void TeRendererTinyGL::renderTransparentMeshes() { meshProperties._scissorHeight);*/ } // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, meshProperties._glTexEnvMode); + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL/*meshProperties._glTexEnvMode*/); tglDrawElements(TGL_TRIANGLES, meshProperties._vertexCount, TGL_UNSIGNED_SHORT, _transparentMeshVertexNums.data() + vertsDrawn); @@ -215,7 +216,7 @@ void TeRendererTinyGL::renderTransparentMeshes() { tglEnableClientState(TGL_COLOR_ARRAY); } // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); if (meshProperties._scissorEnabled) { tglDisable(TGL_SCISSOR_TEST); } @@ -328,8 +329,8 @@ void TeRendererTinyGL::applyMaterial(const TeMaterial &m) { tglTexEnvi(TGL_TEXTURE_ENV, TGL_OPERAND0_ALPHA, TGL_SRC_ALPHA); */ } else { - // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + // TODO: GL_MODULATE supported in TGL + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); if (m._mode != TeMaterial::MaterialMode1) { tglEnable(TGL_ALPHA_TEST); tglAlphaFunc(TGL_GREATER, 0.5); @@ -360,8 +361,8 @@ void TeRendererTinyGL::applyMaterial(const TeMaterial &m) { static const float fullColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; TeLightTinyGL::disableAll(); tglDisable(TGL_ALPHA_TEST); - // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + // TODO: GL_MODULATE not supported in TGL + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); tglMaterialfv(TGL_FRONT_AND_BACK, TGL_AMBIENT, fullColor); tglMaterialfv(TGL_FRONT_AND_BACK, TGL_DIFFUSE, fullColor); tglMaterialfv(TGL_FRONT_AND_BACK, TGL_SPECULAR, fullColor); @@ -374,8 +375,8 @@ void TeRendererTinyGL::applyMaterial(const TeMaterial &m) { tglDisable(TGL_TEXTURE_GEN_R); tglDisable(TGL_TEXTURE_GEN_Q); } else { - // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + // TODO: GL_MODULATE not supported in TGL + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); tglEnable(TGL_TEXTURE_GEN_S); tglEnable(TGL_TEXTURE_GEN_T); tglEnable(TGL_TEXTURE_GEN_R); @@ -384,8 +385,8 @@ void TeRendererTinyGL::applyMaterial(const TeMaterial &m) { TeLightTinyGL::disableAll(); tglDisable(TGL_ALPHA_TEST); enableTexture(); - // TODO: not supported in TGL - //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_MODULATE); + // TODO: GL_MODULATE not supported in TGL + //tglTexEnvi(TGL_TEXTURE_ENV, TGL_TEXTURE_ENV_MODE, TGL_DECAL); const float diffuse[4] = { m._diffuseColor.r() / 255.0f, m._diffuseColor.g() / 255.0f, m._diffuseColor.b() / 255.0f, m._diffuseColor.a() / 255.0f }; @@ -401,6 +402,23 @@ void TeRendererTinyGL::updateGlobalLight() { TeLightTinyGL::updateGlobal(); } +void TeRendererTinyGL::updateScreen() { + Common::List dirtyAreas; + TinyGL::presentBuffer(dirtyAreas); + + Graphics::Surface glBuffer; + TinyGL::getSurfaceRef(glBuffer); + + if (!dirtyAreas.empty()) { + for (Common::List::iterator itRect = dirtyAreas.begin(); itRect != dirtyAreas.end(); ++itRect) { + g_system->copyRectToScreen(glBuffer.getBasePtr((*itRect).left, (*itRect).top), glBuffer.pitch, + (*itRect).left, (*itRect).top, (*itRect).width(), (*itRect).height()); + } + } + + g_system->updateScreen(); +} + Common::String TeRendererTinyGL::vendor() { return "TinyGL vendor"; } diff --git a/engines/tetraedge/te/te_renderer_tinygl.h b/engines/tetraedge/te/te_renderer_tinygl.h index 60db224e5b0..209591e5224 100644 --- a/engines/tetraedge/te/te_renderer_tinygl.h +++ b/engines/tetraedge/te/te_renderer_tinygl.h @@ -54,6 +54,7 @@ public: void shadowMode(enum ShadowMode mode) override; void applyMaterial(const TeMaterial &m) override; void updateGlobalLight() override; + void updateScreen() override; Common::String vendor() override; protected: