[gles, wip] reintroducing egl surface (for win32 at first)

This commit is contained in:
martinfouilleul 2023-02-17 18:56:16 +01:00
parent 20e425494f
commit 333d3e9f9c
13 changed files with 432 additions and 308 deletions

View File

@ -1,2 +1,3 @@
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 /DMG_IMPLEMENTS_BACKEND_GL /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib /out:test.exe
cl /we4013 /Zi /Zc:preprocessor /DMG_IMPLEMENTS_BACKEND_GL /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib user32.lib opengl32.lib gdi32.lib shcore.lib /out:../../bin/example_gl_triangle.exe

View File

@ -12,6 +12,7 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include<math.h> #include<math.h>
#define MG_INCLUDE_GL_API
#include"milepost.h" #include"milepost.h"
#define LOG_SUBSYSTEM "Main" #define LOG_SUBSYSTEM "Main"
@ -67,9 +68,11 @@ int main()
mp_window window = mp_window_create(rect, "test", 0); mp_window window = mp_window_create(rect, "test", 0);
//NOTE: create surface //NOTE: create surface
mg_surface surface = mg_gl_surface_create_for_window(window); mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GL);
//NOTE: init shader and gl state //NOTE: init shader and gl state
mg_surface_prepare(surface);
GLuint vao; GLuint vao;
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
glBindVertexArray(vao); glBindVertexArray(vao);
@ -123,69 +126,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;
} }
@ -200,8 +140,6 @@ int main()
//f32 aspect = frameSize.x/frameSize.y; //f32 aspect = frameSize.x/frameSize.y;
f32 aspect = 800/(f32)600; f32 aspect = 800/(f32)600;
glViewport(0, 0, 800, 600);
GLfloat matrix[] = {cosf(alpha)/aspect, sinf(alpha), 0, 0, GLfloat matrix[] = {cosf(alpha)/aspect, sinf(alpha), 0, 0,
-sinf(alpha)/aspect, cosf(alpha), 0, 0, -sinf(alpha)/aspect, cosf(alpha), 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,

View File

@ -1,2 +1,3 @@
set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /I ../../ext/angle_headers
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib /LIBPATH:../../bin libEGL.dll.lib libGLESv2.dll.lib user32.lib opengl32.lib gdi32.lib /out:../../bin/example_gles_triangle.exe
cl /we4013 /Zi /Zc:preprocessor /std:c11 %INCLUDES% main.c /link /LIBPATH:../../bin milepost.lib /LIBPATH:../../bin libEGL.dll.lib libGLESv2.dll.lib user32.lib opengl32.lib gdi32.lib shcore.lib /out:../../bin/example_gles_triangle.exe

View File

@ -1,232 +1,227 @@
/************************************************************//** /************************************************************//**
* *
* @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<string.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include<math.h> #include<math.h>
#include<GLES3/gl32.h> #include<GLES3/gl32.h>
#include"milepost.h" #include"milepost.h"
#define LOG_SUBSYSTEM "Main" #define LOG_SUBSYSTEM "Main"
unsigned int program;
mg_surface mg_gles_surface_create_for_window(mp_window window);
const char* vshaderSource =
unsigned int program; //"#version 320 es\n"
"attribute vec4 vPosition;\n"
const char* vshaderSource = "uniform mat4 transform;\n"
//"#version 320 es\n" "void main()\n"
"attribute vec4 vPosition;\n" "{\n"
"uniform mat4 transform;\n" " gl_Position = transform*vPosition;\n"
"void main()\n" "}\n";
"{\n"
" gl_Position = transform*vPosition;\n" const char* fshaderSource =
"}\n"; //"#version 320 es\n"
"precision mediump float;\n"
const char* fshaderSource = "void main()\n"
//"#version 320 es\n" "{\n"
"precision mediump float;\n" " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"void main()\n" "}\n";
"{\n"
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" void compile_shader(GLuint shader, const char* source)
"}\n"; {
glShaderSource(shader, 1, &source, 0);
void compile_shader(GLuint shader, const char* source) glCompileShader(shader);
{
glShaderSource(shader, 1, &source, 0); int err = glGetError();
glCompileShader(shader); if(err)
{
int err = glGetError(); printf("gl error: %i\n", err);
if(err) }
{
printf("gl error: %i\n", err); int status = 0;
} glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if(!status)
int status = 0; {
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); char buffer[256];
if(!status) int size = 0;
{ glGetShaderInfoLog(shader, 256, &size, buffer);
char buffer[256]; printf("shader error: %.*s\n", size, buffer);
int size = 0; }
glGetShaderInfoLog(shader, 256, &size, buffer); }
printf("shader error: %.*s\n", size, buffer);
} int main()
} {
LogLevel(LOG_LEVEL_DEBUG);
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}; //NOTE: create surface
mp_window window = mp_window_create(rect, "test", 0); mg_surface surface = mg_surface_create_for_window(window, MG_BACKEND_GLES);
//NOTE: create surface //NOTE: init shader and gl state
mg_surface surface = mg_gles_surface_create_for_window(window); GLuint vao;
glGenVertexArrays(1, &vao);
//NOTE: init shader and gl state glBindVertexArray(vao);
GLuint vao;
glGenVertexArrays(1, &vao); GLuint vertexBuffer;
glBindVertexArray(vao); glGenBuffers(1, &vertexBuffer);
GLuint vertexBuffer; GLfloat vertices[] = {
glGenBuffers(1, &vertexBuffer); -0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
GLfloat vertices[] = { glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0}; glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER); compile_shader(vshader, vshaderSource);
program = glCreateProgram(); compile_shader(fshader, fshaderSource);
compile_shader(vshader, vshaderSource); glAttachShader(program, vshader);
compile_shader(fshader, fshaderSource); glAttachShader(program, fshader);
glLinkProgram(program);
glAttachShader(program, vshader);
glAttachShader(program, fshader); int status = 0;
glLinkProgram(program); glGetProgramiv(program, GL_LINK_STATUS, &status);
if(!status)
int status = 0; {
glGetProgramiv(program, GL_LINK_STATUS, &status); char buffer[256];
if(!status) int size = 0;
{ glGetProgramInfoLog(program, 256, &size, buffer);
char buffer[256]; printf("link error: %.*s\n", size, buffer);
int size = 0; }
glGetProgramInfoLog(program, 256, &size, buffer);
printf("link error: %.*s\n", size, buffer); glUseProgram(program);
}
mp_window_bring_to_front(window);
glUseProgram(program); // 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(mp_next_event(&event))
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;
} mg_surface_prepare(surface);
}
glClearColor(0.3, 0.3, 1, 1);
mg_surface_prepare(surface); glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.3, 0.3, 1, 1); static float alpha = 0;
glClear(GL_COLOR_BUFFER_BIT); //f32 aspect = frameSize.x/frameSize.y;
f32 aspect = 800/(f32)600;
static float alpha = 0;
//f32 aspect = frameSize.x/frameSize.y; GLfloat matrix[] = {cosf(alpha)/aspect, sinf(alpha), 0, 0,
f32 aspect = 800/(f32)600; -sinf(alpha)/aspect, cosf(alpha), 0, 0,
0, 0, 1, 0,
glViewport(0, 0, 800, 600); 0, 0, 0, 1};
GLfloat matrix[] = {cosf(alpha)/aspect, sinf(alpha), 0, 0, alpha += 2*M_PI/120;
-sinf(alpha)/aspect, cosf(alpha), 0, 0,
0, 0, 1, 0, glUniformMatrix4fv(0, 1, false, matrix);
0, 0, 0, 1};
alpha += 2*M_PI/120; glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glUniformMatrix4fv(0, 1, false, matrix); glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); mg_surface_present(surface);
glEnableVertexAttribArray(0); }
glDrawArrays(GL_TRIANGLES, 0, 3); mp_terminate();
mg_surface_present(surface); return(0);
} }
mp_terminate();
return(0);
}

143
src/egl_surface.c Normal file
View File

@ -0,0 +1,143 @@
/************************************************************//**
*
* @file: egl_surface.cpp
* @author: Martin Fouilleul
* @date: 17/02/2023
* @revision:
*
*****************************************************************/
#define EGL_EGLEXT_PROTOTYPES
#include<EGL/egl.h>
#include<EGL/eglext.h>
#include"graphics_internal.h"
#include"gl_loader.h"
typedef struct mg_egl_surface
{
mg_surface_data interface;
void* nativeSurface;
EGLDisplay eglDisplay;
EGLConfig eglConfig;
EGLContext eglContext;
EGLSurface eglSurface;
mg_gl_api api;
} mg_egl_surface;
#if OS_MACOS
#include"osx_app.h"
void* mg_egl_get_native_surface(mp_window_data* window)
{
return((void*)window->osx.nsView);
}
#elif OS_WIN64
#include"win32_app.h"
void* mg_egl_get_native_surface(mp_window_data* window)
{
return((void*)window->win32.hWnd);
}
#endif
void mg_egl_surface_destroy(mg_surface_data* interface)
{
//////////////////////////////////////////////////
//TODO
//////////////////////////////////////////////////
}
void mg_egl_surface_prepare(mg_surface_data* interface)
{
mg_egl_surface* surface = (mg_egl_surface*)interface;
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);
mg_gl_select_api(&surface->api);
}
void mg_egl_surface_present(mg_surface_data* interface)
{
mg_egl_surface* surface = (mg_egl_surface*)interface;
eglSwapBuffers(surface->eglDisplay, surface->eglSurface);
}
/*
mp_rect mg_egl_surface_get_frame(mg_surface_data* interface);
void mg_egl_surface_set_frame(mg_surface_data* interface, mp_rect frame);
void mg_egl_surface_set_hidden(mg_surface_data* interface, bool hidden);
bool mg_egl_surface_get_hidden(mg_surface_data* interface);
*/
mg_surface mg_egl_surface_create_for_window(mp_window window)
{
mg_surface res = mg_surface_nil();
mp_window_data* windowData = mp_window_ptr_from_handle(window);
if(windowData)
{
mg_egl_surface* surface = malloc_type(mg_egl_surface);
memset(surface, 0, sizeof(mg_egl_surface));
surface->interface.backend = MG_BACKEND_GLES;
surface->interface.destroy = mg_egl_surface_destroy;
surface->interface.prepare = mg_egl_surface_prepare;
surface->interface.present = mg_egl_surface_present;
/*TODO
surface->interface.getFrame = mg_egl_surface_get_frame;
surface->interface.setFrame = mg_egl_surface_set_frame;
surface->interface.getHidden = mg_egl_surface_get_hidden;
surface->interface.setHidden = mg_egl_surface_set_hidden;
*/
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};
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
eglInitialize(surface->eglDisplay, NULL, NULL);
EGLint const configAttributes[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_STENCIL_SIZE, 8,
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, EGL_DONT_CARE,
EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT,
EGL_NONE };
int numConfigs = 0;
eglChooseConfig(surface->eglDisplay, configAttributes, &surface->eglConfig, 1, &numConfigs);
EGLint const surfaceAttributes[] = {EGL_NONE};
surface->eglSurface = eglCreateWindowSurface(surface->eglDisplay, surface->eglConfig, surface->nativeSurface, surfaceAttributes);
eglBindAPI(EGL_OPENGL_ES_API);
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE,
EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,
EGL_NONE};
surface->eglContext = eglCreateContext(surface->eglDisplay, surface->eglConfig, EGL_NO_CONTEXT, contextAttributes);
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);
mg_gl_load_gles32(&surface->api, (mg_gl_load_proc)eglGetProcAddress);
eglSwapInterval(surface->eglDisplay, 1);
res = mg_surface_alloc_handle((mg_surface_data*)surface);
}
return(res);
}

