#pragma once #include "Camera.hpp" #include "Material.hpp" #include "RcPtr.hpp" #include "VertexIndex.hpp" #include #include #include // TODO add optional support for OpenGL separate attrib binding & only depend on vertex format class RenderObject { public: glm::mat4 worldMatrix; public: RcPtr autofill_TextureAtlas; private: RcPtr mMaterial; RcPtr mIndexBuf; RcPtr 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; glm::mat4 matrixCombined; 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, size_t count); void EndFrame(); };