clean opengl objects
This commit is contained in:
+21
-17
@@ -169,7 +169,7 @@ static void free_files(File *common_shader_code, File *fragment_shaders,
|
|||||||
|
|
||||||
static void error_callback(int error, const char *description) {
|
static void error_callback(int error, const char *description) {
|
||||||
log_error("[GLFW] %d: %s", error, description);
|
log_error("[GLFW] %d: %s", error, description);
|
||||||
window_close(0, true);
|
window_terminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ static void key_callback(Window *window, int key,
|
|||||||
__attribute__((unused)) int mods) {
|
__attribute__((unused)) int mods) {
|
||||||
if (window_escape_key(key, action)) {
|
if (window_escape_key(key, action)) {
|
||||||
// close window on escape key
|
// close window on escape key
|
||||||
window_close(window, false);
|
window_close(window);
|
||||||
} else if (window_char_key(key, action, 82)) {
|
} else if (window_char_key(key, action, 82)) {
|
||||||
// R: randomize
|
// R: randomize
|
||||||
randomize_context_state();
|
randomize_context_state();
|
||||||
@@ -235,12 +235,7 @@ void forge_run(Parameters params) {
|
|||||||
init_context(params);
|
init_context(params);
|
||||||
|
|
||||||
if (program.error) {
|
if (program.error) {
|
||||||
if (window_output != NULL) {
|
window_terminate();
|
||||||
window_close(window_output, true);
|
|
||||||
}
|
|
||||||
if (window_monitor != NULL) {
|
|
||||||
window_close(window_monitor, true);
|
|
||||||
}
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,16 +248,25 @@ void forge_run(Parameters params) {
|
|||||||
loop(params.hot_reload, &common_shader_code, fragment_shaders, &timer);
|
loop(params.hot_reload, &common_shader_code, fragment_shaders, &timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shaders_free(program);
|
||||||
|
|
||||||
|
if (window_output != NULL) {
|
||||||
|
window_use(window_output, &context);
|
||||||
|
|
||||||
|
shaders_free_window(program, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window_monitor != NULL) {
|
||||||
|
window_use(window_monitor, &context);
|
||||||
|
|
||||||
|
shaders_free_window(program, params.output);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_terminate();
|
||||||
|
|
||||||
|
free_context();
|
||||||
|
|
||||||
free_files(&common_shader_code, fragment_shaders, frag_count);
|
free_files(&common_shader_code, fragment_shaders, frag_count);
|
||||||
|
|
||||||
config_file_free(shader_config);
|
config_file_free(shader_config);
|
||||||
|
|
||||||
if (window_output != NULL) {
|
|
||||||
window_close(window_output, true);
|
|
||||||
}
|
|
||||||
if (window_monitor != NULL) {
|
|
||||||
window_close(window_monitor, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_context();
|
|
||||||
}
|
}
|
||||||
@@ -439,4 +439,20 @@ void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
|||||||
use_program(program,
|
use_program(program,
|
||||||
monitor ? program.frag_monitor_index : program.frag_output_index,
|
monitor ? program.frag_monitor_index : program.frag_output_index,
|
||||||
true, context);
|
true, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaders_free(ShaderProgram program) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < program.frag_count; i++) {
|
||||||
|
glDeleteProgram(program.programs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteFramebuffers(program.frag_count, program.frame_buffers);
|
||||||
|
glDeleteTextures(program.tex_count, program.textures);
|
||||||
|
glDeleteBuffers(1, &program.vertex_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shaders_free_window(ShaderProgram program, bool secondary) {
|
||||||
|
glDeleteVertexArrays(1, &program.vertex_array[secondary ? 1 : 0]);
|
||||||
}
|
}
|
||||||
@@ -12,4 +12,8 @@ void shaders_update(ShaderProgram program, File *fragment_shaders,
|
|||||||
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
void shaders_compute(ShaderProgram program, Context context, bool monitor,
|
||||||
bool output_only);
|
bool output_only);
|
||||||
|
|
||||||
|
void shaders_free(ShaderProgram program);
|
||||||
|
|
||||||
|
void shaders_free_window(ShaderProgram program, bool secondary);
|
||||||
|
|
||||||
#endif /* SHADERS_H */
|
#endif /* SHADERS_H */
|
||||||
+8
-8
@@ -87,6 +87,11 @@ void window_startup(void (*error_callback)(int, const char *)) {
|
|||||||
init_glfw(error_callback);
|
init_glfw(error_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void window_terminate() {
|
||||||
|
log_info("[GLFW] Terminating library...");
|
||||||
|
glfwTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
Window *window_init(char *title, unsigned char monitor_index, bool windowed,
|
Window *window_init(char *title, unsigned char monitor_index, bool windowed,
|
||||||
Window *shared_context,
|
Window *shared_context,
|
||||||
void (*key_callback)(Window *, int, int, int, int)) {
|
void (*key_callback)(Window *, int, int, int, int)) {
|
||||||
@@ -120,14 +125,9 @@ void window_use(Window *window, Context *context) {
|
|||||||
glfwGetFramebufferSize(window, &context->width, &context->height);
|
glfwGetFramebufferSize(window, &context->width, &context->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_close(Window *window, bool hard) {
|
void window_close(Window *window) {
|
||||||
if (hard) {
|
log_info("[GLFW] Closing window...");
|
||||||
log_info("[GLFW] Terminating library...");
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
glfwTerminate();
|
|
||||||
} else {
|
|
||||||
log_info("[GLFW] Closing window...");
|
|
||||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool window_should_close(Window *window) {
|
bool window_should_close(Window *window) {
|
||||||
|
|||||||
+3
-1
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
void window_startup(void (*error_callback)(int, const char *));
|
void window_startup(void (*error_callback)(int, const char *));
|
||||||
|
|
||||||
|
void window_terminate();
|
||||||
|
|
||||||
Window *window_init(char *title, unsigned char monitor_index, bool windowed,
|
Window *window_init(char *title, unsigned char monitor_index, bool windowed,
|
||||||
Window *shared_context,
|
Window *shared_context,
|
||||||
void (*key_callback)(Window *, int, int, int, int));
|
void (*key_callback)(Window *, int, int, int, int));
|
||||||
@@ -19,7 +21,7 @@ void window_refresh(Window *window);
|
|||||||
|
|
||||||
void window_events();
|
void window_events();
|
||||||
|
|
||||||
void window_close(Window *window, bool hard);
|
void window_close(Window *window);
|
||||||
|
|
||||||
bool window_should_close(Window *window);
|
bool window_should_close(Window *window);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user