From db24b566ba1be51255b98aafc34a117aaec65f39 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 17 Jun 2020 15:43:17 +0200 Subject: switch between cpu and gpu rendering while running --- src/assets.c | 97 ++++++++++++++++++-------- src/assets.h | 15 +++- src/linux/platform.c | 6 +- src/platform.h | 4 ++ src/render.c | 28 ++++---- src/render.h | 3 +- src/ui.h | 1 + src/windows/platform.c | 184 ++++++++++++++++++++++++++++--------------------- 8 files changed, 211 insertions(+), 127 deletions(-) diff --git a/src/assets.c b/src/assets.c index c81a70a..e693d7f 100644 --- a/src/assets.c +++ b/src/assets.c @@ -36,13 +36,6 @@ inline static bool is_big_endian() bool assets_do_post_process() { bool result = false; -#if 0 - static PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample = NULL; -#ifdef OS_WIN - if (!glTexImage2DMultisample) - glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC)wglGetProcAddress("glTexImage2DMultisample"); -#endif -#endif mutex_lock(&asset_mutex); @@ -54,6 +47,8 @@ bool assets_do_post_process() { if (task->image->data && task->valid) { + if (!global_use_gpu) { task->image->loaded = true; goto done; } + glGenTextures(1, &task->image->textureID); glBindTexture(GL_TEXTURE_2D, task->image->textureID); @@ -67,18 +62,6 @@ bool assets_do_post_process() glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, task->image->width, task->image->height, 0, GL_BGRA, flag, task->image->data); -#if 0 - if (glTexImage2DMultisample) - glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, task->image->width, task->image->height, FALSE); -#endif - -#if 0 - s32 fbo; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, task->image->textureID, 0); -#endif - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); task->image->loaded = true; @@ -89,6 +72,8 @@ bool assets_do_post_process() { if (task->valid) { + if (!global_use_gpu) { task->font->loaded = true; goto done; } + for (s32 i = TEXT_CHARSET_START; i < TEXT_CHARSET_END; i++) { glyph *g = &task->font->glyphs[i]; @@ -109,8 +94,8 @@ bool assets_do_post_process() } } + done: result = true; - array_remove_at(&global_asset_collection.post_process_queue, i); } @@ -278,7 +263,7 @@ image *assets_load_image(u8 *start_addr, u8 *end_addr) { image *img_at = array_at(&global_asset_collection.images, i); - if (start_addr == img_at->start_addr) + if (start_addr == img_at->start_addr && img_at->references > 0) { // image is already loaded/loading img_at->references++; @@ -317,10 +302,9 @@ void assets_destroy_image(image *image_to_destroy) { glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &image_to_destroy->textureID); - stbi_image_free(image_to_destroy->data); } - //array_remove(&global_asset_collection.images, image_at); + image_to_destroy->references = 0; } else { @@ -335,7 +319,7 @@ font *assets_load_font(u8 *start_addr, u8 *end_addr, s16 size) { font *font_at = array_at(&global_asset_collection.fonts, i); - if (start_addr == font_at->start_addr && font_at->size == size) + if (start_addr == font_at->start_addr && font_at->size == size && font_at->references > 0) { // font is already loaded/loading font_at->references++; @@ -371,8 +355,17 @@ void assets_destroy_font(font *font_to_destroy) { if (font_to_destroy->references == 1) { - //glBindTexture(GL_TEXTURE_2D, 0); - //glDeleteTextures(1, font_to_destroy->textureIDs); + if (global_use_gpu) + { + for (s32 i = TEXT_CHARSET_START; i < TEXT_CHARSET_END; i++) + { + glyph g = font_to_destroy->glyphs[i]; + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &g.textureID); + } + } + + font_to_destroy->references = 0; } else { @@ -403,7 +396,7 @@ image *assets_load_bitmap(u8 *start_addr, u8 *end_addr) { image *img_at = array_at(&global_asset_collection.images, i); - if (start_addr == img_at->start_addr) + if (start_addr == img_at->start_addr && img_at->references > 0) { // image is already loaded/loading img_at->references++; @@ -443,10 +436,58 @@ void assets_destroy_bitmap(image *image_to_destroy) glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &image_to_destroy->textureID); } - //array_remove(&global_asset_collection.images, image_at); + + image_to_destroy->references = 0; } else { image_to_destroy->references--; } } + +void assets_switch_render_method() +{ + for (int i = 0; i < global_asset_collection.images.length; i++) + { + image *img_at = array_at(&global_asset_collection.images, i); + + if (global_use_gpu) + { + asset_task task; + task.type = ASSET_IMAGE; + task.image = img_at; + task.valid = true; + + array_push(&global_asset_collection.post_process_queue, &task); + } + else + { + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &img_at->textureID); + } + } + + for (int i = 0; i < global_asset_collection.fonts.length; i++) + { + font *font_at = array_at(&global_asset_collection.fonts, i); + + if (global_use_gpu) + { + asset_task task; + task.type = ASSET_FONT; + task.font = font_at; + task.valid = true; + + array_push(&global_asset_collection.post_process_queue, &task); + } + else + { + for (s32 i = TEXT_CHARSET_START; i < TEXT_CHARSET_END; i++) + { + glyph g = font_at->glyphs[i]; + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &g.textureID); + } + } + } +} diff --git a/src/assets.h b/src/assets.h index 8b459a8..983ff41 100644 --- a/src/assets.h +++ b/src/assets.h @@ -7,11 +7,22 @@ #ifndef INCLUDE_ASSETS #define INCLUDE_ASSETS +#ifndef ASSET_IMAGE_COUNT +#define ASSET_IMAGE_COUNT 10 +#endif + +#ifndef ASSET_FONT_COUNT +#define ASSET_FONT_COUNT 10 +#endif + +#ifndef ASSET_QUEUE_COUNT +#define ASSET_QUEUE_COUNT 20 +#endif + typedef struct t_image { u8 *start_addr; u8 *end_addr; bool loaded; - bool is_bitmap; s32 width; s32 height; s32 channels; @@ -99,6 +110,8 @@ void assets_destroy_bitmap(image *image); font *assets_load_font(u8 *start_addr, u8 *end_addr, s16 size); void assets_destroy_font(font *font); +void assets_switch_render_method(); + #define load_image(_name, _inmem) assets_load_image(_binary____data_imgs_##_name##_start,_binary____data_imgs_##_name##_end) #define load_font(_name, _size) assets_load_font(_binary____data_fonts_##_name##_start,_binary____data_fonts_##_name##_end, _size) #define load_bitmap(_name) assets_load_bitmap(_binary____data_imgs_##_name##_start,_binary____data_imgs_##_name##_end) diff --git a/src/linux/platform.c b/src/linux/platform.c index 10e812d..d654cac 100644 --- a/src/linux/platform.c +++ b/src/linux/platform.c @@ -21,9 +21,6 @@ #include #include #include -//#include -//#include -//#include #define GET_ATOM(X) window.X = XInternAtom(window.display, #X, False) @@ -39,7 +36,6 @@ struct t_platform_window XEvent event; char *clipboard_str; s32 clipboard_strlen; - bool do_draw; Atom xdnd_req; Atom xdnd_source; @@ -62,6 +58,8 @@ struct t_platform_window Atom _NET_WM_STATE; // shared window properties + bool do_draw; + backbuffer backbuffer; s32 width; s32 height; bool is_open; diff --git a/src/platform.h b/src/platform.h index e72bb8c..0a67946 100644 --- a/src/platform.h +++ b/src/platform.h @@ -179,7 +179,9 @@ typedef struct t_backbuffer s32 width; s32 height; u8 *buffer; // 4bytes color + 1byte depth +#ifdef OS_WIN BITMAPINFO bitmapInfo; +#endif } backbuffer; // NOT IMPLEMENTED ON LINUX: USE FLAGS_NONE @@ -234,6 +236,8 @@ void platform_run_command(char *command); void platform_window_make_current(platform_window *window); void platform_init(int argc, char **argv); void platform_destroy(); +void platform_setup_backbuffer(platform_window *window); +void platform_setup_renderer(); void platform_set_icon(platform_window *window, image *img); void platform_autocomplete_path(char *buffer, bool want_dir); bool platform_directory_exists(char *path); diff --git a/src/render.c b/src/render.c index bd14a37..dcff77b 100644 --- a/src/render.c +++ b/src/render.c @@ -106,9 +106,9 @@ void render_image(image *image, s32 x, s32 y, s32 width, s32 height) float32 alpha = color[3] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 b = ((color[0] * alpha) + (oneminusalpha * buffer_entry[0])); + u8 b = ((color[0] * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((color[1] * alpha) + (oneminusalpha * buffer_entry[1])); - u8 r = ((color[2] * alpha) + (oneminusalpha * buffer_entry[2])); + u8 r = ((color[2] * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[3]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -218,9 +218,9 @@ s32 render_text_ellipsed(font *font, s32 x, s32 y, s32 maxw, char *text, color t float32 alpha = color[0] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[0]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -315,9 +315,9 @@ s32 render_text_with_selection(font *font, s32 x, s32 y, char *text, color tint, float32 alpha = color[0] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[0]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -415,9 +415,9 @@ s32 render_text_with_cursor(font *font, s32 x, s32 y, char *text, color tint, s3 float32 alpha = color[0] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[0]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -512,9 +512,9 @@ s32 render_text(font *font, s32 x, s32 y, char *text, color tint) float32 alpha = color[0] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[0]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -618,9 +618,9 @@ s32 render_text_cutoff(font *font, s32 x, s32 y, char *text, color tint, u16 cut float32 alpha = color[0] / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = color[0]; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); @@ -848,9 +848,9 @@ void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint) float32 alpha = tint.a / 255.0f; float32 oneminusalpha = 1 - alpha; - u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[0])); + u8 r = ((tint.r * alpha) + (oneminusalpha * buffer_entry[2])); u8 g = ((tint.g * alpha) + (oneminusalpha * buffer_entry[1])); - u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[2])); + u8 b = ((tint.b * alpha) + (oneminusalpha * buffer_entry[0])); u8 a = tint.a; s32 c = (a << 24) | (r << 16) | (g << 8) | (b << 0); diff --git a/src/render.h b/src/render.h index c02c740..92b58e2 100644 --- a/src/render.h +++ b/src/render.h @@ -30,7 +30,7 @@ typedef enum t_triangle_direction TRIANGLE_RIGHT, } triangle_direction; -s32 global_use_gpu = 0; +s32 global_use_gpu = 1; u8 render_depth = 1; vec4 current_scissor; @@ -50,7 +50,6 @@ void render_image_tint(image *image, s32 x, s32 y, s32 width, s32 height, color s32 render_text(font *font, s32 x, s32 y, char *text, color tint); s32 render_text_ellipsed(font *font, s32 x, s32 y, s32 maxw, char *text, color tint); s32 render_text_cutoff(font *font, s32 x, s32 y, char *text, color tint, u16 cutoff_width); -s32 render_text_vertical(font *font, s32 x, s32 y, char *text, color tint); s32 render_text_with_cursor(font *font, s32 x, s32 y, char *text, color tint, s32 cursor_pos); s32 render_text_with_selection(font *font, s32 x, s32 y, char *text, color tint, s32 selection_start, s32 selection_length); diff --git a/src/ui.h b/src/ui.h index b75dd13..a957237 100644 --- a/src/ui.h +++ b/src/ui.h @@ -7,6 +7,7 @@ #ifndef INCLUDE_UI #define INCLUDE_UI +#define SCROLL_SPEED 20 #define BLOCK_HEIGHT 25 #define MENU_BAR_HEIGHT 25 #define MENU_HORIZONTAL_PADDING 10 diff --git a/src/windows/platform.c b/src/windows/platform.c index e1a664e..a58a152 100644 --- a/src/windows/platform.c +++ b/src/windows/platform.c @@ -20,9 +20,6 @@ struct t_platform_window HGLRC gl_context; WNDCLASS window_class; s32 flags; - bool do_draw; - - backbuffer backbuffer; s32 min_width; s32 min_height; @@ -30,6 +27,8 @@ struct t_platform_window s32 max_height; // shared window properties + bool do_draw; + backbuffer backbuffer; s32 width; s32 height; bool is_open; @@ -321,7 +320,7 @@ void platform_show_message(platform_window *window, char *message, char *title) static void _allocate_backbuffer(platform_window *window) { - if (window->backbuffer.buffer) mem_free(window->backbuffer.buffer); + if (window->backbuffer.buffer) { mem_free(window->backbuffer.buffer); window->backbuffer.buffer = 0; } BITMAPINFO info; info.bmiHeader.biSize = sizeof(BITMAPINFO); @@ -567,6 +566,89 @@ void platform_hide_window(platform_window *window) ShowWindow(window->window_handle, SW_HIDE); } +void platform_setup_backbuffer(platform_window *window) +{ + static HGLRC share_list = 0; + if (global_use_gpu) + { + if (window->backbuffer.buffer) { mem_free(window->backbuffer.buffer); window->backbuffer.buffer = 0; } + + PIXELFORMATDESCRIPTOR actual_format; + // old pixel format selection + { + PIXELFORMATDESCRIPTOR format; + memset(&format, 0, sizeof(PIXELFORMATDESCRIPTOR)); + format.nSize = sizeof(PIXELFORMATDESCRIPTOR); + format.nVersion = 1; + format.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; + format.cColorBits = 24; + format.cAlphaBits = 8; + format.cDepthBits = 16; + format.iLayerType = PFD_MAIN_PLANE; // PFD_TYPE_RGBA + s32 suggested_format_index = ChoosePixelFormat(window->hdc, &format); // SLOW AF?? + + DescribePixelFormat(window->hdc, suggested_format_index, sizeof(actual_format), &actual_format); + SetPixelFormat(window->hdc, suggested_format_index, &actual_format); + } + + //debug_print_elapsed(startup_stamp, "pixel format"); + + window->gl_context = wglCreateContext(window->hdc); + + //debug_print_elapsed(startup_stamp, "gl context"); + + if (share_list == 0) + { + share_list = window->gl_context; + } + else + { + wglShareLists(share_list, window->gl_context); + } + + wglMakeCurrent(window->hdc, window->gl_context); + } + else + { + share_list = 0; + wglMakeCurrent(NULL, NULL); + wglDeleteContext(window->gl_context); + window->gl_context = 0; + + _allocate_backbuffer(window); + //debug_print_elapsed(startup_stamp, "backbuffer"); + } +} + +void platform_setup_renderer() +{ + if (global_use_gpu) + { + ////// GL SETUP + glDepthMask(GL_TRUE); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthFunc(GL_LEQUAL); + glEnable(GL_DEPTH_TEST); + glAlphaFunc(GL_GREATER, 0.0f); + glEnable(GL_ALPHA_TEST); + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + glEnable(GL_SAMPLE_ALPHA_TO_ONE); + glEnable(GL_MULTISAMPLE); + glEnable(GL_TEXTURE_2D); + glEnable(GL_SCISSOR_TEST); + glEnable(GL_BLEND); + //glEnable(GL_FRAMEBUFFER_SRGB); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_MULTISAMPLE_ARB); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + } +} + platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 max_w, u16 max_h, u16 min_w, u16 min_h, s32 flags) { debug_print_elapsed_title("window creation"); @@ -590,6 +672,7 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m window.next_cursor_type = CURSOR_DEFAULT; window.backbuffer.buffer = 0; window.do_draw = true; + window.gl_context = 0; current_window_to_handle = &window; @@ -655,48 +738,8 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m { window.hdc = GetDC(window.window_handle); - if (global_use_gpu) - { - PIXELFORMATDESCRIPTOR actual_format; - // old pixel format selection - { - PIXELFORMATDESCRIPTOR format; - memset(&format, 0, sizeof(PIXELFORMATDESCRIPTOR)); - format.nSize = sizeof(PIXELFORMATDESCRIPTOR); - format.nVersion = 1; - format.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; - format.cColorBits = 24; - format.cAlphaBits = 8; - format.cDepthBits = 16; - format.iLayerType = PFD_MAIN_PLANE; // PFD_TYPE_RGBA - s32 suggested_format_index = ChoosePixelFormat(window.hdc, &format); // SLOW AF?? - - DescribePixelFormat(window.hdc, suggested_format_index, sizeof(actual_format), &actual_format); - SetPixelFormat(window.hdc, suggested_format_index, &actual_format); - } - - debug_print_elapsed(startup_stamp, "pixel format"); - - window.gl_context = wglCreateContext(window.hdc); - - debug_print_elapsed(startup_stamp, "gl context"); - - static HGLRC share_list = 0; - if (share_list == 0) - { - share_list = window.gl_context; - } - else - { - wglShareLists(share_list, window.gl_context); - } - - wglMakeCurrent(window.hdc, window.gl_context); - } - else - { - _allocate_backbuffer(&window); - } + platform_setup_backbuffer(&window); + debug_print_elapsed(startup_stamp, "backbuffer"); ShowWindow(window.window_handle, cmd_show); if (flags & FLAGS_HIDDEN) @@ -704,33 +747,8 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m else ShowWindow(window.window_handle, SW_SHOW); - if (global_use_gpu) - { - ////// GL SETUP - glDepthMask(GL_TRUE); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthFunc(GL_LEQUAL); - glEnable(GL_DEPTH_TEST); - glAlphaFunc(GL_GREATER, 0.0f); - glEnable(GL_ALPHA_TEST); - glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); - glEnable(GL_SAMPLE_ALPHA_TO_ONE); - glEnable(GL_MULTISAMPLE); - glEnable(GL_TEXTURE_2D); - glEnable(GL_SCISSOR_TEST); - glEnable(GL_BLEND); - //glEnable(GL_FRAMEBUFFER_SRGB); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_MULTISAMPLE_ARB); - } - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - debug_print_elapsed(startup_stamp, "gl setup"); + platform_setup_renderer(); + debug_print_elapsed(startup_stamp, "renderer"); window.is_open = true; @@ -740,7 +758,7 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m track.hwndTrack = window.window_handle; TrackMouseEvent(&track); - debug_print_elapsed(startup_stamp, "track mouse"); + debug_print_elapsed(startup_stamp, "windows nonsense"); } else { @@ -792,14 +810,22 @@ bool platform_window_is_valid(platform_window *window) void platform_destroy_window(platform_window *window) { - wglMakeCurrent(NULL, NULL); - wglDeleteContext(window->gl_context); + if (global_use_gpu) + { + wglMakeCurrent(NULL, NULL); + wglDeleteContext(window->gl_context); + } + else + { + if (window->backbuffer.buffer) { mem_free(window->backbuffer.buffer); window->backbuffer.buffer = 0; } + } ReleaseDC(window->window_handle, window->hdc); CloseWindow(window->window_handle); DestroyWindow(window->window_handle); UnregisterClassA(window->window_class.lpszClassName, instance); window->hdc = 0; + window->gl_context = 0; window->window_handle = 0; } @@ -873,7 +899,8 @@ void platform_handle_events(platform_window *window, mouse_input *mouse, keyboar DispatchMessage(&message); } - glViewport(0, 0, window->width, window->height); + if (global_use_gpu) + glViewport(0, 0, window->width, window->height); } void platform_window_swap_buffers(platform_window *window) @@ -1265,7 +1292,8 @@ void platform_run_command(char *command) void platform_window_make_current(platform_window *window) { - wglMakeCurrent(window->hdc, window->gl_context); + if (global_use_gpu) + wglMakeCurrent(window->hdc, window->gl_context); } void platform_init(int argc, char **argv) -- cgit v1.2.3-70-g09d2