reintroduced GLES backend to osx

This commit is contained in:
Martin Fouilleul 2023-02-20 11:05:01 +01:00
parent 9eaa125129
commit 2232b647ed
23 changed files with 3012 additions and 3053 deletions

164
build.sh
View File

@ -1,82 +1,82 @@
#!/bin/bash
DEBUG_FLAGS="-g -DDEBUG -DLOG_COMPILE_DEBUG"
#DEBUG_FLAGS="-O3"
#--------------------------------------------------------------
# set target
#--------------------------------------------------------------
target="$1"
if [ -z $target ] ; then
target='lib'
fi
shaderFlagParam="$2"
#--------------------------------------------------------------
# Detect OS and set environment variables accordingly
#--------------------------------------------------------------
OS=$(uname -s)
if [ $OS = "Darwin" ] ; then
#echo "Target '$target' for macOS"
CC=clang
CXX=clang++
DYLIB_SUFFIX='dylib'
SYS_LIBS=''
FLAGS="-mmacos-version-min=10.15.4 -maes"
CFLAGS="-std=c11"
elif [ $OS = "Linux" ] ; then
echo "Error: Linux is not supported yet"
exit -1
else
echo "Error: Unsupported OS $OS"
exit -1
fi
#--------------------------------------------------------------
# Set paths
#--------------------------------------------------------------
BINDIR="./bin"
SRCDIR="./src"
EXTDIR="./ext"
RESDIR="./resources"
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$EXTDIR/angle_headers"
#--------------------------------------------------------------
# Build
#--------------------------------------------------------------
if [ ! \( -e bin \) ] ; then
mkdir ./bin
fi
if [ $target = 'lib' ] ; then
# compile metal shader
xcrun -sdk macosx metal $shaderFlagParam -c -o $BINDIR/metal_shader.air $SRCDIR/metal_shader.metal
xcrun -sdk macosx metallib -o $RESDIR/metal_shader.metallib $BINDIR/metal_shader.air
# compile milepost. We use one compilation unit for all C code, and one compilation
# unit for all ObjectiveC code
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_c.o $CFLAGS $FLAGS $INCLUDES $SRCDIR/milepost.c
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_objc.o $FLAGS $INCLUDES $SRCDIR/milepost.m
# build the static library
libtool -static -o $BINDIR/libmilepost.a $BINDIR/milepost_c.o $BINDIR/milepost_objc.o
else
# additional targets
if [ $target = 'test' ] ; then
pushd examples/test_app
./build.sh
popd
elif [ $target = 'clean' ] ; then
rm -r ./bin
else
echo "unrecognized target $target"
exit -1
fi
fi
#!/bin/bash
DEBUG_FLAGS="-g -DDEBUG -DLOG_COMPILE_DEBUG"
#DEBUG_FLAGS="-O3"
#--------------------------------------------------------------
# set target
#--------------------------------------------------------------
target="$1"
if [ -z $target ] ; then
target='lib'
fi
shaderFlagParam="$2"
#--------------------------------------------------------------
# Detect OS and set environment variables accordingly
#--------------------------------------------------------------
OS=$(uname -s)
if [ $OS = "Darwin" ] ; then
#echo "Target '$target' for macOS"
CC=clang
CXX=clang++
DYLIB_SUFFIX='dylib'
SYS_LIBS=''
FLAGS="-mmacos-version-min=10.15.4 -maes"
CFLAGS="-std=c11"
elif [ $OS = "Linux" ] ; then
echo "Error: Linux is not supported yet"
exit -1
else
echo "Error: Unsupported OS $OS"
exit -1
fi
#--------------------------------------------------------------
# Set paths
#--------------------------------------------------------------
BINDIR="./bin"
SRCDIR="./src"
EXTDIR="./ext"
RESDIR="./resources"
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$EXTDIR -I$EXTDIR/angle_headers"
#--------------------------------------------------------------
# Build
#--------------------------------------------------------------
if [ ! \( -e bin \) ] ; then
mkdir ./bin
fi
if [ $target = 'lib' ] ; then
# compile metal shader
xcrun -sdk macosx metal $shaderFlagParam -c -o $BINDIR/mtl_shader.air $SRCDIR/mtl_shader.metal
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
# unit for all ObjectiveC code
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_c.o $CFLAGS $FLAGS $INCLUDES $SRCDIR/milepost.c
$CC $DEBUG_FLAGS -c -o $BINDIR/milepost_objc.o $FLAGS $INCLUDES $SRCDIR/milepost.m
# build the static library
libtool -static -o $BINDIR/libmilepost.a $BINDIR/milepost_c.o $BINDIR/milepost_objc.o
else
# additional targets
if [ $target = 'test' ] ; then
pushd examples/test_app
./build.sh
popd
elif [ $target = 'clean' ] ; then
rm -r ./bin
else
echo "unrecognized target $target"
exit -1
fi
fi

