|
|
@@ -12,6 +12,8 @@
|
|
|
#include <OpenGL/gl3.h>
|
|
|
#endif
|
|
|
|
|
|
+#include "game/graphics/material.hpp"
|
|
|
+#include "game/graphics/vertex.h"
|
|
|
#include "matrix/matrix.hpp"
|
|
|
#include "matrix/matrix_helpers.hpp"
|
|
|
|
|
|
@@ -66,5 +68,43 @@ void opengl_renderer::clear() {
|
|
|
|
|
|
void opengl_renderer::flush() { glFlush(); }
|
|
|
|
|
|
-void opengl_renderer::draw(flyweight<material>, math::matr4 const &,
|
|
|
- std::vector<vertex> const &) {}
|
|
|
+void opengl_renderer::draw(flyweight<material> material,
|
|
|
+ math::matr4 const & object_to_world,
|
|
|
+ std::vector<vertex> const & vertices) {
|
|
|
+ // TODO: Don't activate here?
|
|
|
+ auto const & mat = material.actual();
|
|
|
+ // TODO: Attatch shader-id to material-id
|
|
|
+ unsigned int const id = mat.shaders.id;
|
|
|
+ mat.activate();
|
|
|
+
|
|
|
+ int objectLocation = glGetUniformLocation(id, "u_objectToWorldMatrix");
|
|
|
+ glUniformMatrix4fv(objectLocation, 1, false, &object_to_world(0, 0));
|
|
|
+
|
|
|
+ int clipLocation = glGetUniformLocation(id, "u_worldToClipMatrix");
|
|
|
+ glUniformMatrix4fv(clipLocation, 1, false, &world_to_clip(0, 0));
|
|
|
+
|
|
|
+ int timeLocation = glGetUniformLocation(id, "u_time");
|
|
|
+ glUniform1d(timeLocation, current_time);
|
|
|
+
|
|
|
+ // TODO: Cache attribute locations
|
|
|
+ int positionLocation = glGetAttribLocation(id, "a_position");
|
|
|
+ int colorLocation = glGetAttribLocation(id, "a_color");
|
|
|
+ int texCoordsLocation = glGetAttribLocation(id, "a_texCoords");
|
|
|
+
|
|
|
+ glEnableVertexAttribArray(positionLocation);
|
|
|
+ glEnableVertexAttribArray(colorLocation);
|
|
|
+ glEnableVertexAttribArray(texCoordsLocation);
|
|
|
+
|
|
|
+ glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(vertex),
|
|
|
+ &vertices[0].position);
|
|
|
+ glVertexAttribPointer(colorLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
|
|
+ sizeof(vertex), &vertices[0].color);
|
|
|
+ glVertexAttribPointer(texCoordsLocation, 2, GL_FLOAT, GL_FALSE,
|
|
|
+ sizeof(vertex), &vertices[0].texture_coords);
|
|
|
+
|
|
|
+ glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vertices.size()));
|
|
|
+
|
|
|
+ glDisableVertexAttribArray(positionLocation);
|
|
|
+ glDisableVertexAttribArray(colorLocation);
|
|
|
+ glDisableVertexAttribArray(texCoordsLocation);
|
|
|
+}
|