testing uniforms and shaders
This commit is contained in:
parent
0f823dd419
commit
0f5058bd18
4 changed files with 40 additions and 13 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "pw/core/matrix.hpp"
|
||||
#include "pw/core/mesh.hpp"
|
||||
#include "pw/core/timer.hpp"
|
||||
#include "pw/core/axisangle.hpp"
|
||||
|
||||
#include "pw/core/debug.hpp"
|
||||
#include "pw/visual/pipeline.hpp"
|
||||
|
@ -118,11 +119,11 @@ struct triangle_renderer
|
|||
|
||||
const char* vertex_shader_2 = R"(
|
||||
#version 400
|
||||
uniform mat4 model_mat;
|
||||
in vec3 vertex_p;
|
||||
in vec3 normal_p;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(vp, 1.0);
|
||||
gl_Position = model_mat * vec4(vertex_p, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
|
@ -134,36 +135,37 @@ struct triangle_renderer
|
|||
frag_colour = input_color;
|
||||
})";
|
||||
|
||||
|
||||
shader_p.set_source(vertex_shader_2,shader::vertex);
|
||||
shader_p.set_source(fragment_shader,shader::fragment);
|
||||
shader_p.set_source(vertex_shader,shader::vertex);
|
||||
|
||||
if (!shader_p.build())
|
||||
exit(-1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
double t0 = timer::now();
|
||||
|
||||
shader_p.use();
|
||||
shader_p.use();
|
||||
|
||||
static float v = 0.0f;
|
||||
v+= 0.01f;
|
||||
if (v>1.0f) v = 0.0f;
|
||||
vector4f test({0.5f,1-v,v,1.0f});
|
||||
|
||||
matrix4x4f model_mat; model_mat.set_identity();
|
||||
|
||||
axisangle rot(vector3::right(),v);
|
||||
model_mat = rot.to_matrix();
|
||||
|
||||
// highly inefficient - should be cached -
|
||||
shader_p.bind("input_color",test);
|
||||
shader_p.bind("model_mat",model_mat);
|
||||
|
||||
amesh_renderer.draw();
|
||||
|
||||
debug::d() << 100 * (timer::now() - t0) << "ms";
|
||||
|
||||
// glBindVertexArray(vao);
|
||||
// draw points 0-3 from the currently bound VAO with current in-use shader
|
||||
// glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -185,6 +185,11 @@ shader &shader::bind(int location, const vector4f &v)
|
|||
_impl->bind(location,v); return *this;
|
||||
}
|
||||
|
||||
shader &shader::bind(int location, const matrix4x4f &v)
|
||||
{
|
||||
_impl->bind(location,v); return *this;
|
||||
}
|
||||
|
||||
bool shader::build()
|
||||
{
|
||||
return _impl->build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue