[win32, wip] compile and run simple window example

This commit is contained in:
martinfouilleul 2023-05-12 16:46:13 +02:00
parent 62b8b3323e
commit 52538248d9
8 changed files with 2218 additions and 2674 deletions

View File

@ -1,2 +1,2 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext 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

View File

@ -1,113 +1,111 @@
/************************************************************//** /************************************************************//**
* *
* @file: main.cpp * @file: main.cpp
* @author: Martin Fouilleul * @author: Martin Fouilleul
* @date: 30/07/2022 * @date: 30/07/2022
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include<stdlib.h> #include<stdlib.h>
#include<string.h> #include<stdio.h>
#include<string.h>
#include"milepost.h"
#include"milepost.h"
#define LOG_SUBSYSTEM "Main"
int main()
int main() {
{ mp_init();
LogLevel(LOG_LEVEL_DEBUG);
mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600};
mp_init(); mp_window window = mp_window_create(rect, "test", 0);
mp_rect rect = {.x = 100, .y = 100, .w = 800, .h = 600}; mp_window_bring_to_front(window);
mp_window window = mp_window_create(rect, "test", 0); mp_window_focus(window);
mp_window_bring_to_front(window); while(!mp_should_quit())
mp_window_focus(window); {
mp_pump_events(0);
while(!mp_should_quit()) mp_event *event = 0;
{ while((event = mp_next_event(mem_scratch())) != 0)
mp_pump_events(0); {
mp_event event = {0}; switch(event->type)
while(mp_next_event(&event)) {
{ case MP_EVENT_WINDOW_CLOSE:
switch(event.type) {
{ mp_request_quit();
case MP_EVENT_WINDOW_CLOSE: } break;
{
mp_request_quit(); case MP_EVENT_WINDOW_RESIZE:
} break; {
printf("resized, rect = {%f, %f, %f, %f}\n",
case MP_EVENT_WINDOW_RESIZE: event->frame.rect.x,
{ event->frame.rect.y,
printf("resized, rect = {%f, %f, %f, %f}\n", event->frame.rect.w,
event.frame.rect.x, event->frame.rect.h);
event.frame.rect.y, } break;
event.frame.rect.w,
event.frame.rect.h); case MP_EVENT_WINDOW_MOVE:
} break; {
printf("moved, rect = {%f, %f, %f, %f}\n",
case MP_EVENT_WINDOW_MOVE: event->frame.rect.x,
{ event->frame.rect.y,
printf("moved, rect = {%f, %f, %f, %f}\n", event->frame.rect.w,
event.frame.rect.x, event->frame.rect.h);
event.frame.rect.y, } break;
event.frame.rect.w,
event.frame.rect.h); case MP_EVENT_MOUSE_MOVE:
} break; {
printf("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n",
case MP_EVENT_MOUSE_MOVE: event->move.x,
{ event->move.y,
printf("mouse moved, pos = {%f, %f}, delta = {%f, %f}\n", event->move.deltaX,
event.move.x, event->move.deltaY);
event.move.y, } break;
event.move.deltaX,
event.move.deltaY); case MP_EVENT_MOUSE_WHEEL:
} break; {
printf("mouse wheel, delta = {%f, %f}\n",
case MP_EVENT_MOUSE_WHEEL: event->move.deltaX,
{ event->move.deltaY);
printf("mouse wheel, delta = {%f, %f}\n", } break;
event.move.deltaX,
event.move.deltaY); case MP_EVENT_MOUSE_ENTER:
} break; {
printf("mouse enter\n");
case MP_EVENT_MOUSE_ENTER: } break;
{
printf("mouse enter\n"); case MP_EVENT_MOUSE_LEAVE:
} break; {
printf("mouse leave\n");
case MP_EVENT_MOUSE_LEAVE: } break;
{
printf("mouse leave\n"); case MP_EVENT_MOUSE_BUTTON:
} break; {
printf("mouse button %i: %i\n",
case MP_EVENT_MOUSE_BUTTON: event->key.code,
{ event->key.action == MP_KEY_PRESS ? 1 : 0);
printf("mouse button %i: %i\n", } break;
event.key.code,
event.key.action == MP_KEY_PRESS ? 1 : 0); case MP_EVENT_KEYBOARD_KEY:
} break; {
printf("key %i: %s\n",
case MP_EVENT_KEYBOARD_KEY: event->key.code,
{ event->key.action == MP_KEY_PRESS ? "press" : (event->key.action == MP_KEY_RELEASE ? "release" : "repeat"));
printf("key %i: %s\n", } break;
event.key.code,
event.key.action == MP_KEY_PRESS ? "press" : (event.key.action == MP_KEY_RELEASE ? "release" : "repeat")); case MP_EVENT_KEYBOARD_CHAR:
} break; {
printf("entered char %s\n", event->character.sequence);
case MP_EVENT_KEYBOARD_CHAR: } break;
{
printf("entered char %s\n", event.character.sequence); default:
} break; break;
}
default: }
break; mem_arena_clear(mem_scratch());
} }
}
} mp_terminate();
mp_terminate(); return(0);
}
return(0);
}

View File

@ -1,77 +1,84 @@
## Angle install on macOS ## Angle install on macOS
* Get ninja if needed: `brew install ninja` * Get ninja if needed: `brew install ninja`
* Get the `depot_tools`repo: `git clone https://chromium.googlesource.com/* chromium/tools/depot_tools.git` * Get the `depot_tools`repo: `git clone https://chromium.googlesource.com/* chromium/tools/depot_tools.git`
* Set path: `export PATH=/path/to/depot_tools:$PATH` * Set path: `export PATH=/path/to/depot_tools:$PATH`
* Maybe necessary to fiddle with certificates here, otherwise `fetch angle` fails in the subsequent steps. * Maybe necessary to fiddle with certificates here, otherwise `fetch angle` fails in the subsequent steps.
``` ```
cd /Applications/Python\ 3.6 cd /Applications/Python\ 3.6
sudo ./Install\ Certificates.command sudo ./Install\ Certificates.command
``` ```
* Fetch angle: * Fetch angle:
``` ```
mkdir angle mkdir angle
cd angle cd angle
fetch angle fetch angle
``` ```
* Generate build config: `gn gen out/Debug` * Generate build config: `gn gen out/Debug`
* To see available arguments: `gn args out/Debug --list` * To see available arguments: `gn args out/Debug --list`
* To change arguments: `gn args out/Debug` * To change arguments: `gn args out/Debug`
For example, to generate dwarf dsyms files, set: For example, to generate dwarf dsyms files, set:
``` ```
enable_dsyms=true enable_dsyms=true
use_debug_fission=true use_debug_fission=true
symbol_level=2 symbol_level=2
``` ```
We also need to set `is_component_build=false` in order to have self-contained librarries. We also need to set `is_component_build=false` in order to have self-contained librarries.
Then, build with `autoninja -C out/Debug`and wait until you pass out. Then, build with `autoninja -C out/Debug`and wait until you pass out.
## Angle install on windows ## Angle install on windows
* need Python3 (can install through win app store) * need Python3 (can install through win app store)
* need Windows SDK * need Windows SDK
* clone `depot_tools`: `git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git` * clone `depot_tools`: `git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git`
or download and unzip bundle at [https://storage.googleapis.com/chrome-infra/depot_tools.zip](https://storage.googleapis.com/chrome-infra/depot_tools.zip) or download and unzip bundle at [https://storage.googleapis.com/chrome-infra/depot_tools.zip](https://storage.googleapis.com/chrome-infra/depot_tools.zip)
* set `depot_tools` in path env variable through control panel>System and security>system>advanced system settings * set `depot_tools` in path env variable through control panel>System and security>system>advanced system settings
* run `gclient` in a cmd shell * run `gclient` in a cmd shell
* set `DEPOT_TOOLS_WIN_TOOLCHAIN=0` * set `DEPOT_TOOLS_WIN_TOOLCHAIN=0`
* `mkdir angle` * `mkdir angle`
* `cd angle` * `cd angle`
* `fetch angle` * `fetch angle`
* wait a million years * wait a million years
* if it fails when running `python3 third_party/depot_tools/download_from_google_storage.py ...` * 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 * run `gclient sync` to complete previous step
* `gn gen out/Debug` * `gn gen out/Debug`
* `gn args out/Debug` and edit arguments: * `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
* link with `libEGL.dll.lib` and `libGLESv2.dll.lib` angle_enable_d3d9 = false
* put `libEGL.dll` and `libGLESv2.dll` in same directory as executable angle_enable_gl = false
angle_enable_vulkan = false
## To get debugging kinda working with renderdoc: ```
Run `gn args out/Debug` and set
* `angle_enable_trace = true` * `ninja -C out/Debug`
* `angle_enable_annotator_run_time_checks = true` * link with `libEGL.dll.lib` and `libGLESv2.dll.lib`
* put `libEGL.dll` and `libGLESv2.dll` in same directory as executable
* `autoninja -C out/Debug`
* wait a while ## To get debugging kinda working with renderdoc:
In renderdoc, set env variables Run `gn args out/Debug` and set
`RENDERDOC_HOOK_EGL 0` (if you want to trace underlying native API) * `angle_enable_trace = true`
`RENDERDOC_HOOK_EGL 1` (if you want to trace EGL calls. You also need to put `libEGL` in the renderdoc folder so it's found when capturing stuff. Unfortunately though, that seems to provoke crashes...) * `angle_enable_annotator_run_time_checks = true`
`ANGLE_ENABLE_DEBUG_MARKERS 1` (to turn on debug markers) * `autoninja -C out/Debug`
* wait a while
In renderdoc, set env variables
`RENDERDOC_HOOK_EGL 0` (if you want to trace underlying native API)
`RENDERDOC_HOOK_EGL 1` (if you want to trace EGL calls. You also need to put `libEGL` in the renderdoc folder so it's found when capturing stuff. Unfortunately though, that seems to provoke crashes...)
`ANGLE_ENABLE_DEBUG_MARKERS 1` (to turn on debug markers)

File diff suppressed because it is too large Load Diff

View File

@ -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__

View File

@ -1,407 +1,407 @@
/************************************************************//** /************************************************************//**
* *
* @file: graphics_surface.c * @file: graphics_surface.c
* @author: Martin Fouilleul * @author: Martin Fouilleul
* @date: 25/04/2023 * @date: 25/04/2023
* *
*****************************************************************/ *****************************************************************/
#include"graphics_surface.h" #include"graphics_surface.h"
//--------------------------------------------------------------- //---------------------------------------------------------------
// typed handles functions // typed handles functions
//--------------------------------------------------------------- //---------------------------------------------------------------
mg_surface mg_surface_handle_alloc(mg_surface_data* surface) mg_surface mg_surface_handle_alloc(mg_surface_data* surface)
{ {
mg_surface handle = {.h = mg_handle_alloc(MG_HANDLE_SURFACE, (void*)surface) }; mg_surface handle = {.h = mg_handle_alloc(MG_HANDLE_SURFACE, (void*)surface) };
return(handle); return(handle);
} }
mg_surface_data* mg_surface_data_from_handle(mg_surface handle) mg_surface_data* mg_surface_data_from_handle(mg_surface handle)
{ {
mg_surface_data* data = mg_data_from_handle(MG_HANDLE_SURFACE, handle.h); mg_surface_data* data = mg_data_from_handle(MG_HANDLE_SURFACE, handle.h);
return(data); return(data);
} }
mg_image mg_image_handle_alloc(mg_image_data* image) mg_image mg_image_handle_alloc(mg_image_data* image)
{ {
mg_image handle = {.h = mg_handle_alloc(MG_HANDLE_IMAGE, (void*)image) }; mg_image handle = {.h = mg_handle_alloc(MG_HANDLE_IMAGE, (void*)image) };
return(handle); return(handle);
} }
mg_image_data* mg_image_data_from_handle(mg_image handle) mg_image_data* mg_image_data_from_handle(mg_image handle)
{ {
mg_image_data* data = mg_data_from_handle(MG_HANDLE_IMAGE, handle.h); mg_image_data* data = mg_data_from_handle(MG_HANDLE_IMAGE, handle.h);
return(data); return(data);
} }
//--------------------------------------------------------------- //---------------------------------------------------------------
// surface API // surface API
//--------------------------------------------------------------- //---------------------------------------------------------------
#if MG_COMPILE_GL #if MG_COMPILE_GL
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
#include"wgl_surface.h" #include"wgl_surface.h"
#define gl_surface_create_for_window mg_wgl_surface_create_for_window #define gl_surface_create_for_window mg_wgl_surface_create_for_window
#endif #endif
#endif #endif
#if MG_COMPILE_GLES #if MG_COMPILE_GLES
#include"egl_surface.h" #include"egl_surface.h"
#endif #endif
#if MG_COMPILE_METAL #if MG_COMPILE_METAL
#include"mtl_surface.h" #include"mtl_surface.h"
#endif #endif
#if MG_COMPILE_CANVAS #if MG_COMPILE_CANVAS
#if PLATFORM_MACOS #if PLATFORM_MACOS
mg_surface_data* mtl_canvas_surface_create_for_window(mp_window window); mg_surface_data* mtl_canvas_surface_create_for_window(mp_window window);
#elif PLATFORM_WINDOWS #elif PLATFORM_WINDOWS
//TODO mg_surface_data* gl_canvas_surface_create_for_window(mp_window window);
#endif #endif
#endif #endif
bool mg_is_surface_backend_available(mg_surface_api api) bool mg_is_surface_backend_available(mg_surface_api api)
{ {
bool result = false; bool result = false;
switch(api) switch(api)
{ {
#if MG_COMPILE_METAL #if MG_COMPILE_METAL
case MG_METAL: case MG_METAL:
#endif #endif
#if MG_COMPILE_GL #if MG_COMPILE_GL
case MG_GL: case MG_GL:
#endif #endif
#if MG_COMPILE_GLES #if MG_COMPILE_GLES
case MG_GLES: case MG_GLES:
#endif #endif
#if MG_COMPILE_CANVAS #if MG_COMPILE_CANVAS
case MG_CANVAS: case MG_CANVAS:
#endif #endif
result = true; result = true;
break; break;
default: default:
break; break;
} }
return(result); return(result);
} }
mg_surface mg_surface_nil() { return((mg_surface){.h = 0}); } mg_surface mg_surface_nil() { return((mg_surface){.h = 0}); }
bool mg_surface_is_nil(mg_surface surface) { return(surface.h == 0); } bool mg_surface_is_nil(mg_surface surface) { return(surface.h == 0); }
mg_surface mg_surface_create_for_window(mp_window window, mg_surface_api api) mg_surface mg_surface_create_for_window(mp_window window, mg_surface_api api)
{ {
if(__mgData.init) if(__mgData.init)
{ {
mg_init(); mg_init();
} }
mg_surface surfaceHandle = mg_surface_nil(); mg_surface surfaceHandle = mg_surface_nil();
mg_surface_data* surface = 0; mg_surface_data* surface = 0;
switch(api) switch(api)
{ {
#if MG_COMPILE_GL #if MG_COMPILE_GL
case MG_GL: case MG_GL:
surface = gl_surface_create_for_window(window); surface = gl_surface_create_for_window(window);
break; break;
#endif #endif
#if MG_COMPILE_GLES #if MG_COMPILE_GLES
case MG_GLES: case MG_GLES:
surface = mg_egl_surface_create_for_window(window); surface = mg_egl_surface_create_for_window(window);
break; break;
#endif #endif
#if MG_COMPILE_METAL #if MG_COMPILE_METAL
case MG_METAL: case MG_METAL:
surface = mg_mtl_surface_create_for_window(window); surface = mg_mtl_surface_create_for_window(window);
break; break;
#endif #endif
#if MG_COMPILE_CANVAS #if MG_COMPILE_CANVAS
case MG_CANVAS: case MG_CANVAS:
#if PLATFORM_MACOS #if PLATFORM_MACOS
surface = mtl_canvas_surface_create_for_window(window); surface = mtl_canvas_surface_create_for_window(window);
#elif PLATFORM_WINDOWS #elif PLATFORM_WINDOWS
surface = gl_canvas_surface_create_for_window(window); surface = gl_canvas_surface_create_for_window(window);
#endif #endif
break; break;
#endif #endif
default: default:
break; break;
} }
if(surface) if(surface)
{ {
surfaceHandle = mg_surface_handle_alloc(surface); surfaceHandle = mg_surface_handle_alloc(surface);
} }
return(surfaceHandle); return(surfaceHandle);
} }
mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api) mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api)
{ {
if(__mgData.init) if(__mgData.init)
{ {
mg_init(); mg_init();
} }
mg_surface surfaceHandle = mg_surface_nil(); mg_surface surfaceHandle = mg_surface_nil();
mg_surface_data* surface = 0; mg_surface_data* surface = 0;
switch(api) switch(api)
{ {
#if MG_COMPILE_GLES #if MG_COMPILE_GLES
case MG_GLES: case MG_GLES:
surface = mg_egl_surface_create_remote(width, height); surface = mg_egl_surface_create_remote(width, height);
break; break;
#endif #endif
default: default:
break; break;
} }
if(surface) if(surface)
{ {
surfaceHandle = mg_surface_handle_alloc(surface); surfaceHandle = mg_surface_handle_alloc(surface);
} }
return(surfaceHandle); return(surfaceHandle);
} }
mg_surface mg_surface_create_host(mp_window window) mg_surface mg_surface_create_host(mp_window window)
{ {
if(__mgData.init) if(__mgData.init)
{ {
mg_init(); mg_init();
} }
mg_surface handle = mg_surface_nil(); mg_surface handle = mg_surface_nil();
mg_surface_data* surface = 0; mg_surface_data* surface = 0;
#if PLATFORM_MACOS #if PLATFORM_MACOS
surface = mg_osx_surface_create_host(window); surface = mg_osx_surface_create_host(window);
#elif PLATFORM_WINDOWS #elif PLATFORM_WINDOWS
surface = mg_win32_surface_create_host(window); surface = mg_win32_surface_create_host(window);
#endif #endif
if(surface) if(surface)
{ {
handle = mg_surface_handle_alloc(surface); handle = mg_surface_handle_alloc(surface);
} }
return(handle); return(handle);
} }
void mg_surface_destroy(mg_surface handle) void mg_surface_destroy(mg_surface handle)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surface = mg_surface_data_from_handle(handle); mg_surface_data* surface = mg_surface_data_from_handle(handle);
if(surface) if(surface)
{ {
if(surface->backend && surface->backend->destroy) if(surface->backend && surface->backend->destroy)
{ {
surface->backend->destroy(surface->backend); surface->backend->destroy(surface->backend);
} }
surface->destroy(surface); surface->destroy(surface);
mg_handle_recycle(handle.h); mg_handle_recycle(handle.h);
} }
} }
void mg_surface_prepare(mg_surface surface) void mg_surface_prepare(mg_surface surface)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->prepare) if(surfaceData && surfaceData->prepare)
{ {
surfaceData->prepare(surfaceData); surfaceData->prepare(surfaceData);
} }
} }
void mg_surface_present(mg_surface surface) void mg_surface_present(mg_surface surface)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->present) if(surfaceData && surfaceData->present)
{ {
surfaceData->present(surfaceData); surfaceData->present(surfaceData);
} }
} }
void mg_surface_swap_interval(mg_surface surface, int swap) void mg_surface_swap_interval(mg_surface surface, int swap)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->swapInterval) if(surfaceData && surfaceData->swapInterval)
{ {
surfaceData->swapInterval(surfaceData, swap); surfaceData->swapInterval(surfaceData, swap);
} }
} }
vec2 mg_surface_contents_scaling(mg_surface surface) vec2 mg_surface_contents_scaling(mg_surface surface)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
vec2 scaling = {1, 1}; vec2 scaling = {1, 1};
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->contentsScaling) if(surfaceData && surfaceData->contentsScaling)
{ {
scaling = surfaceData->contentsScaling(surfaceData); scaling = surfaceData->contentsScaling(surfaceData);
} }
return(scaling); return(scaling);
} }
void mg_surface_set_frame(mg_surface surface, mp_rect frame) void mg_surface_set_frame(mg_surface surface, mp_rect frame)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->setFrame) if(surfaceData && surfaceData->setFrame)
{ {
surfaceData->setFrame(surfaceData, frame); surfaceData->setFrame(surfaceData, frame);
} }
} }
mp_rect mg_surface_get_frame(mg_surface surface) mp_rect mg_surface_get_frame(mg_surface surface)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mp_rect res = {0}; mp_rect res = {0};
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->getFrame) if(surfaceData && surfaceData->getFrame)
{ {
res = surfaceData->getFrame(surfaceData); res = surfaceData->getFrame(surfaceData);
} }
return(res); return(res);
} }
void mg_surface_set_hidden(mg_surface surface, bool hidden) void mg_surface_set_hidden(mg_surface surface, bool hidden)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->setHidden) if(surfaceData && surfaceData->setHidden)
{ {
surfaceData->setHidden(surfaceData, hidden); surfaceData->setHidden(surfaceData, hidden);
} }
} }
bool mg_surface_get_hidden(mg_surface surface) bool mg_surface_get_hidden(mg_surface surface)
{ {
DEBUG_ASSERT(__mgData.init); DEBUG_ASSERT(__mgData.init);
bool res = false; bool res = false;
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->getHidden) if(surfaceData && surfaceData->getHidden)
{ {
res = surfaceData->getHidden(surfaceData); res = surfaceData->getHidden(surfaceData);
} }
return(res); return(res);
} }
void* mg_surface_native_layer(mg_surface surface) void* mg_surface_native_layer(mg_surface surface)
{ {
void* res = 0; void* res = 0;
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->nativeLayer) if(surfaceData && surfaceData->nativeLayer)
{ {
res = surfaceData->nativeLayer(surfaceData); res = surfaceData->nativeLayer(surfaceData);
} }
return(res); return(res);
} }
mg_surface_id mg_surface_remote_id(mg_surface handle) mg_surface_id mg_surface_remote_id(mg_surface handle)
{ {
mg_surface_id remoteId = 0; mg_surface_id remoteId = 0;
mg_surface_data* surface = mg_surface_data_from_handle(handle); mg_surface_data* surface = mg_surface_data_from_handle(handle);
if(surface && surface->remoteID) if(surface && surface->remoteID)
{ {
remoteId = surface->remoteID(surface); remoteId = surface->remoteID(surface);
} }
return(remoteId); return(remoteId);
} }
void mg_surface_host_connect(mg_surface handle, mg_surface_id remoteID) void mg_surface_host_connect(mg_surface handle, mg_surface_id remoteID)
{ {
mg_surface_data* surface = mg_surface_data_from_handle(handle); mg_surface_data* surface = mg_surface_data_from_handle(handle);
if(surface && surface->hostConnect) if(surface && surface->hostConnect)
{ {
surface->hostConnect(surface, remoteID); surface->hostConnect(surface, remoteID);
} }
} }
void mg_surface_render_commands(mg_surface surface, void mg_surface_render_commands(mg_surface surface,
mg_color clearColor, mg_color clearColor,
u32 primitiveCount, u32 primitiveCount,
mg_primitive* primitives, mg_primitive* primitives,
u32 eltCount, u32 eltCount,
mg_path_elt* elements) mg_path_elt* elements)
{ {
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->backend) if(surfaceData && surfaceData->backend)
{ {
surfaceData->backend->render(surfaceData->backend, surfaceData->backend->render(surfaceData->backend,
clearColor, clearColor,
primitiveCount, primitiveCount,
primitives, primitives,
eltCount, eltCount,
elements); elements);
} }
} }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
//NOTE(martin): images //NOTE(martin): images
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
vec2 mg_image_size(mg_image image) vec2 mg_image_size(mg_image image)
{ {
vec2 res = {0}; vec2 res = {0};
mg_image_data* imageData = mg_image_data_from_handle(image); mg_image_data* imageData = mg_image_data_from_handle(image);
if(imageData) if(imageData)
{ {
res = imageData->size; res = imageData->size;
} }
return(res); return(res);
} }
mg_image mg_image_create(mg_surface surface, u32 width, u32 height) mg_image mg_image_create(mg_surface surface, u32 width, u32 height)
{ {
mg_image image = mg_image_nil(); mg_image image = mg_image_nil();
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->backend) if(surfaceData && surfaceData->backend)
{ {
DEBUG_ASSERT(surfaceData->api == MG_CANVAS); DEBUG_ASSERT(surfaceData->api == MG_CANVAS);
mg_image_data* imageData = surfaceData->backend->imageCreate(surfaceData->backend, (vec2){width, height}); mg_image_data* imageData = surfaceData->backend->imageCreate(surfaceData->backend, (vec2){width, height});
if(imageData) if(imageData)
{ {
imageData->surface = surface; imageData->surface = surface;
image = mg_image_handle_alloc(imageData); image = mg_image_handle_alloc(imageData);
} }
} }
return(image); return(image);
} }
void mg_image_destroy(mg_image image) void mg_image_destroy(mg_image image)
{ {
mg_image_data* imageData = mg_image_data_from_handle(image); mg_image_data* imageData = mg_image_data_from_handle(image);
if(imageData) if(imageData)
{ {
mg_surface_data* surface = mg_surface_data_from_handle(imageData->surface); mg_surface_data* surface = mg_surface_data_from_handle(imageData->surface);
if(surface && surface->backend) if(surface && surface->backend)
{ {
surface->backend->imageDestroy(surface->backend, imageData); surface->backend->imageDestroy(surface->backend, imageData);
mg_handle_recycle(image.h); mg_handle_recycle(image.h);
} }
} }
} }
void mg_image_upload_region_rgba8(mg_image image, mp_rect region, u8* pixels) void mg_image_upload_region_rgba8(mg_image image, mp_rect region, u8* pixels)
{ {
mg_image_data* imageData = mg_image_data_from_handle(image); mg_image_data* imageData = mg_image_data_from_handle(image);
if(imageData) if(imageData)
{ {
mg_surface_data* surfaceData = mg_surface_data_from_handle(imageData->surface); mg_surface_data* surfaceData = mg_surface_data_from_handle(imageData->surface);
if(surfaceData) if(surfaceData)
{ {
DEBUG_ASSERT(surfaceData->backend); DEBUG_ASSERT(surfaceData->backend);
surfaceData->backend->imageUploadRegion(surfaceData->backend, imageData, region, pixels); surfaceData->backend->imageUploadRegion(surfaceData->backend, imageData, region, pixels);
} }
} }
} }

View File

@ -1,26 +1,27 @@
/************************************************************//** /************************************************************//**
* *
* @file: platform_math.h * @file: platform_math.h
* @author: Martin Fouilleul * @author: Martin Fouilleul
* @date: 26/04/2023 * @date: 26/04/2023
* *
*****************************************************************/ *****************************************************************/
#ifndef __PLATFORM_MATH_H_ #ifndef __PLATFORM_MATH_H_
#define __PLATFORM_MATH_H_ #define __PLATFORM_MATH_H_
#include"platform.h" #include"platform.h"
#if !PLATFORM_ORCA #if !PLATFORM_ORCA
#include<math.h> #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#else #include<math.h>
#else
#define M_PI 3.14159265358979323846
#define M_PI 3.14159265358979323846
double fabs(double x);
double sqrt(double sqrt); double fabs(double x);
double cos(double x); double sqrt(double sqrt);
double sin(double x); double cos(double x);
double sin(double x);
#endif
#endif
#endif //__PLATFORM_MATH_H_
#endif //__PLATFORM_MATH_H_

File diff suppressed because it is too large Load Diff