17
src/egl_surface.h Normal file
View File

@ -0,0 +1,17 @@
/************************************************************//**
*
* @file: egl_surface.h
* @author: Martin Fouilleul
* @date: 28/01/2023
* @revision:
*
*****************************************************************/
#ifndef __EGL_SURFACE_H_
#define __EGL_SURFACE_H_
#include"graphics.h"
#include"mp_app.h"
mg_surface mg_egl_surface_create_for_window(mp_window window);
#endif // __EGL_SURFACE_H_

View File

@ -5,7 +5,7 @@
* @date: 16/022023 * @date: 16/022023
* *
/********************************************************/ /********************************************************/
#include"gl_api.h" #include"gl_loader.h"
#include"platform.h" #include"platform.h"
mp_thread_local mg_gl_api* __mgGLAPI = 0; mp_thread_local mg_gl_api* __mgGLAPI = 0;
@ -1719,4 +1719,3 @@ 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; }

View File

@ -2,7 +2,7 @@
* *
* file: glsl_shaders.h * file: glsl_shaders.h
* note: string literals auto-generated by embed_text.py * note: string literals auto-generated by embed_text.py
* date: 16/022023 * date: 17/022023
* *
**********************************************************************/ **********************************************************************/
#ifndef __GLSL_SHADERS_H__ #ifndef __GLSL_SHADERS_H__

