summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-06-12 14:56:50 +0200
committerAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-06-12 14:56:50 +0200
commit91e66fff08f6101eeffea22d78c68e53dde0d4f0 (patch)
treed600a704f456c4ceb1f58a6802149a48c66265db
parentebd3c08d9c656557bd9692f23926ca46e96d5738 (diff)
working on cpu render layer, cleanup
-rw-r--r--src/linux/platform.c4
-rw-r--r--src/platform.h16
-rw-r--r--src/project_base.h111
-rw-r--r--src/render.c138
-rw-r--r--src/render.h10
-rw-r--r--src/windows/platform.c232
6 files changed, 349 insertions, 162 deletions
diff --git a/src/linux/platform.c b/src/linux/platform.c
index 35c5745..10e812d 100644
--- a/src/linux/platform.c
+++ b/src/linux/platform.c
@@ -144,7 +144,7 @@ void platform_create_config_directory()
{
char *env = getenv("HOME");
char tmp[PATH_MAX];
- snprintf(tmp, PATH_MAX, "%s%s", env, CONFIG_DIRECTORY);
+ snprintf(tmp, PATH_MAX, "%s%s", env, CONFIG_DIRECTORY_LINUX);
if (!platform_directory_exists(tmp))
{
@@ -155,7 +155,7 @@ void platform_create_config_directory()
char* get_config_save_location(char *buffer)
{
char *env = getenv("HOME");
- snprintf(buffer, PATH_MAX, "%s%s", env, CONFIG_DIRECTORY"/config.txt");
+ snprintf(buffer, PATH_MAX, "%s%s", env, CONFIG_DIRECTORY_LINUX"/config.txt");
return buffer;
}
diff --git a/src/platform.h b/src/platform.h
index 4be3938..bf0ae82 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -43,6 +43,7 @@ typedef struct t_search_result
array work_queue;
array files;
array matches;
+ s32 match_count;
u64 find_duration_us;
array errors;
bool show_error_message; // error occured
@@ -167,6 +168,21 @@ typedef struct t_vec2
s32 y;
} vec2;
+typedef struct t_backbuffer_pixel
+{
+ s32 color;
+ u8 depth;
+} backbuffer_pixel;
+
+typedef struct t_backbuffer
+{
+ s32 width;
+ s32 height;
+ u8 *pixels; // 5bytes color
+ u8 *buffer; // 4bytes color + 1byte depth
+ BITMAPINFO bitmapInfo;
+} backbuffer;
+
// NOT IMPLEMENTED ON LINUX: USE FLAGS_NONE
typedef enum t_window_flags
{
diff --git a/src/project_base.h b/src/project_base.h
new file mode 100644
index 0000000..6afb938
--- /dev/null
+++ b/src/project_base.h
@@ -0,0 +1,111 @@
+/*
+* BSD 2-Clause “Simplified” License
+* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com
+* All rights reserved.
+*/
+
+#ifndef INCLUDE_PROJECT_BASE
+#define INCLUDE_PROJECT_BASE
+
+#ifdef _WIN32
+#define OS_WIN
+#include <windows.h>
+#include <time.h>
+#endif
+#ifdef __linux__
+#define OS_LINUX
+#include <sys/times.h>
+#include <sys/vtimes.h>
+#endif
+#ifdef __APPLE__
+#define OS_OSX
+#error platform not supported
+#endif
+
+#include "stdint.h"
+#include "string.h"
+#include "assert.h"
+
+#include <GL/gl.h>
+#ifdef OS_LINUX
+#include <GL/glx.h>
+#endif
+#include <GL/glu.h>
+#include <GL/glext.h>
+
+#define s8 int8_t
+#define s16 int16_t
+#define s32 int32_t
+#define s64 int64_t
+
+#define u8 uint8_t
+#define u16 uint16_t
+#define u32 uint32_t
+#define u64 uint64_t
+
+#define float32 float
+#define float64 double
+
+#ifdef OS_LINUX
+#define bool uint8_t
+#endif
+#ifdef OS_WIN
+#define bool _Bool
+#endif
+
+#define true 1
+#define false 0
+
+#include "thread.h"
+#include "array.h"
+#include "memory.h"
+#include "external/cJSON.h"
+
+#define STB_IMAGE_IMPLEMENTATION
+#define STBI_ONLY_PNG
+#include "external/stb_image.h"
+
+#define STB_TRUETYPE_IMPLEMENTATION
+#include "external/stb_truetype.h"
+
+#include "external/utf8.h"
+#include "input.h"
+#include "timer.h"
+#include "assets.h"
+#include "memory_bucket.h"
+#include "platform.h"
+#include "render.h"
+#include "camera.h"
+#include "ui.h"
+#include "notification.h"
+#include "string_utils.h"
+#include "settings_config.h"
+#include "localization.h"
+
+#include "platform_shared.c"
+
+#ifdef OS_LINUX
+#include "linux/thread.c"
+#include "linux/platform.c"
+#endif
+
+#ifdef OS_WIN
+#include "windows/thread.c"
+#include "windows/platform.c"
+#endif
+
+#include "render.c"
+#include "input.c"
+#include "timer.c"
+#include "array.c"
+#include "assets.c"
+#include "camera.c"
+#include "ui.c"
+#include "notification.c"
+#include "string_utils.c"
+#include "settings_config.c"
+#include "localization.c"
+#include "memory_bucket.c"
+#include "external/cJSON.c"
+
+#endif \ No newline at end of file
diff --git a/src/render.c b/src/render.c
index b19abcd..a5d0d51 100644
--- a/src/render.c
+++ b/src/render.c
@@ -4,10 +4,51 @@
* All rights reserved.
*/
-inline void render_clear()
+static platform_window *drawing_window = 0;
+
+// returns topleft and bottomright corners. not width + height
+static vec4 _get_actual_rect(s32 x, s32 y, s32 width, s32 height)
{
- glClearColor(255/255.0, 255/255.0, 255/255.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ if (x < 0) x = 0;
+ if (y < 0) y = 0;
+ s32 start_x = x;
+ s32 start_y = y;
+ s32 end_x = start_x + width;
+ s32 end_y = start_y + height;
+ if (end_x > drawing_window->backbuffer.width)
+ end_x = drawing_window->backbuffer.width;
+ if (end_y > drawing_window->backbuffer.height)
+ end_y = drawing_window->backbuffer.height;
+
+ if (start_x < current_scissor.x) start_x = current_scissor.x;
+ if (start_y < current_scissor.y) start_y = current_scissor.y;
+ if (end_x > current_scissor.x+current_scissor.w)
+ end_x = current_scissor.x+current_scissor.w;
+ if (end_y > current_scissor.y+current_scissor.h)
+ end_y = current_scissor.y+current_scissor.h;
+
+ return (vec4){start_x,start_y,end_x,end_y};
+}
+
+inline void render_clear(platform_window *window)
+{
+ if (global_use_gpu)
+ {
+ glClearColor(255/255.0, 255/255.0, 255/255.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ }
+ else
+ {
+ drawing_window = window;
+ render_reset_scissor();
+
+ render_depth = 1;
+
+ u8 pixel[5] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
+ s32 pixel_count = window->backbuffer.width*window->backbuffer.height;
+ for (s32 i = 0; i < pixel_count; i++)
+ memcpy(window->backbuffer.buffer+(i*5), pixel, 5);
+ }
}
inline void render_set_rotation(float32 rotation, float32 x, float32 y, s32 depth)
@@ -530,27 +571,33 @@ void render_triangle(s32 x, s32 y, s32 w, s32 h, color tint, triangle_direction
void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint)
{
- glBegin(GL_QUADS);
- glColor4f(tint.r/255.0f, tint.g/255.0f, tint.b/255.0f, tint.a/255.0f);
- glVertex3i(x, y, render_depth);
- glVertex3i(x, y+height, render_depth);
- glVertex3i(x+width, y+height, render_depth);
- glVertex3i(x+width, y, render_depth);
- glEnd();
-}
-
-void render_rectangle_tint(s32 x, s32 y, s32 width, s32 height, color tint[4])
-{
- glBegin(GL_QUADS);
- glColor4f(tint[0].r/255.0f, tint[0].g/255.0f, tint[0].b/255.0f, tint[0].a/255.0f);
- glVertex3i(x, y, render_depth);
- glColor4f(tint[1].r/255.0f, tint[1].g/255.0f, tint[1].b/255.0f, tint[1].a/255.0f);
- glVertex3i(x, y+height, render_depth);
- glColor4f(tint[2].r/255.0f, tint[2].g/255.0f, tint[2].b/255.0f, tint[2].a/255.0f);
- glVertex3i(x+width, y+height, render_depth);
- glColor4f(tint[3].r/255.0f, tint[3].g/255.0f, tint[3].b/255.0f, tint[3].a/255.0f);
- glVertex3i(x+width, y, render_depth);
- glEnd();
+ if (global_use_gpu)
+ {
+ glBegin(GL_QUADS);
+ glColor4f(tint.r/255.0f, tint.g/255.0f, tint.b/255.0f, tint.a/255.0f);
+ glVertex3i(x, y, render_depth);
+ glVertex3i(x, y+height, render_depth);
+ glVertex3i(x+width, y+height, render_depth);
+ glVertex3i(x+width, y, render_depth);
+ glEnd();
+ }
+ else
+ {
+ vec4 rec = _get_actual_rect(x,y,width,height);
+
+ for (s32 x = rec.x; x < rec.w; x++)
+ {
+ for (s32 y = rec.y; y < rec.h; y++)
+ {
+ s32 offset = (y * (drawing_window->backbuffer.width) * 5) + x * 5;
+ u8 *buffer_entry = drawing_window->backbuffer.buffer+offset;
+
+ if (buffer_entry[4] > render_depth) continue;
+ buffer_entry[4] = render_depth;
+ memcpy(buffer_entry, &tint, 4);
+ }
+ }
+ }
}
void render_rectangle_outline(s32 x, s32 y, s32 width, s32 height, u16 outline_w, color tint)
@@ -567,22 +614,43 @@ void render_rectangle_outline(s32 x, s32 y, s32 width, s32 height, u16 outline_w
void render_set_scissor(platform_window *window, s32 x, s32 y, s32 w, s32 h)
{
- glEnable(GL_SCISSOR_TEST);
- glScissor(x-1, window->height-h-y-1, w+1, h+1);
+ if (global_use_gpu)
+ {
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(x-1, window->height-h-y-1, w+1, h+1);
+ }
+ else
+ {
+ current_scissor = (vec4){x,y,w,h};
+ }
}
vec4 render_get_scissor(platform_window *window)
{
- vec4 vec;
- glGetIntegerv(GL_SCISSOR_BOX, (GLint*)(&vec));
- vec.x += 1;
- vec.w -= 1;
- vec.h -= 1;
- vec.y += 1;
- return vec;
+ if (global_use_gpu)
+ {
+ vec4 vec;
+ glGetIntegerv(GL_SCISSOR_BOX, (GLint*)(&vec));
+ vec.x += 1;
+ vec.w -= 1;
+ vec.h -= 1;
+ vec.y += 1;
+ return vec;
+ }
+ else
+ {
+ return current_scissor;
+ }
}
void render_reset_scissor()
{
- glDisable(GL_SCISSOR_TEST);
-} \ No newline at end of file
+ if (global_use_gpu)
+ {
+ glDisable(GL_SCISSOR_TEST);
+ }
+ else
+ {
+ current_scissor = (vec4){0,0,drawing_window->width,drawing_window->height};
+ }
+}
diff --git a/src/render.h b/src/render.h
index bfe3aef..c02c740 100644
--- a/src/render.h
+++ b/src/render.h
@@ -30,13 +30,17 @@ typedef enum t_triangle_direction
TRIANGLE_RIGHT,
} triangle_direction;
-s32 render_depth = 1;
+s32 global_use_gpu = 0;
+u8 render_depth = 1;
+
+vec4 current_scissor;
+
void set_render_depth(s32 depth);
#define rgb(r_,g_,b_) (color){ r_, g_, b_, 255 }
#define rgba(r_,g_,b_,a_) (color){r_,g_,b_,a_}
-void render_clear();
+void render_clear(platform_window *window);
// images
void render_image(image *image, s32 x, s32 y, s32 width, s32 height);
@@ -48,6 +52,7 @@ s32 render_text_ellipsed(font *font, s32 x, s32 y, s32 maxw, char *text, color t
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);
s32 calculate_cursor_position(font *font, char *text, s32 click_x);
s32 calculate_text_width(font *font, char *text);
@@ -56,7 +61,6 @@ s32 calculate_text_width_from_upto(font *font, char *text, s32 from, s32 index);
// primitives
void render_rectangle(s32 x, s32 y, s32 width, s32 height, color tint);
-void render_rectangle_tint(s32 x, s32 y, s32 width, s32 height, color tint[4]);
void render_rectangle_outline(s32 x, s32 y, s32 width, s32 height, u16 outline_w, color tint);
void render_triangle(s32 x, s32 y, s32 w, s32 h, color tint, triangle_direction dir);
diff --git a/src/windows/platform.c b/src/windows/platform.c
index 723cf5a..40d2d7a 100644
--- a/src/windows/platform.c
+++ b/src/windows/platform.c
@@ -4,23 +4,13 @@
* All rights reserved.
*/
-#include <tchar.h>
#include <locale.h>
-#include <windows.h>
#include <GL/gl.h>
#include <GL/glcorearb.h>
#include <GL/wglext.h>
-#include <stdbool.h>
-#include <sysinfoapi.h>
#include <wingdi.h>
-#include <errno.h>
-#include <shlwapi.h>
-#include <objbase.h>
-//#include <shellapi.h>
#include <gdiplus.h>
-#include <winreg.h>
#include <shlobj.h>
-//#include <iphlpapi.h>
#include "../external/LooplessSizeMove.c"
struct t_platform_window
@@ -32,6 +22,8 @@ struct t_platform_window
s32 flags;
bool do_draw;
+ backbuffer backbuffer;
+
s32 min_width;
s32 min_height;
s32 max_width;
@@ -300,7 +292,7 @@ void platform_create_config_directory()
char tmp[PATH_MAX];
if(SUCCEEDED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, tmp)))
{
- string_appendn(tmp, CONFIG_DIRECTORY, PATH_MAX);
+ string_appendn(tmp, CONFIG_DIRECTORY_WINDOWS, PATH_MAX);
}
@@ -314,7 +306,7 @@ char* get_config_save_location(char *buffer)
{
if(SUCCEEDED(SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, buffer)))
{
- string_appendn(buffer, CONFIG_DIRECTORY"\\config.txt", MAX_INPUT_LENGTH);
+ string_appendn(buffer, CONFIG_DIRECTORY_WINDOWS"\\config.txt", MAX_INPUT_LENGTH);
return buffer;
}
@@ -327,6 +319,29 @@ void platform_show_message(platform_window *window, char *message, char *title)
MessageBox(handle, message, title, MB_ICONINFORMATION | MB_OK);
}
+static void _allocate_backbuffer(platform_window *window)
+{
+ if (window->backbuffer.pixels) mem_free(window->backbuffer.pixels);
+ if (window->backbuffer.buffer) mem_free(window->backbuffer.buffer);
+
+ BITMAPINFO info;
+ info.bmiHeader.biSize = sizeof(BITMAPINFO);
+ info.bmiHeader.biWidth = window->width;
+ info.bmiHeader.biHeight = window->height;
+ info.bmiHeader.biPlanes = 1;
+ info.bmiHeader.biBitCount = 32;
+ info.bmiHeader.biCompression = BI_RGB;
+ window->backbuffer.bitmapInfo = info;
+
+ window->backbuffer.width = window->width;
+ window->backbuffer.height = window->height;
+
+ s32 bufferMemorySize = (window->width*window->height)*5;
+ s32 pixelsMemorySize = (window->width*window->height)*4;
+ window->backbuffer.buffer = mem_alloc(bufferMemorySize);
+ window->backbuffer.pixels = mem_alloc(pixelsMemorySize);
+}
+
LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
LRESULT result = 0;
@@ -338,6 +353,9 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam,
current_window_to_handle->width = width;
current_window_to_handle->height = height;
+
+ if (!global_use_gpu)
+ _allocate_backbuffer(current_window_to_handle);
}
else if (message == WM_CHAR)
{
@@ -378,19 +396,6 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam,
keyboard_handle_input_string(current_window_to_handle, current_keyboard_to_handle, ch);
}
}
-#if 0
- else if (message == WM_PAINT)
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(current_window_to_handle->window_handle, &ps);
-
- SetDCPenColor(hdc, RGB(255, 0, 0)); // red
- Rectangle(hdc, 100, 100, 200, 300);
-
- EndPaint(current_window_to_handle->window_handle, &ps);
- return 0;
- }
-#endif
else if (message == WM_KILLFOCUS)
{
if (current_mouse_to_handle && !(current_window_to_handle->flags & FLAGS_GLOBAL_MOUSE))
@@ -492,14 +497,6 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam,
{
current_window_to_handle->curr_cursor_type = -999;
-#if 0
- s32 x = lparam&0xFFFF;
- s32 y = lparam>>16;
-
- current_mouse_to_handle->x = x;
- current_mouse_to_handle->y = y;
-#endif
-
TRACKMOUSEEVENT track;
track.cbSize = sizeof(track);
track.dwFlags = TME_LEAVE;
@@ -532,6 +529,7 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam,
}
current_window_to_handle->do_draw = true;
+
return result;
}
@@ -593,6 +591,8 @@ 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.backbuffer.pixels = 0;
+ window.backbuffer.buffer = 0;
window.do_draw = true;
current_window_to_handle = &window;
@@ -659,81 +659,48 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
{
window.hdc = GetDC(window.window_handle);
- PIXELFORMATDESCRIPTOR actual_format;
- // old pixel format selection
+ if (global_use_gpu)
{
- 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;
+ // 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);
+ }
- 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);
-
- // new pixel format selection
-#if 0
- {
- PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");
+ debug_print_elapsed(startup_stamp, "pixel format");
- PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+ window.gl_context = wglCreateContext(window.hdc);
- if (wglGetPixelFormatAttribivARB && wglChoosePixelFormatARB)
+ debug_print_elapsed(startup_stamp, "gl context");
+
+ static HGLRC share_list = 0;
+ if (share_list == 0)
{
- 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);
+ share_list = window.gl_context;
}
+ else
+ {
+ wglShareLists(share_list, window.gl_context);
+ }
+
+ wglMakeCurrent(window.hdc, window.gl_context);
+ }
+ else
+ {
+ _allocate_backbuffer(&window);
}
-#endif
ShowWindow(window.window_handle, cmd_show);
if (flags & FLAGS_HIDDEN)
@@ -741,24 +708,25 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
else
ShowWindow(window.window_handle, SW_SHOW);
- ////// 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);
-
- window.is_open = true;
+ 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();
@@ -768,6 +736,8 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m
debug_print_elapsed(startup_stamp, "gl setup");
+ window.is_open = true;
+
TRACKMOUSEEVENT track;
track.cbSize = sizeof(track);
track.dwFlags = TME_LEAVE;
@@ -807,6 +777,9 @@ void platform_window_set_size(platform_window *window, u16 width, u16 height)
rec.bottom = height;
AdjustWindowRectEx(&rec, style, menu, 0);
SetWindowPos(window->window_handle,NULL,rec.left,rec.top,rec.right,rec.bottom,SWP_NOMOVE|SWP_NOZORDER);
+
+ if (!global_use_gpu)
+ _allocate_backbuffer(window);
}
void platform_window_set_position(platform_window *window, u16 x, u16 y)
@@ -893,8 +866,6 @@ void platform_handle_events(platform_window *window, mouse_input *mouse, keyboar
mouse->y = p.y - rec.top;
else
mouse->y = p.y - rec.top - GetSystemMetrics(SM_CYSIZE) - GetSystemMetrics(SM_CYFRAME);
-
- //printf("%d %d\n",GetSystemMetrics(SM_CYSIZE), GetSystemMetrics(SM_CYFRAME));
}
#endif
@@ -927,7 +898,24 @@ void platform_window_swap_buffers(platform_window *window)
SetCursor(cursor);
}
- SwapBuffers(window->hdc);
+ if (!global_use_gpu)
+ {
+ s32 pixel_count = window->backbuffer.width * window->backbuffer.height;
+ for (s32 i = 0; i < pixel_count; i++)
+ {
+ u8 *buffer_entry = window->backbuffer.buffer + (i*5);
+ memcpy(window->backbuffer.pixels + (i*4), buffer_entry, 4);
+ }
+
+ StretchDIBits(window->hdc,0,0,window->width,window->height,
+ 0,window->backbuffer.height,window->backbuffer.width,
+ -window->backbuffer.height,
+ window->backbuffer.pixels, &window->backbuffer.bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
+ }
+ else
+ {
+ SwapBuffers(window->hdc);
+ }
}
s32 platform_get_file_size(char *path)