diff --git a/inferno/src/inferno/render/renderer.cpp b/inferno/src/inferno/render/renderer.cpp index 5328ef4..25851ae 100644 --- a/inferno/src/inferno/render/renderer.cpp +++ b/inferno/src/inferno/render/renderer.cpp @@ -1,41 +1,63 @@ #include +#include "inferno/component/transform.h" #include "inferno/render/buffer.h" +#include "inferno/render/camera.h" #include "inferno/render/renderer.h" +#include "inferno/render/shader.h" +#include "inferno/render/texture.h" namespace Inferno { - void Command::clear() + void RenderCommand::clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } - void Command::clearColor(const glm::vec4 &color) + void RenderCommand::clearColor(const glm::vec4& color) { glClearColor(color.r, color.g, color.b, color.a); } - void Command::drawIndexed(const std::shared_ptr &vertexArray) + void RenderCommand::drawIndexed(const std::shared_ptr& vertexArray) { glDrawElements(GL_TRIANGLES, vertexArray->getIndexBuffer()->getCount(), GL_UNSIGNED_INT, nullptr); } // ----------------------------------------- - void Renderer::beginScene() - { + std::shared_ptr Renderer2D::m_camera = nullptr; + void Renderer2D::beginScene(const std::shared_ptr& camera) + { + m_camera = camera; } - void Renderer::endScene() + void Renderer2D::endScene() { } - void Renderer::submit(const std::shared_ptr &vertexArray) + void Renderer2D::submit(const std::shared_ptr& vertexArray) { vertexArray->bind(); - Command::drawIndexed(vertexArray); + RenderCommand::drawIndexed(vertexArray); + vertexArray->unbind(); + } + + void Renderer2D::submit(const RenderBundle& bundle) + { + bundle.shader->bind(); + if (bundle.texture) bundle.texture->bind(); + bundle.vertexArray->bind(); + + bundle.shader->setFloat("u_projectionView", m_camera->projection() * m_camera->transform()->transform()); + bundle.shader->setFloat("u_model", bundle.transform->transform()); + RenderCommand::drawIndexed(bundle.vertexArray); + + bundle.vertexArray->unbind(); + if (bundle.texture) bundle.texture->unbind(); + bundle.shader->unbind(); } } diff --git a/inferno/src/inferno/render/renderer.h b/inferno/src/inferno/render/renderer.h index 1c7e42c..8acb3af 100644 --- a/inferno/src/inferno/render/renderer.h +++ b/inferno/src/inferno/render/renderer.h @@ -3,28 +3,43 @@ #include // std::shared_ptr -#include +#include "glm/ext/vector_float4.hpp" // glm::vec4 namespace Inferno { + class Camera; + class Shader; + class Texture; + class Transform; class VertexArray; - class Command { + struct RenderBundle { + const std::shared_ptr& shader; + const std::shared_ptr& texture; + const std::shared_ptr& transform; + const std::shared_ptr& vertexArray; + }; + + class RenderCommand { public: static void clear(); - static void clearColor(const glm::vec4 &color); + static void clearColor(const glm::vec4& color); - static void drawIndexed(const std::shared_ptr &vertexArray); + static void drawIndexed(const std::shared_ptr& vertexArray); }; // ----------------------------------------- - class Renderer { + class Renderer2D { public: - static void beginScene(); + static void beginScene(const std::shared_ptr& camera); static void endScene(); - static void submit(const std::shared_ptr &vertexArray); + static void submit(const std::shared_ptr& vertexArray); + static void submit(const RenderBundle& bundle); + + private: + static std::shared_ptr m_camera; }; }