View File

@ -302,6 +302,10 @@ mg_font_data* mg_font_data_from_handle(mg_font font)
#endif #endif
#endif #endif
#if MG_COMPILE_BACKEND_GLES
#include"egl_surface.h"
#endif
#if MG_COMPILE_BACKEND_METAL #if MG_COMPILE_BACKEND_METAL
#include"mtl_surface.h" #include"mtl_surface.h"
#endif #endif
@ -361,6 +365,12 @@ mg_surface mg_surface_create_for_window(mp_window window, mg_backend_id backend)
break; break;
#endif #endif
#if MG_COMPILE_BACKEND_GLES
case MG_BACKEND_GLES:
surface = mg_egl_surface_create_for_window(window);
break;
#endif
#if MG_COMPILE_BACKEND_METAL #if MG_COMPILE_BACKEND_METAL
case MG_METAL_BACKEND: case MG_METAL_BACKEND:
surface = mg_mtl_surface_create_for_window(window); surface = mg_mtl_surface_create_for_window(window);

View File

@ -46,6 +46,10 @@ typedef enum {
#define MG_COMPILE_BACKEND_GL 1 #define MG_COMPILE_BACKEND_GL 1
#endif #endif
#ifndef MG_COMPILE_BACKEND_GLES
#define MG_COMPILE_BACKEND_GLES 1
#endif
#if MG_COMPILE_BACKEND_GL #if MG_COMPILE_BACKEND_GL
#define MG_BACKEND_DEFAULT MG_BACKEND_GL #define MG_BACKEND_DEFAULT MG_BACKEND_GL
#else #else

View File

@ -55,10 +55,17 @@
#include"win32_app.c" #include"win32_app.c"
#include"graphics.c" #include"graphics.c"
#if MG_COMPILE_BACKEND_GL || MG_COMPILE_BACKEND_GLES
#include"gl_loader.c"
#endif
#if MG_COMPILE_BACKEND_GL #if MG_COMPILE_BACKEND_GL
#include"wgl_surface.c" #include"wgl_surface.c"
#include"gl_canvas.c" #include"gl_canvas.c"
#include"gl_loader.c" #endif
#if MG_COMPILE_BACKEND_GLES
#include"egl_surface.c"
#endif #endif
#elif defined(OS_MACOS) #elif defined(OS_MACOS)

View File

@ -39,7 +39,9 @@
#include"graphics.h" #include"graphics.h"
#if defined(OS_WIN64) #if defined(OS_WIN64)
#include"gl_api.h" #ifdef MG_INCLUDE_GL_API
#include"gl_api.h"
#endif
#endif #endif
//#include"ui.h" //#include"ui.h"

View File

@ -7,7 +7,8 @@ Overview
[.] Make backend selection easier [.] Make backend selection easier
[x] rename backend-specific files with api prefix (e.g. egl_, nsgl_, wgl_, mtl_, ...) [x] rename backend-specific files with api prefix (e.g. egl_, nsgl_, wgl_, mtl_, ...)
[x] option macros to select surface/canvas backends to compile into milepost lib [x] option macros to select surface/canvas backends to compile into milepost lib
[/] option macros to select backend-specific APIs to include when building an app [.] option macros to select backend-specific APIs to include when building an app
(ie, include gl_api.h when using gl backend)
[x] surface/canvas functions that take a backend id [x] surface/canvas functions that take a backend id
[x] feature-detection functions to know what surface/canvas backends are available at run-time [x] feature-detection functions to know what surface/canvas backends are available at run-time
[>] write doc about these options [>] write doc about these options
@ -17,12 +18,18 @@ Overview
[ ] Baked fonts? [ ] Baked fonts?
[x] Allow different versions of GL/GLES to co-exist [x] Allow different versions of GL/GLES to co-exist
[!] Keep dummy window/dummy context around for gl context creation, and don't reload wgl functions every time [>] Allow selecting version of GL/GLES context when creating surface
- pass/set attributes when creating surface?
[/] Keep dummy window/dummy context around for gl context creation, and don't reload wgl functions every time
[>] Reintroduce GLES surface [>] Reintroduce GLES surface
[>] 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 [?] Backport canvas to GLES
[ ] Back surface by child windows and implement moving frame/hiding/overlay
[ ] Delegated drawing API+Impl [ ] Delegated drawing API+Impl