Merge branch 'win32' into orca
This commit is contained in:
commit
43c23627e2
|
@ -6,6 +6,6 @@ set glsl_shaders=src\glsl_shaders\common.glsl src\glsl_shaders\blit_vertex.glsl
|
|||
call python3 scripts\embed_text.py %glsl_shaders% --prefix=glsl_ --output src\glsl_shaders.h
|
||||
|
||||
set INCLUDES=/I src /I src/util /I src/platform /I ext /I ext/angle_headers
|
||||
set LIBS=user32.lib opengl32.lib gdi32.lib shcore.lib delayimp.lib dwmapi.lib /LIBPATH:./bin libEGL.dll.lib libGLESv2.dll.lib /DELAYLOAD:libEGL.dll /DELAYLOAD:libGLESv2.dll
|
||||
set LIBS=user32.lib opengl32.lib gdi32.lib shcore.lib delayimp.lib dwmapi.lib comctl32.lib ole32.lib shell32.lib /LIBPATH:./bin libEGL.dll.lib libGLESv2.dll.lib /DELAYLOAD:libEGL.dll /DELAYLOAD:libGLESv2.dll
|
||||
|
||||
cl /we4013 /Zi /Zc:preprocessor /DMP_BUILD_DLL /std:c11 %INCLUDES% src/milepost.c /Fo:bin/milepost.o /LD /link %LIBS% /OUT:bin/milepost.dll /IMPLIB:bin/milepost.dll.lib
|
||||
cl /we4013 /Zi /Zc:preprocessor /DMP_BUILD_DLL /std:c11 %INCLUDES% src/milepost.c /Fo:bin/milepost.o /LD /link /MANIFEST:EMBED /MANIFESTINPUT:src/win32_manifest.xml %LIBS% /OUT:bin/milepost.dll /IMPLIB:bin/milepost.dll.lib
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
#include<errno.h>
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ mg_font create_font(const char* path)
|
|||
return(font);
|
||||
}
|
||||
|
||||
enum { FONT_COUNT = 3 };
|
||||
|
||||
int main()
|
||||
{
|
||||
mp_init();
|
||||
|
@ -109,17 +111,16 @@ int main()
|
|||
|
||||
mg_canvas canvas = mg_canvas_create();
|
||||
|
||||
const int fontCount = 3;
|
||||
int fontIndex = 0;
|
||||
mg_font fonts[fontCount] = {create_font("../resources/OpenSansLatinSubset.ttf"),
|
||||
mg_font fonts[FONT_COUNT] = {create_font("../resources/OpenSansLatinSubset.ttf"),
|
||||
create_font("../resources/CMUSerif-Roman.ttf"),
|
||||
create_font("../resources/courier.ttf")};
|
||||
|
||||
mg_font_extents extents[fontCount];
|
||||
f32 fontScales[fontCount];
|
||||
f32 lineHeights[fontCount];
|
||||
mg_font_extents extents[FONT_COUNT];
|
||||
f32 fontScales[FONT_COUNT];
|
||||
f32 lineHeights[FONT_COUNT];
|
||||
|
||||
for(int i=0; i<fontCount; i++)
|
||||
for(int i=0; i<FONT_COUNT; i++)
|
||||
{
|
||||
extents[i] = mg_font_get_extents(fonts[i]);
|
||||
fontScales[i] = mg_font_get_scale_for_em_pixels(fonts[i], 14);
|
||||
|
@ -206,7 +207,7 @@ int main()
|
|||
{
|
||||
if(event->key.code == MP_KEY_SPACE && event->key.action == MP_KEY_PRESS)
|
||||
{
|
||||
fontIndex = (fontIndex+1)%fontCount;
|
||||
fontIndex = (fontIndex+1)%FONT_COUNT;
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -313,7 +314,7 @@ int main()
|
|||
}
|
||||
|
||||
|
||||
for(int i=0; i<fontCount; i++)
|
||||
for(int i=0; i<FONT_COUNT; i++)
|
||||
{
|
||||
mg_font_destroy(fonts[i]);
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext
|
||||
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib /out:test.exe
|
||||
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib user32.lib opengl32.lib gdi32.lib /out:../../bin/example_window.exe
|
||||
|
|
|
@ -7,16 +7,13 @@
|
|||
*
|
||||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
#include"milepost.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Main"
|
||||
|
||||
int main()
|
||||
{
|
||||
LogLevel(LOG_LEVEL_DEBUG);
|
||||
|
||||
mp_init();
|
||||
|
||||
mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600};
|
||||
|
@ -28,10 +25,10 @@ int main()
|
|||
while(!mp_should_quit())
|
||||
{
|
||||
mp_pump_events(0);
|
||||
mp_event event = {0};
|
||||
while(mp_next_event(&event))
|
||||
mp_event *event = 0;
|
||||
while((event = mp_next_event(mem_scratch())) != 0)
|
||||
{
|
||||
switch(event.type)
|
||||
switch(event->type)
|
||||
{
|
||||
case MP_EVENT_WINDOW_CLOSE:
|
||||
{
|
||||
|
@ -41,35 +38,35 @@ int main()
|
|||
case MP_EVENT_WINDOW_RESIZE:
|
||||
{
|
||||
printf("resized, rect = {%f, %f, %f, %f}\n",
|
||||
event.frame.rect.x,
|
||||
event.frame.rect.y,
|
||||
event.frame.rect.w,
|
||||
event.frame.rect.h);
|
||||
event->frame.rect.x,
|
||||
event->frame.rect.y,
|
||||
event->frame.rect.w,
|
||||
event->frame.rect.h);
|
||||
} break;
|
||||
|
||||
case MP_EVENT_WINDOW_MOVE:
|
||||
{
|
||||
printf("moved, rect = {%f, %f, %f, %f}\n",
|
||||
event.frame.rect.x,
|
||||
event.frame.rect.y,
|
||||
event.frame.rect.w,
|
||||
event.frame.rect.h);
|
||||
event->frame.rect.x,
|
||||
event->frame.rect.y,
|
||||
event->frame.rect.w,
|
||||
event->frame.rect.h);
|
||||
} break;
|
||||
|
||||
case MP_EVENT_MOUSE_MOVE:
|
||||
{
|
||||
printf("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n",
|
||||
event.move.x,
|
||||
event.move.y,
|
||||
event.move.deltaX,
|
||||
event.move.deltaY);
|
||||
event->move.x,
|
||||
event->move.y,
|
||||
event->move.deltaX,
|
||||
event->move.deltaY);
|
||||
} break;
|
||||
|
||||
case MP_EVENT_MOUSE_WHEEL:
|
||||
{
|
||||
printf("mouse wheel, delta = {%f, %f}\n",
|
||||
event.move.deltaX,
|
||||
event.move.deltaY);
|
||||
event->move.deltaX,
|
||||
event->move.deltaY);
|
||||
} break;
|
||||
|
||||
case MP_EVENT_MOUSE_ENTER:
|
||||
|
@ -85,26 +82,27 @@ int main()
|
|||
case MP_EVENT_MOUSE_BUTTON:
|
||||
{
|
||||
printf("mouse button %i: %i\n",
|
||||
event.key.code,
|
||||
event.key.action == MP_KEY_PRESS ? 1 : 0);
|
||||
event->key.code,
|
||||
event->key.action == MP_KEY_PRESS ? 1 : 0);
|
||||
} break;
|
||||
|
||||
case MP_EVENT_KEYBOARD_KEY:
|
||||
{
|
||||
printf("key %i: %s\n",
|
||||
event.key.code,
|
||||
event.key.action == MP_KEY_PRESS ? "press" : (event.key.action == MP_KEY_RELEASE ? "release" : "repeat"));
|
||||
event->key.code,
|
||||
event->key.action == MP_KEY_PRESS ? "press" : (event->key.action == MP_KEY_RELEASE ? "release" : "repeat"));
|
||||
} break;
|
||||
|
||||
case MP_EVENT_KEYBOARD_CHAR:
|
||||
{
|
||||
printf("entered char %s\n", event.character.sequence);
|
||||
printf("entered char %s\n", event->character.sequence);
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
mem_arena_clear(mem_scratch());
|
||||
}
|
||||
|
||||
mp_terminate();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
|
||||
|
||||
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_canvas.exe
|
||||
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.dll.lib /out:../../bin/example_tiger.exe
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<errno.h>
|
||||
|
||||
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @revision:
|
||||
*
|
||||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
||||
|
@ -15,8 +15,6 @@
|
|||
#define MG_INCLUDE_GL_API
|
||||
#include"milepost.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Main"
|
||||
|
||||
unsigned int program;
|
||||
|
||||
const char* vshaderSource =
|
||||
|
@ -60,15 +58,13 @@ void compile_shader(GLuint shader, const char* source)
|
|||
|
||||
int main()
|
||||
{
|
||||
LogLevel(LOG_LEVEL_DEBUG);
|
||||
|
||||
mp_init();
|
||||
|
||||
mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600};
|
||||
mp_window window = mp_window_create(rect, "test", 0);
|
||||
|
||||
//NOTE: create surface
|
||||
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GL);
|
||||
mg_surface surface = mg_surface_create_for_window(window, MG_GL);
|
||||
|
||||
//NOTE: init shader and gl state
|
||||
mg_surface_prepare(surface);
|
||||
|
@ -116,10 +112,10 @@ int main()
|
|||
while(!mp_should_quit())
|
||||
{
|
||||
mp_pump_events(0);
|
||||
mp_event event = {0};
|
||||
while(mp_next_event(&event))
|
||||
mp_event* event = 0;
|
||||
while((event = mp_next_event(mem_scratch())) != 0)
|
||||
{
|
||||
switch(event.type)
|
||||
switch(event->type)
|
||||
{
|
||||
case MP_EVENT_WINDOW_CLOSE:
|
||||
{
|
||||
|
@ -157,6 +153,8 @@ int main()
|
|||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
mg_surface_present(surface);
|
||||
|
||||
mem_arena_clear(mem_scratch());
|
||||
}
|
||||
|
||||
mp_terminate();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*****************************************************************/
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<errno.h>
|
||||
|
||||
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
||||
|
@ -15,8 +16,6 @@
|
|||
|
||||
#include"milepost.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "Main"
|
||||
|
||||
void debug_print_indent(int indent)
|
||||
{
|
||||
for(int i=0; i<indent; i++)
|
||||
|
@ -206,12 +205,12 @@ void widget_end_view(void)
|
|||
|
||||
int main()
|
||||
{
|
||||
LogLevel(LOG_LEVEL_WARNING);
|
||||
|
||||
mp_init();
|
||||
mp_clock_init(); //TODO put that in mp_init()?
|
||||
|
||||
ui_init();
|
||||
ui_context context;
|
||||
ui_init(&context);
|
||||
ui_set_context(&context);
|
||||
|
||||
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
|
||||
mp_window window = mp_window_create(windowRect, "test", 0);
|
||||
|
@ -219,11 +218,11 @@ int main()
|
|||
mp_rect contentRect = mp_window_get_content_rect(window);
|
||||
|
||||
//NOTE: create surface
|
||||
mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_DEFAULT);
|
||||
mg_surface surface = mg_surface_create_for_window(window, MG_CANVAS);
|
||||
mg_surface_swap_interval(surface, 0);
|
||||
|
||||
//TODO: create canvas
|
||||
mg_canvas canvas = mg_canvas_create(surface);
|
||||
mg_canvas canvas = mg_canvas_create();
|
||||
|
||||
if(mg_canvas_is_nil(canvas))
|
||||
{
|
||||
|
@ -247,10 +246,12 @@ int main()
|
|||
f64 startTime = mp_get_time(MP_CLOCK_MONOTONIC);
|
||||
|
||||
mp_pump_events(0);
|
||||
mp_event event = {0};
|
||||
while(mp_next_event(&event))
|
||||
mp_event* event = 0;
|
||||
while((event = mp_next_event(mem_scratch())) != 0)
|
||||
{
|
||||
switch(event.type)
|
||||
ui_process_event(event);
|
||||
|
||||
switch(event->type)
|
||||
{
|
||||
case MP_EVENT_WINDOW_CLOSE:
|
||||
{
|
||||
|
@ -260,7 +261,7 @@ int main()
|
|||
|
||||
case MP_EVENT_KEYBOARD_KEY:
|
||||
{
|
||||
if(event.key.action == MP_KEY_PRESS && event.key.code == MP_KEY_P)
|
||||
if(event->key.action == MP_KEY_PRESS && event->key.code == MP_KEY_P)
|
||||
{
|
||||
printDebugStyle = true;
|
||||
}
|
||||
|
@ -289,7 +290,11 @@ int main()
|
|||
ui_flags debugFlags = UI_FLAG_DRAW_BORDER;
|
||||
|
||||
ui_box* root = 0;
|
||||
ui_frame(&defaultStyle, defaultMask)
|
||||
|
||||
mp_rect frameRect = mg_surface_get_frame(surface);
|
||||
vec2 frameSize = {frameRect.w, frameRect.h};
|
||||
|
||||
ui_frame(frameSize, &defaultStyle, defaultMask)
|
||||
{
|
||||
root = ui_box_top();
|
||||
ui_style_match_before(ui_pattern_all(), &defaultStyle, defaultMask);
|
||||
|
@ -401,9 +406,32 @@ int main()
|
|||
UI_STYLE_SIZE);
|
||||
widget_view("Buttons")
|
||||
{
|
||||
ui_button("Button 1");
|
||||
ui_button("Button 2");
|
||||
ui_button("Button 3");
|
||||
if(ui_button("Test Dialog").clicked)
|
||||
{
|
||||
char* options[] = {"Accept", "Reject"};
|
||||
int res = mp_alert_popup("test dialog", "dialog message", 2, options);
|
||||
if(res >= 0)
|
||||
{
|
||||
printf("selected options %i: %s\n", res, options[res]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("no options selected\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(ui_button("Open").clicked)
|
||||
{
|
||||
char* filters[] = {"md"};
|
||||
str8 file = mp_open_dialog(mem_scratch(), "Open File", "C:\\Users", 1, filters, false);
|
||||
printf("selected file %.*s\n", (int)file.len, file.ptr);
|
||||
}
|
||||
|
||||
if(ui_button("Save").clicked)
|
||||
{
|
||||
str8 file = mp_save_dialog(mem_scratch(), "Save File", "C:\\Users", 0, 0);
|
||||
printf("selected file %.*s\n", (int)file.len, file.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
ui_style_next(&(ui_style){.size.width = {UI_SIZE_PARENT, 0.5},
|
||||
|
@ -518,7 +546,7 @@ int main()
|
|||
UI_STYLE_SIZE);
|
||||
widget_view("Test")
|
||||
{
|
||||
ui_pattern pattern = {};
|
||||
ui_pattern pattern = {0};
|
||||
ui_pattern_push(mem_scratch(), &pattern, (ui_selector){.kind = UI_SEL_TEXT, .text = STR8("panel")});
|
||||
ui_style_match_after(pattern, &(ui_style){.bgColor = {0.3, 0.3, 1, 1}}, UI_STYLE_BG_COLOR);
|
||||
|
||||
|
@ -592,7 +620,7 @@ int main()
|
|||
|
||||
ui_draw();
|
||||
|
||||
mg_flush();
|
||||
mg_render(surface, canvas);
|
||||
mg_surface_present(surface);
|
||||
|
||||
mem_arena_clear(mem_scratch());
|
||||
|
|
|
@ -49,15 +49,22 @@ or download and unzip bundle at [https://storage.googleapis.com/chrome-infra/dep
|
|||
* wait a million years
|
||||
|
||||
* if it fails when running `python3 third_party/depot_tools/download_from_google_storage.py ...`
|
||||
-> open `DEPS` and change `third_party/depot_tools` to `../depot/tools`
|
||||
-> open `DEPS` and change `third_party/depot_tools` to `../depot_tools`
|
||||
* run `gclient sync` to complete previous step
|
||||
|
||||
* `gn gen out/Debug`
|
||||
* `gn args out/Debug` and edit arguments:
|
||||
* `angle_enable_vulkan = false`
|
||||
* `angle_build_tests = false`
|
||||
* `is_component_build = false`
|
||||
```
|
||||
is_component_build = false
|
||||
angle_build_tests = false
|
||||
angle_enable_metal = false
|
||||
angle_enable_d3d9 = false
|
||||
angle_enable_gl = false
|
||||
angle_enable_vulkan = false
|
||||
```
|
||||
|
||||
|
||||
* `ninja -C out/Debug`
|
||||
* link with `libEGL.dll.lib` and `libGLESv2.dll.lib`
|
||||
* put `libEGL.dll` and `libGLESv2.dll` in same directory as executable
|
||||
|
||||
|
|
1643
src/gl_canvas.c
1643
src/gl_canvas.c
File diff suppressed because it is too large
Load Diff
|
@ -1,469 +0,0 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* file: glsl_shaders.h
|
||||
* note: string literals auto-generated by embed_text.py
|
||||
* date: 09/032023
|
||||
*
|
||||
**********************************************************************/
|
||||
#ifndef __GLSL_SHADERS_H__
|
||||
#define __GLSL_SHADERS_H__
|
||||
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\common.glsl
|
||||
const char* glsl_common =
|
||||
"\n"
|
||||
"layout(std430) buffer;\n"
|
||||
"\n"
|
||||
"struct vertex {\n"
|
||||
" vec4 cubic;\n"
|
||||
" vec2 pos;\n"
|
||||
" int shapeIndex;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct shape {\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 clip;\n"
|
||||
" float uvTransform[6];\n"
|
||||
"};\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\blit_vertex.glsl
|
||||
const char* glsl_blit_vertex =
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"out vec2 uv;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" /* generate (0, 0) (1, 0) (1, 1) (1, 1) (0, 1) (0, 0)*/\n"
|
||||
"\n"
|
||||
" float x = float(((uint(gl_VertexID) + 2u) / 3u)%2u);\n"
|
||||
" float y = float(((uint(gl_VertexID) + 1u) / 3u)%2u);\n"
|
||||
"\n"
|
||||
" gl_Position = vec4(-1.0f + x*2.0f, -1.0f+y*2.0f, 0.0f, 1.0f);\n"
|
||||
" uv = vec2(x, 1-y);\n"
|
||||
"}\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\blit_fragment.glsl
|
||||
const char* glsl_blit_fragment =
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"in vec2 uv;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"\n"
|
||||
"layout(location=0) uniform sampler2D tex;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" fragColor = texture(tex, uv);\n"
|
||||
"}\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\clear_counters.glsl
|
||||
const char* glsl_clear_counters =
|
||||
"\n"
|
||||
"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"layout(std430) buffer;\n"
|
||||
"\n"
|
||||
"layout(binding = 0) coherent restrict writeonly buffer tileCounterBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileCounterBuffer ;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" uint tileIndex = gl_WorkGroupID.x;\n"
|
||||
" tileCounterBuffer.elements[tileIndex] = 0u;\n"
|
||||
"}\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\tile.glsl
|
||||
const char* glsl_tile =
|
||||
"\n"
|
||||
"layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;\n"
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"layout(binding = 0) restrict readonly buffer vertexBufferSSBO {\n"
|
||||
" vertex elements[];\n"
|
||||
"} vertexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 1) restrict readonly buffer shapeBufferSSBO {\n"
|
||||
" shape elements[];\n"
|
||||
"} shapeBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 2) restrict readonly buffer indexBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} indexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 3) coherent restrict buffer tileCounterBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileCounterBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 4) coherent restrict writeonly buffer tileArrayBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileArrayBuffer ;\n"
|
||||
"\n"
|
||||
"layout(location = 0) uniform uint indexCount;\n"
|
||||
"layout(location = 1) uniform uvec2 tileCount;\n"
|
||||
"layout(location = 2) uniform uint tileSize;\n"
|
||||
"layout(location = 3) uniform uint tileArraySize;\n"
|
||||
"layout(location = 4) uniform vec2 scaling;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" uint triangleIndex = (gl_WorkGroupID.x*gl_WorkGroupSize.x + gl_LocalInvocationIndex) * 3u;\n"
|
||||
" if(triangleIndex >= indexCount)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" uint i0 = indexBuffer.elements[triangleIndex];\n"
|
||||
" uint i1 = indexBuffer.elements[triangleIndex+1u];\n"
|
||||
" uint i2 = indexBuffer.elements[triangleIndex+2u];\n"
|
||||
"\n"
|
||||
" vec2 p0 = vertexBuffer.elements[i0].pos * scaling;\n"
|
||||
" vec2 p1 = vertexBuffer.elements[i1].pos * scaling;\n"
|
||||
" vec2 p2 = vertexBuffer.elements[i2].pos * scaling;\n"
|
||||
"\n"
|
||||
" int shapeIndex = vertexBuffer.elements[i0].shapeIndex;\n"
|
||||
" vec4 clip = shapeBuffer.elements[shapeIndex].clip * vec4(scaling, scaling);\n"
|
||||
"\n"
|
||||
" vec4 fbox = vec4(max(min(min(p0.x, p1.x), p2.x), clip.x),\n"
|
||||
" max(min(min(p0.y, p1.y), p2.y), clip.y),\n"
|
||||
" min(max(max(p0.x, p1.x), p2.x), clip.z),\n"
|
||||
" min(max(max(p0.y, p1.y), p2.y), clip.w));\n"
|
||||
"\n"
|
||||
" ivec4 box = ivec4(floor(fbox))/int(tileSize);\n"
|
||||
"\n"
|
||||
" //NOTE(martin): it's importat to do the computation with signed int, so that we can have negative xMax/yMax\n"
|
||||
" // otherwise all triangles on the left or below the x/y axis are attributed to tiles on row/column 0.\n"
|
||||
" int xMin = max(0, box.x);\n"
|
||||
" int yMin = max(0, box.y);\n"
|
||||
" int xMax = min(box.z, int(tileCount.x) - 1);\n"
|
||||
" int yMax = min(box.w, int(tileCount.y) - 1);\n"
|
||||
"\n"
|
||||
" for(int y = yMin; y <= yMax; y++)\n"
|
||||
" {\n"
|
||||
" for(int x = xMin ; x <= xMax; x++)\n"
|
||||
" {\n"
|
||||
" uint tileIndex = uint(y)*tileCount.x + uint(x);\n"
|
||||
" uint tileCounter = atomicAdd(tileCounterBuffer.elements[tileIndex], 1u);\n"
|
||||
" if(tileCounter < tileArraySize)\n"
|
||||
" {\n"
|
||||
" tileArrayBuffer.elements[tileArraySize*tileIndex + tileCounter] = triangleIndex;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\sort.glsl
|
||||
const char* glsl_sort =
|
||||
"\n"
|
||||
"layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"\n"
|
||||
"layout(binding = 0) restrict readonly buffer vertexBufferSSBO {\n"
|
||||
" vertex elements[];\n"
|
||||
"} vertexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 1) restrict readonly buffer shapeBufferSSBO {\n"
|
||||
" shape elements[];\n"
|
||||
"} shapeBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 2) restrict readonly buffer indexBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} indexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 3) coherent readonly restrict buffer tileCounterBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileCounterBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 4) coherent restrict buffer tileArrayBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileArrayBuffer ;\n"
|
||||
"\n"
|
||||
"layout(location = 0) uniform uint indexCount;\n"
|
||||
"layout(location = 1) uniform uvec2 tileCount;\n"
|
||||
"layout(location = 2) uniform uint tileSize;\n"
|
||||
"layout(location = 3) uniform uint tileArraySize;\n"
|
||||
"\n"
|
||||
"int get_shape_index(uint tileArrayOffset, uint tileArrayIndex)\n"
|
||||
"{\n"
|
||||
" uint triangleIndex = tileArrayBuffer.elements[tileArrayOffset + tileArrayIndex];\n"
|
||||
" uint i0 = indexBuffer.elements[triangleIndex];\n"
|
||||
" int shapeIndex = vertexBuffer.elements[i0].shapeIndex;\n"
|
||||
" return(shapeIndex);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" uint tileIndex = gl_WorkGroupID.x;\n"
|
||||
" uint tileArrayOffset = tileArraySize * tileIndex;\n"
|
||||
" uint tileArrayCount = min(tileCounterBuffer.elements[tileIndex], tileArraySize);\n"
|
||||
"\n"
|
||||
" for(uint tileArrayIndex=1u; tileArrayIndex < tileArrayCount; tileArrayIndex++)\n"
|
||||
" {\n"
|
||||
" for(uint sortIndex = tileArrayIndex; sortIndex > 0u; sortIndex--)\n"
|
||||
" {\n"
|
||||
" int shapeIndex = get_shape_index(tileArrayOffset, sortIndex);\n"
|
||||
" int prevShapeIndex = get_shape_index(tileArrayOffset, sortIndex-1u);\n"
|
||||
"\n"
|
||||
" if(shapeIndex >= prevShapeIndex)\n"
|
||||
" {\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" uint tmp = tileArrayBuffer.elements[tileArrayOffset + sortIndex];\n"
|
||||
" tileArrayBuffer.elements[tileArrayOffset + sortIndex] = tileArrayBuffer.elements[tileArrayOffset + sortIndex - 1u];\n"
|
||||
" tileArrayBuffer.elements[tileArrayOffset + sortIndex - 1u] = tmp;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
//NOTE: string imported from src\glsl_shaders\draw.glsl
|
||||
const char* glsl_draw =
|
||||
"\n"
|
||||
"#extension GL_ARB_gpu_shader_int64 : require\n"
|
||||
"layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;\n"
|
||||
"\n"
|
||||
"precision mediump float;\n"
|
||||
"//precision mediump image2D;\n"
|
||||
"\n"
|
||||
"layout(binding = 0) restrict readonly buffer vertexBufferSSBO {\n"
|
||||
" vertex elements[];\n"
|
||||
"} vertexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 1) restrict readonly buffer shapeBufferSSBO {\n"
|
||||
" shape elements[];\n"
|
||||
"} shapeBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 2) restrict readonly buffer indexBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} indexBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 3) restrict readonly buffer tileCounterBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileCounterBuffer ;\n"
|
||||
"\n"
|
||||
"layout(binding = 4) restrict readonly buffer tileArrayBufferSSBO {\n"
|
||||
" uint elements[];\n"
|
||||
"} tileArrayBuffer ;\n"
|
||||
"\n"
|
||||
"layout(location = 0) uniform uint indexCount;\n"
|
||||
"layout(location = 1) uniform uvec2 tileCount;\n"
|
||||
"layout(location = 2) uniform uint tileSize;\n"
|
||||
"layout(location = 3) uniform uint tileArraySize;\n"
|
||||
"layout(location = 4) uniform vec2 scaling;\n"
|
||||
"layout(location = 5) uniform uint useTexture;\n"
|
||||
"\n"
|
||||
"layout(rgba8, binding = 0) uniform restrict writeonly image2D outTexture;\n"
|
||||
"\n"
|
||||
"layout(binding = 1) uniform sampler2D srcTexture;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"bool is_top_left(ivec2 a, ivec2 b)\n"
|
||||
"{\n"
|
||||
" return( (a.y == b.y && b.x < a.x)\n"
|
||||
" ||(b.y < a.y));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"//////////////////////////////////////////////////////////////////////////////\n"
|
||||
"//TODO: we should do these computations on 64bits, because otherwise\n"
|
||||
"// we might overflow for values > 2048.\n"
|
||||
"// Unfortunately this is costly.\n"
|
||||
"// Another way is to precompute triangle edges (b - a) in full precision\n"
|
||||
"// once to avoid doing it all the time...\n"
|
||||
"//////////////////////////////////////////////////////////////////////////////\n"
|
||||
"int orient2d(ivec2 a, ivec2 b, ivec2 p)\n"
|
||||
"{\n"
|
||||
" return((b.x-a.x)*(p.y-a.y) - (b.y-a.y)*(p.x-a.x));\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"int is_clockwise(ivec2 p0, ivec2 p1, ivec2 p2)\n"
|
||||
"{\n"
|
||||
" return((p1 - p0).x*(p2 - p0).y - (p1 - p0).y*(p2 - p0).x);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" ivec2 pixelCoord = ivec2(gl_WorkGroupID.xy*uvec2(16, 16) + gl_LocalInvocationID.xy);\n"
|
||||
" uvec2 tileCoord = uvec2(pixelCoord) / tileSize;\n"
|
||||
" uint tileIndex = tileCoord.y * tileCount.x + tileCoord.x;\n"
|
||||
" uint tileCounter = min(tileCounterBuffer.elements[tileIndex], tileArraySize);\n"
|
||||
"\n"
|
||||
" const float subPixelFactor = 16.;\n"
|
||||
" ivec2 centerPoint = ivec2((vec2(pixelCoord) + vec2(0.5, 0.5)) * subPixelFactor);\n"
|
||||
"\n"
|
||||
"//*\n"
|
||||
" const int sampleCount = 8;\n"
|
||||
" ivec2 samplePoints[sampleCount] = ivec2[sampleCount](centerPoint + ivec2(1, 3),\n"
|
||||
" centerPoint + ivec2(-1, -3),\n"
|
||||
" centerPoint + ivec2(5, -1),\n"
|
||||
" centerPoint + ivec2(-3, 5),\n"
|
||||
" centerPoint + ivec2(-5, -5),\n"
|
||||
" centerPoint + ivec2(-7, 1),\n"
|
||||
" centerPoint + ivec2(3, -7),\n"
|
||||
" centerPoint + ivec2(7, 7));\n"
|
||||
"/*/\n"
|
||||
" const int sampleCount = 4;\n"
|
||||
" ivec2 samplePoints[sampleCount] = ivec2[sampleCount](centerPoint + ivec2(-2, 6),\n"
|
||||
" centerPoint + ivec2(6, 2),\n"
|
||||
" centerPoint + ivec2(-6, -2),\n"
|
||||
" centerPoint + ivec2(2, -6));\n"
|
||||
"//*/\n"
|
||||
" //DEBUG\n"
|
||||
"/*\n"
|
||||
" {\n"
|
||||
" vec4 fragColor = vec4(0);\n"
|
||||
"\n"
|
||||
" if( pixelCoord.x % 16 == 0\n"
|
||||
" ||pixelCoord.y % 16 == 0)\n"
|
||||
" {\n"
|
||||
" fragColor = vec4(0, 0, 0, 1);\n"
|
||||
" }\n"
|
||||
" else if(tileCounterBuffer.elements[tileIndex] == 0xffffu)\n"
|
||||
" {\n"
|
||||
" fragColor = vec4(1, 0, 1, 1);\n"
|
||||
" }\n"
|
||||
" else if(tileCounter != 0u)\n"
|
||||
" {\n"
|
||||
" fragColor = vec4(0, 1, 0, 1);\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" fragColor = vec4(1, 0, 0, 1);\n"
|
||||
" }\n"
|
||||
" imageStore(outTexture, pixelCoord, fragColor);\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"//*/\n"
|
||||
" //----\n"
|
||||
"\n"
|
||||
" vec4 sampleColor[sampleCount];\n"
|
||||
" vec4 currentColor[sampleCount];\n"
|
||||
" int currentShapeIndex[sampleCount];\n"
|
||||
" int flipCount[sampleCount];\n"
|
||||
"\n"
|
||||
" for(int i=0; i<sampleCount; i++)\n"
|
||||
" {\n"
|
||||
" currentShapeIndex[i] = -1;\n"
|
||||
" flipCount[i] = 0;\n"
|
||||
" sampleColor[i] = vec4(0, 0, 0, 0);\n"
|
||||
" currentColor[i] = vec4(0, 0, 0, 0);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" for(uint tileArrayIndex=0u; tileArrayIndex < tileCounter; tileArrayIndex++)\n"
|
||||
" {\n"
|
||||
" uint triangleIndex = tileArrayBuffer.elements[tileArraySize * tileIndex + tileArrayIndex];\n"
|
||||
"\n"
|
||||
" uint i0 = indexBuffer.elements[triangleIndex];\n"
|
||||
" uint i1 = indexBuffer.elements[triangleIndex+1u];\n"
|
||||
" uint i2 = indexBuffer.elements[triangleIndex+2u];\n"
|
||||
"\n"
|
||||
" ivec2 p0 = ivec2((vertexBuffer.elements[i0].pos * scaling) * subPixelFactor);\n"
|
||||
" ivec2 p1 = ivec2((vertexBuffer.elements[i1].pos * scaling) * subPixelFactor);\n"
|
||||
" ivec2 p2 = ivec2((vertexBuffer.elements[i2].pos * scaling) * subPixelFactor);\n"
|
||||
"\n"
|
||||
" int shapeIndex = vertexBuffer.elements[i0].shapeIndex;\n"
|
||||
" vec4 color = shapeBuffer.elements[shapeIndex].color;\n"
|
||||
" color.rgb *= color.a;\n"
|
||||
"\n"
|
||||
" ivec4 clip = ivec4(round((shapeBuffer.elements[shapeIndex].clip * vec4(scaling, scaling) + vec4(0.5, 0.5, 0.5, 0.5)) * subPixelFactor));\n"
|
||||
"\n"
|
||||
" mat3 uvTransform = mat3(shapeBuffer.elements[shapeIndex].uvTransform[0],\n"
|
||||
" shapeBuffer.elements[shapeIndex].uvTransform[3],\n"
|
||||
" 0.,\n"
|
||||
" shapeBuffer.elements[shapeIndex].uvTransform[1],\n"
|
||||
" shapeBuffer.elements[shapeIndex].uvTransform[4],\n"
|
||||
" 0.,\n"
|
||||
" shapeBuffer.elements[shapeIndex].uvTransform[2],\n"
|
||||
" shapeBuffer.elements[shapeIndex].uvTransform[5],\n"
|
||||
" 1.);\n"
|
||||
"\n"
|
||||
" //NOTE(martin): reorder triangle counter-clockwise and compute bias for each edge\n"
|
||||
" int cw = is_clockwise(p0, p1, p2);\n"
|
||||
" if(cw < 0)\n"
|
||||
" {\n"
|
||||
" uint tmpIndex = i1;\n"
|
||||
" i1 = i2;\n"
|
||||
" i2 = tmpIndex;\n"
|
||||
"\n"
|
||||
" ivec2 tmpPoint = p1;\n"
|
||||
" p1 = p2;\n"
|
||||
" p2 = tmpPoint;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" vec4 cubic0 = vertexBuffer.elements[i0].cubic;\n"
|
||||
" vec4 cubic1 = vertexBuffer.elements[i1].cubic;\n"
|
||||
" vec4 cubic2 = vertexBuffer.elements[i2].cubic;\n"
|
||||
"\n"
|
||||
" int bias0 = is_top_left(p1, p2) ? 0 : -1;\n"
|
||||
" int bias1 = is_top_left(p2, p0) ? 0 : -1;\n"
|
||||
" int bias2 = is_top_left(p0, p1) ? 0 : -1;\n"
|
||||
"\n"
|
||||
" for(int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)\n"
|
||||
" {\n"
|
||||
" ivec2 samplePoint = samplePoints[sampleIndex];\n"
|
||||
"\n"
|
||||
" if( samplePoint.x < clip.x\n"
|
||||
" || samplePoint.x > clip.z\n"
|
||||
" || samplePoint.y < clip.y\n"
|
||||
" || samplePoint.y > clip.w)\n"
|
||||
" {\n"
|
||||
" continue;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" int w0 = orient2d(p1, p2, samplePoint);\n"
|
||||
" int w1 = orient2d(p2, p0, samplePoint);\n"
|
||||
" int w2 = orient2d(p0, p1, samplePoint);\n"
|
||||
"\n"
|
||||
" if((w0+bias0) >= 0 && (w1+bias1) >= 0 && (w2+bias2) >= 0)\n"
|
||||
" {\n"
|
||||
" vec4 cubic = (cubic0*float(w0) + cubic1*float(w1) + cubic2*float(w2))/(float(w0)+float(w1)+float(w2));\n"
|
||||
"\n"
|
||||
" float eps = 0.0001;\n"
|
||||
" if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps)\n"
|
||||
" {\n"
|
||||
" if(shapeIndex == currentShapeIndex[sampleIndex])\n"
|
||||
" {\n"
|
||||
" flipCount[sampleIndex]++;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if((flipCount[sampleIndex] & 0x01) != 0)\n"
|
||||
" {\n"
|
||||
" sampleColor[sampleIndex] = currentColor[sampleIndex];\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" vec4 nextColor = color;\n"
|
||||
" if(useTexture)\n"
|
||||
" {\n"
|
||||
" vec3 sampleFP = vec3(vec2(samplePoint).xy/(subPixelFactor*2.), 1);\n"
|
||||
" vec2 uv = (uvTransform * sampleFP).xy;\n"
|
||||
" vec4 texColor = texture(srcTexture, uv);\n"
|
||||
" texColor.rgb *= texColor.a;\n"
|
||||
" nextColor *= texColor;\n"
|
||||
" }\n"
|
||||
" currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-nextColor.a) + nextColor;\n"
|
||||
" currentShapeIndex[sampleIndex] = shapeIndex;\n"
|
||||
" flipCount[sampleIndex] = 1;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" vec4 pixelColor = vec4(0);\n"
|
||||
" for(int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++)\n"
|
||||
" {\n"
|
||||
" if((flipCount[sampleIndex] & 0x01) != 0)\n"
|
||||
" {\n"
|
||||
" sampleColor[sampleIndex] = currentColor[sampleIndex];\n"
|
||||
" }\n"
|
||||
" pixelColor += sampleColor[sampleIndex];\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" imageStore(outTexture, pixelCoord, pixelColor/float(sampleCount));\n"
|
||||
"}\n";
|
||||
|
||||
#endif // __GLSL_SHADERS_H__
|
|
@ -59,7 +59,7 @@ mg_image_data* mg_image_data_from_handle(mg_image handle)
|
|||
#if PLATFORM_MACOS
|
||||
mg_surface_data* mtl_canvas_surface_create_for_window(mp_window window);
|
||||
#elif PLATFORM_WINDOWS
|
||||
//TODO
|
||||
mg_surface_data* gl_canvas_surface_create_for_window(mp_window window);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -88,27 +88,23 @@ typedef struct mg_vertex_layout
|
|||
char* cubicBuffer;
|
||||
u32 cubicStride;
|
||||
|
||||
char* uvTransformBuffer;
|
||||
u32 uvTransformStride;
|
||||
char* shapeIndexBuffer;
|
||||
u32 shapeIndexStride;
|
||||
|
||||
char* colorBuffer;
|
||||
u32 colorStride;
|
||||
|
||||
char* texturedBuffer;
|
||||
u32 texturedStride;
|
||||
|
||||
char* shapeIndexBuffer;
|
||||
u32 shapeIndexStride;
|
||||
|
||||
char* clipBuffer;
|
||||
u32 clipStride;
|
||||
|
||||
char* uvTransformBuffer;
|
||||
u32 uvTransformStride;
|
||||
|
||||
char* indexBuffer;
|
||||
u32 indexStride;
|
||||
|
||||
} mg_vertex_layout;
|
||||
|
||||
|
||||
typedef void (*mg_canvas_backend_destroy_proc)(mg_canvas_backend* backend);
|
||||
typedef void (*mg_canvas_backend_begin_proc)(mg_canvas_backend* backend, mg_color clearColor);
|
||||
typedef void (*mg_canvas_backend_end_proc)(mg_canvas_backend* backend);
|
||||
|
@ -135,7 +131,7 @@ typedef void (*mg_canvas_backend_render_proc)(mg_canvas_backend* backend,
|
|||
|
||||
typedef struct mg_canvas_backend
|
||||
{
|
||||
mg_vertex_layout vertexLayout;
|
||||
// mg_vertex_layout vertexLayout;
|
||||
|
||||
mg_canvas_backend_destroy_proc destroy;
|
||||
mg_canvas_backend_begin_proc begin;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include"platform.h"
|
||||
|
||||
#if !PLATFORM_ORCA
|
||||
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
|
||||
#include<math.h>
|
||||
#else
|
||||
|
||||
|
|
8
src/ui.c
8
src/ui.c
|
@ -449,6 +449,8 @@ ui_box* ui_box_make_str8(str8 string, ui_flags flags)
|
|||
|
||||
|
||||
//NOTE: set scroll
|
||||
if(ui_box_hovering(box, ui_mouse_position()))
|
||||
{
|
||||
vec2 wheel = ui_mouse_wheel();
|
||||
if(box->flags & UI_FLAG_SCROLL_WHEEL_X)
|
||||
{
|
||||
|
@ -458,7 +460,7 @@ ui_box* ui_box_make_str8(str8 string, ui_flags flags)
|
|||
{
|
||||
box->scroll.y += wheel.y;
|
||||
}
|
||||
|
||||
}
|
||||
return(box);
|
||||
}
|
||||
|
||||
|
@ -1813,7 +1815,9 @@ void ui_panel_begin(const char* str, ui_flags flags)
|
|||
| UI_FLAG_CLIP
|
||||
| UI_FLAG_BLOCK_MOUSE
|
||||
| UI_FLAG_ALLOW_OVERFLOW_X
|
||||
| UI_FLAG_ALLOW_OVERFLOW_Y;
|
||||
| UI_FLAG_ALLOW_OVERFLOW_Y
|
||||
| UI_FLAG_SCROLL_WHEEL_X
|
||||
| UI_FLAG_SCROLL_WHEEL_Y;
|
||||
|
||||
ui_box_begin(str, flags);
|
||||
}
|
||||
|
|
291
src/win32_app.c
291
src/win32_app.c
|
@ -155,7 +155,7 @@ void mp_init()
|
|||
__mpApp.win32.savedConsoleCodePage = GetConsoleOutputCP();
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,6 @@ static void process_mouse_event(mp_window_data* window, mp_key_action action, mp
|
|||
}
|
||||
}
|
||||
|
||||
mp_update_key_state(&__mpApp.inputState.mouse.buttons[button], action);
|
||||
//TODO click/double click
|
||||
|
||||
mp_event event = {0};
|
||||
|
@ -235,7 +234,7 @@ static void process_wheel_event(mp_window_data* window, f32 x, f32 y)
|
|||
event.window = mp_window_handle_from_ptr(window);
|
||||
event.type = MP_EVENT_MOUSE_WHEEL;
|
||||
event.move.deltaX = x/30.0f;
|
||||
event.move.deltaY = y/30.0f;
|
||||
event.move.deltaY = -y/30.0f;
|
||||
event.move.mods = mp_get_mod_keys();
|
||||
|
||||
mp_queue_event(&event);
|
||||
|
@ -385,15 +384,12 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
event.move.x = LOWORD(lParam) / scaling;
|
||||
event.move.y = HIWORD(lParam) / scaling;
|
||||
|
||||
if(__mpApp.inputState.mouse.posValid)
|
||||
if(__mpApp.win32.mouseTracked || __mpApp.win32.mouseCaptureMask)
|
||||
{
|
||||
event.move.deltaX = event.move.x - __mpApp.inputState.mouse.pos.x;
|
||||
event.move.deltaY = event.move.y - __mpApp.inputState.mouse.pos.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
__mpApp.inputState.mouse.posValid = true;
|
||||
event.move.deltaX = event.move.x - __mpApp.win32.lastMousePos.x;
|
||||
event.move.deltaY = event.move.y - __mpApp.win32.lastMousePos.y;
|
||||
}
|
||||
__mpApp.win32.lastMousePos = (vec2){event.move.x, event.move.y};
|
||||
|
||||
if(!__mpApp.win32.mouseTracked)
|
||||
{
|
||||
|
@ -413,8 +409,6 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
mp_queue_event(&enter);
|
||||
}
|
||||
|
||||
mp_update_mouse_move(event.move.x, event.move.y, event.move.deltaX, event.move.deltaY);
|
||||
|
||||
mp_queue_event(&event);
|
||||
} break;
|
||||
|
||||
|
@ -422,11 +416,6 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
__mpApp.win32.mouseTracked = false;
|
||||
|
||||
if(!__mpApp.win32.mouseCaptureMask)
|
||||
{
|
||||
__mpApp.inputState.mouse.posValid = false;
|
||||
}
|
||||
|
||||
mp_event event = {0};
|
||||
event.window = mp_window_handle_from_ptr(mpWindow);
|
||||
event.type = MP_EVENT_MOUSE_LEAVE;
|
||||
|
@ -453,9 +442,6 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
event.key.code = mp_convert_win32_key(HIWORD(lParam) & 0x1ff);
|
||||
event.key.mods = mp_get_mod_keys();
|
||||
mp_queue_event(&event);
|
||||
|
||||
mp_update_key_mods(event.key.mods);
|
||||
mp_update_key_state(&__mpApp.inputState.keyboard.keys[event.key.code], event.key.action);
|
||||
} break;
|
||||
|
||||
case WM_KEYUP:
|
||||
|
@ -468,10 +454,6 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
event.key.code = mp_convert_win32_key(HIWORD(lParam) & 0x1ff);
|
||||
event.key.mods = mp_get_mod_keys();
|
||||
mp_queue_event(&event);
|
||||
|
||||
mp_update_key_mods(event.key.mods);
|
||||
mp_update_key_state(&__mpApp.inputState.keyboard.keys[event.key.code], event.key.action);
|
||||
|
||||
} break;
|
||||
|
||||
case WM_CHAR:
|
||||
|
@ -485,8 +467,6 @@ LRESULT WinProc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
str8 seq = utf8_encode(event.character.sequence, event.character.codepoint);
|
||||
event.character.seqLen = seq.len;
|
||||
mp_queue_event(&event);
|
||||
|
||||
mp_update_text(event.character.codepoint);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -525,8 +505,6 @@ void mp_request_quit()
|
|||
|
||||
void mp_pump_events(f64 timeout)
|
||||
{
|
||||
__mpApp.inputState.frameCounter++;
|
||||
|
||||
MSG message;
|
||||
while(PeekMessage(&message, 0, 0, 0, PM_REMOVE))
|
||||
{
|
||||
|
@ -1051,7 +1029,7 @@ mg_surface_data* mg_win32_surface_create_host(mp_window window)
|
|||
memset(surface, 0, sizeof(mg_surface_data));
|
||||
mg_surface_init_for_window(surface, windowData);
|
||||
|
||||
surface->backend = MG_BACKEND_HOST;
|
||||
surface->api = MG_HOST;
|
||||
surface->hostConnect = mg_win32_surface_host_connect;
|
||||
}
|
||||
}
|
||||
|
@ -1102,3 +1080,258 @@ str8 mp_app_get_resource_path(mem_arena* arena, const char* name)
|
|||
return(result);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// native open/save/alert windows
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
//TODO: GetOpenFileName() doesn't seem to support selecting folders, and
|
||||
// requires filters which pair a "descriptive" name with an extension
|
||||
|
||||
#define interface struct
|
||||
#include<shobjidl.h>
|
||||
#include<shtypes.h>
|
||||
#undef interface
|
||||
|
||||
|
||||
MP_API str8 mp_open_dialog(mem_arena* arena,
|
||||
const char* title,
|
||||
const char* defaultPath,
|
||||
int filterCount,
|
||||
const char** filters,
|
||||
bool directory)
|
||||
{
|
||||
str8 res = {0};
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IFileOpenDialog* dialog = 0;
|
||||
hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_ALL, &IID_IFileOpenDialog, (void**)&dialog);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
if(directory)
|
||||
{
|
||||
FILEOPENDIALOGOPTIONS opt;
|
||||
dialog->lpVtbl->GetOptions(dialog, &opt);
|
||||
dialog->lpVtbl->SetOptions(dialog, opt | FOS_PICKFOLDERS);
|
||||
}
|
||||
|
||||
if(filterCount && filters)
|
||||
{
|
||||
mem_arena_marker mark = mem_arena_mark(arena);
|
||||
COMDLG_FILTERSPEC* filterSpecs = mem_arena_alloc_array(arena, COMDLG_FILTERSPEC, filterCount);
|
||||
for(int i=0; i<filterCount; i++)
|
||||
{
|
||||
str8_list list = {0};
|
||||
str8_list_push(arena, &list, STR8("*."));
|
||||
str8_list_push(arena, &list, STR8(filters[i]));
|
||||
str8 filter = str8_list_join(arena, list);
|
||||
|
||||
int filterWideSize = 1 + MultiByteToWideChar(CP_UTF8, 0, filter.ptr, filter.len, NULL, 0);
|
||||
filterSpecs[i].pszSpec = mem_arena_alloc_array(arena, wchar_t, filterWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, filter.ptr, filter.len, (LPWSTR)filterSpecs[i].pszSpec, filterWideSize);
|
||||
((LPWSTR)(filterSpecs[i].pszSpec))[filterWideSize-1] = 0;
|
||||
|
||||
filterSpecs[i].pszName = filterSpecs[i].pszSpec;
|
||||
}
|
||||
|
||||
hr = dialog->lpVtbl->SetFileTypes(dialog, filterCount, filterSpecs);
|
||||
|
||||
mem_arena_clear_to(arena, mark);
|
||||
}
|
||||
|
||||
if(defaultPath)
|
||||
{
|
||||
mem_arena_marker mark = mem_arena_mark(arena);
|
||||
int pathWideSize = MultiByteToWideChar(CP_UTF8, 0, defaultPath, -1, NULL, 0);
|
||||
LPWSTR pathWide = mem_arena_alloc_array(arena, wchar_t, pathWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, defaultPath, -1, pathWide, pathWideSize);
|
||||
|
||||
IShellItem* item = 0;
|
||||
hr = SHCreateItemFromParsingName(pathWide, NULL, &IID_IShellItem, (void**)&item);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
hr = dialog->lpVtbl->SetFolder(dialog, item);
|
||||
item->lpVtbl->Release(item);
|
||||
}
|
||||
mem_arena_clear_to(arena, mark);
|
||||
}
|
||||
|
||||
hr = dialog->lpVtbl->Show(dialog, NULL);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IShellItem* item;
|
||||
hr = dialog->lpVtbl->GetResult(dialog, &item);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
PWSTR filePath;
|
||||
hr = item->lpVtbl->GetDisplayName(item, SIGDN_FILESYSPATH, &filePath);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
int utf8Size = WideCharToMultiByte(CP_UTF8, 0, filePath, -1, NULL, 0, NULL, NULL);
|
||||
if(utf8Size > 0)
|
||||
{
|
||||
res.ptr = mem_arena_alloc(arena, utf8Size);
|
||||
res.len = utf8Size-1;
|
||||
WideCharToMultiByte(CP_UTF8, 0, filePath, -1, res.ptr, utf8Size, NULL, NULL);
|
||||
}
|
||||
CoTaskMemFree(filePath);
|
||||
}
|
||||
item->lpVtbl->Release(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CoUninitialize();
|
||||
return(res);
|
||||
}
|
||||
|
||||
MP_API str8 mp_save_dialog(mem_arena* arena,
|
||||
const char* title,
|
||||
const char* defaultPath,
|
||||
int filterCount,
|
||||
const char** filters)
|
||||
{
|
||||
str8 res = {0};
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IFileOpenDialog* dialog = 0;
|
||||
hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_ALL, &IID_IFileSaveDialog, (void**)&dialog);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
if(filterCount && filters)
|
||||
{
|
||||
mem_arena_marker mark = mem_arena_mark(arena);
|
||||
COMDLG_FILTERSPEC* filterSpecs = mem_arena_alloc_array(arena, COMDLG_FILTERSPEC, filterCount);
|
||||
for(int i=0; i<filterCount; i++)
|
||||
{
|
||||
str8_list list = {0};
|
||||
str8_list_push(arena, &list, STR8("*."));
|
||||
str8_list_push(arena, &list, STR8(filters[i]));
|
||||
str8 filter = str8_list_join(arena, list);
|
||||
|
||||
int filterWideSize = 1 + MultiByteToWideChar(CP_UTF8, 0, filter.ptr, filter.len, NULL, 0);
|
||||
filterSpecs[i].pszSpec = mem_arena_alloc_array(arena, wchar_t, filterWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, filter.ptr, filter.len, (LPWSTR)filterSpecs[i].pszSpec, filterWideSize);
|
||||
((LPWSTR)(filterSpecs[i].pszSpec))[filterWideSize-1] = 0;
|
||||
|
||||
filterSpecs[i].pszName = filterSpecs[i].pszSpec;
|
||||
}
|
||||
|
||||
hr = dialog->lpVtbl->SetFileTypes(dialog, filterCount, filterSpecs);
|
||||
|
||||
mem_arena_clear_to(arena, mark);
|
||||
}
|
||||
|
||||
if(defaultPath)
|
||||
{
|
||||
mem_arena_marker mark = mem_arena_mark(arena);
|
||||
int pathWideSize = MultiByteToWideChar(CP_UTF8, 0, defaultPath, -1, NULL, 0);
|
||||
LPWSTR pathWide = mem_arena_alloc_array(arena, wchar_t, pathWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, defaultPath, -1, pathWide, pathWideSize);
|
||||
|
||||
IShellItem* item = 0;
|
||||
hr = SHCreateItemFromParsingName(pathWide, NULL, &IID_IShellItem, (void**)&item);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
hr = dialog->lpVtbl->SetFolder(dialog, item);
|
||||
item->lpVtbl->Release(item);
|
||||
}
|
||||
mem_arena_clear_to(arena, mark);
|
||||
}
|
||||
|
||||
hr = dialog->lpVtbl->Show(dialog, NULL);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IShellItem* item;
|
||||
hr = dialog->lpVtbl->GetResult(dialog, &item);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
PWSTR filePath;
|
||||
hr = item->lpVtbl->GetDisplayName(item, SIGDN_FILESYSPATH, &filePath);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
int utf8Size = WideCharToMultiByte(CP_UTF8, 0, filePath, -1, NULL, 0, NULL, NULL);
|
||||
if(utf8Size > 0)
|
||||
{
|
||||
res.ptr = mem_arena_alloc(arena, utf8Size);
|
||||
res.len = utf8Size-1;
|
||||
WideCharToMultiByte(CP_UTF8, 0, filePath, -1, res.ptr, utf8Size, NULL, NULL);
|
||||
}
|
||||
CoTaskMemFree(filePath);
|
||||
}
|
||||
item->lpVtbl->Release(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CoUninitialize();
|
||||
return(res);
|
||||
}
|
||||
|
||||
#include<commctrl.h>
|
||||
|
||||
MP_API int mp_alert_popup(const char* title,
|
||||
const char* message,
|
||||
u32 count,
|
||||
const char** options)
|
||||
{
|
||||
mem_arena* scratch = mem_scratch();
|
||||
mem_arena_marker marker = mem_arena_mark(scratch);
|
||||
TASKDIALOG_BUTTON* buttons = mem_arena_alloc_array(scratch, TASKDIALOG_BUTTON, count);
|
||||
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
int textWideSize = MultiByteToWideChar(CP_UTF8, 0, options[i], -1, NULL, 0);
|
||||
wchar_t* textWide = mem_arena_alloc_array(scratch, wchar_t, textWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, options[i], -1, textWide, textWideSize);
|
||||
|
||||
buttons[i].nButtonID = i+1;
|
||||
buttons[i].pszButtonText = textWide;
|
||||
}
|
||||
|
||||
int titleWideSize = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
|
||||
wchar_t* titleWide = mem_arena_alloc_array(scratch, wchar_t, titleWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, title, -1, titleWide, titleWideSize);
|
||||
|
||||
int messageWideSize = MultiByteToWideChar(CP_UTF8, 0, message, -1, NULL, 0);
|
||||
wchar_t* messageWide = mem_arena_alloc_array(scratch, wchar_t, messageWideSize);
|
||||
MultiByteToWideChar(CP_UTF8, 0, message, -1, messageWide, messageWideSize);
|
||||
|
||||
TASKDIALOGCONFIG config =
|
||||
{
|
||||
.cbSize = sizeof(TASKDIALOGCONFIG),
|
||||
.hwndParent = NULL,
|
||||
.hInstance = NULL,
|
||||
.dwFlags = 0,
|
||||
.dwCommonButtons = 0,
|
||||
.pszWindowTitle = titleWide,
|
||||
.hMainIcon = 0,
|
||||
.pszMainIcon = TD_WARNING_ICON,
|
||||
.pszMainInstruction = messageWide,
|
||||
.pszContent = NULL,
|
||||
.cButtons = count,
|
||||
.pButtons = buttons,
|
||||
.nDefaultButton = 0,
|
||||
};
|
||||
|
||||
int button = -1;
|
||||
HRESULT hRes = TaskDialogIndirect(&config, &button, NULL, NULL);
|
||||
if(hRes == S_OK)
|
||||
{
|
||||
if(button == IDCANCEL)
|
||||
{
|
||||
button = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
button--;
|
||||
}
|
||||
}
|
||||
|
||||
mem_arena_clear_to(scratch, marker);
|
||||
return(button);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct win32_app_data
|
|||
|
||||
int mouseCaptureMask;
|
||||
bool mouseTracked;
|
||||
vec2 lastMousePos;
|
||||
|
||||
} win32_app_data;
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity
|
||||
version="0.0.0.1"
|
||||
processorArchitecture="*"
|
||||
name="forkingpaths.orca.runtime"
|
||||
type="win32"
|
||||
/>
|
||||
<description>Orca Runtime</description>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity
|
||||
type="win32"
|
||||
name="Microsoft.Windows.Common-Controls"
|
||||
version="6.0.0.0"
|
||||
processorArchitecture="*"
|
||||
publicKeyToken="6595b64144ccf1df"
|
||||
language="*"
|
||||
/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
Loading…
Reference in New Issue