hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/platform/opengl/opengl_shader.cpp43
-rw-r--r--src/platform/opengl/opengl_shader.h1
-rw-r--r--src/platform/opengl/opengl_texture.cpp4
3 files changed, 33 insertions, 15 deletions
diff --git a/src/platform/opengl/opengl_shader.cpp b/src/platform/opengl/opengl_shader.cpp
index ddcd5e2..e7c3d6a 100644
--- a/src/platform/opengl/opengl_shader.cpp
+++ b/src/platform/opengl/opengl_shader.cpp
@@ -19,9 +19,26 @@ namespace Donut
return 0;
}
+ static std::string ResolveShaderPath(const std::string& filepath)
+ {
+ size_t slash = filepath.find_last_of("/\\");
+ std::string dir = (slash == std::string::npos) ? std::string() : filepath.substr(0, slash + 1);
+ std::string file = (slash == std::string::npos) ? filepath : filepath.substr(slash + 1);
+ size_t dot = file.rfind('.');
+ std::string base = (dot == std::string::npos) ? file : file.substr(0, dot);
+
+ std::string generated = dir + "generated/" + base + ".glsl";
+ std::ifstream test(generated);
+ if (test.good())
+ return generated;
+ return filepath;
+ }
+
OpenGLShader::OpenGLShader(const std::string& filepath)
{
- std::string source = read_file(filepath);
+ std::string resolved = ResolveShaderPath(filepath);
+ m_is_slang = (resolved != filepath);
+ std::string source = read_file(resolved);
auto shader_sources = pre_process(source);
compile(shader_sources);
@@ -33,7 +50,7 @@ namespace Donut
}
OpenGLShader::OpenGLShader(const std::string& name, const std::string& vertex_src, const std::string& fragment_src)
- : m_name(name)
+ : m_name(name)
{
std::unordered_map<uint32_t, std::string> sources;
sources[GL_VERTEX_SHADER] = vertex_src;
@@ -42,7 +59,7 @@ namespace Donut
}
OpenGLShader::OpenGLShader(const std::string& name, const std::string& compute_src)
- : m_name(name)
+ : m_name(name)
{
std::unordered_map<uint32_t, std::string> sources;
sources[GL_COMPUTE_SHADER] = compute_src;
@@ -57,9 +74,9 @@ namespace Donut
std::string OpenGLShader::read_file(const std::string& filepath)
{
std::string result;
- std::ifstream in(filepath, std::ios::in |
+ std::ifstream in(filepath, std::ios::in |
std::ios::binary);
-
+
if (in)
{
in.seekg(0, std::ios::end);
@@ -90,7 +107,7 @@ namespace Donut
size_t next_line_pos = source.find_first_not_of("\r\n", eol);
pos = source.find(type_token, next_line_pos);
- shader_sources[ShaderTypeFromString(type)] = (pos == std::string::npos) ? source.substr(next_line_pos) :
+ shader_sources[ShaderTypeFromString(type)] = (pos == std::string::npos) ? source.substr(next_line_pos) :
source.substr(next_line_pos, pos - next_line_pos);
}
@@ -222,34 +239,34 @@ namespace Donut
glUniform1f(location, value);
}
- void OpenGLShader::upload_uniform_float2(const std::string& name, const glm::vec2& value)
+ void OpenGLShader::upload_uniform_float2(const std::string& name, const glm::vec2& value)
{
int location = glGetUniformLocation(m_renderer_id, name.c_str());
glUniform2f(location, value.x, value.y);
}
- void OpenGLShader::upload_uniform_float3(const std::string& name, const glm::vec3& value)
+ void OpenGLShader::upload_uniform_float3(const std::string& name, const glm::vec3& value)
{
int location = glGetUniformLocation(m_renderer_id, name.c_str());
glUniform3f(location, value.x, value.y, value.z);
}
- void OpenGLShader::upload_uniform_float4(const std::string& name, const glm::vec4& value)
+ void OpenGLShader::upload_uniform_float4(const std::string& name, const glm::vec4& value)
{
int location = glGetUniformLocation(m_renderer_id, name.c_str());
glUniform4f(location, value.x, value.y, value.z, value.w);
}
- void OpenGLShader::upload_uniform_mat3(const std::string& name, const glm::mat3& matrix)
+ void OpenGLShader::upload_uniform_mat3(const std::string& name, const glm::mat3& matrix)
{
int location = glGetUniformLocation(m_renderer_id, name.c_str());
- glUniformMatrix3fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
+ glUniformMatrix3fv(location, 1, m_is_slang ? GL_TRUE : GL_FALSE, glm::value_ptr(matrix));
}
- void OpenGLShader::upload_uniform_mat4(const std::string& name, const glm::mat4& matrix)
+ void OpenGLShader::upload_uniform_mat4(const std::string& name, const glm::mat4& matrix)
{
int location = glGetUniformLocation(m_renderer_id, name.c_str());
- glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix));
+ glUniformMatrix4fv(location, 1, m_is_slang ? GL_TRUE : GL_FALSE, glm::value_ptr(matrix));
}
void OpenGLShader::dispatch(uint32_t x, uint32_t y, uint32_t z)
diff --git a/src/platform/opengl/opengl_shader.h b/src/platform/opengl/opengl_shader.h
index 29c23a4..978b56a 100644
--- a/src/platform/opengl/opengl_shader.h
+++ b/src/platform/opengl/opengl_shader.h
@@ -50,5 +50,6 @@ namespace Donut
private:
uint32_t m_renderer_id = 0;
std::string m_name;
+ bool m_is_slang = false;
};
};
diff --git a/src/platform/opengl/opengl_texture.cpp b/src/platform/opengl/opengl_texture.cpp
index 8471ee8..13125a6 100644
--- a/src/platform/opengl/opengl_texture.cpp
+++ b/src/platform/opengl/opengl_texture.cpp
@@ -218,7 +218,7 @@ namespace Donut
glUseProgram(shader_program);
glUniform1i(glGetUniformLocation(shader_program, "u_EquirectangularMap"), 0);
- glUniformMatrix4fv(glGetUniformLocation(shader_program, "u_Projection"), 1, GL_FALSE, &capture_projection[0][0]);
+ glUniformMatrix4fv(glGetUniformLocation(shader_program, "u_Projection"), 1, GL_TRUE, &capture_projection[0][0]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, hdr_texture);
@@ -226,7 +226,7 @@ namespace Donut
glBindFramebuffer(GL_FRAMEBUFFER, capture_fbo);
for (unsigned int i = 0; i < 6; ++i)
{
- glUniformMatrix4fv(glGetUniformLocation(shader_program, "u_View"), 1, GL_FALSE, &capture_views[i][0][0]);
+ glUniformMatrix4fv(glGetUniformLocation(shader_program, "u_View"), 1, GL_TRUE, &capture_views[i][0][0]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, m_renderer_id, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(cube_vao);