Renderer: Move RenderCommand to separate file
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#include "inferno/render/context.h"
|
#include "inferno/render/context.h"
|
||||||
#include "inferno/render/font.h"
|
#include "inferno/render/font.h"
|
||||||
// #include "inferno/render/gltf.h"
|
// #include "inferno/render/gltf.h"
|
||||||
|
#include "inferno/render/render-command.h"
|
||||||
#include "inferno/render/renderer.h"
|
#include "inferno/render/renderer.h"
|
||||||
#include "inferno/render/shader.h"
|
#include "inferno/render/shader.h"
|
||||||
#include "inferno/render/texture.h"
|
#include "inferno/render/texture.h"
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -11,70 +11,13 @@
|
|||||||
#include "ruc/format/log.h"
|
#include "ruc/format/log.h"
|
||||||
|
|
||||||
#include "inferno/render/buffer.h"
|
#include "inferno/render/buffer.h"
|
||||||
|
#include "inferno/render/render-command.h"
|
||||||
#include "inferno/render/renderer.h"
|
#include "inferno/render/renderer.h"
|
||||||
#include "inferno/render/shader.h"
|
#include "inferno/render/shader.h"
|
||||||
#include "inferno/render/texture.h"
|
#include "inferno/render/texture.h"
|
||||||
|
|
||||||
namespace Inferno {
|
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;
|
uint32_t Renderer::m_supportedTextureUnitPerBatch = 0;
|
||||||
|
|
||||||
void Renderer::initialize()
|
void Renderer::initialize()
|
||||||
|
|||||||
@@ -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 {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
static constexpr const uint32_t vertexPerQuad = 4;
|
static constexpr const uint32_t vertexPerQuad = 4;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "inferno/io/input.h"
|
#include "inferno/io/input.h"
|
||||||
#include "inferno/keycodes.h"
|
#include "inferno/keycodes.h"
|
||||||
#include "inferno/render/context.h"
|
#include "inferno/render/context.h"
|
||||||
|
#include "inferno/render/render-command.h"
|
||||||
#include "inferno/render/renderer.h"
|
#include "inferno/render/renderer.h"
|
||||||
#include "inferno/settings.h"
|
#include "inferno/settings.h"
|
||||||
#include "inferno/window.h"
|
#include "inferno/window.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user