commit 5a4a912
uint
·
2026-08-05 01:51:16 +0000 UTC
parent 85e6e35
remove renderer_backend layer
7 files changed,
+40,
-111
M
TODO
+1,
-1
1@@ -1,6 +1,5 @@
2 uint:
3 [ ] Remove `renderer_backend`
4-[ ] mc_*, mg_random type cleanup (int->i8 on bool)
5 [ ] Review `block`
6 [ ] Small3DLib inline?? check ANSI
7
8@@ -21,6 +20,7 @@ uint:
9
10 [ ] Check it works on Windows
11
12+[X] mc_*, mg_random type cleanup (int->i8 on bool)
13 [X] Clean up test_scene.h
14 [X] Maus wayland
15 [X] Wireframe
+1,
-3
1@@ -65,9 +65,7 @@ mgmath_dep = declare_dependency(
2
3 renderer_c_args = []
4 platform_c_args = []
5-renderer_sources = [
6- 'source/renderer/renderer.c',
7-]
8+renderer_sources = []
9
10 if window_backend == 'sdl'
11 sources += [ 'source/platform/platform_sdl.c' ]
+1,
-1
1@@ -52,7 +52,7 @@ void player_server_handle_position(Player* player, MGCamera* cam, const MCPacket
2 cam->yaw = MG_AngleDeg(player->yaw - 180.0f);
3 cam->pitch = MG_AngleDeg(-player->pitch);
4 }
5-
6+
7 void player_server_send_position(Player* player, MGCamera* cam, MCClient* client)
8 {
9 static u32 last_send;
+0,
-52
1@@ -1,52 +0,0 @@
2-#include "renderer/renderer.h"
3-#include "renderer_backend.h"
4-
5-void renderer_create(MGContext* ctx)
6-{
7- renderer_backend_create(ctx);
8-}
9-
10-void renderer_begin(void)
11-{
12- renderer_backend_begin();
13-}
14-
15-void renderer_end(void)
16-{
17- renderer_backend_end();
18-}
19-
20-void renderer_destroy(void)
21-{
22- renderer_backend_destroy();
23-}
24-
25-MGMesh renderer_mesh_create(const MGMeshDesc* desc)
26-{
27- return renderer_backend_mesh_create(desc);
28-}
29-
30-void renderer_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp)
31-{
32- renderer_backend_mesh_draw(mesh, texture, mvp);
33-}
34-
35-void renderer_mesh_destroy(MGMesh mesh)
36-{
37- renderer_backend_mesh_destroy(mesh);
38-}
39-
40-MGTexture renderer_texture_load(const char* path)
41-{
42- return renderer_backend_texture_load(path);
43-}
44-
45-MGTexture renderer_texture_create(const MGTextureDesc* desc)
46-{
47- return renderer_backend_texture_create(desc);
48-}
49-
50-void renderer_texture_destroy(MGTexture texture)
51-{
52- renderer_backend_texture_destroy(texture);
53-}
+0,
-19
1@@ -1,19 +0,0 @@
2-#ifndef RENDERER_BACKEND_H
3-#define RENDERER_BACKEND_H
4-
5-#include "renderer/renderer.h"
6-
7-void renderer_backend_create(MGContext* ctx);
8-void renderer_backend_begin(void);
9-void renderer_backend_end(void);
10-void renderer_backend_destroy(void);
11-
12-MGMesh renderer_backend_mesh_create(const MGMeshDesc* desc);
13-void renderer_backend_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp);
14-void renderer_backend_mesh_destroy(MGMesh mesh);
15-
16-MGTexture renderer_backend_texture_load(const char* path);
17-MGTexture renderer_backend_texture_create(const MGTextureDesc* desc);
18-void renderer_backend_texture_destroy(MGTexture texture);
19-
20-#endif /* RENDERER_BACKEND_H */
+24,
-21
1@@ -10,7 +10,6 @@
2 #include "types.h"
3 #include "platform/platform.h"
4 #include "renderer/renderer.h"
5-#include "renderer_backend.h"
6
7 #define MAX_MESHES (16384)
8 #define MAX_TEXTURES (512)
9@@ -85,13 +84,15 @@ static void create_screen_texture(i32 width, i32 height);
10 /* destroy the SDL texture and software framebuffer */
11 static void destroy_screen_texture(void);
12
13-static ClipVertex transform_vertex(const MGMat4* mvp, const MGVertex* v);
14-static i8 triangle_outside(const ClipVertex* a, const ClipVertex* b, const ClipVertex* c);
15-static i8 triangle_front_facing(const ClipVertex* a, const ClipVertex* b, const ClipVertex* c);
16-static S3L_Vec4 clip_to_screen(const ClipVertex* v);
17-static u32 sample_texture(const RendererMesh* mesh, const RendererTexture* texture, const S3L_PixelInfo* pixel);
18-static u16 rgba_to_rgb565(u32 rgba);
19-static u32 rgb565_to_argb(u16 rgb);
20+static ClipVertex transform_vertex(const MGMat4* mvp, const MGVertex* v);
21+static i8 triangle_outside(const ClipVertex* a, const ClipVertex* b, const ClipVertex* c);
22+static i8 triangle_front_facing(const ClipVertex* a, const ClipVertex* b, const ClipVertex* c);
23+static S3L_Vec4 clip_to_screen(const ClipVertex* v);
24+static u32 sample_texture(const RendererMesh* mesh, const RendererTexture* texture, const S3L_PixelInfo* pixel);
25+static u16 rgba_to_rgb565(u32 rgba);
26+#ifndef MG_PLATFORM_SDL
27+static u32 rgb565_to_argb(u16 rgb);
28+#endif
29 static u32 pack_texture_pixel(u32 rgba);
30 static inline void small3dlib_pixel(S3L_PixelInfo* pixel);
31
32@@ -332,6 +333,7 @@ static u16 rgba_to_rgb565(u32 rgba)
33 return (u16)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
34 }
35
36+#ifndef MG_PLATFORM_SDL
37 /* convert RGB565 colour to ARGB8
38 returns ARGB8 colour */
39 static u32 rgb565_to_argb(u16 rgb)
40@@ -346,6 +348,7 @@ static u32 rgb565_to_argb(u16 rgb)
41
42 return 0xff000000 | (r << 16) | (g << 8) | b;
43 }
44+#endif
45
46 /* pack texture pixel for renderer
47 returns packed texture pixel */
48@@ -354,7 +357,7 @@ static u32 pack_texture_pixel(u32 rgba)
49 return ((rgba >> 24) << 24) | rgba_to_rgb565(rgba);
50 }
51
52-void renderer_backend_create(MGContext* ctx)
53+void renderer_create(MGContext* ctx)
54 {
55 ren.ctx = ctx;
56 ren.pass = 0;
57@@ -363,7 +366,7 @@ void renderer_backend_create(MGContext* ctx)
58 ren.active_triangle = (u32)-1;
59 }
60
61-void renderer_backend_begin(void)
62+void renderer_begin(void)
63 {
64 i32 width;
65 i32 height;
66@@ -398,7 +401,7 @@ void renderer_backend_begin(void)
67 ren.pass = 1;
68 }
69
70-void renderer_backend_end(void)
71+void renderer_end(void)
72 {
73 #ifdef MG_PLATFORM_MAUS
74 i32 x;
75@@ -427,16 +430,16 @@ void renderer_backend_end(void)
76 ren.pass = 0;
77 }
78
79-void renderer_backend_destroy(void)
80+void renderer_destroy(void)
81 {
82 u32 id;
83
84 /* the values could be different in future so
85 probably should keep them separate */
86 for (id = 1; id < MAX_MESHES; id++)
87- renderer_backend_mesh_destroy(id);
88+ renderer_mesh_destroy(id);
89 for (id = 1; id < MAX_TEXTURES; id++)
90- renderer_backend_texture_destroy(id);
91+ renderer_texture_destroy(id);
92
93 destroy_screen_texture();
94 free(ren.clip_vertices);
95@@ -452,7 +455,7 @@ void renderer_backend_destroy(void)
96 ren.pass = 0;
97 }
98
99-MGMesh renderer_backend_mesh_create(const MGMeshDesc* desc)
100+MGMesh renderer_mesh_create(const MGMeshDesc* desc)
101 {
102 RendererMesh* mesh;
103 u32 id;
104@@ -495,7 +498,7 @@ MGMesh renderer_backend_mesh_create(const MGMeshDesc* desc)
105 return id;
106 }
107
108-void renderer_backend_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp)
109+void renderer_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp)
110 {
111 RendererMesh* rmesh;
112 RendererTexture* rtexture;
113@@ -562,7 +565,7 @@ void renderer_backend_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mv
114 ren.active_triangle = (u32)-1;
115 }
116
117-void renderer_backend_mesh_destroy(MGMesh id)
118+void renderer_mesh_destroy(MGMesh id)
119 {
120 RendererMesh* mesh;
121
122@@ -578,7 +581,7 @@ void renderer_backend_mesh_destroy(MGMesh id)
123 *mesh = (RendererMesh){ 0 };
124 }
125
126-MGTexture renderer_backend_texture_load(const char* path)
127+MGTexture renderer_texture_load(const char* path)
128 {
129 stbi_uc* pixels;
130 int width;
131@@ -597,12 +600,12 @@ MGTexture renderer_backend_texture_load(const char* path)
132 desc.pixels = pixels;
133 desc.width = width;
134 desc.height = height > width && height % width == 0 ? width : height;
135- texture = renderer_backend_texture_create(&desc);
136+ texture = renderer_texture_create(&desc);
137 stbi_image_free(pixels);
138 return texture;
139 }
140
141-MGTexture renderer_backend_texture_create(const MGTextureDesc* desc)
142+MGTexture renderer_texture_create(const MGTextureDesc* desc)
143 {
144 RendererTexture* texture;
145 size_t size;
146@@ -642,7 +645,7 @@ MGTexture renderer_backend_texture_create(const MGTextureDesc* desc)
147 return id;
148 }
149
150-void renderer_backend_texture_destroy(MGTexture id)
151+void renderer_texture_destroy(MGTexture id)
152 {
153 RendererTexture* texture;
154
+13,
-14
1@@ -6,7 +6,6 @@
2 #include "types.h"
3 #include "platform/platform.h"
4 #include "renderer/renderer.h"
5-#include "renderer_backend.h"
6
7 #define MAX_MESHES 8192
8 #define MAX_TEXTURES 256
9@@ -150,7 +149,7 @@ static void sokol_log(const char* tag, u32 level, u32 item, const char* msg, u32
10 mg_log(type, "%s: %s [%s:%u]", tag ? tag : "Sokol", msg ? msg : "No message", file ? file : "Unknown", ln);
11 }
12
13-void renderer_backend_create(MGContext* ctx)
14+void renderer_create(MGContext* ctx)
15 {
16 sg_desc desc = { 0 };
17
18@@ -172,7 +171,7 @@ void renderer_backend_create(MGContext* ctx)
19 create_sampler();
20 }
21
22-void renderer_backend_begin(void)
23+void renderer_begin(void)
24 {
25 sg_pass pass = { 0 };
26 i32 width;
27@@ -207,7 +206,7 @@ void renderer_backend_begin(void)
28 ren.pass = 1;
29 }
30
31-void renderer_backend_end(void)
32+void renderer_end(void)
33 {
34 if (!ren.pass)
35 return;
36@@ -218,16 +217,16 @@ void renderer_backend_end(void)
37 ren.pass = 0;
38 }
39
40-void renderer_backend_destroy(void)
41+void renderer_destroy(void)
42 {
43 u32 id;
44
45 /* the values could be different in future so
46 probably should keep them separate */
47 for (id = 1; id < MAX_MESHES; id++)
48- renderer_backend_mesh_destroy(id);
49+ renderer_mesh_destroy(id);
50 for (id = 1; id < MAX_TEXTURES; id++)
51- renderer_backend_texture_destroy(id);
52+ renderer_texture_destroy(id);
53
54 sg_destroy_sampler(ren.sampler);
55 sg_destroy_pipeline(ren.pipeline);
56@@ -240,7 +239,7 @@ void renderer_backend_destroy(void)
57 ren.pass = 0;
58 }
59
60-MGMesh renderer_backend_mesh_create(const MGMeshDesc* desc)
61+MGMesh renderer_mesh_create(const MGMeshDesc* desc)
62 {
63 sg_buffer_desc buffer_desc = { 0 };
64 RendererMesh* mesh;
65@@ -293,7 +292,7 @@ MGMesh renderer_backend_mesh_create(const MGMeshDesc* desc)
66 return id;
67 }
68
69-void renderer_backend_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp)
70+void renderer_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mvp)
71 {
72 RendererMesh* rmesh;
73 RendererTexture* rtexture;
74@@ -329,7 +328,7 @@ void renderer_backend_mesh_draw(MGMesh mesh, MGTexture texture, const MGMat4* mv
75 sg_draw(0, rmesh->ic, 1);
76 }
77
78-void renderer_backend_mesh_destroy(MGMesh id)
79+void renderer_mesh_destroy(MGMesh id)
80 {
81 RendererMesh* mesh;
82
83@@ -346,7 +345,7 @@ void renderer_backend_mesh_destroy(MGMesh id)
84 *mesh = (RendererMesh){ 0 };
85 }
86
87-MGTexture renderer_backend_texture_load(const char* path)
88+MGTexture renderer_texture_load(const char* path)
89 {
90 stbi_uc* pixels;
91 int width;
92@@ -367,12 +366,12 @@ MGTexture renderer_backend_texture_load(const char* path)
93 desc.pixels = pixels;
94 desc.width = width;
95 desc.height = height > width && height % width == 0 ? width : height;
96- texture = renderer_backend_texture_create(&desc);
97+ texture = renderer_texture_create(&desc);
98 stbi_image_free(pixels);
99 return texture;
100 }
101
102-MGTexture renderer_backend_texture_create(const MGTextureDesc* desc)
103+MGTexture renderer_texture_create(const MGTextureDesc* desc)
104 {
105 sg_image_desc image_desc = { 0 };
106 sg_view_desc view_desc = { 0 };
107@@ -421,7 +420,7 @@ MGTexture renderer_backend_texture_create(const MGTextureDesc* desc)
108 return id;
109 }
110
111-void renderer_backend_texture_destroy(MGTexture id)
112+void renderer_texture_destroy(MGTexture id)
113 {
114 RendererTexture* texture;
115