[Scummvm-git-logs] scummvm master -> 8576ca1dddf789cf7664c06cd2140d7a503ad321
lephilousophe
noreply at scummvm.org
Sun Feb 16 15:11:20 UTC 2025
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:
8576ca1ddd FREESCAPE: Implement skybox for opengl with shaders
Commit: 8576ca1dddf789cf7664c06cd2140d7a503ad321
https://github.com/scummvm/scummvm/commit/8576ca1dddf789cf7664c06cd2140d7a503ad321
Author: cmd05 (splendid.snippet670 at slmail.me)
Date: 2025-02-16T16:11:16+01:00
Commit Message:
FREESCAPE: Implement skybox for opengl with shaders
Changed paths:
A engines/freescape/shaders/freescape_cubemap.fragment
A engines/freescape/shaders/freescape_cubemap.vertex
engines/freescape/gfx.h
engines/freescape/gfx_opengl_shaders.cpp
engines/freescape/gfx_opengl_shaders.h
diff --git a/engines/freescape/gfx.h b/engines/freescape/gfx.h
index 6ac1d58f625..3c6884d097c 100644
--- a/engines/freescape/gfx.h
+++ b/engines/freescape/gfx.h
@@ -238,6 +238,20 @@ public:
{ 81280.0f, -8128.0f, -81280.0f },//4
};
+ unsigned int _skyIndices[24] = {
+ 0, 1, 2, // front
+ 0, 2, 3,
+
+ 4, 5, 6, // back
+ 4, 6, 7,
+
+ 8, 9, 10, // left
+ 8, 10, 11,
+
+ 12, 13, 14, // right
+ 12, 14, 15,
+ };
+
byte *_palette;
void setColorMap(ColorMap *colorMap_);
ColorMap *_colorMap;
diff --git a/engines/freescape/gfx_opengl_shaders.cpp b/engines/freescape/gfx_opengl_shaders.cpp
index aa7a2c224bc..cb9d188876a 100644
--- a/engines/freescape/gfx_opengl_shaders.cpp
+++ b/engines/freescape/gfx_opengl_shaders.cpp
@@ -52,6 +52,11 @@ OpenGLShaderRenderer::OpenGLShaderRenderer(int screenW, int screenH, Common::Ren
_bitmapShader = nullptr;
_bitmapVBO = 0;
+ _cubemapShader = nullptr;
+ _cubemapVertVBO = 0;
+ _cubemapTexCoordVBO = 0;
+ _cubemapEBO = 0;
+
_texturePixelFormat = getRGBAPixelFormat();
_isAccelerated = true;
}
@@ -61,6 +66,10 @@ OpenGLShaderRenderer::~OpenGLShaderRenderer() {
delete _triangleShader;
OpenGL::Shader::freeBuffer(_bitmapVBO);
delete _bitmapShader;
+ OpenGL::Shader::freeBuffer(_cubemapVertVBO);
+ OpenGL::Shader::freeBuffer(_cubemapTexCoordVBO);
+ OpenGL::Shader::freeBuffer(_cubemapEBO);
+ delete _cubemapShader;
free(_verts);
}
@@ -95,6 +104,15 @@ void OpenGLShaderRenderer::init() {
_bitmapShader->enableVertexAttribute("position", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
_bitmapShader->enableVertexAttribute("texcoord", _bitmapVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
+ static const char *cubemapAttributes[] = { "position", "texcoord", nullptr };
+ _cubemapShader = OpenGL::Shader::fromFiles("freescape_cubemap", cubemapAttributes);
+ _cubemapVertVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(_skyVertices), _skyVertices);
+ _cubemapTexCoordVBO = OpenGL::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(_skyUvs1008), _skyUvs1008);
+ _cubemapEBO = OpenGL::Shader::createBuffer(GL_ELEMENT_ARRAY_BUFFER, sizeof(_skyIndices), _skyIndices);
+
+ _cubemapShader->enableVertexAttribute("position", _cubemapVertVBO, 3, GL_FLOAT, GL_TRUE, 3 * sizeof(float), 0);
+ _cubemapShader->enableVertexAttribute("texcoord", _cubemapTexCoordVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
+
// populate default stipple data for shader rendering
for(int i = 0; i < 128; i++)
_defaultShaderStippleArray[i] = _defaultStippleArray[i];
@@ -140,6 +158,45 @@ void OpenGLShaderRenderer::drawTexturedRect2D(const Common::Rect &screenRect, co
_bitmapShader->unbind();
}
+void OpenGLShaderRenderer::drawSkybox(Texture *texture, Math::Vector3d camera) {
+ OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
+
+ Math::Matrix4 proj = _projectionMatrix;
+ Math::Matrix4 model = _modelViewMatrix;
+ // remove translation
+ model(3, 0) = 0.0f;
+ model(3, 1) = 0.0f;
+ model(3, 2) = 0.0f;
+
+ proj.transpose();
+ model.transpose();
+
+ Math::Matrix4 skyboxMVP = proj * model;
+ skyboxMVP.transpose();
+
+ _cubemapShader->use();
+ _cubemapShader->setUniform("mvpMatrix", skyboxMVP);
+
+ glDisable(GL_DEPTH_TEST);
+
+ glBindBuffer(GL_ARRAY_BUFFER, _cubemapTexCoordVBO);
+ if (texture->_width == 1008)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(_skyUvs1008), _skyUvs1008, GL_DYNAMIC_DRAW);
+ else if (texture->_width == 128)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(_skyUvs128), _skyUvs128, GL_DYNAMIC_DRAW);
+ else
+ error("Unsupported skybox texture width %d", texture->_width);
+
+ glBindTexture(GL_TEXTURE_2D, glTexture->_id);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+
+ glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, 0);
+
+ glEnable(GL_DEPTH_TEST);
+
+ _cubemapShader->unbind();
+}
+
void OpenGLShaderRenderer::updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) {
float xmaxValue = nearClipPlane * tan(Math::deg2rad(fov) / 2);
float ymaxValue = xmaxValue / aspectRatio;
diff --git a/engines/freescape/gfx_opengl_shaders.h b/engines/freescape/gfx_opengl_shaders.h
index eacd556f9b7..38252a69954 100644
--- a/engines/freescape/gfx_opengl_shaders.h
+++ b/engines/freescape/gfx_opengl_shaders.h
@@ -60,8 +60,12 @@ public:
OpenGL::Shader *_triangleShader;
OpenGL::Shader *_bitmapShader;
+ OpenGL::Shader *_cubemapShader;
GLuint _triangleVBO;
GLuint _bitmapVBO;
+ GLuint _cubemapVertVBO;
+ GLuint _cubemapTexCoordVBO;
+ GLuint _cubemapEBO;
int _defaultShaderStippleArray[128];
int _variableStippleArray[128];
@@ -88,6 +92,7 @@ public:
virtual void renderPlayerShootBall(byte color, const Common::Point position, int frame, const Common::Rect viewPort) override;
virtual void renderPlayerShootRay(byte color, const Common::Point position, const Common::Rect viewPort) override;
void drawCelestialBody(Math::Vector3d position, float radius, uint8 color) override;
+ void drawSkybox(Texture *texture, Math::Vector3d camera) override;
virtual void renderCrossair(const Common::Point crossairPosition) override;
diff --git a/engines/freescape/shaders/freescape_cubemap.fragment b/engines/freescape/shaders/freescape_cubemap.fragment
new file mode 100644
index 00000000000..321b5da7b2c
--- /dev/null
+++ b/engines/freescape/shaders/freescape_cubemap.fragment
@@ -0,0 +1,10 @@
+in vec2 TexCoord;
+
+OUTPUT
+
+uniform sampler2D skyTexture;
+
+void main()
+{
+ outColor = texture(skyTexture, TexCoord);
+}
diff --git a/engines/freescape/shaders/freescape_cubemap.vertex b/engines/freescape/shaders/freescape_cubemap.vertex
new file mode 100644
index 00000000000..97203741f2e
--- /dev/null
+++ b/engines/freescape/shaders/freescape_cubemap.vertex
@@ -0,0 +1,11 @@
+in vec3 position;
+in vec2 texcoord;
+
+uniform mat4 mvpMatrix;
+out vec2 TexCoord;
+
+void main()
+{
+ TexCoord = texcoord;
+ gl_Position = mvpMatrix * vec4(position, 1.0);
+}
More information about the Scummvm-git-logs
mailing list