blob: b4ca7359668bf15ecc8a12fd91fc38fe0c704a0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#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
// By default, RenderObject sets a default material but not data buffers.
class RenderObject {
public:
glm::mat4 worldMatrix;
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();
};
class Renderer {
private:
Camera* mFrame_Cam;
glm::mat4 mFrame_Transform;
float mFrame_Time;
float mFrame_DeltaTime;
bool mInsideFrame = false;
public:
void BeginFrame(Camera& camera, float currentTime, float deltaTime);
void Draw(const RenderObject* objects, size_t count);
void EndFrame();
};
|