reintroduced GLES backend to osx
This commit is contained in:
parent
9eaa125129
commit
2232b647ed
6
build.sh
6
build.sh
|
@ -42,7 +42,7 @@ BINDIR="./bin"
|
||||||
SRCDIR="./src"
|
SRCDIR="./src"
|
||||||
EXTDIR="./ext"
|
EXTDIR="./ext"
|
||||||
RESDIR="./resources"
|
RESDIR="./resources"
|
||||||
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$EXTDIR/angle_headers"
|
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$EXTDIR -I$EXTDIR/angle_headers"
|
||||||
|
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
# Build
|
# Build
|
||||||
|
@ -55,8 +55,8 @@ fi
|
||||||
if [ $target = 'lib' ] ; then
|
if [ $target = 'lib' ] ; then
|
||||||
|
|
||||||
# compile metal shader
|
# compile metal shader
|
||||||
xcrun -sdk macosx metal $shaderFlagParam -c -o $BINDIR/metal_shader.air $SRCDIR/metal_shader.metal
|
xcrun -sdk macosx metal $shaderFlagParam -c -o $BINDIR/mtl_shader.air $SRCDIR/mtl_shader.metal
|
||||||
xcrun -sdk macosx metallib -o $RESDIR/metal_shader.metallib $BINDIR/metal_shader.air
|
xcrun -sdk macosx metallib -o $RESDIR/mtl_shader.metallib $BINDIR/mtl_shader.air
|
||||||
|
|
||||||
# compile milepost. We use one compilation unit for all C code, and one compilation
|
# compile milepost. We use one compilation unit for all C code, and one compilation
|
||||||
# unit for all ObjectiveC code
|
# unit for all ObjectiveC code
|
||||||
|
|
|
@ -52,7 +52,7 @@ mg_font create_font()
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
LogLevel(LOG_LEVEL_DEBUG);
|
LogLevel(LOG_LEVEL_WARNING);
|
||||||
|
|
||||||
mp_init();
|
mp_init();
|
||||||
mp_clock_init(); //TODO put that in mp_init()?
|
mp_clock_init(); //TODO put that in mp_init()?
|
||||||
|
|
|
@ -8,4 +8,4 @@ INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app -I$SRCDIR/gr
|
||||||
LIBS="-L$BINDIR -lmilepost -framework Cocoa -framework Carbon -framework Metal -framework QuartzCore"
|
LIBS="-L$BINDIR -lmilepost -framework Cocoa -framework Carbon -framework Metal -framework QuartzCore"
|
||||||
FLAGS="-O2 -mmacos-version-min=10.15.4"
|
FLAGS="-O2 -mmacos-version-min=10.15.4"
|
||||||
|
|
||||||
clang++ -g $FLAGS $LIBS $INCLUDES -o $BINDIR/textbench main.cpp
|
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/perf_text main.c
|
||||||
|
|
|
@ -125,69 +125,6 @@ int main()
|
||||||
mp_request_quit();
|
mp_request_quit();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
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);
|
|
||||||
} 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);
|
|
||||||
} 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);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MP_EVENT_MOUSE_WHEEL:
|
|
||||||
{
|
|
||||||
printf("mouse wheel, delta = {%f, %f}\n",
|
|
||||||
event.move.deltaX,
|
|
||||||
event.move.deltaY);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MP_EVENT_MOUSE_ENTER:
|
|
||||||
{
|
|
||||||
printf("mouse enter\n");
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MP_EVENT_MOUSE_LEAVE:
|
|
||||||
{
|
|
||||||
printf("mouse leave\n");
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MP_EVENT_MOUSE_BUTTON:
|
|
||||||
{
|
|
||||||
printf("mouse button %i: %i\n",
|
|
||||||
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"));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MP_EVENT_KEYBOARD_CHAR:
|
|
||||||
{
|
|
||||||
printf("entered char %s\n", event.character.sequence);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ def emit_doc(f, name, ext):
|
||||||
f.write("*\t@note: auto-generated by glapi.py from gl.xml\n")
|
f.write("*\t@note: auto-generated by glapi.py from gl.xml\n")
|
||||||
f.write("*\t@date: %s\n" % datetime.now().strftime("%d/%m%Y"))
|
f.write("*\t@date: %s\n" % datetime.now().strftime("%d/%m%Y"))
|
||||||
f.write("*\n")
|
f.write("*\n")
|
||||||
f.write("/********************************************************/\n")
|
f.write("*********************************************************/\n")
|
||||||
|
|
||||||
|
|
||||||
def emit_begin_guard(f, name):
|
def emit_begin_guard(f, name):
|
||||||
|
@ -143,7 +143,7 @@ f = open(loaderCPath, 'w')
|
||||||
|
|
||||||
emit_doc(f, loaderName, '.c')
|
emit_doc(f, loaderName, '.c')
|
||||||
|
|
||||||
f.write('#include"' + apiName + '.h"\n')
|
f.write('#include"' + loaderName + '.h"\n')
|
||||||
f.write('#include"platform.h"\n\n')
|
f.write('#include"platform.h"\n\n')
|
||||||
|
|
||||||
f.write("mp_thread_local mg_gl_api* __mgGLAPI = 0;\n\n")
|
f.write("mp_thread_local mg_gl_api* __mgGLAPI = 0;\n\n")
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include<EGL/egl.h>
|
#include<EGL/egl.h>
|
||||||
#include<EGL/eglext.h>
|
#include<EGL/eglext.h>
|
||||||
|
|
||||||
|
#include"mp_app_internal.h"
|
||||||
#include"graphics_internal.h"
|
#include"graphics_internal.h"
|
||||||
#include"gl_loader.h"
|
#include"gl_loader.h"
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ typedef struct mg_egl_surface
|
||||||
|
|
||||||
void* mg_egl_get_native_surface(mp_window_data* window)
|
void* mg_egl_get_native_surface(mp_window_data* window)
|
||||||
{
|
{
|
||||||
return((void*)window->osx.nsView);
|
return((void*)window->osx.nsView.layer);
|
||||||
}
|
}
|
||||||
#elif OS_WIN64
|
#elif OS_WIN64
|
||||||
#include"win32_app.h"
|
#include"win32_app.h"
|
||||||
|
@ -94,10 +95,20 @@ mg_surface mg_egl_surface_create_for_window(mp_window window)
|
||||||
|
|
||||||
surface->nativeSurface = mg_egl_get_native_surface(windowData);
|
surface->nativeSurface = mg_egl_get_native_surface(windowData);
|
||||||
|
|
||||||
|
|
||||||
|
#if OS_MACOS
|
||||||
|
//NOTE: we need to explicitly set EGL_PLATFORM_ANGLE_TYPE_ANGLE to EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE, because
|
||||||
|
// EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE defaults to using CGL, and eglSetSwapInterval is broken for this backend
|
||||||
|
EGLAttrib displayAttribs[] = {
|
||||||
|
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE,
|
||||||
|
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
|
||||||
|
EGL_NONE};
|
||||||
|
#else
|
||||||
EGLAttrib displayAttribs[] = {
|
EGLAttrib displayAttribs[] = {
|
||||||
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE,
|
EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE,
|
||||||
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
|
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
|
||||||
EGL_NONE};
|
EGL_NONE};
|
||||||
|
#endif
|
||||||
|
|
||||||
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
|
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
|
||||||
eglInitialize(surface->eglDisplay, NULL, NULL);
|
eglInitialize(surface->eglDisplay, NULL, NULL);
|
||||||
|
@ -124,7 +135,7 @@ mg_surface mg_egl_surface_create_for_window(mp_window window)
|
||||||
eglBindAPI(EGL_OPENGL_ES_API);
|
eglBindAPI(EGL_OPENGL_ES_API);
|
||||||
EGLint contextAttributes[] = {
|
EGLint contextAttributes[] = {
|
||||||
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
|
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
|
||||||
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
|
EGL_CONTEXT_MINOR_VERSION_KHR, 0,
|
||||||
EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE,
|
EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE,
|
||||||
EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
|
EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
|
||||||
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,
|
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,
|
||||||
|
|
2128
src/gl_api.h
2128
src/gl_api.h
File diff suppressed because it is too large
Load Diff
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* @file: gl_loader.c
|
* @file: gl_loader.c
|
||||||
* @note: auto-generated by glapi.py from gl.xml
|
* @note: auto-generated by glapi.py from gl.xml
|
||||||
* @date: 16/022023
|
* @date: 20/022023
|
||||||
*
|
*
|
||||||
/********************************************************/
|
*********************************************************/
|
||||||
#include"gl_loader.h"
|
#include"gl_loader.h"
|
||||||
#include"platform.h"
|
#include"platform.h"
|
||||||
|
|
||||||
|
@ -1719,3 +1719,4 @@ void mg_gl_load_gles32(mg_gl_api* api, mg_gl_load_proc loadProc)
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_gl_select_api(mg_gl_api* api){ __mgGLAPI = api; }
|
void mg_gl_select_api(mg_gl_api* api){ __mgGLAPI = api; }
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
*
|
*
|
||||||
* @file: gl_loader.h
|
* @file: gl_loader.h
|
||||||
* @note: auto-generated by glapi.py from gl.xml
|
* @note: auto-generated by glapi.py from gl.xml
|
||||||
* @date: 16/022023
|
* @date: 20/022023
|
||||||
*
|
*
|
||||||
/********************************************************/
|
*********************************************************/
|
||||||
#ifndef __GL_LOADER_H__
|
#ifndef __GL_LOADER_H__
|
||||||
#define __GL_LOADER_H__
|
#define __GL_LOADER_H__
|
||||||
|
|
||||||
|
|
|
@ -372,7 +372,7 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MG_COMPILE_BACKEND_METAL
|
#if MG_COMPILE_BACKEND_METAL
|
||||||
case MG_METAL_BACKEND:
|
case MG_BACKEND_METAL:
|
||||||
surface = mg_mtl_surface_create_for_window(window);
|
surface = mg_mtl_surface_create_for_window(window);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2656,11 +2656,11 @@ mp_rect mg_text_bounding_box(mg_font font, f32 fontSize, str8 text)
|
||||||
//NOTE(martin): graphics canvas API
|
//NOTE(martin): graphics canvas API
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef MG_COMPILE_BACKEND_METAL
|
#if MG_COMPILE_BACKEND_METAL
|
||||||
mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface);
|
mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MG_COMPILE_BACKEND_GL
|
#if MG_COMPILE_BACKEND_GL
|
||||||
mg_canvas_backend* mg_gl_canvas_create(mg_surface surface);
|
mg_canvas_backend* mg_gl_canvas_create(mg_surface surface);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2673,13 +2673,13 @@ mg_canvas mg_canvas_create(mg_surface surface)
|
||||||
mg_canvas_backend* backend = 0;
|
mg_canvas_backend* backend = 0;
|
||||||
switch(surfaceData->backend)
|
switch(surfaceData->backend)
|
||||||
{
|
{
|
||||||
#ifdef MG_COMPILE_BACKEND_METAL
|
#if MG_COMPILE_BACKEND_METAL
|
||||||
case MG_BACKEND_METAL:
|
case MG_BACKEND_METAL:
|
||||||
backend = mg_mtl_canvas_create(surface);
|
backend = mg_mtl_canvas_create(surface);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MG_COMPILE_BACKEND_GL
|
#if MG_COMPILE_BACKEND_GL
|
||||||
case MG_BACKEND_GL:
|
case MG_BACKEND_GL:
|
||||||
backend = mg_gl_canvas_create(surface);
|
backend = mg_gl_canvas_create(surface);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include"typedefs.h"
|
#include"typedefs.h"
|
||||||
#include"platform.h"
|
#include"platform.h"
|
||||||
|
#include"mp_app.h"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
//NOTE(martin): backends selection
|
//NOTE(martin): backends selection
|
||||||
|
@ -29,10 +30,12 @@ typedef enum {
|
||||||
#define MG_COMPILE_BACKEND_METAL 1
|
#define MG_COMPILE_BACKEND_METAL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MG_COMPILE_BACKEND_GL
|
#ifndef MG_COMPILE_BACKEND_GLES
|
||||||
#define MG_COMPILE_BACKEND_GL 1
|
#define MG_COMPILE_BACKEND_GLES 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MG_COMPILE_BACKEND_GL 0
|
||||||
|
|
||||||
#if MG_COMPILE_BACKEND_METAL
|
#if MG_COMPILE_BACKEND_METAL
|
||||||
#define MG_BACKEND_DEFAULT MG_BACKEND_METAL
|
#define MG_BACKEND_DEFAULT MG_BACKEND_METAL
|
||||||
#elif MG_COMPILE_BACKEND_GL
|
#elif MG_COMPILE_BACKEND_GL
|
||||||
|
|
|
@ -70,7 +70,6 @@
|
||||||
|
|
||||||
#elif defined(OS_MACOS)
|
#elif defined(OS_MACOS)
|
||||||
//NOTE: macos application layer and graphics backends are defined in milepost.m
|
//NOTE: macos application layer and graphics backends are defined in milepost.m
|
||||||
#include"graphics.c"
|
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform"
|
#error "Unsupported platform"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,11 +38,9 @@
|
||||||
#include"mp_app.h"
|
#include"mp_app.h"
|
||||||
#include"graphics.h"
|
#include"graphics.h"
|
||||||
|
|
||||||
#if defined(OS_WIN64)
|
|
||||||
#ifdef MG_INCLUDE_GL_API
|
#ifdef MG_INCLUDE_GL_API
|
||||||
#include"gl_api.h"
|
#include"gl_api.h"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
//#include"ui.h"
|
//#include"ui.h"
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,18 @@
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
|
|
||||||
#include"osx_app.m"
|
#include"osx_app.m"
|
||||||
#include"graphics.h"
|
#include"graphics.c"
|
||||||
|
|
||||||
#if MG_COMPILE_BACKEND_METAL
|
#if MG_COMPILE_BACKEND_METAL
|
||||||
#include"mtl_surface.m"
|
#include"mtl_surface.m"
|
||||||
#include"mtl_canvas.m"
|
#include"mtl_canvas.m"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MG_COMPILE_BACKEND_GLES
|
||||||
|
#include"gl_loader.c"
|
||||||
|
#include"egl_surface.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
|
@ -148,5 +148,6 @@ typedef struct mp_app
|
||||||
MP_PLATFORM_APP_DATA
|
MP_PLATFORM_APP_DATA
|
||||||
} mp_app;
|
} mp_app;
|
||||||
|
|
||||||
|
mp_window_data* mp_window_ptr_from_handle(mp_window handle);
|
||||||
|
|
||||||
#endif // __MP_APP_INTERNAL_H_
|
#endif // __MP_APP_INTERNAL_H_
|
||||||
|
|
|
@ -91,7 +91,7 @@ void mg_mtl_canvas_draw_batch(mg_canvas_backend* interface, u32 vertexCount, u32
|
||||||
|
|
||||||
ASSERT(indexCount * sizeof(i32) < [backend->indexBuffer length]);
|
ASSERT(indexCount * sizeof(i32) < [backend->indexBuffer length]);
|
||||||
|
|
||||||
f32 scale = surface->metalLayer.contentsScale;
|
f32 scale = surface->mtlLayer.contentsScale;
|
||||||
vector_uint2 viewportSize = {backend->viewPort.w * scale, backend->viewPort.h * scale};
|
vector_uint2 viewportSize = {backend->viewPort.w * scale, backend->viewPort.h * scale};
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
|
@ -218,7 +218,7 @@ void mg_mtl_canvas_viewport(mg_canvas_backend* interface, mp_rect viewPort)
|
||||||
|
|
||||||
@autoreleasepool
|
@autoreleasepool
|
||||||
{
|
{
|
||||||
f32 scale = surface->metalLayer.contentsScale;
|
f32 scale = surface->mtlLayer.contentsScale;
|
||||||
CGSize drawableSize = (CGSize){.width = viewPort.w * scale, .height = viewPort.h * scale};
|
CGSize drawableSize = (CGSize){.width = viewPort.w * scale, .height = viewPort.h * scale};
|
||||||
|
|
||||||
[backend->outTexture release];
|
[backend->outTexture release];
|
||||||
|
@ -249,8 +249,8 @@ void mg_mtl_canvas_update_vertex_layout(mg_mtl_canvas_backend* backend)
|
||||||
.cubicStride = sizeof(mg_vertex),
|
.cubicStride = sizeof(mg_vertex),
|
||||||
.posBuffer = vertexBase + offsetof(mg_vertex, pos),
|
.posBuffer = vertexBase + offsetof(mg_vertex, pos),
|
||||||
.posStride = sizeof(mg_vertex),
|
.posStride = sizeof(mg_vertex),
|
||||||
.zIndexBuffer = vertexBase + offsetof(mg_vertex, zIndex),
|
.shapeIndexBuffer = vertexBase + offsetof(mg_vertex, shapeIndex),
|
||||||
.zIndexStride = sizeof(mg_vertex),
|
.shapeIndexStride = sizeof(mg_vertex),
|
||||||
|
|
||||||
.colorBuffer = shapeBase + offsetof(mg_shape, color),
|
.colorBuffer = shapeBase + offsetof(mg_shape, color),
|
||||||
.colorStride = sizeof(mg_shape),
|
.colorStride = sizeof(mg_shape),
|
||||||
|
@ -316,7 +316,7 @@ mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface)
|
||||||
|
|
||||||
@autoreleasepool
|
@autoreleasepool
|
||||||
{
|
{
|
||||||
f32 scale = metalSurface->metalLayer.contentsScale;
|
f32 scale = metalSurface->mtlLayer.contentsScale;
|
||||||
CGSize drawableSize = (CGSize){.width = backend->viewPort.w * scale, .height = backend->viewPort.h * scale};
|
CGSize drawableSize = (CGSize){.width = backend->viewPort.w * scale, .height = backend->viewPort.h * scale};
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
|
@ -446,7 +446,7 @@ mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface)
|
||||||
pipelineStateDescriptor.label = @"My simple pipeline";
|
pipelineStateDescriptor.label = @"My simple pipeline";
|
||||||
pipelineStateDescriptor.vertexFunction = vertexFunction;
|
pipelineStateDescriptor.vertexFunction = vertexFunction;
|
||||||
pipelineStateDescriptor.fragmentFunction = fragmentFunction;
|
pipelineStateDescriptor.fragmentFunction = fragmentFunction;
|
||||||
pipelineStateDescriptor.colorAttachments[0].pixelFormat = metalSurface->metalLayer.pixelFormat;
|
pipelineStateDescriptor.colorAttachments[0].pixelFormat = metalSurface->mtlLayer.pixelFormat;
|
||||||
|
|
||||||
// create render pipeline
|
// create render pipeline
|
||||||
backend->renderPipeline = [metalSurface->device newRenderPipelineStateWithDescriptor: pipelineStateDescriptor error:&err];
|
backend->renderPipeline = [metalSurface->device newRenderPipelineStateWithDescriptor: pipelineStateDescriptor error:&err];
|
||||||
|
|
|
@ -22,7 +22,7 @@ typedef struct mg_vertex
|
||||||
{
|
{
|
||||||
vector_float4 cubic; // canonical implicit curve space coordinates
|
vector_float4 cubic; // canonical implicit curve space coordinates
|
||||||
vector_float2 pos; // position
|
vector_float2 pos; // position
|
||||||
int zIndex;
|
int shapeIndex;
|
||||||
} mg_vertex;
|
} mg_vertex;
|
||||||
|
|
||||||
typedef struct mg_shape
|
typedef struct mg_shape
|
||||||
|
@ -38,7 +38,7 @@ typedef struct mg_triangle_data
|
||||||
uint i0;
|
uint i0;
|
||||||
uint i1;
|
uint i1;
|
||||||
uint i2;
|
uint i2;
|
||||||
uint zIndex;
|
uint shapeIndex;
|
||||||
|
|
||||||
vector_float2 p0;
|
vector_float2 p0;
|
||||||
vector_float2 p1;
|
vector_float2 p1;
|
||||||
|
|
|
@ -57,11 +57,9 @@ kernel void BoundingBoxKernel(constant mg_vertex* vertexBuffer [[buffer(0)]],
|
||||||
float2 boxMax = max(max(p0, p1), p2);
|
float2 boxMax = max(max(p0, p1), p2);
|
||||||
|
|
||||||
//NOTE(martin): clip bounding box against clip rect
|
//NOTE(martin): clip bounding box against clip rect
|
||||||
int shapeIndex = vertexBuffer[i0].zIndex;
|
int shapeIndex = vertexBuffer[i0].shapeIndex;
|
||||||
|
|
||||||
vector_float4 clip = contentsScaling[0]*shapeBuffer[shapeIndex].clip;
|
vector_float4 clip = contentsScaling[0]*shapeBuffer[shapeIndex].clip;
|
||||||
float2 clipMin(clip.x, clip.y);
|
|
||||||
float2 clipMax(clip.x + clip.z-1, clip.y + clip.w-1);
|
|
||||||
|
|
||||||
//NOTE(martin): intersect with current clip
|
//NOTE(martin): intersect with current clip
|
||||||
boxMin = max(boxMin, clip.xy);
|
boxMin = max(boxMin, clip.xy);
|
||||||
|
@ -86,7 +84,7 @@ kernel void BoundingBoxKernel(constant mg_vertex* vertexBuffer [[buffer(0)]],
|
||||||
//NOTE(martin): fill triangle data
|
//NOTE(martin): fill triangle data
|
||||||
boxArray[triangleIndex] = float4(boxMin.x, boxMin.y, boxMax.x, boxMax.y);
|
boxArray[triangleIndex] = float4(boxMin.x, boxMin.y, boxMax.x, boxMax.y);
|
||||||
|
|
||||||
triangleArray[triangleIndex].zIndex = shapeIndex;
|
triangleArray[triangleIndex].shapeIndex = shapeIndex;
|
||||||
triangleArray[triangleIndex].i0 = i0;
|
triangleArray[triangleIndex].i0 = i0;
|
||||||
triangleArray[triangleIndex].i1 = i1;
|
triangleArray[triangleIndex].i1 = i1;
|
||||||
triangleArray[triangleIndex].i2 = i2;
|
triangleArray[triangleIndex].i2 = i2;
|
||||||
|
@ -140,13 +138,13 @@ kernel void SortKernel(const device uint* tileCounters [[buffer(0)]],
|
||||||
for(int eltIndex=0; eltIndex < (int)tileBufferSize; eltIndex++)
|
for(int eltIndex=0; eltIndex < (int)tileBufferSize; eltIndex++)
|
||||||
{
|
{
|
||||||
uint elt = tileBuffer[eltIndex];
|
uint elt = tileBuffer[eltIndex];
|
||||||
uint eltZIndex = triangleArray[elt].zIndex;
|
uint eltZIndex = triangleArray[elt].shapeIndex;
|
||||||
|
|
||||||
int backIndex = eltIndex-1;
|
int backIndex = eltIndex-1;
|
||||||
for(; backIndex >= 0; backIndex--)
|
for(; backIndex >= 0; backIndex--)
|
||||||
{
|
{
|
||||||
uint backElt = tileBuffer[backIndex];
|
uint backElt = tileBuffer[backIndex];
|
||||||
uint backEltZIndex = triangleArray[backElt].zIndex;
|
uint backEltZIndex = triangleArray[backElt].shapeIndex;
|
||||||
if(eltZIndex >= backEltZIndex)
|
if(eltZIndex >= backEltZIndex)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -278,12 +276,12 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
|
||||||
float4 cubic1 = v1->cubic;
|
float4 cubic1 = v1->cubic;
|
||||||
float4 cubic2 = v2->cubic;
|
float4 cubic2 = v2->cubic;
|
||||||
|
|
||||||
int zIndex = v0->zIndex;
|
int shapeIndex = v0->shapeIndex;
|
||||||
float4 color = shapeBuffer[zIndex].color;
|
float4 color = shapeBuffer[shapeIndex].color;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
//TODO: dummy uv while we figure out image handling.
|
//TODO: dummy uv while we figure out image handling.
|
||||||
float2 uv0 = shapeBuffer[zIndex].uv;
|
float2 uv0 = shapeBuffer[shapeIndex].uv;
|
||||||
float2 uv1 = uv0;
|
float2 uv1 = uv0;
|
||||||
float2 uv2 = uv0;
|
float2 uv2 = uv0;
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -322,7 +320,7 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
|
||||||
float eps = 0.0001;
|
float eps = 0.0001;
|
||||||
if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps)
|
if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps)
|
||||||
{
|
{
|
||||||
if(zIndex == zIndices[i])
|
if(shapeIndex == zIndices[i])
|
||||||
{
|
{
|
||||||
flipCounts[i]++;
|
flipCounts[i]++;
|
||||||
}
|
}
|
||||||
|
@ -336,7 +334,7 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
|
||||||
float4 nextCol = color*texColor;
|
float4 nextCol = color*texColor;
|
||||||
nextColors[i] = pixelColors[i]*(1-nextCol.a) +nextCol.a*nextCol;
|
nextColors[i] = pixelColors[i]*(1-nextCol.a) +nextCol.a*nextCol;
|
||||||
|
|
||||||
zIndices[i] = zIndex;
|
zIndices[i] = shapeIndex;
|
||||||
flipCounts[i] = 1;
|
flipCounts[i] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include"graphics.h"
|
#include"graphics.h"
|
||||||
|
|
||||||
#ifdef __OBJC__
|
#ifdef __OBJC__
|
||||||
#import<Mtl/Metal.h>
|
#import<Metal/Metal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mg_surface mg_mtl_surface_create_for_window(mp_window window);
|
mg_surface mg_mtl_surface_create_for_window(mp_window window);
|
||||||
|
|
|
@ -197,7 +197,7 @@ mg_surface mg_mtl_surface_create_for_window(mp_window window)
|
||||||
mg_mtl_surface* surface = (mg_mtl_surface*)malloc(sizeof(mg_mtl_surface));
|
mg_mtl_surface* surface = (mg_mtl_surface*)malloc(sizeof(mg_mtl_surface));
|
||||||
|
|
||||||
//NOTE(martin): setup interface functions
|
//NOTE(martin): setup interface functions
|
||||||
surface->interface.backend = MG_BACKEND_MTL;
|
surface->interface.backend = MG_BACKEND_METAL;
|
||||||
surface->interface.destroy = mg_mtl_surface_destroy;
|
surface->interface.destroy = mg_mtl_surface_destroy;
|
||||||
surface->interface.prepare = mg_mtl_surface_prepare;
|
surface->interface.prepare = mg_mtl_surface_prepare;
|
||||||
surface->interface.present = mg_mtl_surface_present;
|
surface->interface.present = mg_mtl_surface_present;
|
||||||
|
@ -222,7 +222,7 @@ mg_surface mg_mtl_surface_create_for_window(mp_window window)
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
surface->device = MTLCreateSystemDefaultDevice();
|
surface->device = MTLCreateSystemDefaultDevice();
|
||||||
[surface->device retain];
|
[surface->device retain];
|
||||||
surface->mtlLayer = [CAMtlLayer layer];
|
surface->mtlLayer = [CAMetalLayer layer];
|
||||||
[surface->mtlLayer retain];
|
[surface->mtlLayer retain];
|
||||||
[surface->mtlLayer setOpaque:NO];
|
[surface->mtlLayer setOpaque:NO];
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ mg_surface mg_mtl_surface_create_for_window(mp_window window)
|
||||||
void* mg_mtl_surface_layer(mg_surface surface)
|
void* mg_mtl_surface_layer(mg_surface surface)
|
||||||
{
|
{
|
||||||
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
||||||
if(surfaceData && surfaceData->backend == MG_BACKEND_MTL)
|
if(surfaceData && surfaceData->backend == MG_BACKEND_METAL)
|
||||||
{
|
{
|
||||||
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
||||||
return(mtlSurface->mtlLayer);
|
return(mtlSurface->mtlLayer);
|
||||||
|
@ -280,7 +280,7 @@ void* mg_mtl_surface_layer(mg_surface surface)
|
||||||
void* mg_mtl_surface_drawable(mg_surface surface)
|
void* mg_mtl_surface_drawable(mg_surface surface)
|
||||||
{
|
{
|
||||||
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
||||||
if(surfaceData && surfaceData->backend == MG_BACKEND_MTL)
|
if(surfaceData && surfaceData->backend == MG_BACKEND_METAL)
|
||||||
{
|
{
|
||||||
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
||||||
return(mtlSurface->drawable);
|
return(mtlSurface->drawable);
|
||||||
|
@ -294,7 +294,7 @@ void* mg_mtl_surface_drawable(mg_surface surface)
|
||||||
void* mg_mtl_surface_command_buffer(mg_surface surface)
|
void* mg_mtl_surface_command_buffer(mg_surface surface)
|
||||||
{
|
{
|
||||||
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
|
||||||
if(surfaceData && surfaceData->backend == MG_BACKEND_MTL)
|
if(surfaceData && surfaceData->backend == MG_BACKEND_METAL)
|
||||||
{
|
{
|
||||||
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
|
||||||
return(mtlSurface->commandBuffer);
|
return(mtlSurface->commandBuffer);
|
||||||
|
|
|
@ -728,6 +728,7 @@ static void mp_update_key_mods(mp_key_mods mods)
|
||||||
{
|
{
|
||||||
window = mpWindow;
|
window = mpWindow;
|
||||||
mpWindow->osx.nsView = self;
|
mpWindow->osx.nsView = self;
|
||||||
|
[mpWindow->osx.nsView setWantsLayer:YES];
|
||||||
|
|
||||||
NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited
|
NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited
|
||||||
| NSTrackingMouseMoved
|
| NSTrackingMouseMoved
|
||||||
|
|
9
todo.txt
9
todo.txt
|
@ -23,13 +23,18 @@ Overview
|
||||||
|
|
||||||
[/] Keep dummy window/dummy context around for gl context creation, and don't reload wgl functions every time
|
[/] Keep dummy window/dummy context around for gl context creation, and don't reload wgl functions every time
|
||||||
|
|
||||||
[>] Reintroduce GLES surface
|
[.] Reintroduce GLES surface
|
||||||
|
[ ] See how we can isolate platform-specific stuff and just deal with egl there..
|
||||||
|
|
||||||
[>] Back surface by child windows and implement moving frame/hiding/overlay
|
[>] Back surface by child windows and implement moving frame/hiding/overlay
|
||||||
|
|
||||||
[>] Check that we can make GLES and GL surfaces co-exist in the app
|
[>] Check that we can make GLES and GL surfaces co-exist in the app
|
||||||
|
|
||||||
[?] Backport canvas to GLES
|
[?] Backport canvas to GLES
|
||||||
|
|
||||||
|
[!] Fix canvas shader precision issue on OSX
|
||||||
|
[!] Fix canvas perf issue on OSX
|
||||||
|
[!] osx: Remove need to include objc defs from osx_app.h in egl impl. Also properly guard angle backend attribute (must be metal on osx and default on win32)
|
||||||
|
|
||||||
[ ] Delegated drawing API+Impl
|
[ ] Delegated drawing API+Impl
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue