Asset+Component+Render: Render quads in the world as 3D objects
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "inferno/asset/asset-manager.h"
|
||||
#include "inferno/asset/model.h"
|
||||
#include "inferno/asset/texture.h"
|
||||
#include "inferno/component/spritecomponent.h" // TODO: Move glm::x toJson/fromJson to separate file
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
@@ -15,6 +16,9 @@ void fromJson(const ruc::Json& json, ModelComponent& value)
|
||||
{
|
||||
VERIFY(json.type() == ruc::Json::Type::Object);
|
||||
|
||||
if (json.exists("color")) {
|
||||
json.at("color").getTo(value.color);
|
||||
}
|
||||
if (json.exists("model") && json.at("model").type() == ruc::Json::Type::String) {
|
||||
value.model = AssetManager::the().load<Model>(json.at("model").asString());
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
namespace Inferno {
|
||||
|
||||
struct ModelComponent {
|
||||
glm::vec4 color { 1.0f };
|
||||
std::shared_ptr<Model> model;
|
||||
std::shared_ptr<Texture2D> texture;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <span>
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include "glm/ext/vector_float4.hpp" // glm::vec4
|
||||
#include "ruc/format/log.h"
|
||||
|
||||
#include "inferno/asset/asset-manager.h"
|
||||
@@ -274,7 +275,7 @@ void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color,
|
||||
|
||||
void Renderer2D::loadShader()
|
||||
{
|
||||
m_shader = AssetManager::the().load<Shader>("assets/glsl/batch-quad");
|
||||
m_shader = AssetManager::the().load<Shader>("assets/glsl/batch-2d");
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
@@ -487,6 +488,7 @@ Renderer3D::Renderer3D(s)
|
||||
vertexBuffer->setLayout({
|
||||
{ BufferElementType::Vec3, "a_position" },
|
||||
{ BufferElementType::Vec3, "a_normal" },
|
||||
{ BufferElementType::Vec4, "a_color" },
|
||||
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
||||
{ BufferElementType::Uint, "a_textureIndex" },
|
||||
});
|
||||
@@ -495,7 +497,7 @@ Renderer3D::Renderer3D(s)
|
||||
ruc::info("Renderer3D initialized");
|
||||
}
|
||||
|
||||
void Renderer3D::drawModel(std::span<const Vertex> vertices, std::span<const uint32_t> elements, const TransformComponent& transform, std::shared_ptr<Texture> texture)
|
||||
void Renderer3D::drawModel(std::span<const Vertex> vertices, std::span<const uint32_t> elements, const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture)
|
||||
{
|
||||
// ruc::error("drawModel");
|
||||
|
||||
@@ -513,6 +515,7 @@ void Renderer3D::drawModel(std::span<const Vertex> vertices, std::span<const uin
|
||||
for (const auto& vertex : vertices) {
|
||||
m_vertexBufferPtr->position = transform.transform * glm::vec4(vertex.position, 1.0f);
|
||||
m_vertexBufferPtr->normal = vertex.normal;
|
||||
m_vertexBufferPtr->color = color;
|
||||
m_vertexBufferPtr->textureCoordinates = vertex.textureCoordinates;
|
||||
m_vertexBufferPtr->textureIndex = textureUnitIndex;
|
||||
m_vertexBufferPtr++;
|
||||
|
||||
@@ -24,16 +24,16 @@ class TransformComponent;
|
||||
class VertexArray;
|
||||
|
||||
struct QuadVertex {
|
||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
||||
uint32_t textureIndex = 0;
|
||||
glm::vec3 position { 0.0f };
|
||||
glm::vec4 color { 1.0f };
|
||||
glm::vec2 textureCoordinates { 0.0f };
|
||||
uint32_t textureIndex { 0 };
|
||||
};
|
||||
|
||||
struct CubemapVertex {
|
||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
uint32_t textureIndex = 0;
|
||||
glm::vec3 position { 0.0f };
|
||||
glm::vec4 color { 1.0f };
|
||||
uint32_t textureIndex { 0 };
|
||||
};
|
||||
|
||||
struct SymbolVertex {
|
||||
@@ -45,16 +45,17 @@ struct SymbolVertex {
|
||||
// Outline
|
||||
float borderWidth = 0.7f;
|
||||
float borderEdge = 0.1f;
|
||||
glm::vec4 borderColor { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
glm::vec4 borderColor { 1.0f };
|
||||
// Dropshadow
|
||||
float offset = 0.0f;
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 normal { 1.0f, 1.0f, 1.0f };
|
||||
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
||||
uint32_t textureIndex = 0;
|
||||
glm::vec3 position { 0.0f };
|
||||
glm::vec3 normal { 1.0f };
|
||||
glm::vec4 color { 1.0f };
|
||||
glm::vec2 textureCoordinates { 0.0f };
|
||||
uint32_t textureIndex { 0 };
|
||||
};
|
||||
|
||||
// -------------------------------------
|
||||
@@ -197,7 +198,7 @@ public:
|
||||
|
||||
using Singleton<Renderer3D>::destroy;
|
||||
|
||||
void drawModel(std::span<const Vertex> vertices, std::span<const uint32_t> indices, const TransformComponent& transform, std::shared_ptr<Texture> texture);
|
||||
void drawModel(std::span<const Vertex> vertices, std::span<const uint32_t> indices, const TransformComponent& transform, glm::vec4 color, std::shared_ptr<Texture> texture);
|
||||
|
||||
private:
|
||||
void createElementBuffer() override;
|
||||
|
||||
@@ -46,6 +46,7 @@ void RenderSystem::render()
|
||||
Renderer3D::the().drawModel(model.model->vertices(),
|
||||
model.model->elements(),
|
||||
transform,
|
||||
model.color,
|
||||
model.model->texture() ? model.model->texture() : model.texture);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user