Skip to content

Commit

Permalink
Add MultiDrawIndirect to RendererAPI
Browse files Browse the repository at this point in the history
Fix glad loader
  • Loading branch information
KredeGC committed Sep 20, 2024
1 parent c105763 commit e1a72db
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 180 deletions.
132 changes: 57 additions & 75 deletions Mahakam/src/Mahakam/Renderer/GL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Mahakam/Core/Profiler.h"
#include "Mahakam/Core/SharedLibrary.h"

#include "Mahakam/Asset/Asset.h"

#include "Mesh.h"
#include "Texture.h"

Expand Down Expand Up @@ -101,160 +103,140 @@ namespace Mahakam
}

#pragma region Mesh
//Ref<Mesh> GL::GetScreenQuad()
MH_DEFINE_FUNC(GL::GetScreenQuad, Ref<SubMesh>)
Ref<SubMesh> GL::GetScreenQuad()
{
return s_StaticScreenQuad;
};
}

//Ref<Mesh> GL::GetSphere()
MH_DEFINE_FUNC(GL::GetSphere, Ref<SubMesh>)
Ref<SubMesh> GL::GetSphere()
{
return s_StaticSphereMesh;
};
}

//Ref<Mesh> GL::GetInvertedPyramid()
MH_DEFINE_FUNC(GL::GetInvertedPyramid, Ref<SubMesh>)
Ref<SubMesh> GL::GetInvertedPyramid()
{
return s_StaticInvertedPyramid;
};
}

//Ref<Mesh> GL::GetInvertedSphere()
MH_DEFINE_FUNC(GL::GetInvertedSphere, Ref<SubMesh>)
Ref<SubMesh> GL::GetInvertedSphere()
{
return s_StaticInvertedSphereMesh;
};
}

//Ref<Mesh> GL::GetInvertedCube()
MH_DEFINE_FUNC(GL::GetInvertedCube, Ref<SubMesh>)
Ref<SubMesh> GL::GetInvertedCube()
{
return s_StaticInvertedCubemapMesh;
};
}

//Ref<Mesh> GL::GetCube()
MH_DEFINE_FUNC(GL::GetCube, Ref<SubMesh>)
Ref<SubMesh> GL::GetCube()
{
return s_StaticCube;
};
}
#pragma endregion

#pragma region Texture
//Ref<Texture2D> GL::GetTexture2DRed()
MH_DEFINE_FUNC(GL::GetTexture2DRed, Asset<Texture2D>)
Asset<Texture2D> GL::GetTexture2DRed()
{
return s_Texture2DRed;
};
}

//Ref<Texture2D> GL::GetTexture2DWhite()
MH_DEFINE_FUNC(GL::GetTexture2DWhite, Asset<Texture2D>)
Asset<Texture2D> GL::GetTexture2DWhite()
{
return s_Texture2DWhite;
};
}

//Ref<Texture2D> GL::GetTexture2DBlack()
MH_DEFINE_FUNC(GL::GetTexture2DBlack, Asset<Texture2D>)
Asset<Texture2D> GL::GetTexture2DBlack()
{
return s_Texture2DBlack;
};
}

//Ref<Texture2D> GL::GetTexture2DBump()
MH_DEFINE_FUNC(GL::GetTexture2DBump, Asset<Texture2D>)
Asset<Texture2D> GL::GetTexture2DBump()
{
return s_Texture2DBump;
};
}

//Ref<TextureCube> GL::GetTextureCubeWhite()
MH_DEFINE_FUNC(GL::GetTextureCubeWhite, Asset<TextureCube>)
Asset<TextureCube> GL::GetTextureCubeWhite()
{
return s_TextureCubeWhite;
};
}

//Ref<TextureCube> GL::GetTextureCubeGrey()
MH_DEFINE_FUNC(GL::GetTextureCubeGrey, Asset<TextureCube>)
Asset<TextureCube> GL::GetTextureCubeGrey()
{
return s_TextureCubeGrey;
};
}
#pragma endregion

//const char* GL::GetGraphicsVendor()
MH_DEFINE_FUNC(GL::GetGraphicsVendor, const char*)
const char* GL::GetGraphicsVendor()
{
return s_RendererAPI->GetGraphicsVendor();
};
}

//void GL::SetViewportImpl(uint32_t x, uint32_t y, uint32_t w, uint32_t h, bool scissor)
MH_DEFINE_FUNC(GL::SetViewportImpl, void, uint32_t x, uint32_t y, uint32_t w, uint32_t h, bool scissor)
void GL::SetViewportImpl(uint32_t x, uint32_t y, uint32_t w, uint32_t h, bool scissor)
{
s_RendererAPI->SetViewport(x, y, w, h, scissor);
};
}

//void GL::FinishRendering()
MH_DEFINE_FUNC(GL::FinishRendering, void)
void GL::FinishRendering()
{
s_RendererAPI->FinishRendering();
};
}

