Skip to content

Commit d0c8294

Browse files
committed
Fix: Use right OpenGL version in GLSL code
1 parent 06fb34c commit d0c8294

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/atta/graphics/apis/openGL/shader.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,21 @@ Shader::~Shader() {
2626
}
2727

2828
std::string Shader::generateApiCode(ShaderType type, std::string iCode) {
29-
std::string apiCode = "#version 300 es\n"
30-
"precision mediump float;\n" +
31-
iCode;
29+
uint32_t openGLVersion = gfx::getGraphicsAPI()->getAPIVersion();
30+
std::string apiCode;
31+
32+
if (openGLVersion >= 410) {
33+
// macOS (OpenGL Core 4.1)
34+
apiCode = "#version 410 core\n";
35+
} else if (openGLVersion >= 300 && openGLVersion < 400) {
36+
// OpenGL ES (Linux, Android, Web)
37+
apiCode = "#version 300 es\n"
38+
"precision mediump float;\n";
39+
} else {
40+
// Default fallback (use OpenGL 3.0 if nothing else works)
41+
apiCode = "#version 300 core\n";
42+
}
43+
apiCode += iCode;
3244

3345
// Replace perFrame/perDraw
3446
apiCode = std::regex_replace(apiCode, std::regex(R"(\b(perFrame|perDraw))"), "uniform");

0 commit comments

Comments
 (0)