summaryrefslogtreecommitdiffstats
path: root/src/Gal.hpp
blob: 51d3bd66fc2644989f97d8d5a34bf44e3ef7ada3 (plain) (blame)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#pragma once

#include <cstdint>
#include <memory>
#include <vector>
#include <string>
#include <string_view>

#include <glm/glm.hpp>

namespace Gal {

    struct Impl;
    struct Buffer;
    struct BufferBinding;
    struct TextureConfig;
    struct Texture;
    struct PipelineConfig;
    struct Pipeline;
    struct PipelineInstance;
    struct FramebufferConfig;
    struct Framebuffer;
    struct ShaderParameters;
    struct Shader;


    enum class Type {
        Float,
        Double,
        Uint8,
        Uint16,
        Uint32,
        Int8,
        Int16,
        Int32,
        Vec2,
        Vec2u8,
        Vec2u16,
        Vec2u32,
        Vec2i8,
        Vec2i16,
        Vec2i32,
        Vec3,
        Vec3u8,
        Vec3u16,
        Vec3u32,
        Vec3i8,
        Vec3i16,
        Vec3i32,
        Vec4,
        Vec4u8,
        Vec4u16,
        Vec4u32,
        Vec4i8,
        Vec4i16,
        Vec4i32,
        Mat2,
        Mat3,
        Mat4,
    };

    enum class Format {
        R8G8B8,
        R8G8B8A8,
    };

    enum class Filtering {
        Nearest,
        Bilinear,
        Trilinear,
        Anisotropy,
    };

    enum class Wrapping {
        Repeat,
        Mirror,
        Clamp,
    };

    enum class Primitive {
        Line,
        Triangle,
        TriangleStrip,
        TriangleFan,
    };

    struct VertexAttribute {
        std::string name;
        Type type;
        size_t count = 1;
        size_t instances = 0;
    };

    Impl* GetImplementation();

    struct Impl {

        virtual void Init() = 0;

        virtual void DeInit() = 0;

        virtual void Cleanup() = 0;

        virtual void SetScissor(size_t x=0, size_t y=0, size_t width=0, size_t height=0) = 0;

        virtual void SetScissor(bool enabled) = 0;


        virtual std::shared_ptr<Buffer> CreateBuffer() = 0;


        virtual std::shared_ptr<TextureConfig> CreateTexture2DConfig(size_t width, size_t height, Format format) = 0;

        virtual std::shared_ptr<TextureConfig> CreateTexture3DConfig(size_t width, size_t height, size_t depth, bool interpolateLayers, Format format) = 0;

        virtual std::shared_ptr<Texture> BuildTexture(std::shared_ptr<TextureConfig> config) = 0;


        virtual std::shared_ptr<PipelineConfig> CreatePipelineConfig() = 0;

        virtual std::shared_ptr<Pipeline> BuildPipeline(std::shared_ptr<PipelineConfig> config) = 0;


        virtual std::shared_ptr<FramebufferConfig> CreateFramebufferConfig() = 0;

        virtual std::shared_ptr<Framebuffer> BuildFramebuffer(std::shared_ptr<FramebufferConfig> config) = 0;

        virtual std::shared_ptr<Framebuffer> GetDefaultFramebuffer() = 0;


        virtual std::shared_ptr<ShaderParameters> GetGlobalShaderParameters() = 0;

        virtual std::shared_ptr<Shader> LoadVertexShader(std::string_view code) = 0;

        virtual std::shared_ptr<Shader> LoadPixelShader(std::string_view code) = 0;

    };

    struct Buffer {
        virtual ~Buffer() = default;

        virtual void SetData(std::vector<std::byte>&& data) = 0;
    };

    struct BufferBinding {
        virtual ~BufferBinding() = default;
    };

    struct TextureConfig {
        virtual ~TextureConfig() = default;

        virtual void SetMinFilter(Filtering filter) = 0;

        virtual void SetMaxFilter(Filtering filter) = 0;

        virtual void SetWrapping(Wrapping wrapping) = 0;

    };

    struct Texture {
        virtual ~Texture() = default;

        virtual void SetData(std::vector<std::byte>&& data, size_t mipLevel = 0) = 0;
    };

    struct PipelineConfig {
        virtual ~PipelineConfig() = default;

        virtual void SetVertexShader(std::shared_ptr<Shader> shader) = 0;

        virtual void SetPixelShader(std::shared_ptr<Shader> shader) = 0;

        virtual void AddShaderParameter(std::string_view name, Type type) = 0;

        virtual void SetTarget(std::shared_ptr<Framebuffer> target) = 0;

        virtual void SetPrimitive(Primitive primitive) = 0;

        virtual std::shared_ptr<BufferBinding> BindVertexBuffer(std::vector<VertexAttribute> &&bufferLayout) = 0;

        virtual std::shared_ptr<BufferBinding> BindIndexBuffer() = 0;
    };

    struct Pipeline {
        virtual ~Pipeline() = default;

        virtual void Activate() = 0;

        virtual std::shared_ptr<PipelineInstance> CreateInstance(std::vector<std::pair<std::shared_ptr<BufferBinding>, std::shared_ptr<Buffer>>> &&buffers) = 0;

        virtual void SetDynamicTexture(std::string_view name, std::shared_ptr<Texture> texture) = 0;

        virtual void SetShaderParameter(std::string_view name, float value) = 0;

        virtual void SetShaderParameter(std::string_view name, double value) = 0;

        virtual void SetShaderParameter(std::string_view name, int8_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, int16_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, int32_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, uint8_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, uint16_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, uint32_t value) = 0;

        virtual void SetShaderParameter(std::string_view name, glm::vec2 value) = 0;

        virtual void SetShaderParameter(std::string_view name, glm::uvec2 value) = 0;

        virtual void SetShaderParameter(std::string_view name, glm::vec3 value) = 0;

        virtual void SetShaderParameter(std::string_view name, glm::vec4 value) = 0;

        virtual void SetShaderParameter(std::string_view name, glm::mat4 value) = 0;
    };

    struct PipelineInstance {
        virtual ~PipelineInstance() = default;

        virtual void Activate() = 0;

        virtual void Render(size_t offset = 0, size_t count = -1) = 0;

        virtual void SetInstancesCount(size_t count) = 0;
    };

    struct Framebuffer {
        virtual ~Framebuffer() = default;

        virtual void Clear() = 0;

        virtual void SetViewport(size_t x, size_t y, size_t w, size_t h) = 0;
    };

    struct FramebufferConfig {
        virtual ~FramebufferConfig() = default;
    };

    struct ShaderParameters {
        virtual ~ShaderParameters() = default;

        virtual void AddGlobalShaderParameter(std::string_view name, Type type) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, float value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, double value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, int8_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, int16_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, int32_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, uint8_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, uint16_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, uint32_t value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, glm::vec2 value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, glm::vec3 value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, glm::vec4 value) = 0;

        virtual void SetGlobalShaderParameter(std::string_view name, glm::mat4 value) = 0;
    };

    struct Shader {
        virtual ~Shader() = default;
    };
}