diff options
author | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
commit | 60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (patch) | |
tree | 02ec83cc8387abfd08bd5ee7ea4e8115f1bfb8d0 /source/Game/Renderer.hpp | |
parent | c2ef7737536bf1f8c81fcfae95c0183b21c9753f (diff) |
Changeset: 63 [WIP] Rename directories
Diffstat (limited to 'source/Game/Renderer.hpp')
-rw-r--r-- | source/Game/Renderer.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/source/Game/Renderer.hpp b/source/Game/Renderer.hpp new file mode 100644 index 0000000..98a9f28 --- /dev/null +++ b/source/Game/Renderer.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include "Camera.hpp" +#include "Material.hpp" +#include "RcPtr.hpp" +#include "VertexIndex.hpp" + +#include <glad/glad.h> +#include <cstddef> +#include <glm/glm.hpp> + +// TODO add optional support for OpenGL separate attrib binding & only depend on vertex format + +class GameObject; + +class RenderObject { +public: + RcPtr<Texture> autofill_TextureAtlas; + +private: + RcPtr<Material> mMaterial; + RcPtr<GpuIndexBuffer> mIndexBuf; + RcPtr<VertexFormat> mVertexFormat; + BufferBindings mVertexBufBinding; + GLuint mVao; + +public: + RenderObject(); + ~RenderObject(); + + GLuint GetGLVao() const; + void RebuildIfNecessary(); + + Material* GetMaterial() const { return mMaterial.Get(); } + void SetMaterial(Material* material); + + GpuIndexBuffer* GetIndexBuffer() const { return mIndexBuf.Get(); } + const VertexFormat* GetVertexFormat() const { return mVertexFormat.Get(); } + const BufferBindings& GetVertexBufferBindings() const { return mVertexBufBinding; } + void UpdateIndexBuffer(GpuIndexBuffer* indexBuffer); + void UpdateVertexFormat(VertexFormat* vertexFormat); + // Assumes the fetched BufferBinding object is modified + void UpdateVertexBufferBindings(BufferBindings** bindingsOut); + void SetFormat(VertexFormat* vertexFormat, Tags::IndexType indexFormat); + +private: + void DeleteGLObjects(); +}; + +struct RendererFrameInfo { + Camera* camera; + glm::mat4 matrixView; + glm::mat4 matrixProj; + float time; + float deltaTime; +}; + +class Renderer { +private: + RendererFrameInfo mFrame; + bool mInsideFrame = false; + +public: + void BeginFrame(Camera& camera, float currentTime, float deltaTime); + const RendererFrameInfo& GetLastFrameInfo() const { return mFrame; } + void Draw(const RenderObject* objects, const GameObject* gameObject, size_t count); + void EndFrame(); +}; |