Browse Source

Renderer: Move RenderCommand to separate file

master
Riyyi 3 months ago
parent
commit
52611beeab
  1. 1
      src/inferno/application.cpp
  2. 73
      src/inferno/render/render-command.cpp
  3. 31
      src/inferno/render/render-command.h
  4. 59
      src/inferno/render/renderer.cpp
  5. 18
      src/inferno/render/renderer.h
  6. 1
      src/inferno/window.cpp

1
src/inferno/application.cpp

@ -23,6 +23,7 @@
#include "inferno/render/context.h"
#include "inferno/render/font.h"
// #include "inferno/render/gltf.h"
#include "inferno/render/render-command.h"
#include "inferno/render/renderer.h"
#include "inferno/render/shader.h"
#include "inferno/render/texture.h"

73
src/inferno/render/render-command.cpp

@ -0,0 +1,73 @@
/*
* Copyright (C) 2024 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "glad/glad.h"
#include "ruc/format/log.h"
#include "inferno/render/buffer.h"
#include "inferno/render/render-command.h"
namespace Inferno {
void RenderCommand::initialize()
{
setDepthTest(true);
// Enable transparency
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
ruc::info("RenderCommand initialized");
}
void RenderCommand::destroy()
{
}
void RenderCommand::clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void RenderCommand::clearColor(const glm::vec4& color)
{
glClearColor(color.r, color.g, color.b, color.a);
}
void RenderCommand::drawIndexed(const VertexArray& vertexArray, uint32_t indexCount)
{
uint32_t count = indexCount ? indexCount : vertexArray.getIndexBuffer()->getCount();
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
}
void RenderCommand::setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height)
{
glViewport(x, y, width, height);
}
void RenderCommand::setDepthTest(bool enabled)
{
// Set z-buffer / depth buffer
enabled ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
}
bool RenderCommand::depthTest()
{
unsigned char depthTest = GL_FALSE;
glGetBooleanv(GL_DEPTH_TEST, &depthTest);
return depthTest == GL_TRUE;
}
int32_t RenderCommand::textureUnitAmount()
{
int32_t amount = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &amount);
return amount;
}
} // namespace Inferno

31
src/inferno/render/render-command.h

@ -0,0 +1,31 @@
/*
* Copyright (C) 2024 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4
namespace Inferno {
class VertexArray;
class RenderCommand {
public:
static void initialize();
static void destroy();
static void clear();
static void clearColor(const glm::vec4& color);
static void drawIndexed(const VertexArray& vertexArray, uint32_t indexCount = 0);
static void setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height);
static void setDepthTest(bool enabled);
static bool depthTest();
static int32_t textureUnitAmount();
};
} // namespace Inferno

59
src/inferno/render/renderer.cpp

@ -11,70 +11,13 @@
#include "ruc/format/log.h"
#include "inferno/render/buffer.h"
#include "inferno/render/render-command.h"
#include "inferno/render/renderer.h"
#include "inferno/render/shader.h"
#include "inferno/render/texture.h"
namespace Inferno {
void RenderCommand::initialize()
{
setDepthTest(true);
// Enable transparency
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
ruc::info("RenderCommand initialized");
}
void RenderCommand::destroy()
{
}
void RenderCommand::clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void RenderCommand::clearColor(const glm::vec4& color)
{
glClearColor(color.r, color.g, color.b, color.a);
}
void RenderCommand::drawIndexed(const VertexArray& vertexArray, uint32_t indexCount)
{
uint32_t count = indexCount ? indexCount : vertexArray.getIndexBuffer()->getCount();
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr);
}
void RenderCommand::setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height)
{
glViewport(x, y, width, height);
}
void RenderCommand::setDepthTest(bool enabled)
{
// Set z-buffer / depth buffer
enabled ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
}
bool RenderCommand::depthTest()
{
unsigned char depthTest = GL_FALSE;
glGetBooleanv(GL_DEPTH_TEST, &depthTest);
return depthTest == GL_TRUE;
}
int32_t RenderCommand::textureUnitAmount()
{
int32_t amount = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &amount);
return amount;
}
// -----------------------------------------
uint32_t Renderer::m_supportedTextureUnitPerBatch = 0;
void Renderer::initialize()

18
src/inferno/render/renderer.h

@ -52,24 +52,6 @@ struct CharacterVertex {
// -------------------------------------
class RenderCommand {
public:
static void initialize();
static void destroy();
static void clear();
static void clearColor(const glm::vec4& color);
static void drawIndexed(const VertexArray& vertexArray, uint32_t indexCount = 0);
static void setViewport(int32_t x, int32_t y, uint32_t width, uint32_t height);
static void setDepthTest(bool enabled);
static bool depthTest();
static int32_t textureUnitAmount();
};
// -------------------------------------
class Renderer {
public:
static constexpr const uint32_t vertexPerQuad = 4;

1
src/inferno/window.cpp

@ -18,6 +18,7 @@
#include "inferno/io/input.h"
#include "inferno/keycodes.h"
#include "inferno/render/context.h"
#include "inferno/render/render-command.h"
#include "inferno/render/renderer.h"
#include "inferno/settings.h"
#include "inferno/window.h"

Loading…
Cancel
Save