|
|
@@ -62,7 +62,7 @@ void opengl_renderer::draw(::identity<material> material_id,
|
|
|
math::matr4 const & object_to_world,
|
|
|
std::vector<vertex> const & vertices) {
|
|
|
material const & mat = manager()->get(material_id);
|
|
|
- if (material_id != active_material) { mat.activate(); }
|
|
|
+ activate(mat);
|
|
|
// TODO: Attatch shader-id to material-id
|
|
|
unsigned int const id = mat.program.id;
|
|
|
|
|
|
@@ -99,6 +99,21 @@ void opengl_renderer::draw(::identity<material> material_id,
|
|
|
glDisableVertexAttribArray(texCoordsLocation);
|
|
|
}
|
|
|
|
|
|
+void opengl_renderer::activate(material const & mat) {
|
|
|
+ if (mat.id == active_material) return;
|
|
|
+ glUseProgram(mat.program.id);
|
|
|
+
|
|
|
+ for (unsigned int i = 0; i < mat.uniforms.size(); i++) {
|
|
|
+ const uniform & uniform = mat.uniforms[i];
|
|
|
+ glActiveTexture(i + GL_TEXTURE0);
|
|
|
+ // glEnable(GL_TEXTURE_2D);
|
|
|
+ glBindTexture(GL_TEXTURE_2D, uniform.texture.id);
|
|
|
+ glUniform1i(uniform.uniform_id, i);
|
|
|
+ }
|
|
|
+
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
+}
|
|
|
+
|
|
|
template <> renderer_impl * graphics::get_renderer_impl<driver::openGL>() {
|
|
|
static opengl_renderer impl;
|
|
|
return &impl;
|