summaryrefslogtreecommitdiff
path: root/gfx/src/core/core_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/src/core/core_impl.h')
-rw-r--r--gfx/src/core/core_impl.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/gfx/src/core/core_impl.h b/gfx/src/core/core_impl.h
new file mode 100644
index 0000000..e27c0f2
--- /dev/null
+++ b/gfx/src/core/core_impl.h
@@ -0,0 +1,66 @@
1#pragma once
2
3#include <gfx/core.h>
4#include <gfx/sizes.h>
5
6#include "buffer.h"
7#include "framebuffer.h"
8#include "geometry.h"
9#include "renderbuffer.h"
10#include "shader.h"
11#include "shader_program.h"
12#include "texture.h"
13
14#include <mempool.h>
15
16#include <stdint.h>
17
18// TODO: Make a generic (hash, void*) structure and define functions over it.
19// Then define a macro that defines type-safe macros given the type of the
20// entry.
21typedef struct ShaderCacheEntry {
22 uint64_t hash;
23 Shader* shader;
24} ShaderCacheEntry;
25
26typedef struct ShaderProgramCacheEntry {
27 uint64_t hash;
28 ShaderProgram* program;
29} ShaderProgramCacheEntry;
30
31DEF_MEMPOOL(buffer_pool, Buffer, GFX_MAX_NUM_BUFFERS)
32DEF_MEMPOOL(framebuffer_pool, FrameBuffer, GFX_MAX_NUM_FRAMEBUFFERS)
33DEF_MEMPOOL(geometry_pool, Geometry, GFX_MAX_NUM_GEOMETRIES)
34DEF_MEMPOOL(renderbuffer_pool, RenderBuffer, GFX_MAX_NUM_RENDERBUFFERS)
35DEF_MEMPOOL(shader_pool, Shader, GFX_MAX_NUM_SHADERS)
36DEF_MEMPOOL(shader_program_pool, ShaderProgram, GFX_MAX_NUM_SHADER_PROGRAMS)
37DEF_MEMPOOL(texture_pool, Texture, GFX_MAX_NUM_TEXTURES)
38
39DEF_MEMPOOL(ShaderCache, ShaderCacheEntry, GFX_MAX_NUM_SHADERS)
40DEF_MEMPOOL(ProgramCache, ShaderProgramCacheEntry, GFX_MAX_NUM_SHADER_PROGRAMS)
41
42typedef struct {
43 int width;
44 int height;
45} Viewport;
46
47typedef struct GfxCore {
48 Viewport viewport;
49 // mempools for render-specific objects: textures, geometry, etc.
50 buffer_pool buffers;
51 framebuffer_pool framebuffers;
52 geometry_pool geometries;
53 renderbuffer_pool renderbuffers;
54 shader_pool shaders;
55 shader_program_pool shader_programs;
56 texture_pool textures;
57 // Caches.
58 ShaderCache shader_cache;
59 ProgramCache program_cache;
60} GfxCore;
61
62/// Create a new render backend.
63void gfx_init_gfxcore(GfxCore*);
64
65/// Destroy the render backend.
66void gfx_del_gfxcore(GfxCore*);