[wip] changing backend enum to api enum, and adding canvas api in here

This commit is contained in:
Martin Fouilleul 2023-04-25 14:54:52 +02:00
parent 7c273f494b
commit 3769b70753
8 changed files with 50 additions and 52 deletions

View File

@ -86,7 +86,7 @@ void mg_egl_surface_init(mg_egl_surface* surface)
{
void* nativeLayer = surface->interface.nativeLayer((mg_surface_data*)surface);
surface->interface.backend = MG_BACKEND_GLES;
surface->interface.api = MG_GLES;
surface->interface.destroy = mg_egl_surface_destroy;
surface->interface.prepare = mg_egl_surface_prepare;

View File

@ -300,19 +300,19 @@ mg_image_data* mg_image_data_from_handle(mg_image handle)
#include"mtl_surface.h"
#endif
bool mg_is_surface_backend_available(mg_backend_id backend)
bool mg_is_surface_backend_available(mg_surface_api api)
{
bool result = false;
switch(backend)
switch(api)
{
#if MG_COMPILE_BACKEND_METAL
case MG_BACKEND_METAL:
case MG_METAL:
#endif
#if MG_COMPILE_BACKEND_GL
case MG_BACKEND_GL:
case MG_GL:
#endif
#if MG_COMPILE_BACKEND_GLES
case MG_BACKEND_GLES:
case MG_GLES:
#endif
result = true;
break;
@ -323,16 +323,16 @@ bool mg_is_surface_backend_available(mg_backend_id backend)
return(result);
}
bool mg_is_canvas_backend_available(mg_backend_id backend)
bool mg_is_canvas_backend_available(mg_surface_api api)
{
bool result = false;
switch(backend)
switch(api)
{
#if MG_COMPILE_BACKEND_METAL
case MG_BACKEND_METAL:
case MG_METAL:
#endif
#if MG_COMPILE_BACKEND_GL && defined(PLATFORM_WIN64)
case MG_BACKEND_GL:
case MG_GL:
#endif
result = true;
break;
@ -346,7 +346,7 @@ bool mg_is_canvas_backend_available(mg_backend_id backend)
mg_surface mg_surface_nil() { return((mg_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_backend_id backend)
mg_surface mg_surface_create_for_window(mp_window window, mg_surface_api api)
{
if(__mgData.init)
{
@ -355,22 +355,22 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend)
mg_surface surfaceHandle = mg_surface_nil();
mg_surface_data* surface = 0;
switch(backend)
switch(api)
{
#if MG_COMPILE_BACKEND_GL
case MG_BACKEND_GL:
case MG_GL:
surface = gl_surface_create_for_window(window);
break;
#endif
#if MG_COMPILE_BACKEND_GLES
case MG_BACKEND_GLES:
case MG_GLES:
surface = mg_egl_surface_create_for_window(window);
break;
#endif
#if MG_COMPILE_BACKEND_METAL
case MG_BACKEND_METAL:
case MG_METAL:
surface = mg_mtl_surface_create_for_window(window);
break;
#endif
@ -385,7 +385,7 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend)
return(surfaceHandle);
}
mg_surface mg_surface_create_remote(u32 width, u32 height, mg_backend_id backend)
mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api)
{
if(__mgData.init)
{
@ -394,10 +394,10 @@ mg_surface mg_surface_create_remote(u32 width, u32 height, mg_backend_id backend
mg_surface surfaceHandle = mg_surface_nil();
mg_surface_data* surface = 0;
switch(backend)
switch(api)
{
#if MG_COMPILE_BACKEND_GLES
case MG_BACKEND_GLES:
case MG_GLES:
surface = mg_egl_surface_create_remote(width, height);
break;
#endif
@ -2636,16 +2636,16 @@ mg_canvas mg_canvas_create(mg_surface surface)
if(surfaceData)
{
mg_canvas_backend* backend = 0;
switch(surfaceData->backend)
switch(surfaceData->api)
{
#if MG_COMPILE_BACKEND_METAL
case MG_BACKEND_METAL:
case MG_METAL:
backend = mg_mtl_canvas_create(surface);
break;
#endif
#if MG_COMPILE_BACKEND_GL
case MG_BACKEND_GL:
case MG_GL:
backend = mg_gl_canvas_create(surface);
break;
#endif

View File

@ -18,11 +18,12 @@
//------------------------------------------------------------------------------------------
typedef enum {
MG_BACKEND_NONE,
MG_BACKEND_METAL,
MG_BACKEND_GL,
MG_BACKEND_GLES,
MG_BACKEND_HOST } mg_backend_id;
MG_NONE,
MG_METAL,
MG_GL,
MG_GLES,
MG_CANVAS,
MG_HOST } mg_surface_api;
//NOTE: these macros are used to select which backend to include when building milepost
// they can be overridden by passing them to the compiler command line
@ -35,16 +36,12 @@ typedef enum {
#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
#define MG_BACKEND_DEFAULT MG_BACKEND_GL
#else
#define MG_BACKEND_DEFAULT MG_BACKEND_NONE
#ifndef MG_COMPILE_BACKEND_CANVAS
#define MG_COMPILE_BACKEND_CANVAS 1
#endif
#define MG_COMPILE_BACKEND_GL 0
#elif defined(PLATFORM_WIN64)
#ifndef MG_COMPILE_BACKEND_GL
#define MG_COMPILE_BACKEND_GL 1
@ -54,10 +51,8 @@ typedef enum {
#define MG_COMPILE_BACKEND_GLES 1
#endif
#if MG_COMPILE_BACKEND_GL
#define MG_BACKEND_DEFAULT MG_BACKEND_GL
#else
#define MG_BACKEND_DEFAULT MG_BACKEND_NONE
#ifndef MG_COMPILE_BACKEND_CANVAS
#define MG_COMPILE_BACKEND_CANVAS 1
#endif
#elif defined(PLATFORM_LINUX)
@ -65,6 +60,10 @@ typedef enum {
#define MG_COMPILE_BACKEND_GL 1
#endif
#ifndef MG_COMPILE_BACKEND_CANVAS
#define MG_COMPILE_BACKEND_CANVAS 1
#endif
#endif
//NOTE: these macros are used to select backend-specific APIs to include when using milepost
@ -80,8 +79,7 @@ typedef enum {
//TODO: add MG_INCLUDE_OPENGL/GLES/etc, once we know how we make different gl versions co-exist
MP_API bool mg_is_surface_backend_available(mg_backend_id id);
MP_API bool mg_is_canvas_backend_available(mg_backend_id id);
MP_API bool mg_is_surface_api_available(mg_surface_api api);
//------------------------------------------------------------------------------------------
//NOTE(martin): graphics surface
@ -91,7 +89,7 @@ typedef struct mg_surface { u64 h; } mg_surface;
MP_API mg_surface mg_surface_nil();
MP_API bool mg_surface_is_nil(mg_surface surface);
MP_API mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend);
MP_API mg_surface mg_surface_create_for_window(mp_window window, mg_surface_api api);
MP_API void mg_surface_destroy(mg_surface surface);
MP_API void mg_surface_prepare(mg_surface surface);
MP_API void mg_surface_present(mg_surface surface);
@ -105,7 +103,7 @@ MP_API void mg_surface_set_hidden(mg_surface surface, bool hidden);
//NOTE(martin): surface sharing
typedef u64 mg_surface_id;
MP_API mg_surface mg_surface_create_remote(u32 width, u32 height, mg_backend_id backend);
MP_API mg_surface mg_surface_create_remote(u32 width, u32 height, mg_surface_api api);
MP_API mg_surface mg_surface_create_host(mp_window window);
MP_API mg_surface_id mg_surface_remote_id(mg_surface surface);
MP_API void mg_surface_host_connect(mg_surface surface, mg_surface_id remoteId);

View File

@ -36,7 +36,7 @@ typedef void (*mg_surface_host_connect_proc)(mg_surface_data* surface, mg_surfac
typedef struct mg_surface_data
{
mg_backend_id backend;
mg_surface_api api;
mp_layer layer;
mg_surface_destroy_proc destroy;

View File

@ -830,7 +830,7 @@ void mg_mtl_canvas_render(mg_canvas_backend* interface,
//NOTE: prepare rendering
mg_mtl_surface* surface = (mg_mtl_surface*)mg_surface_data_from_handle(backend->surface);
ASSERT(surface && surface->interface.backend == MG_BACKEND_METAL);
ASSERT(surface && surface->interface.api == MG_METAL);
mp_rect frame = mg_surface_get_frame(backend->surface);
f32 scale = surface->mtlLayer.contentsScale;
@ -1070,7 +1070,7 @@ mg_image_data* mg_mtl_canvas_image_create(mg_canvas_backend* interface, vec2 siz
mg_mtl_canvas_backend* backend = (mg_mtl_canvas_backend*)interface;
mg_mtl_surface* surface = (mg_mtl_surface*)mg_surface_data_from_handle(backend->surface);
if(surface && surface->interface.backend == MG_BACKEND_METAL)
if(surface && surface->interface.api == MG_METAL)
{
@autoreleasepool{
@ -1134,7 +1134,7 @@ mg_canvas_backend* mg_mtl_canvas_create(mg_surface surface)
mg_mtl_canvas_backend* backend = 0;
mg_surface_data* surfaceData = mg_surface_data_from_handle(surface);
if(surfaceData && surfaceData->backend == MG_BACKEND_METAL)
if(surfaceData && surfaceData->api == MG_METAL)
{
mg_mtl_surface* metalSurface = (mg_mtl_surface*)surfaceData;

View File

@ -155,7 +155,7 @@ mg_surface_data* mg_mtl_surface_create_for_window(mp_window window)
mg_surface_init_for_window((mg_surface_data*)surface, windowData);
//NOTE(martin): setup interface functions
surface->interface.backend = MG_BACKEND_METAL;
surface->interface.api = MG_METAL;
surface->interface.destroy = mg_mtl_surface_destroy;
surface->interface.prepare = mg_mtl_surface_prepare;
surface->interface.present = mg_mtl_surface_present;
@ -213,7 +213,7 @@ mg_surface_data* 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_METAL)
if(surfaceData && surfaceData->api == MG_METAL)
{
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
return(mtlSurface->mtlLayer);
@ -227,7 +227,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_METAL)
if(surfaceData && surfaceData->api == MG_METAL)
{
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
mg_mtl_surface_acquire_drawable(mtlSurface);
@ -242,7 +242,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_METAL)
if(surfaceData && surfaceData->api == MG_METAL)
{
mg_mtl_surface* mtlSurface = (mg_mtl_surface*)surfaceData;
mg_mtl_surface_acquire_command_buffer(mtlSurface);

View File

@ -1782,7 +1782,7 @@ void mg_osx_surface_host_connect(mg_surface_data* surface, mg_surface_id remoteI
void mg_surface_init_host(mg_surface_data* surface, mp_window_data* window)
{@autoreleasepool{
surface->backend = MG_BACKEND_HOST;
surface->api = MG_HOST;
surface->nativeLayer = mg_osx_surface_native_layer;
surface->contentsScaling = mg_osx_surface_contents_scaling;
surface->getFrame = mg_osx_surface_get_frame;

View File

@ -189,7 +189,7 @@ mg_surface_data* mg_wgl_surface_create_for_window(mp_window window)
{
mg_surface_init_for_window((mg_surface_data*)surface, windowData);
surface->interface.backend = MG_BACKEND_GL;
surface->interface.api = MG_GL;
surface->interface.destroy = mg_wgl_surface_destroy;
surface->interface.prepare = mg_wgl_surface_prepare;
surface->interface.present = mg_wgl_surface_present;