summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/assets.c20
-rw-r--r--src/assets.h2
-rw-r--r--src/external/stb_image.h2
-rw-r--r--src/input.h2
-rw-r--r--src/linux/platform.c3
-rw-r--r--src/linux/thread.c7
-rw-r--r--src/notification.c2
-rw-r--r--src/thread.h1
-rw-r--r--src/windows/platform.c75
-rw-r--r--src/windows/thread.c5
10 files changed, 99 insertions, 20 deletions
diff --git a/src/assets.c b/src/assets.c
index 3eddf02..5b90ea3 100644
--- a/src/assets.c
+++ b/src/assets.c
@@ -33,11 +33,12 @@ inline static bool is_big_endian()
return !((*((uint8_t*)(&i))) == 0x67);
}
-void assets_do_post_process()
+bool assets_do_post_process()
{
+ bool result = false;
#if 0
static PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample = NULL;
-#ifdef OS_WINDOWS
+#ifdef OS_WIN
if (!glTexImage2DMultisample)
glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC)wglGetProcAddress("glTexImage2DMultisample");
#endif
@@ -64,7 +65,14 @@ void assets_do_post_process()
#if 0
if (glTexImage2DMultisample)
- glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 16, GL_RGBA8, task->image->width, task->image->height, TRUE);
+ 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);
@@ -102,10 +110,14 @@ void assets_do_post_process()
}
}
+ result = true;
+
array_remove_at(&global_asset_collection.post_process_queue, i);
}
mutex_unlock(&asset_mutex);
+
+ return result;
}
bool assets_queue_worker_load_bitmap(image *image)
@@ -231,6 +243,8 @@ void *assets_queue_worker()
thread_sleep(1000);
}
+ thread_exit();
+
return 0;
}
diff --git a/src/assets.h b/src/assets.h
index 870ab97..30f0ebf 100644
--- a/src/assets.h
+++ b/src/assets.h
@@ -88,7 +88,7 @@ assets global_asset_collection;
void assets_create();
void assets_destroy();
-void assets_do_post_process();
+bool assets_do_post_process();
void *assets_queue_worker();
image *assets_load_image(u8 *start_addr, u8 *end_addr, bool keep_in_memory);
diff --git a/src/external/stb_image.h b/src/external/stb_image.h
index a6202a3..7a2d751 100644
--- a/src/external/stb_image.h
+++ b/src/external/stb_image.h
@@ -1476,6 +1476,7 @@ stbi_inline static stbi_uc stbi__get8(stbi__context *s)
return 0;
}
+#ifndef STBI_ONLY_PNG
stbi_inline static int stbi__at_eof(stbi__context *s)
{
if (s->io.read) {
@@ -1487,6 +1488,7 @@ stbi_inline static int stbi__at_eof(stbi__context *s)
return s->img_buffer >= s->img_buffer_end;
}
+#endif
static void stbi__skip(stbi__context *s, int n)
{
diff --git a/src/input.h b/src/input.h
index 189df68..8774e29 100644
--- a/src/input.h
+++ b/src/input.h
@@ -157,7 +157,7 @@
#ifdef OS_WIN
#define MAX_INPUT_LENGTH 4096+1
-#define MAX_PATH_LENGTH 259+1
+#define MAX_PATH_LENGTH MAX_PATH+1
#endif
typedef struct t_mouse_input
diff --git a/src/linux/platform.c b/src/linux/platform.c
index 6083670..f87b4ac 100644
--- a/src/linux/platform.c
+++ b/src/linux/platform.c
@@ -39,6 +39,7 @@ struct t_platform_window
XEvent event;
char *clipboard_str;
s32 clipboard_strlen;
+ bool do_draw;
Atom xdnd_req;
Atom xdnd_source;
@@ -682,6 +683,7 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
window.next_cursor_type = CURSOR_DEFAULT;
window.clipboard_str = 0;
window.clipboard_strlen = 0;
+ window.do_draw = true;
static int att[] =
{
@@ -979,6 +981,7 @@ void platform_handle_events(platform_window *window, mouse_input *mouse, keyboar
mouse->move_y = 0;
mouse->scroll_state = 0;
keyboard->text_changed = false;
+ window->do_draw = true;
XClientMessageEvent m;
diff --git a/src/linux/thread.c b/src/linux/thread.c
index b6295ef..f7c4c3c 100644
--- a/src/linux/thread.c
+++ b/src/linux/thread.c
@@ -48,7 +48,7 @@ inline void thread_join(thread *thread)
}
}
-bool thread_tryjoin(thread *thread)
+inline bool thread_tryjoin(thread *thread)
{
if (thread->valid)
{
@@ -59,6 +59,11 @@ bool thread_tryjoin(thread *thread)
return false;
}
+inline void thread_exit()
+{
+ pthread_exit(0);
+}
+
inline void thread_stop(thread *thread)
{
if (thread->valid)
diff --git a/src/notification.c b/src/notification.c
index f89ca48..50ac244 100644
--- a/src/notification.c
+++ b/src/notification.c
@@ -30,6 +30,8 @@ void update_render_notifications()
for (s32 i = 0; i < global_notifications.length; i++)
{
+ main_window->do_draw = true;
+
notification *n = array_at(&global_notifications, i);
float32 duration_ms = (float32)n->duration/TARGET_FRAMERATE;
s32 y = 0;
diff --git a/src/thread.h b/src/thread.h
index b019fdb..e0266e3 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -54,6 +54,7 @@ void thread_detach(thread *thread);
void thread_stop(thread *thread);
u32 thread_get_id();
void thread_sleep(u64 microseconds);
+void thread_exit();
mutex mutex_create_recursive();
mutex mutex_create();
diff --git a/src/windows/platform.c b/src/windows/platform.c
index fee91c7..375024a 100644
--- a/src/windows/platform.c
+++ b/src/windows/platform.c
@@ -8,6 +8,7 @@
#include <windows.h>
#include <GL/gl.h>
#include <GL/glcorearb.h>
+#include <GL/wglext.h>
#include <stdbool.h>
#include <sysinfoapi.h>
#include <wingdi.h>
@@ -28,6 +29,7 @@ struct t_platform_window
HGLRC gl_context;
WNDCLASS window_class;
s32 flags;
+ bool do_draw;
s32 min_width;
s32 min_height;
@@ -512,6 +514,7 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam,
result = LSMProc(window, message, wparam, lparam);
}
+ current_window_to_handle->do_draw = true;
return result;
}
@@ -566,6 +569,7 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
window.max_height = max_h;
window.curr_cursor_type = -1;
window.next_cursor_type = CURSOR_DEFAULT;
+ window.do_draw = true;
current_window_to_handle = &window;
@@ -635,20 +639,23 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
{
window.hdc = GetDC(window.window_handle);
- 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??
-
PIXELFORMATDESCRIPTOR actual_format;
- DescribePixelFormat(window.hdc, suggested_format_index, sizeof(actual_format), &actual_format);
- SetPixelFormat(window.hdc, suggested_format_index, &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");
@@ -668,6 +675,46 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
wglMakeCurrent(window.hdc, window.gl_context);
+ // new pixel format selection
+#if 0
+ {
+ PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
+
+ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+
+ if (wglGetPixelFormatAttribivARB && wglChoosePixelFormatARB)
+ {
+ float pfAttribFList[] = { 0, 0 };
+ s32 maxFormats = 50;
+ s32 piFormats[maxFormats];
+ u32 nNumFormatsFound;
+ const int pixel_format_attrib_list[] =
+ {
+ WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
+ WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
+ WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
+ WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
+ WGL_COLOR_BITS_ARB, 24,
+ WGL_ALPHA_BITS_ARB, 8,
+ WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
+ WGL_SAMPLES_ARB, 4,
+ 0, 0,
+ };
+
+ bool result = wglChoosePixelFormatARB(window.hdc, pixel_format_attrib_list, pfAttribFList, maxFormats, piFormats, &nNumFormatsFound);
+
+ printf("result: %d, count: %d\n", result, nNumFormatsFound);
+
+ for (s32 i = 0; i < nNumFormatsFound; i++)
+ {
+ printf("format: %d\n", piFormats[i]);
+ }
+
+ SetPixelFormat(window.hdc, piFormats[0], &actual_format);
+ }
+ }
+#endif
+
ShowWindow(window.window_handle, cmd_show);
if (flags & FLAGS_HIDDEN)
ShowWindow(window.window_handle, SW_HIDE);
@@ -1230,7 +1277,7 @@ void platform_init(int argc, char **argv)
platform_create_config_directory();
- char buf[MAX_INPUT_LENGTH];
+ char buf[MAX_PATH_LENGTH];
get_directory_from_path(buf, binary_path);
string_copyn(binary_path, buf, MAX_INPUT_LENGTH);
diff --git a/src/windows/thread.c b/src/windows/thread.c
index 9669158..fbf5209 100644
--- a/src/windows/thread.c
+++ b/src/windows/thread.c
@@ -58,6 +58,11 @@ u32 thread_get_id()
return GetCurrentThreadId();
}
+void thread_exit()
+{
+ ExitThread(0);
+}
+
void thread_sleep(u64 microseconds)
{
Sleep(microseconds/1000);