summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/CMakeLists.txt3
-rw-r--r--app/contrib/glad.zip (renamed from gfx/contrib/glad.zip)bin369997 -> 369997 bytes
-rw-r--r--app/contrib/glad/CMakeLists.txt (renamed from gfx/contrib/glad/CMakeLists.txt)0
-rw-r--r--app/contrib/glad/README.md (renamed from gfx/contrib/glad/README.md)0
-rw-r--r--app/contrib/glad/include/KHR/khrplatform.h (renamed from gfx/contrib/glad/include/KHR/khrplatform.h)0
-rw-r--r--app/contrib/glad/include/glad/glad.h (renamed from gfx/contrib/glad/include/glad/glad.h)0
-rw-r--r--app/contrib/glad/src/glad.c (renamed from gfx/contrib/glad/src/glad.c)0
-rw-r--r--app/include/gfx/app.h18
-rw-r--r--app/src/app.c8
-rw-r--r--game/src/game.c14
-rw-r--r--gfx/CMakeLists.txt3
-rw-r--r--gfx/src/gfx.c5
12 files changed, 32 insertions, 19 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 7e60351..4db314d 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -1,5 +1,7 @@
1cmake_minimum_required(VERSION 3.0) 1cmake_minimum_required(VERSION 3.0)
2 2
3add_subdirectory(contrib/glad)
4
3project(gfx-app) 5project(gfx-app)
4 6
5add_library(gfx-app 7add_library(gfx-app
@@ -9,6 +11,7 @@ target_include_directories(gfx-app PUBLIC
9 include/) 11 include/)
10 12
11target_link_libraries(gfx-app PUBLIC 13target_link_libraries(gfx-app PUBLIC
14 glad
12 glfw 15 glfw
13 log 16 log
14 timer) 17 timer)
diff --git a/gfx/contrib/glad.zip b/app/contrib/glad.zip
index d5d3564..d5d3564 100644
--- a/gfx/contrib/glad.zip
+++ b/app/contrib/glad.zip
Binary files differ
diff --git a/gfx/contrib/glad/CMakeLists.txt b/app/contrib/glad/CMakeLists.txt
index 08b550c..08b550c 100644
--- a/gfx/contrib/glad/CMakeLists.txt
+++ b/app/contrib/glad/CMakeLists.txt
diff --git a/gfx/contrib/glad/README.md b/app/contrib/glad/README.md
index a0c9908..a0c9908 100644
--- a/gfx/contrib/glad/README.md
+++ b/app/contrib/glad/README.md
diff --git a/gfx/contrib/glad/include/KHR/khrplatform.h b/app/contrib/glad/include/KHR/khrplatform.h
index dd22d92..dd22d92 100644
--- a/gfx/contrib/glad/include/KHR/khrplatform.h
+++ b/app/contrib/glad/include/KHR/khrplatform.h
diff --git a/gfx/contrib/glad/include/glad/glad.h b/app/contrib/glad/include/glad/glad.h
index 0556552..0556552 100644
--- a/gfx/contrib/glad/include/glad/glad.h
+++ b/app/contrib/glad/include/glad/glad.h
diff --git a/gfx/contrib/glad/src/glad.c b/app/contrib/glad/src/glad.c
index 4a3cf51..4a3cf51 100644
--- a/gfx/contrib/glad/src/glad.c
+++ b/app/contrib/glad/src/glad.c
diff --git a/app/include/gfx/app.h b/app/include/gfx/app.h
index ffff4bc..3843d92 100644
--- a/app/include/gfx/app.h
+++ b/app/include/gfx/app.h
@@ -60,6 +60,10 @@ typedef enum Key {
60 KeyZ, 60 KeyZ,
61} Key; 61} Key;
62 62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
63/// Create a window with an OpenGL context and run the main loop. 67/// Create a window with an OpenGL context and run the main loop.
64bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*); 68bool gfx_app_run(const GfxAppDesc*, const GfxAppCallbacks*);
65 69
@@ -69,6 +73,10 @@ void gfx_app_get_mouse_position(double* x, double* y);
69/// Return true if the given key is pressed. 73/// Return true if the given key is pressed.
70bool gfx_is_key_pressed(Key); 74bool gfx_is_key_pressed(Key);
71 75
76#ifdef __cplusplus
77} // extern "C"
78#endif
79
72/// Define a main function that initializes and puts the application in a loop. 80/// Define a main function that initializes and puts the application in a loop.
73/// See also: gfx_app_run(). 81/// See also: gfx_app_run().
74#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, TITLE) \ 82#define GFX_APP_MAIN(WIDTH, HEIGHT, MAX_FPS, TITLE) \
@@ -86,10 +94,10 @@ bool gfx_is_key_pressed(Key);
86 .app_state = &app_state, \ 94 .app_state = &app_state, \
87 }, \ 95 }, \
88 &(GfxAppCallbacks){ \ 96 &(GfxAppCallbacks){ \
89 .init = (GfxAppInit)app_init, \ 97 .init = (GfxAppInit)Init, \
90 .update = (GfxAppUpdate)app_update, \ 98 .shutdown = (GfxAppShutdown)Shutdown, \
91 .render = (GfxAppRender)app_render, \ 99 .update = (GfxAppUpdate)Update, \
92 .resize = (GfxAppResize)app_resize, \ 100 .render = (GfxAppRender)Render, \
93 .shutdown = (GfxAppShutdown)app_end}); \ 101 .resize = (GfxAppResize)Resize}); \
94 return 0; \ 102 return 0; \
95 } 103 }
diff --git a/app/src/app.c b/app/src/app.c
index b6d10ca..1e636af 100644
--- a/app/src/app.c
+++ b/app/src/app.c
@@ -1,5 +1,7 @@
1#include <gfx/app.h> 1#include <gfx/app.h>
2 2
3#include <glad/glad.h>
4
3#include <GLFW/glfw3.h> 5#include <GLFW/glfw3.h>
4#include <log/log.h> 6#include <log/log.h>
5#include <timer.h> 7#include <timer.h>
@@ -110,6 +112,12 @@ bool gfx_app_run(const GfxAppDesc* desc, const GfxAppCallbacks* callbacks) {
110 } 112 }
111 glfwMakeContextCurrent(g_gfx_app.window); 113 glfwMakeContextCurrent(g_gfx_app.window);
112 114
115 // Load GL before calling the application init clalback.
116 if (!gladLoadGL()) {
117 LOGE("Failed loading glad!");
118 return 0;
119 }
120
113 // Initialize the application's state before setting any callbacks. 121 // Initialize the application's state before setting any callbacks.
114 if (!(*g_gfx_app.callbacks.init)( 122 if (!(*g_gfx_app.callbacks.init)(
115 g_gfx_app.app_state, desc->argc, desc->argv)) { 123 g_gfx_app.app_state, desc->argc, desc->argv)) {
diff --git a/game/src/game.c b/game/src/game.c
index 425119f..10c69aa 100644
--- a/game/src/game.c
+++ b/game/src/game.c
@@ -115,9 +115,9 @@ static void resize_plugin(Game* game, int width, int height) {
115 } 115 }
116} 116}
117 117
118void app_end(Game* game); 118static void Shutdown(Game* game);
119 119
120bool app_init(Game* game, int argc, const char** argv) { 120static bool Init(Game* game, int argc, const char** argv) {
121 assert(game); 121 assert(game);
122 122
123 if (argc <= 1) { 123 if (argc <= 1) {
@@ -170,11 +170,11 @@ bool app_init(Game* game, int argc, const char** argv) {
170 170
171cleanup: 171cleanup:
172 LOGE("Gfx error: %s", get_error()); 172 LOGE("Gfx error: %s", get_error());
173 app_end(game); 173 Shutdown(game);
174 return false; 174 return false;
175} 175}
176 176
177void app_end(Game* game) { 177static void Shutdown(Game* game) {
178 assert(game); 178 assert(game);
179 shutdown_plugin(game); 179 shutdown_plugin(game);
180 if (game->gfx) { 180 if (game->gfx) {
@@ -188,7 +188,7 @@ void app_end(Game* game) {
188 } 188 }
189} 189}
190 190
191void app_update(Game* game, double t, double dt) { 191static void Update(Game* game, double t, double dt) {
192 plugin_engine_update(game->plugin_engine); 192 plugin_engine_update(game->plugin_engine);
193 if (plugin_reloaded(game->plugin)) { 193 if (plugin_reloaded(game->plugin)) {
194 shutdown_plugin(game); 194 shutdown_plugin(game);
@@ -203,14 +203,14 @@ void app_update(Game* game, double t, double dt) {
203 update_plugin(game, t, dt); 203 update_plugin(game, t, dt);
204} 204}
205 205
206void app_render(const Game* game) { 206static void Render(const Game* game) {
207 GfxCore* gfxcore = gfx_get_core(game->gfx); 207 GfxCore* gfxcore = gfx_get_core(game->gfx);
208 gfx_start_frame(gfxcore); 208 gfx_start_frame(gfxcore);
209 render_plugin(game); 209 render_plugin(game);
210 gfx_end_frame(gfxcore); 210 gfx_end_frame(gfxcore);
211} 211}
212 212
213void app_resize(Game* game, int width, int height) { 213static void Resize(Game* game, int width, int height) {
214 game->width = width; 214 game->width = width;
215 game->height = height; 215 game->height = height;
216 216
diff --git a/gfx/CMakeLists.txt b/gfx/CMakeLists.txt
index 7aa118b..7d629dc 100644
--- a/gfx/CMakeLists.txt
+++ b/gfx/CMakeLists.txt
@@ -4,7 +4,6 @@ include(cmake/shader.txt)
4 4
5add_subdirectory(contrib/cgltf) 5add_subdirectory(contrib/cgltf)
6add_subdirectory(contrib/cgltf-tangents) 6add_subdirectory(contrib/cgltf-tangents)
7add_subdirectory(contrib/glad)
8add_subdirectory(contrib/stb) 7add_subdirectory(contrib/stb)
9 8
10project(gfx) 9project(gfx)
@@ -79,7 +78,7 @@ target_link_libraries(gfx PRIVATE
79 cgltf 78 cgltf
80 cgltf-tangents 79 cgltf-tangents
81 error 80 error
82 glad 81 gfx-app
83 log 82 log
84 mempool 83 mempool
85 shaders 84 shaders
diff --git a/gfx/src/gfx.c b/gfx/src/gfx.c
index 36020df..cd2ac90 100644
--- a/gfx/src/gfx.c
+++ b/gfx/src/gfx.c
@@ -19,11 +19,6 @@ typedef struct Gfx {
19} Gfx; 19} Gfx;
20 20
21Gfx* gfx_init(void) { 21Gfx* gfx_init(void) {
22 if (!gladLoadGL()) {
23 LOGE("Failed loading glad!");
24 return 0;
25 }
26
27 Gfx* gfx = calloc(1, sizeof(Gfx)); 22 Gfx* gfx = calloc(1, sizeof(Gfx));
28 if (!gfx) { 23 if (!gfx) {
29 return 0; 24 return 0;