Browse Source

Add RenderBundle struct and submit()

master
Riyyi 4 years ago
parent
commit
0b9f4715fc
  1. 38
      inferno/src/inferno/render/renderer.cpp
  2. 23
      inferno/src/inferno/render/renderer.h

38
inferno/src/inferno/render/renderer.cpp

@ -1,41 +1,63 @@
#include <glad/glad.h> #include <glad/glad.h>
#include "inferno/component/transform.h"
#include "inferno/render/buffer.h" #include "inferno/render/buffer.h"
#include "inferno/render/camera.h"
#include "inferno/render/renderer.h" #include "inferno/render/renderer.h"
#include "inferno/render/shader.h"
#include "inferno/render/texture.h"
namespace Inferno { namespace Inferno {
void Command::clear() void RenderCommand::clear()
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 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); glClearColor(color.r, color.g, color.b, color.a);
} }
void Command::drawIndexed(const std::shared_ptr<VertexArray> &vertexArray) void RenderCommand::drawIndexed(const std::shared_ptr<VertexArray>& vertexArray)
{ {
glDrawElements(GL_TRIANGLES, vertexArray->getIndexBuffer()->getCount(), GL_UNSIGNED_INT, nullptr); glDrawElements(GL_TRIANGLES, vertexArray->getIndexBuffer()->getCount(), GL_UNSIGNED_INT, nullptr);
} }
// ----------------------------------------- // -----------------------------------------
void Renderer::beginScene() std::shared_ptr<Camera> Renderer2D::m_camera = nullptr;
{
void Renderer2D::beginScene(const std::shared_ptr<Camera>& camera)
{
m_camera = camera;
} }
void Renderer::endScene() void Renderer2D::endScene()
{ {
} }
void Renderer::submit(const std::shared_ptr<VertexArray> &vertexArray) void Renderer2D::submit(const std::shared_ptr<VertexArray>& vertexArray)
{ {
vertexArray->bind(); 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();
} }
} }

23
inferno/src/inferno/render/renderer.h

@ -3,13 +3,24 @@
#include <memory> // std::shared_ptr #include <memory> // std::shared_ptr
#include <glm/vec4.hpp> #include "glm/ext/vector_float4.hpp" // glm::vec4
namespace Inferno { namespace Inferno {
class Camera;
class Shader;
class Texture;
class Transform;
class VertexArray; class VertexArray;
class Command { struct RenderBundle {
const std::shared_ptr<Shader>& shader;
const std::shared_ptr<Texture>& texture;
const std::shared_ptr<Transform>& transform;
const std::shared_ptr<VertexArray>& vertexArray;
};
class RenderCommand {
public: public:
static void clear(); static void clear();
static void clearColor(const glm::vec4& color); static void clearColor(const glm::vec4& color);
@ -19,12 +30,16 @@ namespace Inferno {
// ----------------------------------------- // -----------------------------------------
class Renderer { class Renderer2D {
public: public:
static void beginScene(); static void beginScene(const std::shared_ptr<Camera>& camera);
static void endScene(); static void endScene();
static void submit(const std::shared_ptr<VertexArray>& vertexArray); static void submit(const std::shared_ptr<VertexArray>& vertexArray);
static void submit(const RenderBundle& bundle);
private:
static std::shared_ptr<Camera> m_camera;
}; };
} }

Loading…
Cancel
Save