//void GL::SetClearColor(const glm::vec4& color)
MH_DEFINE_FUNC(GL::SetClearColor, void, const glm::vec4& color)
void GL::SetClearColor(const glm::vec4& color)
{
s_RendererAPI->SetClearColor(color);
};
}

//void GL::ClearImpl(bool color, bool depth)
MH_DEFINE_FUNC(GL::ClearImpl, void, bool color, bool depth)
void GL::ClearImpl(bool color, bool depth)
{
s_RendererAPI->Clear(color, depth);
};
}

//void GL::EnableCullingImpl(bool enable, bool cullFront)
MH_DEFINE_FUNC(GL::EnableCullingImpl, void, bool enable, bool cullFront)
void GL::EnableCullingImpl(bool enable, bool cullFront)
{
s_RendererAPI->EnableCulling(enable, cullFront);
};
}

//void GL::EnableZWriting(bool enable)
MH_DEFINE_FUNC(GL::EnableZWriting, void, bool enable)
void GL::EnableZWriting(bool enable)
{
s_RendererAPI->EnableZWriting(enable);
};
}

//void GL::SetZTesting(RendererAPI::DepthMode mode)
MH_DEFINE_FUNC(GL::SetZTesting, void, RendererAPI::DepthMode mode)
void GL::SetZTesting(RendererAPI::DepthMode mode)
{
s_RendererAPI->SetZTesting(mode);
};
}

//void GL::SetFillMode(bool enable)
MH_DEFINE_FUNC(GL::SetFillMode, void, bool enable)
void GL::SetFillMode(bool enable)
{
s_RendererAPI->SetFillMode(enable);
};
}

//void GL::SetBlendMode(RendererAPI::BlendMode src, RendererAPI::BlendMode dst, bool enable)
MH_DEFINE_FUNC(GL::SetBlendMode, void, RendererAPI::BlendMode src, RendererAPI::BlendMode dst, bool enable)
void GL::SetBlendMode(RendererAPI::BlendMode src, RendererAPI::BlendMode dst, bool enable)
{
s_RendererAPI->SetBlendMode(src, dst, enable);
};
}

#pragma region Draw
//void GL::DrawScreenQuad()
MH_DEFINE_FUNC(GL::DrawScreenQuad, void)
void GL::DrawScreenQuad()
{
s_StaticScreenQuad->Bind();
s_RendererAPI->DrawIndexed(s_StaticScreenQuad->GetIndexCount());
};
}

//void GL::DrawIndexed(uint32_t indexCount)
MH_DEFINE_FUNC(GL::DrawIndexed, void, uint32_t indexCount)
void GL::DrawIndexed(uint32_t indexCount)
{
s_RendererAPI->DrawIndexed(indexCount);
};
}

//void GL::DrawInstanced(uint32_t indexCount, uint32_t count)
MH_DEFINE_FUNC(GL::DrawInstanced, void, uint32_t indexCount, uint32_t count)
void GL::DrawInstanced(uint32_t indexCount, uint32_t count)
{
s_RendererAPI->DrawInstanced(indexCount, count);
};
}

void GL::MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count)
{
s_RendererAPI->MultiDrawIndexed(indirect, stride, count);
}
#pragma endregion

Ref<SubMesh> GL::CreateScreenQuad()
Expand Down
27 changes: 18 additions & 9 deletions Mahakam/src/Mahakam/Renderer/GL.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#include "Mahakam/Core/Types.h"

#include "Mahakam/Asset/Asset.h"

namespace Mahakam
{
template<typename T>
class Asset;

class SubMesh;
class Texture2D;
class TextureCube;
Expand Down Expand Up @@ -42,10 +43,10 @@ namespace Mahakam
MH_DECLARE_FUNC(GetInvertedCube, Ref<SubMesh>);
MH_DECLARE_FUNC(GetCube, Ref<SubMesh>);

MH_DECLARE_FUNC(GetTexture2DRed, Asset<Texture2D>);
MH_DECLARE_FUNC(GetTexture2DWhite, Asset<Texture2D>);
MH_DECLARE_FUNC(GetTexture2DBlack, Asset<Texture2D>);
MH_DECLARE_FUNC(GetTexture2DBump, Asset<Texture2D>);
static Asset<Texture2D> GetTexture2DRed();
static Asset<Texture2D> GetTexture2DWhite();
static Asset<Texture2D> GetTexture2DBlack();
static Asset<Texture2D> GetTexture2DBump();
MH_DECLARE_FUNC(GetTextureCubeWhite, Asset<TextureCube>);
MH_DECLARE_FUNC(GetTextureCubeGrey, Asset<TextureCube>);

Expand All @@ -66,11 +67,19 @@ namespace Mahakam
MH_DECLARE_FUNC(SetFillMode, void, bool fill);
MH_DECLARE_FUNC(SetBlendMode, void, RendererAPI::BlendMode src, RendererAPI::BlendMode dst, bool enable);

MH_DECLARE_FUNC(DrawScreenQuad, void);
MH_DECLARE_FUNC(DrawIndexed, void, uint32_t indexCount);
MH_DECLARE_FUNC(DrawInstanced, void, uint32_t indexCount, uint32_t count);
static void DrawScreenQuad();
static void DrawIndexed(uint32_t indexCount);
static void DrawInstanced(uint32_t indexCount, uint32_t count);

template<typename T>
static void MultiDrawIndexed(const T* indirect, uint32_t count)
{
MultiDrawIndexed(indirect, sizeof(T), count);
}

private:
static void MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count);

