Working system

This commit is contained in:
Arnau Alier Torres 2025-05-07 18:09:37 +02:00
parent 52d34f48ab
commit 8529fb1a66
7 changed files with 56 additions and 15 deletions

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "Deer/Components.h" #include "Deer/Components.h"
#include "DeerRender/Render/VertexArray.h" #include "DeerRender/Mesh.h"
#include "DeerRender/Render/Shader.h" #include "DeerRender/Shader.h"
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include "glm/gtc/quaternion.hpp" #include "glm/gtc/quaternion.hpp"
@ -13,19 +13,57 @@
namespace Deer { namespace Deer {
struct MeshComponent { struct MeshComponent {
MeshComponent() = default; MeshComponent() { clear(); }
MeshComponent(uint16_t _meshId) : meshId(_meshId) { } MeshComponent(uint16_t _meshId) : meshId(_meshId), active(true) { }
MeshComponent(const MeshComponent&) = default; MeshComponent(const MeshComponent&) = default;
inline void setMesh(uint16_t _meshId) {
active = true;
meshId = _meshId;
}
inline void clear() {
active = false;
meshId = 0;
}
inline VertexArray& getMesh() {
return MeshManager::getModel(meshId);
}
inline bool isActive() {
return active;
}
private:
uint16_t meshId; uint16_t meshId;
bool active;
}; };
struct ShaderComponent { struct ShaderComponent {
ShaderComponent() = default; ShaderComponent() { clear(); }
ShaderComponent(uint16_t _shaderId) : shaderId(_shaderId) { } ShaderComponent(uint16_t _shaderId) : shaderId(_shaderId), active(true) { }
ShaderComponent(const ShaderComponent&) = default; ShaderComponent(const ShaderComponent&) = default;
inline void setShader(uint16_t _shaderId) {
active = true;
shaderId = _shaderId;
}
inline void clear() {
active = false;
shaderId = 0;
}
inline Shader& getShader() {
return ShaderManager::getShader(shaderId);
}
inline bool isActive() {
return active;
}
private:
uint16_t shaderId; uint16_t shaderId;
bool active;
}; };
struct TextureBindingComponent { struct TextureBindingComponent {

View File

@ -32,7 +32,7 @@ namespace Deer {
} }
VertexArray& MeshManager::getModel(uint16_t model_id) { VertexArray& MeshManager::getModel(uint16_t model_id) {
DEER_CORE_ASSERT(model_id > 0 && model_id < minModelId, "Invalid model id, id is not loaded"); DEER_CORE_ASSERT(model_id >= 0 && model_id < minModelId, "Invalid model id, id is not loaded");
return *meshes[model_id]; return *meshes[model_id];
} }

View File

@ -31,14 +31,14 @@ namespace Deer {
Entity& entity = getEntity(tagComponent.entityUID); Entity& entity = getEntity(tagComponent.entityUID);
glm::mat4 matrix = entity.getWorldMatrix(); glm::mat4 matrix = entity.getWorldMatrix();
Shader& shader = ShaderManager::getShader(shaderComponent.shaderId); Shader& shader = shaderComponent.getShader();
shader.bind(); shader.bind();
shader.uploadUniformMat4("u_viewMatrix", cameraProjectionMatrix); shader.uploadUniformMat4("u_viewMatrix", cameraProjectionMatrix);
shader.uploadUniformMat4("u_worldMatrix", matrix); shader.uploadUniformMat4("u_worldMatrix", matrix);
shader.uploadUniformInt("u_objectID", entity.getId()); shader.uploadUniformInt("u_objectID", entity.getId());
VertexArray& vertexArray = MeshManager::getModel(meshComponent.meshId); VertexArray& vertexArray = meshComponent.getMesh();
vertexArray.bind(); vertexArray.bind();
Render::submit(vertexArray); Render::submit(vertexArray);

View File

@ -33,7 +33,7 @@ namespace Deer {
} }
} }
std::unordered_map<std::string, std::string> preProcess(const std::string& source) { std::unordered_map<std::string, std::string> DataStore::preProcess(const std::string& source) {
std::unordered_map<std::string, std::string> shaderSource; std::unordered_map<std::string, std::string> shaderSource;
const std::string typeToken = "#type "; const std::string typeToken = "#type ";

View File

@ -31,7 +31,7 @@ namespace Deer {
} }
Shader& ShaderManager::getShader(uint16_t shaderId) { Shader& ShaderManager::getShader(uint16_t shaderId) {
DEER_CORE_ASSERT(shaderId > 0 && shaderId < minShaderId, "Invalid shader id, id is not loaded"); DEER_CORE_ASSERT(shaderId >= 0 && shaderId < minShaderId, "Invalid shader id, id is not loaded");
return *shaders[shaderId]; return *shaders[shaderId];
} }

View File

@ -58,13 +58,16 @@ namespace Deer {
Entity& exampleObject = env.createEntity("Example"); Entity& exampleObject = env.createEntity("Example");
MeshComponent& renderComponent = exampleObject.addComponent<MeshComponent>(); MeshComponent& renderComponent = exampleObject.addComponent<MeshComponent>();
ShaderComponent& shaderComponent = exampleObject.addComponent<ShaderComponent>();
MeshData meshData; MeshData meshData;
DataStore::loadModel(meshData, "example"); DataStore::loadModel(meshData, "example");
renderComponent.meshId = MeshManager::loadModel(meshData); ShaderData shaderData;
// Shader::create(DataStore::rootPath / DEER_SHADER_PATH / "shader.glsl"); DataStore::loadShader(shaderData, "shader");
//renderComponent.vertexArray = Mesh::loadModelToGPU(meshData);
renderComponent.setMesh(MeshManager::loadModel(meshData));
shaderComponent.setShader(ShaderManager::loadShader(shaderData));
return 0; return 0;
} }

View File

@ -97,7 +97,7 @@ DockSpace ID=0xA1672E74 Window=0x4647B76E Pos=0,24 Size=1280,696 Split=Y
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=878,338 Split=X Selected=0x13926F0B DockNode ID=0x00000003 Parent=0x00000001 SizeRef=878,338 Split=X Selected=0x13926F0B
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=256,446 Selected=0xE45B9F93 DockNode ID=0x00000005 Parent=0x00000003 SizeRef=256,446 Selected=0xE45B9F93
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=620,446 CentralNode=1 Selected=0x13926F0B DockNode ID=0x00000006 Parent=0x00000003 SizeRef=620,446 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=400,338 Selected=0xA35A27E3 DockNode ID=0x00000004 Parent=0x00000001 SizeRef=400,338 Selected=0x2A2C795E
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702 DockNode ID=0x00000002 Parent=0x00000007 SizeRef=2560,331 Selected=0xCF339702
DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,220 Selected=0xD962995A DockNode ID=0x00000008 Parent=0xA1672E74 SizeRef=1280,220 Selected=0xD962995A