Skip to content

Commit

Permalink
Merge pull request #93 from legacyclonk/gamma_shader
Browse files Browse the repository at this point in the history
StdGL: Move gamma calculation to shaders if shaders are enabled
  • Loading branch information
Fulgen301 authored Sep 10, 2024
2 parents b98d764 + 78bf2c6 commit 3dc4420
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/C4Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void C4ConfigGraphics::CompileFunc(StdCompiler *pComp)
#endif

pComp->Value(mkNamingAdapt(ShowFolderMaps, "ShowFolderMaps", true));
pComp->Value(mkNamingAdapt(UseShaderGamma, "UseShaderGamma", true));
}

void C4ConfigSound::CompileFunc(StdCompiler *pComp)
Expand Down
1 change: 1 addition & 0 deletions src/C4Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class C4ConfigGraphics
int PositionY;
#endif
bool ShowFolderMaps; // if true, folder maps are shown
bool UseShaderGamma; // whether to use shader-based gamma correction

void CompileFunc(StdCompiler *pComp);
};
Expand Down
2 changes: 1 addition & 1 deletion src/C4Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ bool C4Game::SaveGameTitle(C4Group &hGroup)
0.0f, 0.0f, float(Application.DDraw->lpBack->Wdt), float(Application.DDraw->lpBack->Hgt),
surface.get(), 0, 0, surfaceWidth, surfaceHeight);

if (!surface->SavePNG(Config.AtTempPath(C4CFN_TempTitle), false, true, false))
if (!surface->SavePNG(Config.AtTempPath(C4CFN_TempTitle), false, !Config.Graphics.Shader, false))
{
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions src/C4GraphicsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ bool C4GraphicsSystem::DoSaveScreenshot(bool fSaveAll, const char *szFilename)
// transfer each pixel - slooow...
for (int32_t iY2 = 0; iY2 < bkHgt2; ++iY2)
for (int32_t iX2 = 0; iX2 < bkWdt2; ++iX2)
bmp.SetPixel24(iRealX + iX2, iRealY + iY2, Application.DDraw->ApplyGammaTo(Application.DDraw->lpBack->GetPixDw(iX2, iY2, false, scale)));
{
const std::uint32_t pixel{Application.DDraw->lpBack->GetPixDw(iX2, iY2, false, scale)};
bmp.SetPixel24(iRealX + iX2, iRealY + iY2, Config.Graphics.Shader ? pixel : Application.DDraw->ApplyGammaTo(pixel));
}
// done; unlock
Application.DDraw->lpBack->Unlock();
}
Expand All @@ -597,7 +600,7 @@ bool C4GraphicsSystem::DoSaveScreenshot(bool fSaveAll, const char *szFilename)
return true;
}
// Save primary surface
return Application.DDraw->lpBack->SavePNG(szFilename, false, true, false, scale);
return Application.DDraw->lpBack->SavePNG(szFilename, false, !Config.Graphics.Shader, false, scale);
}

void C4GraphicsSystem::DeactivateDebugOutput()
Expand Down
1 change: 1 addition & 0 deletions src/StdDDraw2.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class CStdShaderProgram
bool AddShader(CStdShader *shader);

virtual void Link() = 0;
virtual void Validate() = 0;
void Select();
static void Deselect();
virtual void Clear();
Expand Down
Loading

0 comments on commit 3dc4420

Please sign in to comment.