View File

@ -1,11 +1,11 @@
#!/bin/bash
BINDIR=../../bin
RESDIR=../../resources
SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore"
FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG -Wl,-dead_strip"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c
#!/bin/bash
BINDIR=../../bin
RESDIR=../../resources
SRCDIR=../../src
INCLUDES="-I$SRCDIR -I$SRCDIR/util -I$SRCDIR/platform -I$SRCDIR/app"
LIBS="-L$BINDIR -lmilepost -framework Carbon -framework Cocoa -framework Metal -framework QuartzCore"
FLAGS="-mmacos-version-min=10.15.4 -DDEBUG -DLOG_COMPILE_DEBUG -Wl,-dead_strip"
clang -g $FLAGS $LIBS $INCLUDES -o $BINDIR/example_canvas main.c

View File

@ -52,7 +52,7 @@ mg_font create_font()
int main()
{
LogLevel(LOG_LEVEL_DEBUG);
LogLevel(LOG_LEVEL_WARNING);
mp_init();
mp_clock_init(); //TODO put that in mp_init()?

2
examples/perf_text/build.sh Normal file → Executable file
View File

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

View File

@ -125,69 +125,6 @@ int main()
mp_request_quit();
} 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:
break;
}

View File

@ -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@date: %s\n" % datetime.now().strftime("%d/%m%Y"))
f.write("*\n")
f.write("/********************************************************/\n")
f.write("*********************************************************/\n")
def emit_begin_guard(f, name):
@ -143,7 +143,7 @@ f = open(loaderCPath, 'w')
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("mp_thread_local mg_gl_api* __mgGLAPI = 0;\n\n")

View File

