|
|
@ -1,7 +1,7 @@ |
|
|
|
#ifndef RENDERER_H |
|
|
|
#ifndef RENDERER_H |
|
|
|
#define RENDERER_H |
|
|
|
#define RENDERER_H |
|
|
|
|
|
|
|
|
|
|
|
#include <cstdint> // std::int32_t, std::uint32_t |
|
|
|
#include <cstdint> // int32_t, uint32_t |
|
|
|
#include <memory> // std::shared_ptr, std::unique_ptr, std::make_shared, std::make_unique |
|
|
|
#include <memory> // std::shared_ptr, std::unique_ptr, std::make_shared, std::make_unique |
|
|
|
|
|
|
|
|
|
|
|
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4 |
|
|
|
#include "glm/ext/matrix_float4x4.hpp" // glm::mat4 |
|
|
@ -10,6 +10,7 @@ |
|
|
|
#include "glm/ext/vector_float4.hpp" // glm::vec4 |
|
|
|
#include "glm/ext/vector_float4.hpp" // glm::vec4 |
|
|
|
|
|
|
|
|
|
|
|
#include "inferno/component/transformcomponent.h" |
|
|
|
#include "inferno/component/transformcomponent.h" |
|
|
|
|
|
|
|
#include "inferno/singleton.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace Inferno { |
|
|
|
namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
@ -29,12 +30,14 @@ namespace Inferno { |
|
|
|
struct CharacterVertex { |
|
|
|
struct CharacterVertex { |
|
|
|
QuadVertex quad; |
|
|
|
QuadVertex quad; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Font
|
|
|
|
float width = 0.44f; |
|
|
|
float width = 0.44f; |
|
|
|
float edge = 0.15f; |
|
|
|
float edge = 0.15f; |
|
|
|
|
|
|
|
// Outline
|
|
|
|
float borderWidth = 0.7f; |
|
|
|
float borderWidth = 0.7f; |
|
|
|
float borderEdge = 0.1f; |
|
|
|
float borderEdge = 0.1f; |
|
|
|
glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f }; |
|
|
|
glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f }; |
|
|
|
|
|
|
|
// Dropshadow
|
|
|
|
float offset = 0.0f; |
|
|
|
float offset = 0.0f; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -65,8 +68,10 @@ namespace Inferno { |
|
|
|
static const uint32_t textureUnitPerBatch = 32; |
|
|
|
static const uint32_t textureUnitPerBatch = 32; |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
virtual void initialize() = 0; |
|
|
|
Renderer() {} |
|
|
|
virtual void destroy() = 0; |
|
|
|
|
|
|
|
|
|
|
|
void initialize(); |
|
|
|
|
|
|
|
void destroy(); |
|
|
|
|
|
|
|
|
|
|
|
uint32_t addTextureUnit(std::shared_ptr<Texture> texture); |
|
|
|
uint32_t addTextureUnit(std::shared_ptr<Texture> texture); |
|
|
|
|
|
|
|
|
|
|
@ -91,15 +96,20 @@ namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class Renderer2D final : public Renderer { |
|
|
|
class Renderer2D final |
|
|
|
|
|
|
|
: public Renderer |
|
|
|
|
|
|
|
, public Singleton<Renderer2D> { |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
Renderer2D(s); |
|
|
|
|
|
|
|
virtual ~Renderer2D(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Singleton<Renderer2D>::initialize; |
|
|
|
|
|
|
|
using Singleton<Renderer2D>::destroy; |
|
|
|
|
|
|
|
|
|
|
|
static const uint32_t quadCount = 1000; |
|
|
|
static const uint32_t quadCount = 1000; |
|
|
|
static const uint32_t vertexCount = quadCount * vertexPerQuad; |
|
|
|
static const uint32_t vertexCount = quadCount * vertexPerQuad; |
|
|
|
static const uint32_t indexCount = quadCount * indexPerQuad; |
|
|
|
static const uint32_t indexCount = quadCount * indexPerQuad; |
|
|
|
|
|
|
|
|
|
|
|
void initialize() override; |
|
|
|
|
|
|
|
void destroy() override; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void beginScene(glm::mat4 cameraProjectionView); |
|
|
|
void beginScene(glm::mat4 cameraProjectionView); |
|
|
|
void endScene(); |
|
|
|
void endScene(); |
|
|
|
|
|
|
|
|
|
|
@ -107,9 +117,6 @@ namespace Inferno { |
|
|
|
void drawQuad(const TransformComponent& transform, glm::mat4 color); |
|
|
|
void drawQuad(const TransformComponent& transform, glm::mat4 color); |
|
|
|
void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture); |
|
|
|
void drawQuad(const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture); |
|
|
|
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture); |
|
|
|
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture); |
|
|
|
|
|
|
|
|
|
|
|
static inline Renderer2D& the() { return *s_instance; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
void loadShader() override; |
|
|
|
void loadShader() override; |
|
|
|
void flush() override; |
|
|
|
void flush() override; |
|
|
@ -122,28 +129,28 @@ namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
|
// Default quad vertex positions
|
|
|
|
// Default quad vertex positions
|
|
|
|
glm::vec4 m_vertexPositions[vertexPerQuad]; |
|
|
|
glm::vec4 m_vertexPositions[vertexPerQuad]; |
|
|
|
|
|
|
|
|
|
|
|
static Renderer2D* s_instance; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class RendererCharacter final : public Renderer { |
|
|
|
class RendererCharacter final |
|
|
|
|
|
|
|
: public Renderer |
|
|
|
|
|
|
|
, public Singleton<RendererCharacter> { |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
RendererCharacter(s); |
|
|
|
|
|
|
|
virtual ~RendererCharacter(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Singleton<RendererCharacter>::initialize; |
|
|
|
|
|
|
|
using Singleton<RendererCharacter>::destroy; |
|
|
|
|
|
|
|
|
|
|
|
static const uint32_t quadCount = 1000; |
|
|
|
static const uint32_t quadCount = 1000; |
|
|
|
static const uint32_t vertexCount = quadCount * vertexPerQuad; |
|
|
|
static const uint32_t vertexCount = quadCount * vertexPerQuad; |
|
|
|
static const uint32_t indexCount = quadCount * indexPerQuad; |
|
|
|
static const uint32_t indexCount = quadCount * indexPerQuad; |
|
|
|
|
|
|
|
|
|
|
|
void initialize() override; |
|
|
|
|
|
|
|
void destroy() override; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void beginScene(); |
|
|
|
void beginScene(); |
|
|
|
void endScene(); |
|
|
|
void endScene(); |
|
|
|
|
|
|
|
|
|
|
|
void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture); |
|
|
|
void drawCharacter(std::array<CharacterVertex, vertexPerQuad>& characterQuad, std::shared_ptr<Texture> texture); |
|
|
|
|
|
|
|
|
|
|
|
static inline RendererCharacter& the() { return *s_instance; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
void loadShader() override; |
|
|
|
void loadShader() override; |
|
|
|
void flush() override; |
|
|
|
void flush() override; |
|
|
@ -153,8 +160,6 @@ namespace Inferno { |
|
|
|
// CPU quad vertices
|
|
|
|
// CPU quad vertices
|
|
|
|
std::unique_ptr<CharacterVertex[]> m_vertexBufferBase = nullptr; |
|
|
|
std::unique_ptr<CharacterVertex[]> m_vertexBufferBase = nullptr; |
|
|
|
CharacterVertex* m_vertexBufferPtr = nullptr; |
|
|
|
CharacterVertex* m_vertexBufferPtr = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
static RendererCharacter* s_instance; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|