From 855da86feae1a5cc14dc2d486ccf115f484dbc2e Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 25 Apr 2022 20:22:07 -0700 Subject: Changeset: 16 Initial work on rendering sprites to screen --- source/Renderer.hpp | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'source/Renderer.hpp') diff --git a/source/Renderer.hpp b/source/Renderer.hpp index 18a1e6e..b4ca735 100644 --- a/source/Renderer.hpp +++ b/source/Renderer.hpp @@ -1,46 +1,61 @@ #pragma once +#include "Camera.hpp" #include "Material.hpp" -#include "Mesh.hpp" #include "RcPtr.hpp" +#include "VertexIndex.hpp" #include +#include #include +// TODO add optional support for OpenGL separate attrib binding & only depend on vertex format + +// By default, RenderObject sets a default material but not data buffers. class RenderObject { public: glm::mat4 worldMatrix; private: RcPtr mMaterial; - RcPtr mMesh; + RcPtr mIndexBuf; + RcPtr mVertexFormat; + BufferBindings mVertexBufBinding; GLuint mVao; public: - RenderObject(GpuMesh* mesh, Material* material); + RenderObject(); ~RenderObject(); - GLuint GetGLVao() const { return mVao; } + GLuint GetGLVao() const; + void RebuildIfNecessary(); + Material* GetMaterial() const { return mMaterial.Get(); } - GpuMesh* GetMesh() const { return mMesh.Get(); } -}; + void SetMaterial(Material* material); -class Camera { -public: - glm::mat4 viewMatrix; - glm::mat4 projectionMatrix; + 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); -public: - void Move(glm::vec3 pos); - void LookAt(glm::vec3 pos); +private: + void DeleteGLObjects(); }; class Renderer { private: - Camera* mCam; + Camera* mFrame_Cam; + glm::mat4 mFrame_Transform; + float mFrame_Time; + float mFrame_DeltaTime; + bool mInsideFrame = false; public: - void BeginFrame(); + void BeginFrame(Camera& camera, float currentTime, float deltaTime); + void Draw(const RenderObject* objects, size_t count); void EndFrame(); - void Draw(RenderObject& object); }; -- cgit v1.2.3-70-g09d2