@ -11,6 +11,7 @@
#include<EGL/egl.h>
#include<EGL/eglext.h>
#include"mp_app_internal.h"
#include"graphics_internal.h"
#include"gl_loader.h"
@ -34,7 +35,7 @@ typedef struct mg_egl_surface
void* mg_egl_get_native_surface(mp_window_data* window)
{
return((void*)window->osx.nsView);
return((void*)window->osx.nsView.layer);
}
#elif OS_WIN64
#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);
EGLAttrib displayAttribs[] = {
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_NONE};
#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[] = {
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_NONE};
#endif
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
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);
EGLint contextAttributes[] = {
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_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,22 @@
/********************************************************
*
* @file: gl_loader.h
* @note: auto-generated by glapi.py from gl.xml
* @date: 16/022023
*
/********************************************************/
#ifndef __GL_LOADER_H__
#define __GL_LOADER_H__
#include"gl_api.h"
typedef void*(*mg_gl_load_proc)(const char* name);
void mg_gl_load_gl41(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gl43(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gles32(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_select_api(mg_gl_api* api);
#endif // __GL_LOADER_H__
/********************************************************
*
* @file: gl_loader.h
* @note: auto-generated by glapi.py from gl.xml
* @date: 20/022023
*
*********************************************************/
#ifndef __GL_LOADER_H__
#define __GL_LOADER_H__
#include"gl_api.h"
typedef void*(*mg_gl_load_proc)(const char* name);
void mg_gl_load_gl41(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gl43(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gles32(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_select_api(mg_gl_api* api);
#endif // __GL_LOADER_H__

View File

@ -372,7 +372,7 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend)
#endif
#if MG_COMPILE_BACKEND_METAL
case MG_METAL_BACKEND:
case MG_BACKEND_METAL:
surface = mg_mtl_surface_create_for_window(window);
break;
#endif
@ -2656,11 +2656,11 @@ mp_rect mg_text_bounding_box(mg_font font, f32 fontSize, str8 text)
//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);
#endif
#ifdef MG_COMPILE_BACKEND_GL
#if MG_COMPILE_BACKEND_GL
mg_canvas_backend* mg_gl_canvas_create(mg_surface surface);
#endif
@ -2673,13 +2673,13 @@ mg_canvas mg_canvas_create(mg_surface surface)
mg_canvas_backend* backend = 0;
switch(surfaceData->backend)
{
#ifdef MG_COMPILE_BACKEND_METAL
#if MG_COMPILE_BACKEND_METAL
case MG_BACKEND_METAL:
backend = mg_mtl_canvas_create(surface);
break;
#endif
#ifdef MG_COMPILE_BACKEND_GL
#if MG_COMPILE_BACKEND_GL
case MG_BACKEND_GL:
backend = mg_gl_canvas_create(surface);
break;

View File

@ -11,6 +11,7 @@
#include"typedefs.h"
#include"platform.h"
#include"mp_app.h"
//------------------------------------------------------------------------------------------
//NOTE(martin): backends selection
@ -29,10 +30,12 @@ typedef enum {
#define MG_COMPILE_BACKEND_METAL 1
#endif
#ifndef MG_COMPILE_BACKEND_GL
#define MG_COMPILE_BACKEND_GL 1
#ifndef MG_COMPILE_BACKEND_GLES
#define MG_COMPILE_BACKEND_GLES 1
#endif
#define MG_COMPILE_BACKEND_GL 0
#if MG_COMPILE_BACKEND_METAL
#define MG_BACKEND_DEFAULT MG_BACKEND_METAL
#elif MG_COMPILE_BACKEND_GL

View File

@ -70,7 +70,6 @@
#elif defined(OS_MACOS)
//NOTE: macos application layer and graphics backends are defined in milepost.m
#include"graphics.c"
#else
#error "Unsupported platform"
#endif

View File

@ -38,10 +38,8 @@
#include"mp_app.h"
#include"graphics.h"
#if defined(OS_WIN64)
#ifdef MG_INCLUDE_GL_API
#include"gl_api.h"
#endif
#ifdef MG_INCLUDE_GL_API
#include"gl_api.h"
#endif
//#include"ui.h"

View File

@ -8,13 +8,18 @@
*****************************************************************/
#include"osx_app.m"
#include"graphics.h"
#include"graphics.c"
#if MG_COMPILE_BACKEND_METAL
#include"mtl_surface.m"
#include"mtl_canvas.m"
#endif
#if MG_COMPILE_BACKEND_GLES
#include"gl_loader.c"
#include"egl_surface.c"
#endif
/*
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

View File

@ -148,5 +148,6 @@ typedef struct mp_app
MP_PLATFORM_APP_DATA
} mp_app;
mp_window_data* mp_window_ptr_from_handle(mp_window handle);
#endif // __MP_APP_INTERNAL_H_

View File

@ -91,7 +91,7 @@ void mg_mtl_canvas_draw_batch(mg_canvas_backend* interface, u32 vertexCount, u32
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};
//-----------------------------------------------------------
@ -218,7 +218,7 @@ void mg_mtl_canvas_viewport(mg_canvas_backend* interface, mp_rect viewPort)
@autoreleasepool
{
f32 scale = surface->metalLayer.contentsScale;
f32 scale = surface->mtlLayer.contentsScale;
CGSize drawableSize = (CGSize){.width = viewPort.w * scale, .height = viewPort.h * scale};
[backend->outTexture release];
@ -249,8 +249,8 @@ void mg_mtl_canvas_update_vertex_layout(mg_mtl_canvas_backend* backend)
.cubicStride = sizeof(mg_vertex),
.posBuffer = vertexBase + offsetof(mg_vertex, pos),
.posStride = sizeof(mg_vertex),
.zIndexBuffer = vertexBase + offsetof(mg_vertex, zIndex),
.zIndexStride = sizeof(mg_vertex),
.shapeIndexBuffer = vertexBase + offsetof(mg_vertex, shapeIndex),
.shapeIndexStride = sizeof(mg_vertex),
.colorBuffer = shapeBase + offsetof(mg_shape, color),
.colorStride = sizeof(mg_shape),
@ -316,7 +316,7 @@ mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface)
@autoreleasepool
{
f32 scale = metalSurface->metalLayer.contentsScale;
f32 scale = metalSurface->mtlLayer.contentsScale;
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.vertexFunction = vertexFunction;
pipelineStateDescriptor.fragmentFunction = fragmentFunction;
pipelineStateDescriptor.colorAttachments[0].pixelFormat = metalSurface->metalLayer.pixelFormat;
pipelineStateDescriptor.colorAttachments[0].pixelFormat = metalSurface->mtlLayer.pixelFormat;
// create render pipeline
backend->renderPipeline = [metalSurface->device newRenderPipelineStateWithDescriptor: pipelineStateDescriptor error:&err];

View File

@ -22,7 +22,7 @@ typedef struct mg_vertex
{
vector_float4 cubic; // canonical implicit curve space coordinates
vector_float2 pos; // position
int zIndex;
int shapeIndex;
} mg_vertex;
typedef struct mg_shape
@ -38,7 +38,7 @@ typedef struct mg_triangle_data
uint i0;
uint i1;
uint i2;
uint zIndex;
uint shapeIndex;
vector_float2 p0;
vector_float2 p1;

View File

@ -57,11 +57,9 @@ kernel void BoundingBoxKernel(constant mg_vertex* vertexBuffer [[buffer(0)]],
float2 boxMax = max(max(p0, p1), p2);
//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;
float2 clipMin(clip.x, clip.y);
float2 clipMax(clip.x + clip.z-1, clip.y + clip.w-1);
//NOTE(martin): intersect with current clip
boxMin = max(boxMin, clip.xy);
@ -86,7 +84,7 @@ kernel void BoundingBoxKernel(constant mg_vertex* vertexBuffer [[buffer(0)]],
//NOTE(martin): fill triangle data
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].i1 = i1;
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++)
{
uint elt = tileBuffer[eltIndex];
uint eltZIndex = triangleArray[elt].zIndex;
uint eltZIndex = triangleArray[elt].shapeIndex;
int backIndex = eltIndex-1;
for(; backIndex >= 0; backIndex--)
{
uint backElt = tileBuffer[backIndex];
uint backEltZIndex = triangleArray[backElt].zIndex;
uint backEltZIndex = triangleArray[backElt].shapeIndex;
if(eltZIndex >= backEltZIndex)
{
break;
@ -278,12 +276,12 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
float4 cubic1 = v1->cubic;
float4 cubic2 = v2->cubic;
int zIndex = v0->zIndex;
float4 color = shapeBuffer[zIndex].color;
int shapeIndex = v0->shapeIndex;
float4 color = shapeBuffer[shapeIndex].color;
/////////////////////////////////////////////////////////////////////////
//TODO: dummy uv while we figure out image handling.
float2 uv0 = shapeBuffer[zIndex].uv;
float2 uv0 = shapeBuffer[shapeIndex].uv;
float2 uv1 = uv0;
float2 uv2 = uv0;
/////////////////////////////////////////////////////////////////////////
@ -322,7 +320,7 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
float eps = 0.0001;
if(cubic.w*(cubic.x*cubic.x*cubic.x - cubic.y*cubic.z) <= eps)
{
if(zIndex == zIndices[i])
if(shapeIndex == zIndices[i])
{
flipCounts[i]++;
}
@ -336,7 +334,7 @@ kernel void RenderKernel(texture2d<float, access::write> outTexture [[texture(0)
float4 nextCol = color*texColor;
nextColors[i] = pixelColors[i]*(1-nextCol.a) +nextCol.a*nextCol;
zIndices[i] = zIndex;
zIndices[i] = shapeIndex;
flipCounts[i] = 1;
}
}

View File

@ -12,7 +12,7 @@
#include"graphics.h"
#ifdef __OBJC__
#import<Mtl/Metal.h>
#import<Metal/Metal.h>
#endif
mg_surface mg_mtl_surface_create_for_window(mp_window window);

View File

@ -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));
//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.prepare = mg_mtl_surface_prepare;
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 retain];
surface->mtlLayer = [CAMtlLayer layer];
surface->mtlLayer = [CAMetalLayer layer];
[surface->mtlLayer retain];
[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)
{
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;
return(mtlSurface->mtlLayer);
@ -280,7 +280,7 @@ void* mg_mtl_surface_layer(mg_surface surface)
void* mg_mtl_surface_drawable(mg_surface 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;
return(mtlSurface->drawable);
@ -294,7 +294,7 @@ void* mg_mtl_surface_drawable(mg_surface surface)
void* mg_mtl_surface_command_buffer(mg_surface 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;
return(mtlSurface->commandBuffer);

View File

@ -728,6 +728,7 @@ static void mp_update_key_mods(mp_key_mods mods)
{
window = mpWindow;
mpWindow->osx.nsView = self;
[mpWindow->osx.nsView setWantsLayer:YES];
NSTrackingAreaOptions trackingOptions = NSTrackingMouseEnteredAndExited
| NSTrackingMouseMoved

View File

@ -23,13 +23,18 @@ Overview
[/] 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
[>] Check that we can make GLES and GL surfaces co-exist in the app
[?] 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