[Scummvm-git-logs] scummvm master -> 3e2380b5ce3ee4068e123b8ee16fef41fef230b6

grisenti noreply at scummvm.org
Fri Nov 3 14:07:29 UTC 2023


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:
3e2380b5ce HPL1: Implement gamma correction


Commit: 3e2380b5ce3ee4068e123b8ee16fef41fef230b6
    https://github.com/scummvm/scummvm/commit/3e2380b5ce3ee4068e123b8ee16fef41fef230b6
Author: grisenti (emanuele at grisenti.net)
Date: 2023-11-03T15:07:10+01:00

Commit Message:
HPL1: Implement gamma correction

Changed paths:
  A engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.fragment
  A engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.vertex
    engines/hpl1/engine/impl/LowLevelGraphicsSDL.cpp
    engines/hpl1/engine/impl/LowLevelGraphicsSDL.h


diff --git a/engines/hpl1/engine/impl/LowLevelGraphicsSDL.cpp b/engines/hpl1/engine/impl/LowLevelGraphicsSDL.cpp
index dd9f6a957bf..0ce048733b1 100644
--- a/engines/hpl1/engine/impl/LowLevelGraphicsSDL.cpp
+++ b/engines/hpl1/engine/impl/LowLevelGraphicsSDL.cpp
@@ -37,6 +37,7 @@
 #include "hpl1/engine/system/low_level_system.h"
 
 #include "common/algorithm.h"
+#include "common/config-manager.h"
 #include "common/system.h"
 #include "engines/util.h"
 #include "hpl1/debug.h"
@@ -127,6 +128,7 @@ cLowLevelGraphicsSDL::~cLowLevelGraphicsSDL() {
 	hplFree(mpIndexArray);
 	for (int i = 0; i < MAX_TEXTUREUNITS; i++)
 		hplFree(mpTexCoordArray[i]);
+	hplDelete(_gammaCorrectionProgram);
 }
 
 bool cLowLevelGraphicsSDL::Init(int alWidth, int alHeight, int alBpp, int abFullscreen,
@@ -134,13 +136,19 @@ bool cLowLevelGraphicsSDL::Init(int alWidth, int alHeight, int alBpp, int abFull
 	mvScreenSize.x = alWidth;
 	mvScreenSize.y = alHeight;
 	mlBpp = alBpp;
-
 	mlMultisampling = alMultisampling;
 	initGraphics3d(alWidth, alHeight);
 	SetupGL();
 	ShowCursor(false);
 	// CheckMultisampleCaps();
 	g_system->updateScreen();
+
+	_gammaCorrectionProgram = CreateGpuProgram("hpl1_gamma_correction", "hpl1_gamma_correction");
+	_screenBuffer = CreateTexture(cVector2l(
+									  (int)mvScreenSize.x, (int)mvScreenSize.y),
+								  32, cColor(0, 0, 0, 0), false,
+								  eTextureType_Normal, eTextureTarget_Rect);
+
 	return true;
 }
 
@@ -580,7 +588,32 @@ void cLowLevelGraphicsSDL::DrawRect(const cVector2f &avPos, const cVector2f &avS
 void cLowLevelGraphicsSDL::FlushRendering() {
 	GL_CHECK(glFlush());
 }
+
+void cLowLevelGraphicsSDL::applyGammaCorrection() {
+	if (!_gammaCorrectionProgram)
+		return;
+
+	SetBlendActive(false);
+
+	// Copy screen to texture
+	CopyContextToTexure(_screenBuffer, 0,
+						cVector2l((int)mvScreenSize.x, (int)mvScreenSize.y));
+
+	tVertexVec vVtx;
+	vVtx.push_back(cVertex(cVector3f(-1.0, 1.0, 0), cVector2f(0, mvScreenSize.y), cColor(0)));
+	vVtx.push_back(cVertex(cVector3f(1.0, 1.0, 0), cVector2f(mvScreenSize.x, mvScreenSize.y), cColor(0)));
+	vVtx.push_back(cVertex(cVector3f(1.0, -1.0, 0), cVector2f(mvScreenSize.x, 0), cColor(0)));
+	vVtx.push_back(cVertex(cVector3f(-1.0, -1.0, 0), cVector2f(0, 0), cColor(0)));
+
+	_gammaCorrectionProgram->Bind();
+	SetTexture(0, _screenBuffer);
+	_gammaCorrectionProgram->SetFloat("gamma", mfGammaCorrection);
+	DrawQuad(vVtx);
+	_gammaCorrectionProgram->UnBind();
+}
+
 void cLowLevelGraphicsSDL::SwapBuffers() {
+	applyGammaCorrection();
 	GL_CHECK(glFlush());
 	g_system->updateScreen();
 }
diff --git a/engines/hpl1/engine/impl/LowLevelGraphicsSDL.h b/engines/hpl1/engine/impl/LowLevelGraphicsSDL.h
index 6106420e3c7..9e1710e1d36 100644
--- a/engines/hpl1/engine/impl/LowLevelGraphicsSDL.h
+++ b/engines/hpl1/engine/impl/LowLevelGraphicsSDL.h
@@ -271,12 +271,17 @@ private:
 	// Texture
 	iTexture *mpCurrentTexture[MAX_TEXTUREUNITS];
 
+	iTexture *_screenBuffer;
+	iGpuProgram *_gammaCorrectionProgram;
+
 	// CG Compiler Variables
 	// CGcontext mCG_Context;
 
 	// Multisample
 	void CheckMultisampleCaps();
 
+	void applyGammaCorrection();
+
 	// Batch helper
 	void SetUpBatchArrays();
 
diff --git a/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.fragment b/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.fragment
new file mode 100644
index 00000000000..e0f43f0ca53
--- /dev/null
+++ b/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.fragment
@@ -0,0 +1,14 @@
+// hpl1_gamma_correction.fragment
+
+in vec2 vUv;
+
+uniform sampler2DRect tex0;
+uniform float gamma;
+
+OUTPUT
+
+void main()
+{
+    vec4 color = texture2DRect(tex0, vUv);
+    outColor = vec4(pow(color.r, 1/gamma), pow(color.g, 1/gamma), pow(color.b, 1/gamma), color.a);
+}
\ No newline at end of file
diff --git a/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.vertex b/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.vertex
new file mode 100644
index 00000000000..812231c9f24
--- /dev/null
+++ b/engines/hpl1/engine/impl/shaders/hpl1_gamma_correction.vertex
@@ -0,0 +1,11 @@
+// hpl1_gamma_correction.fragment
+
+vec4 position = gl_Vertex;
+vec2 uv = gl_MultiTexCoord0.xy;
+
+out vec2 vUv;
+
+void main() {
+    gl_Position = position;
+    vUv = uv;
+}
\ No newline at end of file




More information about the Scummvm-git-logs mailing list