static Ref<SubMesh> CreateScreenQuad();
static Ref<SubMesh> CreatePyramid();

Expand Down
1 change: 1 addition & 0 deletions Mahakam/src/Mahakam/Renderer/RendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace Mahakam
virtual void SetFillMode(bool fill) = 0;
virtual void SetBlendMode(BlendMode src, BlendMode dst, bool enable) = 0;

virtual void MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count) = 0;
virtual void DrawIndexed(uint32_t count) = 0;
virtual void DrawInstanced(uint32_t indexCount, uint32_t count) = 0;

Expand Down
2 changes: 2 additions & 0 deletions Mahakam/src/Platform/Headless/HeadlessRendererAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Mahakam

void HeadlessRendererAPI::SetBlendMode(BlendMode src, BlendMode dst, bool enable) {}

void HeadlessRendererAPI::MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count) {}

void HeadlessRendererAPI::DrawIndexed(uint32_t count) {}

void HeadlessRendererAPI::DrawInstanced(uint32_t indexCount, uint32_t count) {}
Expand Down
1 change: 1 addition & 0 deletions Mahakam/src/Platform/Headless/HeadlessRendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Mahakam
virtual void SetFillMode(bool fill) override;
virtual void SetBlendMode(BlendMode src, BlendMode dst, bool enable) override;

virtual void MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count) override;
virtual void DrawIndexed(uint32_t count) override;
virtual void DrawInstanced(uint32_t indexCount, uint32_t count) override;
};
Expand Down
2 changes: 1 addition & 1 deletion Mahakam/src/Platform/OpenGL/OpenGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Mahakam
{
MH_PROFILE_FUNCTION();

int status = gladLoadGL(glfwGetProcAddress);
int status = gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
MH_ASSERT(status, "Could not initialize glad!");

MH_ASSERT(glGetError, "Could not initialize OpenGL functions!");
Expand Down
5 changes: 5 additions & 0 deletions Mahakam/src/Platform/OpenGL/OpenGLRendererAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ namespace Mahakam
}
}

void OpenGLRendererAPI::MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count)
{
MH_GL_CALL(glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, indirect, count, stride));
}

void OpenGLRendererAPI::DrawIndexed(uint32_t count)
{
MH_GL_CALL(glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr));
Expand Down
1 change: 1 addition & 0 deletions Mahakam/src/Platform/OpenGL/OpenGLRendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Mahakam
virtual void SetFillMode(bool fill) override;
virtual void SetBlendMode(BlendMode src, BlendMode dst, bool enable) override;

virtual void MultiDrawIndexed(const void* indirect, uint32_t stride, uint32_t count) override;
virtual void DrawIndexed(uint32_t count) override;
virtual void DrawInstanced(uint32_t indexCount, uint32_t count) override;
};
Expand Down
2 changes: 0 additions & 2 deletions Mahakam/src/Platform/OpenGL/OpenGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ namespace Mahakam

void OpenGLTexture2D::Bind(uint32_t slot) const
{
//glGetTextureHandleARB(m_RendererID);

MH_GL_CALL(glBindTextureUnit(slot, m_RendererID));
}

Expand Down
12 changes: 0 additions & 12 deletions Sandbox/assets/10127498216877445756.asset.legacy

This file was deleted.

1 change: 0 additions & 1 deletion Sandbox/assets/11869644962294522068.asset.legacy

This file was deleted.

5 changes: 0 additions & 5 deletions Sandbox/assets/11945816250811211738.asset.legacy

This file was deleted.

5 changes: 0 additions & 5 deletions Sandbox/assets/13155307824895996659.asset.legacy

This file was deleted.

1 change: 0 additions & 1 deletion Sandbox/assets/13750326872447612574.asset.legacy

This file was deleted.

3 changes: 0 additions & 3 deletions Sandbox/assets/1413214223373882268.asset.legacy

This file was deleted.

3 changes: 0 additions & 3 deletions Sandbox/assets/1413214623375882268.asset.legacy

This file was deleted.

7 changes: 0 additions & 7 deletions Sandbox/assets/15739498696759362444.asset.legacy

This file was deleted.

1 change: 0 additions & 1 deletion Sandbox/assets/332566198138111729.asset.legacy

This file was deleted.

12 changes: 0 additions & 12 deletions Sandbox/assets/46003763570734560.asset.legacy

This file was deleted.

Loading

0 comments on commit e1a72db

Please sign in to comment.