diff options
Diffstat (limited to 'src/render.cpp')
-rw-r--r-- | src/render.cpp | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/render.cpp b/src/render.cpp index 0c60b00..b991b2f 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -27,6 +27,7 @@ void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities, [[maybe_unused]] entityx::EventManager& events) { + events.subscribe<WorldMeshUpdateEvent>(*this); init(); } @@ -179,27 +180,28 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities, glDrawArrays(GL_TRIANGLES, 0, 6); }); - std::basic_string<WorldMeshData>& wm = worldSystem.current()->getMesh(); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, worldSystem.current()->getTexture()); - glUniform1i(q, 0); + // If we were given a world VBO render it + if (worldVBO) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, worldTexture); + glUniform1i(q, 0); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, worldSystem.current()->getNormal()); - glUniform1i(n, 1); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, worldNormal); + glUniform1i(n, 1); - glBindBuffer(GL_ARRAY_BUFFER, world_vbo); - glBufferData(GL_ARRAY_BUFFER, - wm.size() * sizeof(WorldMeshData), - &wm.front(), - GL_STREAM_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, worldVBO); + //glBufferData(GL_ARRAY_BUFFER, + // wm.size() * sizeof(WorldMeshData), + // &wm.front(), + // GL_STREAM_DRAW); - glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE, - 6*sizeof(float), 0); - glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE, - 6*sizeof(float), (void*)(3*sizeof(float))); - glDrawArrays(GL_TRIANGLES, 0, wm.size()); + glVertexAttribPointer(a, 3, GL_FLOAT, GL_FALSE, + 6*sizeof(float), 0); + glVertexAttribPointer(t, 2, GL_FLOAT, GL_FALSE, + 6*sizeof(float), (void*)(3*sizeof(float))); + glDrawArrays(GL_TRIANGLES, 0, worldVertex); + } /************* * CLEANUP * @@ -283,8 +285,17 @@ int RenderSystem::init(void) //glClearColor(0.6, 0.8, 1.0, 0.0); camPos = glm::vec3(0.0f, 0.0f, 5.0f); - glGenBuffers(1, &world_vbo); return 0; } +/************ +* EVENTS * +************/ +void RenderSystem::receive(const WorldMeshUpdateEvent &wmu) +{ + worldVBO = wmu.worldVBO; + worldVertex = wmu.numVertex; + worldTexture = wmu.worldTexture; + worldNormal = wmu.worldNormal; +} |