Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particles #194

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DX12Renderer/DX12Renderer/D3D12Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ void C_D3D12Device::DestroySampler(Renderer::I_TextureSampler2D& texture)
throw std::logic_error("The method or operation is not implemented.");
}

//=================================================================================
bool C_D3D12Device::AllocateBuffer(Renderer::I_Buffer& buffer)
{
throw std::logic_error("The method or operation is not implemented.");
}

} // namespace GLEngine::DX12Renderer
2 changes: 2 additions & 0 deletions DX12Renderer/DX12Renderer/D3D12Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class C_D3D12Device : public Renderer::I_Device {

bool AllocateSampler(Renderer::I_TextureSampler2D& texture) override;
void DestroySampler(Renderer::I_TextureSampler2D& texture) override;

bool AllocateBuffer(Renderer::I_Buffer& buffer) override;
};
} // namespace GLEngine::DX12Renderer
4 changes: 2 additions & 2 deletions Entity/Entity/BasicEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ C_BasicEntity::~C_BasicEntity()
}

//=================================================================================
void C_BasicEntity::Update()
void C_BasicEntity::Update(float dt)
{
for (auto& comp : *m_Components)
{
comp.second->Update();
comp.second->Update(dt);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Entity/Entity/BasicEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class C_BasicEntity : public I_Entity, public std::enable_shared_from_this<C_Bas
explicit C_BasicEntity();
virtual ~C_BasicEntity();

virtual void Update() override;
virtual void Update(float dt) override;
virtual void PostUpdate() override;

//================================================================================
Expand Down
4 changes: 2 additions & 2 deletions Entity/Entity/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ void C_EntityManager::AddEntity(std::shared_ptr<I_Entity> entity)
}

//=================================================================================
void C_EntityManager::OnUpdate()
void C_EntityManager::OnUpdate(float dt)
{
for (auto& entity : m_Entities)
{
entity->Update();
entity->Update(dt);
}

for (auto& entity : m_Entities)
Expand Down
2 changes: 1 addition & 1 deletion Entity/Entity/EntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ENTITY_API_EXPORT C_EntityManager : public Core::I_EventReciever {
[[nodiscard]] const std::vector<std::shared_ptr<I_Entity>>& GetEntities() const;
void ClearLevel();
void AddEntity(std::shared_ptr<I_Entity> entity);
void OnUpdate();
void OnUpdate(float dt);
[[nodiscard]] Physics::Primitives::S_RayIntersection Select(const Physics::Primitives::S_Ray& ray);

void SetFilename(const std::filesystem::path& filename);
Expand Down
2 changes: 1 addition & 1 deletion Entity/Entity/IComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ENTITY_API_EXPORT I_Component : public Core::I_EventReciever {

virtual void OnEvent(Core::I_Event& event) override {}

virtual void Update(){};
virtual void Update(float dt){};
virtual void PostUpdate(){};

// draws inside of prepared window
Expand Down
3 changes: 2 additions & 1 deletion Entity/Entity/IEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ RTTR_REGISTRATION
rttr::registration::enumeration<E_ComponentType>("E_ComponentType")(
rttr::value("Graphical", E_ComponentType::Graphical),
rttr::value("Light", E_ComponentType::Light),
rttr::value("Camera", E_ComponentType::Camera)
rttr::value("Camera", E_ComponentType::Camera),
rttr::value("Particle", E_ComponentType::Particle)
);
}

Expand Down
3 changes: 2 additions & 1 deletion Entity/Entity/IEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class E_ComponentType
Graphical,
Light,
Camera,
Particle,
};

class ENTITY_API_EXPORT I_Entity : public Core::I_EventReciever {
Expand All @@ -40,7 +41,7 @@ class ENTITY_API_EXPORT I_Entity : public Core::I_EventReciever {
[[nodiscard]] virtual const glm::mat4& GetModelMatrix() const = 0;
[[nodiscard]] const std::string& GetName() const { return m_Name; };

virtual void Update(){};
virtual void Update(float dt){};
virtual void PostUpdate(){};

Physics::Primitives::S_AABB GetAABB() const;
Expand Down
24 changes: 24 additions & 0 deletions GLRenderer/GLRenderer/Buffers/GLBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,32 @@
*/
#pragma once

#include <Renderer/Buffer.h>

#include <GLRenderer/Helpers/BufferHelpers.h>

namespace GLEngine::GLRenderer {
class C_GLDevice;
}

namespace GLEngine::GLRenderer::Buffers {

// TODO Rename once the others deleted
class C_GLBufferImpl : public Renderer::I_Buffer {
public:
C_GLBufferImpl(const Renderer::BufferDescriptor& desc)
: Renderer::I_Buffer(desc)
{
}

// missing part!
void bind() override { glBindBuffer(GetBufferUsage(m_Desc.type), m_id); }

friend class ::GLEngine::GLRenderer::C_GLDevice;
protected:
GLuint m_id;
};

class I_GLBufferBase {
public:
virtual ~I_GLBufferBase() = default;
Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Components/SkeletalMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void C_SkeletalMesh::PerformDraw() const
}

//=================================================================================
void C_SkeletalMesh::Update()
void C_SkeletalMesh::Update(float dt)
{
C_DebugDraw::Instance().DrawSkeleton(glm::vec3(1.0f, .0f, .0f), m_Skeleton);
m_AnimationProgress += .01f;
Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Components/SkeletalMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class C_SkeletalMesh : public Renderer::I_RenderableComponent {
public:
C_SkeletalMesh(std::shared_ptr<Entity::I_Entity> owner, std::string meshFile, std::string meshFolder = "Models");
virtual void PerformDraw() const override;
virtual void Update() override;
virtual void Update(float dt) override;

virtual void DebugDrawGUI() override;
virtual bool HasDebugDrawGUI() const override;
Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Components/StaticMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ GLEngine::Physics::Primitives::S_AABB C_StaticMesh::GetAABB() const
}

//=================================================================================
void C_StaticMesh::Update()
void C_StaticMesh::Update(float dt)
{
if (m_MeshResource && m_Mesh.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Components/StaticMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class C_StaticMesh : public Renderer::I_RenderableComponent {

void SetMaterial(std::shared_ptr<Renderer::C_Material> material);

virtual void Update() override;
virtual void Update(float dt) override;

RTTR_ENABLE(Renderer::I_RenderableComponent);

Expand Down
4 changes: 2 additions & 2 deletions GLRenderer/GLRenderer/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ void C_DebugDraw::DrawMergedGeoms()
std::vector<glm::vec3> mergedColors(m_LinesColors);
mergedVertices.insert(mergedVertices.end(), m_PointsVertices.begin(), m_PointsVertices.end());
mergedColors.insert(mergedColors.end(), m_PointsColors.begin(), m_PointsColors.end());
m_VAOlines.SetBufferData<0, GL_ARRAY_BUFFER>(mergedVertices, true);
m_VAOlines.SetBufferData<1, GL_ARRAY_BUFFER>(mergedColors, true);
m_VAOlines.SetBufferData<0, GL_ARRAY_BUFFER>(mergedVertices, Renderer::BufferDynamics::Dynamic);
m_VAOlines.SetBufferData<1, GL_ARRAY_BUFFER>(mergedColors, Renderer::BufferDynamics::Dynamic);

const auto lineVertices = static_cast<GLsizei>(m_LinesVertices.size());
const auto pointsVertices = static_cast<GLsizei>(m_PointsVertices.size());
Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Entities/TerrainEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void C_TerrainEntity::OnEvent(Core::I_Event& event)
}

//=================================================================================
void C_TerrainEntity::Update()
void C_TerrainEntity::Update(float dt)
{
WholeTerrain([](T_TerrainPtr patch) { patch->UpdateStats(); });

Expand Down
2 changes: 1 addition & 1 deletion GLRenderer/GLRenderer/Entities/TerrainEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class C_TerrainEntity : public Entity::I_Entity {
[[nodiscard]] virtual Entity::I_Entity::T_ComponentRange GetComponents(Entity::E_ComponentType type) const override;
virtual void OnEvent(Core::I_Event& event) override;

virtual void Update() override;
virtual void Update(float dt) override;

void AddPatch(T_TerrainPtr);
void AddPatch(glm::ivec2 coord);
Expand Down
61 changes: 61 additions & 0 deletions GLRenderer/GLRenderer/Helpers/BufferHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include <GLRendererStdafx.h>

#include <Renderer/Buffer.h>

#include <Core/CoreMacros.h>

namespace GLEngine::GLRenderer {
inline GLenum GetBufferUsage(const Renderer::BufferDynamics dynamics, const Renderer::BufferAccess access)
{
switch (dynamics)
{
case Renderer::Stream:
switch (access)
{
case Renderer::Draw:
return GL_STREAM_DRAW;
case Renderer::Read:
return GL_STREAM_READ;
case Renderer::Copy:
return GL_STREAM_COPY;
}
case Renderer::Static:
switch (access)
{
case Renderer::Draw:
return GL_STATIC_DRAW;
case Renderer::Read:
return GL_STATIC_READ;
case Renderer::Copy:
return GL_STATIC_COPY;
}
case Renderer::Dynamic:
switch (access)
{
case Renderer::Draw:
return GL_DYNAMIC_DRAW;
case Renderer::Read:
return GL_DYNAMIC_READ;
case Renderer::Copy:
return GL_DYNAMIC_COPY;
}
}
GLE_ASSERT(false, "Unknown type");
return GL_STATIC_DRAW;
}

inline GLenum GetBufferUsage(const Renderer::E_BufferType type)
{
switch (type)
{
case Renderer::VertexAttribute:
return GL_ARRAY_BUFFER;
case Renderer::Uniform:
return GL_UNIFORM_BUFFER;
}
GLE_ASSERT(false, "Unknown type");
return GL_ARRAY_BUFFER;
}
} // namespace GLEngine::GLRenderer
46 changes: 41 additions & 5 deletions GLRenderer/GLRenderer/OGLDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <GLRendererStdafx.h>

#include <GLRenderer/Buffers/GLBuffer.h>
#include <GLRenderer/FBO/Framebuffer.h>
#include <GLRenderer/Helpers/BufferHelpers.h>
#include <GLRenderer/Helpers/TextureHelpers.h>
#include <GLRenderer/OGLDevice.h>
#include <GLRenderer/Textures/Sampler.h>
#include <GLRenderer/Textures/Texture.h>
#include <GLRenderer/FBO/Framebuffer.h>

#include <Renderer/Textures/DeviceTexture.h>
#include <Renderer/Textures/TextureDefinitions.h>
Expand Down Expand Up @@ -96,12 +98,12 @@ bool C_GLDevice::AllocateTexture(Renderer::I_DeviceTexture& texture)
textureGL->SetParameter(GL_TEXTURE_BASE_LEVEL, 0);
textureGL->SetParameter(GL_TEXTURE_MAX_LEVEL, descriptor.m_Levels - 1);

AllocateSampler(textureGL->m_DefaultSampler); // TODO once proper sampler system ready delete this
if (!AllocateSampler(textureGL->m_DefaultSampler)) // TODO once proper sampler system ready delete this
return false;
return true;
}
case Renderer::E_TextureType::TEXTURE_2D_ARRAY: {
glTextureStorage3D(texID, descriptor.m_Levels, GetOpenGLInternalFormat(descriptor.format),
static_cast<GLsizei>(descriptor.width), static_cast<GLsizei>(descriptor.height),
glTextureStorage3D(texID, descriptor.m_Levels, GetOpenGLInternalFormat(descriptor.format), static_cast<GLsizei>(descriptor.width), static_cast<GLsizei>(descriptor.height),
static_cast<GLsizei>(descriptor.m_NumTextures));
memory = descriptor.width * descriptor.height * Renderer::GetNumberChannels(descriptor.format) * SizeOfGLType(OpenGLUnderlyingType(descriptor.format))
* descriptor.m_NumTextures;
Expand All @@ -111,7 +113,8 @@ bool C_GLDevice::AllocateTexture(Renderer::I_DeviceTexture& texture)
textureGL->SetParameter(GL_TEXTURE_BASE_LEVEL, 0);
textureGL->SetParameter(GL_TEXTURE_MAX_LEVEL, descriptor.m_Levels - 1);

AllocateSampler(textureGL->m_DefaultSampler); // TODO once proper sampler system ready delete this
if (!AllocateSampler(textureGL->m_DefaultSampler)) // TODO once proper sampler system ready delete this
return false;
return true;
}
default:
Expand Down Expand Up @@ -141,6 +144,18 @@ void C_GLDevice::DestroyTexture(Renderer::I_DeviceTexture& texture)
textureGL->m_texture = 0;
DestroySampler(textureGL->m_DefaultSampler);
textureGL->m_IsPresentOnGPU = false;
// release memory coutnter?
}

//=================================================================================
void C_GLDevice::DestroyBuffer(Renderer::I_Buffer& buffer)
{
auto* bufferGL = reinterpret_cast<Buffers::C_GLBufferImpl*>(&buffer);
GLE_ASSERT(bufferGL, "Wrong API buffer passed in");

const auto& descriptor = buffer.GetDescriptor();
m_MemoryUsed -= descriptor.size;
glDeleteBuffers(1, &bufferGL->m_id);
}

//=================================================================================
Expand Down Expand Up @@ -194,4 +209,25 @@ Renderer::I_Device::T_TextureHandle C_GLDevice::CreateTextureHandle(const Render
return std::make_shared<Textures::C_Texture>(desc);
}

//=================================================================================
bool C_GLDevice::AllocateBuffer(Renderer::I_Buffer& buffer)
{
auto* bufferGL = reinterpret_cast<Buffers::C_GLBufferImpl*>(&buffer);
GLE_ASSERT(bufferGL, "Wrong API buffer passed in");
const auto& descriptor = buffer.GetDescriptor();

glGenBuffers(1, &bufferGL->m_id);
glNamedBufferData(bufferGL->m_id, descriptor.size, nullptr, GetBufferUsage(descriptor.dynamics, descriptor.access));

m_MemoryUsed += descriptor.size;

return true;
}

//=================================================================================
Renderer::I_Device::T_BufferHandle C_GLDevice::CreateBufferHandle(const Renderer::BufferDescriptor& desc)
{
return std::make_shared<Buffers::C_GLBufferImpl>(desc);
}

} // namespace GLEngine::GLRenderer
4 changes: 4 additions & 0 deletions GLRenderer/GLRenderer/OGLDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class C_GLDevice : public Renderer::I_Device {
[[nodiscard]] virtual bool AllocateSampler(Renderer::I_TextureSampler2D& texture) override;
virtual void DestroySampler(Renderer::I_TextureSampler2D& texture) override;

bool AllocateBuffer(Renderer::I_Buffer& buffer) override;
T_BufferHandle CreateBufferHandle(const Renderer::BufferDescriptor& desc) override;
virtual void DestroyBuffer(Renderer::I_Buffer& buffer) override;

private:
[[nodiscard]] bool HasExtension(const std::string_view ext) const;

Expand Down
13 changes: 9 additions & 4 deletions GLRenderer/GLRenderer/VAO/VAO.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <GLRenderer/Buffers/GLBuffer.h>
#include <GLRenderer/Helpers/OpenGLTypesHelpers.h>
#include <GLRenderer/Helpers/BufferHelpers.h>

#include <Renderer/Buffer.h>

namespace GLEngine::GLRenderer::VAO {

Expand Down Expand Up @@ -55,10 +58,11 @@ template <int BUFFERS> class C_GLVAO : public I_GLVAOBase {
NameBuffer<INDEX>("indices");
}

template <int INDEX, GLenum BUFFERTYPE, class T, typename = T_EnableIndex<INDEX>> void SetBufferData(const std::vector<T>& data, bool dynamicDraw = false)
template <int INDEX, GLenum BUFFERTYPE, class T, typename = T_EnableIndex<INDEX>>
void SetBufferData(const std::vector<T>& data, const Renderer::BufferDynamics dynamics = Renderer::BufferDynamics::Static)
{
BindBuffer<INDEX>();
InnerSetBufferData<INDEX, BUFFERTYPE>(data, dynamicDraw);
InnerSetBufferData<INDEX, BUFFERTYPE>(data, dynamics);
m_Buffers[INDEX]->unbind();
}

Expand All @@ -74,9 +78,10 @@ template <int BUFFERS> class C_GLVAO : public I_GLVAOBase {
std::array<std::unique_ptr<Buffers::I_GLBufferBase>, BUFFERS> m_Buffers;

private:
template <int INDEX, GLenum BUFFERTYPE, class T, typename = T_EnableIndex<INDEX>> void InnerSetBufferData(const std::vector<T>& data, bool dynamicDraw = false)
template <int INDEX, GLenum BUFFERTYPE, class T, typename = T_EnableIndex<INDEX>>
void InnerSetBufferData(const std::vector<T>& data, const Renderer::BufferDynamics dynamics = Renderer::BufferDynamics::Static)
{
const auto usage = dynamicDraw ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
const auto usage = GetBufferUsage(dynamics, Renderer::BufferAccess::Draw);
m_Buffers[INDEX]->AllocateMemory(data.size() * sizeof(T), usage, data.data());
}
};
Expand Down
Loading