Skip to content

Commit 8a44a1c

Browse files
committed
Fix: Wrong phong renderer mesh transform
1 parent 57ea44c commit 8a44a1c

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ void OpenGLAPI::startUp() {
6868
nullptr);
6969
#endif // ATTA_DEBUG_BUILD
7070

71-
// Enable cubemap seamless if supported
71+
// Enable cubemap seamless if supported (desktop OpenGL only, not available in WebGL/GLES)
72+
#ifndef ATTA_OS_WEB
7273
if (_apiVersion >= 320)
7374
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
75+
#endif
7476

7577
glEnable(GL_DEPTH_TEST);
7678
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ std::string Shader::generateApiCode(ShaderType type, std::string iCode) {
3333
apiCode = "#version 330 core\n";
3434
} else if (openGLVersion >= 300) {
3535
apiCode = "#version 300 es\n"
36-
"precision mediump float;\n";
36+
"precision highp float;\n"
37+
"precision highp int;\n";
3738
} else {
3839
LOG_ERROR("gfx::gl::Shader", "Compiling shaders for OpenGL version [w]$0[] is not supported", openGLVersion);
3940
return "";
@@ -71,6 +72,11 @@ std::string Shader::generateApiCode(ShaderType type, std::string iCode) {
7172
// Move to the next match
7273
start = match.suffix().first;
7374
}
75+
76+
// Strip f/F suffix from float literals for GLSL ES (e.g. 1.0f -> 1.0)
77+
if (openGLVersion < 330)
78+
apiCode = std::regex_replace(apiCode, std::regex(R"((\d+\.\d*)[fF]\b)"), "$1");
79+
7480
// LOG_DEBUG("gfx::gl::Shader", "Generated API code for shader [g]$1[]\n[w]$0[]", apiCode, _file.string());
7581

7682
return apiCode;

src/atta/graphics/renderers/phongRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void PhongRenderer::render(std::shared_ptr<Camera> camera) {
110110
int i = numPointLights++;
111111
_geometryPipeline->setVec3(("uPointLights[" + std::to_string(i) + "].position").c_str(), position);
112112
_geometryPipeline->setVec3(("uPointLights[" + std::to_string(i) + "].intensity").c_str(), pl->intensity);
113+
} else if (pl) {
114+
LOG_WARN("gfx::PhongRenderer", "Maximum number of point lights reached, 10 lights");
113115
}
114116
if (dl) {
115117
hasDirectionalLight = true;
@@ -118,8 +120,6 @@ void PhongRenderer::render(std::shared_ptr<Camera> camera) {
118120
_geometryPipeline->setVec3("uDirectionalLight.direction", direction);
119121
_geometryPipeline->setVec3("uDirectionalLight.intensity", dl->intensity);
120122
}
121-
if (numPointLights++ == 10)
122-
LOG_WARN("gfx::PhongRenderer", "Maximum number of point lights reached, 10 lights");
123123
}
124124
}
125125
_geometryPipeline->setInt("uNumPointLights", numPointLights);

src/atta/graphics/shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ std::string Shader::generateICode(ShaderType type, std::string aslCode) {
175175
for (size_t i = 0; i < _vertexLayout.getElements().size(); i++) {
176176
BufferLayout::Element element = _vertexLayout.getElements()[i];
177177
std::string typeStr = BufferLayout::Element::typeToString(element.type);
178-
input += "in " + typeStr + " " + element.name + ";\n";
178+
input += "layout(location = " + std::to_string(i) + ") in " + typeStr + " " + element.name + ";\n";
179179
params += element.name;
180180
if (i != _vertexLayout.getElements().size() - 1)
181181
params += ", ";

0 commit comments

Comments
 (0)