16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00

ubo (ugly for now)

This commit is contained in:
milek7
2018-06-26 01:05:46 +02:00
parent a9713a6ee4
commit 1c26096c5c
8 changed files with 145 additions and 54 deletions

View File

@@ -3,36 +3,6 @@
void gl::program_mvp::init()
{
mv_uniform = glGetUniformLocation(*this, "modelview");
mvn_uniform = glGetUniformLocation(*this, "modelviewnormal");
p_uniform = glGetUniformLocation(*this, "projection");
}
void gl::program_mvp::set_mv(const glm::mat4 &m)
{
if (last_mv == m)
return;
last_mv = m;
if (mvn_uniform != -1)
{
glm::mat3 mvn = glm::mat3(glm::transpose(glm::inverse(m)));
glUniformMatrix3fv(mvn_uniform, 1, GL_FALSE, glm::value_ptr(mvn));
}
glUniformMatrix4fv(mv_uniform, 1, GL_FALSE, glm::value_ptr(m));
}
void gl::program_mvp::set_p(const glm::mat4 &m)
{
if (last_p == m)
return;
last_p = m;
glUniformMatrix4fv(p_uniform, 1, GL_FALSE, glm::value_ptr(m));
}
void gl::program_mvp::copy_gl_mvp()
{
set_mv(OpenGLMatrices.data(GL_MODELVIEW));
set_p(OpenGLMatrices.data(GL_PROJECTION));
glUniformBlockBinding(*this, 0, glGetUniformBlockIndex(*this, "scene_ubo"));
glUniformBlockBinding(*this, 1, glGetUniformBlockIndex(*this, "model_ubo"));
}