summaryrefslogtreecommitdiff
path: root/gfx/src/render/core_impl.h
blob: e27c0f27361e517cb71f953bbf47f15fe9bcf693 (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
62
63
64
65
66
#pragma once

#include <gfx/core.h>
#include <gfx/sizes.h>

#include "buffer.h"
#include "framebuffer.h"
#include "geometry.h"
#include "renderbuffer.h"
#include "shader.h"
#include "shader_program.h"
#include "texture.h"

#include <mempool.h>

#include <stdint.h>

// TODO: Make a generic (hash, void*) structure and define functions over it.
// Then define a macro that defines type-safe macros given the type of the
// entry.
typedef struct ShaderCacheEntry {
  uint64_t hash;
  Shader*  shader;
} ShaderCacheEntry;

typedef struct ShaderProgramCacheEntry {
  uint64_t       hash;
  ShaderProgram* program;
} ShaderProgramCacheEntry;

DEF_MEMPOOL(buffer_pool, Buffer, GFX_MAX_NUM_BUFFERS)
DEF_MEMPOOL(framebuffer_pool, FrameBuffer, GFX_MAX_NUM_FRAMEBUFFERS)
DEF_MEMPOOL(geometry_pool, Geometry, GFX_MAX_NUM_GEOMETRIES)
DEF_MEMPOOL(renderbuffer_pool, RenderBuffer, GFX_MAX_NUM_RENDERBUFFERS)
DEF_MEMPOOL(shader_pool, Shader, GFX_MAX_NUM_SHADERS)
DEF_MEMPOOL(shader_program_pool, ShaderProgram, GFX_MAX_NUM_SHADER_PROGRAMS)
DEF_MEMPOOL(texture_pool, Texture, GFX_MAX_NUM_TEXTURES)

DEF_MEMPOOL(ShaderCache, ShaderCacheEntry, GFX_MAX_NUM_SHADERS)
DEF_MEMPOOL(ProgramCache, ShaderProgramCacheEntry, GFX_MAX_NUM_SHADER_PROGRAMS)

typedef struct {
  int width;
  int height;
} Viewport;

typedef struct GfxCore {
  Viewport viewport;
  // mempools for render-specific objects: textures, geometry, etc.
  buffer_pool         buffers;
  framebuffer_pool    framebuffers;
  geometry_pool       geometries;
  renderbuffer_pool   renderbuffers;
  shader_pool         shaders;
  shader_program_pool shader_programs;
  texture_pool        textures;
  // Caches.
  ShaderCache  shader_cache;
  ProgramCache program_cache;
} GfxCore;

/// Create a new render backend.
void gfx_init_gfxcore(GfxCore*);

/// Destroy the render backend.
void gfx_del_gfxcore(GfxCore*);