Skip to content

Commit 2294c43

Browse files
committed
fix(ApiGL): normalised frame buffer to sRGB
1 parent 7b2c4af commit 2294c43

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/examples/demo/DemoApp.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ class DemoApp : public system::BaseApp
119119
inline int Run() override
120120
{
121121
const uint32_t width = 1280, height = 720;
122-
std::shared_ptr<system::WindowingGLFW> windowing = std::make_shared<system::WindowingGLFW>(width, height, false);
122+
std::shared_ptr<system::WindowingGLFW> windowing = std::make_shared<system::WindowingGLFW>(width, height, true);
123123

124-
gfx::GraphicsApiVkOptions options = {};
124+
gfx::GraphicsApiGLOptions options = {};
125125
options.mainViewport = {width, height};
126-
options.windowingPtr = windowing;
126+
// options.windowingPtr = windowing;
127127

128-
// windowing->SetAsCurrentContext();
128+
windowing->SetAsCurrentContext();
129129

130130
// Create new graphics engine instance
131131
gfx::GraphicsEngine engine(&options, windowing);
@@ -142,23 +142,22 @@ class DemoApp : public system::BaseApp
142142
fragShaderSrc = system::FileSystem::Read("../../Content/GLSL/Unlit/RGBVertex_GL.frag"),
143143
vertShaderSrc2 = system::FileSystem::Read("../../Content/GLSL/Unlit/SolidColour.vert"),
144144
fragShaderSrc2 = system::FileSystem::Read("../../Content/GLSL/Unlit/SolidColour.frag");
145-
/*gfx::ShaderCompiledResult
145+
gfx::ShaderCompiledResult
146146
vertShader = gfx::ShaderCompilerGLSL::Singleton().CompileShader(vertShaderSrc.c_str(), vertShaderSrc.length(), gfx::VertexShader),
147147
fragShader = gfx::ShaderCompilerGLSL::Singleton().CompileShader(fragShaderSrc.c_str(), fragShaderSrc.length(), gfx::FragmentShader),
148148
vertShader2 = gfx::ShaderCompilerGLSL::Singleton().CompileShader(vertShaderSrc2.c_str(), vertShaderSrc2.length(), gfx::VertexShader),
149149
fragShader2 = gfx::ShaderCompilerGLSL::Singleton().CompileShader(fragShaderSrc2.c_str(), fragShaderSrc2.length(), gfx::FragmentShader);
150150

151-
*/
152151
// Register shader with the API.
153-
auto& api = engine.GetApi<gfx::GraphicsApiVk>();
152+
auto& api = engine.GetApi<gfx::GraphicsApiGL>();
154153
engine.GetSceneGraph().SetCamera(&m_Camera);
155154

156155
lepus::gfx::Material baseMaterial, otherMaterial;
157-
// lepus::gfx::GLShader baseShader(lepus::gfx::ShaderInfo("RGBVertex")), redShader(lepus::gfx::ShaderInfo("SolidColour"));
158-
/*baseShader.SetGLProgram(gfx::ShaderCompilerGLSL::Singleton().BuildProgram(vertShader, fragShader));
156+
lepus::gfx::GLShader baseShader(lepus::gfx::ShaderInfo("RGBVertex")), redShader(lepus::gfx::ShaderInfo("SolidColour"));
157+
baseShader.SetGLProgram(gfx::ShaderCompilerGLSL::Singleton().BuildProgram(vertShader, fragShader));
159158
redShader.SetGLProgram(gfx::ShaderCompilerGLSL::Singleton().BuildProgram(vertShader2, fragShader2));
160159
baseMaterial.SetShader(&baseShader);
161-
otherMaterial.SetShader(&redShader);*/
160+
otherMaterial.SetShader(&redShader);
162161

163162
types::Vector3 baseColour(1.f, 1.f, 1.f);
164163
auto baseColourIndex = otherMaterial.Attributes().Add<const types::Vector3&>("colour", baseColour);
@@ -168,7 +167,7 @@ class DemoApp : public system::BaseApp
168167
m_Camera.Transform().Origin(m_Camera.Transform().Forward() * -2.f);
169168

170169
// Instantiate two Renderables in the scene graph, each with its own transform, using the same cube mesh data.
171-
auto cubeMesh = static_cast<lepus::gfx::VkMesh*>(engine.CreateMesh(lepus::utility::Primitives::Cube()));
170+
auto cubeMesh = static_cast<lepus::gfx::GLMesh*>(engine.CreateMesh(lepus::utility::Primitives::Cube()));
172171
auto cube = lepus::gfx::Renderable(cubeMesh, lepus::math::Transform(), baseMaterial);
173172
auto cube2 = lepus::gfx::Renderable(cubeMesh, lepus::math::Transform(), otherMaterial);
174173
auto cube3 = lepus::gfx::Renderable(cubeMesh, lepus::math::Transform(), otherMaterial);

src/lepus/gfx/GraphicsEngine/Apis/ApiGL/ApiGL.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void GraphicsApiGL::CreatePipeline()
4646
glEnable(GL_CULL_FACE);
4747
glCullFace(GL_FRONT);
4848
glFrontFace(GL_CCW);
49+
glEnable(GL_FRAMEBUFFER_SRGB);
4950
}
5051

5152
void GraphicsApiGL::UpdateUniforms(const SceneGraph& scene)
@@ -169,7 +170,9 @@ void GraphicsApiGL::Draw(const SceneGraph& scene)
169170

170171
void GraphicsApiGL::ClearFrameBuffer(float r, float g, float b)
171172
{
172-
glClearColor(r, g, b, 1.f);
173+
// Adjust for OpenGL's sRGB mapping (gamma correction)
174+
const float gamma = 2.2f;
175+
glClearColor(powf(r, gamma), powf(g, gamma), powf(b, gamma), 1.f);
173176
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
174177
}
175178

0 commit comments

Comments
 (0)