summaryrefslogtreecommitdiff
path: root/src/new_render/render.h
blob: ef11b5f11f41e44d5dc5c6d5170a3a8312e69d63 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
 * @brief
 */

#pragma once
#include "defines.h"
#include "maths_types.h"
#include "ral_types.h"
#include "render_types.h"
#include "shadows.h"

typedef struct Renderer Renderer;
typedef struct GLFWwindow GLFWwindow;
typedef struct RendererConfig {
  char window_name[256];
  u32 scr_width, scr_height;
  Vec3 clear_colour;
} RendererConfig;

typedef struct RenderFlags {
  bool wireframe;
} RenderFlags;

typedef struct RenderCtx {
  Mat4 view;
  Mat4 projection;
} RenderCtx;

// #define MESH_GET(h) (Mesh_pool_get(g_core.renderer->meshes, h))
// #define MATERIAL_GET(h) (Material_pool_get(g_core.renderer->material, h))

// --- Lifecycle

PUB bool Renderer_Init(RendererConfig config, Renderer* renderer, GLFWwindow** out_window,
                       GLFWwindow* optional_window);
PUB void Renderer_Shutdown(Renderer* renderer);
PUB size_t Renderer_GetMemReqs();
void Render_WindowSizeChanged(GLFWwindow* window, i32 new_width, i32 new_height);

// internal init functions
void DefaultPipelinesInit(Renderer* renderer);

// NOTE: All of these functions grab the Renderer instance off the global Core
PUB void Render_FrameBegin(Renderer* renderer);
PUB void Render_FrameEnd(Renderer* renderer);

/** @brief  */
PUB void Render_RenderEntities(RenderEnt* entities, size_t entity_count);

// TODO: Render_FrameDraw(); - this will

// --- Resources

PUB TextureData TextureDataLoad(const char* path, bool invert_y);
PUB void TextureUpload(TextureHandle handle, size_t n_bytes, const void* data);
PUB TextureHandle TextureLoadFromFile(const char* path);
PUB ModelHandle ModelLoad(const char* debug_name, const char* filepath);

// --- Rendering Data

PUB Mesh Mesh_Create(Geometry* geometry, bool free_on_upload);
PUB void Mesh_Delete(Mesh* mesh);
void Geometry_Destroy(Geometry* geometry);

// --- Drawing

// NOTE: These functions use the globally bound camera in RenderScene
PUB void DrawMesh(Mesh* mesh, Material* material, Mat4 model);

/** @brief the renderer does some internal bookkeeping for terrain so we use the terrain
           stored on the Renderer rather than accept it as a parameter */
PUB void Render_DrawTerrain();

// --- Getters (not in love with this but I'm finding keeping Renderer internals private to be okay)
arena* GetRenderFrameArena(Renderer* r);

typedef struct RenderScene RenderScene;
typedef struct Shadow_Storage Shadow_Storage;
typedef struct Terrain_Storage Terrain_Storage;

RenderScene* Render_GetScene();
Shadow_Storage* Render_GetShadowStorage();
Terrain_Storage* Render_GetTerrainStorage();
TextureHandle Render_GetWhiteTexture();
arena* Render_GetFrameArena();
Mesh_pool* Render_GetMeshPool();
Material_pool* Render_GetMaterialPool();