This repository was archived by the owner on Jan 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitan_Graphics.hpp
More file actions
157 lines (126 loc) · 3.8 KB
/
Copy pathTitan_Graphics.hpp
File metadata and controls
157 lines (126 loc) · 3.8 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Titan Graphics Header
*
* Graphics device abstraction and rendering
*/
#ifndef TITAN_GRAPHICS_HPP
#define TITAN_GRAPHICS_HPP
#include "Titan_Core.hpp"
#include "Titan_Math.hpp"
#include <vector>
namespace Titan::Graphics {
// ============================================================================
// Handle Types
// ============================================================================
struct Handle
{
uint32 id = 0;
bool IsValid() const { return id != 0; }
};
struct BufferHandle : Handle {};
struct ShaderHandle : Handle {};
struct TextureHandle : Handle {};
// ============================================================================
// Enums
// ============================================================================
enum class BufferType
{
Vertex,
Index
};
enum class BufferUsage
{
Static,
Dynamic
};
enum class AttributeType
{
Float,
Byte,
UByte
};
enum class TextureFormat
{
R8,
RGBA8,
RGB8,
Depth24
};
enum class TextureFilter
{
Nearest,
Linear
};
// ============================================================================
// Descriptors
// ============================================================================
struct VertexAttribute
{
uint32 count;
AttributeType type;
bool normalized;
};
struct BufferDesc
{
BufferType type;
BufferUsage usage;
usize size;
const void* data;
std::vector<VertexAttribute> layout;
};
struct TextureDesc
{
uint32 width;
uint32 height;
TextureFormat format;
TextureFilter filter;
const void* data;
};
// ============================================================================
// Render Device Interface
// ============================================================================
class IRenderDevice
{
public:
virtual ~IRenderDevice() = default;
virtual void Init() = 0;
virtual void Shutdown() = 0;
// Buffer operations
virtual BufferHandle CreateBuffer(const BufferDesc& Desc) = 0;
virtual void UpdateBuffer(BufferHandle Handle, usize Offset, usize Size, const void* Data) = 0;
virtual void DestroyBuffer(BufferHandle Handle) = 0;
// Shader operations
virtual ShaderHandle CreateShader(const char* VertexSource, const char* FragmentSource) = 0;
virtual void DestroyShader(ShaderHandle Handle) = 0;
// Texture operations
virtual TextureHandle CreateTexture(const TextureDesc& Desc) = 0;
virtual void DestroyTexture(TextureHandle Handle) = 0;
// Binding
virtual void BindPipeline(ShaderHandle Handle) = 0;
virtual void BindVertexBuffer(BufferHandle Handle) = 0;
virtual void BindIndexBuffer(BufferHandle Handle) = 0;
virtual void BindTexture(TextureHandle Handle, uint32 Slot) = 0;
// Uniforms
virtual void SetUniformMat4(ShaderHandle Handle, const char* Name, const Math::Mat4& Matrix) = 0;
virtual void SetUniformVec4(ShaderHandle Handle, const char* Name, const Math::Vec4& Vector) = 0;
virtual void SetUniformInt(ShaderHandle Handle, const char* Name, int32 Value) = 0;
// Drawing
virtual void Clear(float R, float G, float B) = 0;
virtual void DrawIndexed(uint32 Count, uint32 Offset) = 0;
virtual void DrawArrays(uint32 Count, uint32 First) = 0;
};
// ============================================================================
// Global Device
// ============================================================================
extern IRenderDevice* g_Device;
// ============================================================================
// Backend Utilities
// ============================================================================
struct Backend
{
static void Init();
static void Shutdown();
static void Clear(float R, float G, float B);
};
} // namespace Titan::Graphics
#endif // TITAN_GRAPHICS_HPP