hardcode GL/GLES versions per-platform for now

This commit is contained in:
martinfouilleul 2023-02-22 18:30:10 +01:00
parent 4b9b182762
commit 1250dfd7c1
7 changed files with 1100 additions and 1092 deletions

View File

@ -20,7 +20,7 @@ loaderHeaderPath = args.directory + '/' + loaderName + '.h'
loaderCPath = args.directory + '/' + loaderName + '.c' loaderCPath = args.directory + '/' + loaderName + '.c'
#--------------------------------------------------------------- #---------------------------------------------------------------
#NOTE: gather all GL functions in OpenGL 4.3 #NOTE: gather all GL functions in GL 4.1, 4.3, and GLES 3.0 and 3.1
#--------------------------------------------------------------- #---------------------------------------------------------------
def gather_api(tree, api, version): def gather_api(tree, api, version):
@ -44,10 +44,10 @@ tree = et.parse(args.spec)
gl41 = gather_api(tree, 'gl', 4.1) gl41 = gather_api(tree, 'gl', 4.1)
gl43 = gather_api(tree, 'gl', 4.3) gl43 = gather_api(tree, 'gl', 4.3)
gles31 = gather_api(tree, 'gles2', 3.1) gles30 = gather_api(tree, 'gles2', 3.1)
gles32 = gather_api(tree, 'gles2', 3.2) gles31 = gather_api(tree, 'gles2', 3.2)
glall = list(set().union(gl41, gl43, gles31, gles32)) glall = list(set().union(gl41, gl43, gles30, gles31))
#--------------------------------------------------------------- #---------------------------------------------------------------
@ -122,8 +122,8 @@ f.write("typedef void*(*mg_gl_load_proc)(const char* name);\n\n")
f.write("void mg_gl_load_gl41(mg_gl_api* api, mg_gl_load_proc loadProc);\n") f.write("void mg_gl_load_gl41(mg_gl_api* api, mg_gl_load_proc loadProc);\n")
f.write("void mg_gl_load_gl43(mg_gl_api* api, mg_gl_load_proc loadProc);\n") f.write("void mg_gl_load_gl43(mg_gl_api* api, mg_gl_load_proc loadProc);\n")
f.write("void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc);\n") f.write("void mg_gl_load_gles30(mg_gl_api* api, mg_gl_load_proc loadProc);\n")
f.write("void mg_gl_load_gles32(mg_gl_api* api, mg_gl_load_proc loadProc);\n\n") f.write("void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc);\n\n")
f.write("void mg_gl_select_api(mg_gl_api* api);\n\n") f.write("void mg_gl_select_api(mg_gl_api* api);\n\n")
@ -152,8 +152,8 @@ f.write("mp_thread_local mg_gl_api* __mgGLAPI = 0;\n\n")
emit_loader(f, 'gl41', gl41) emit_loader(f, 'gl41', gl41)
emit_loader(f, 'gl43', gl43) emit_loader(f, 'gl43', gl43)
emit_loader(f, 'gles30', gles30)
emit_loader(f, 'gles31', gles31) emit_loader(f, 'gles31', gles31)
emit_loader(f, 'gles32', gles32)
f.write("void mg_gl_select_api(mg_gl_api* api){ __mgGLAPI = api; }\n") f.write("void mg_gl_select_api(mg_gl_api* api){ __mgGLAPI = api; }\n")
f.write("mg_gl_api* mg_gl_get_api(void) { return(__mgGLAPI); }\n\n") f.write("mg_gl_api* mg_gl_get_api(void) { return(__mgGLAPI); }\n\n")

View File

@ -10,11 +10,27 @@
#define EGL_EGLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES
#include<EGL/egl.h> #include<EGL/egl.h>
#include<EGL/eglext.h> #include<EGL/eglext.h>
#include"mp_app_internal.h" #include"mp_app_internal.h"
#include"graphics_internal.h" #include"graphics_internal.h"
#include"gl_loader.h" #include"gl_loader.h"
#if OS_MACOS
//NOTE: EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE on osx defaults to CGL backend, which doesn't handle SwapInterval correctly
#define MG_EGL_PLATFORM_ANGLE_TYPE EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE
//NOTE: hardcode GLES versions for now
//TODO: use version hints, once we have all api versions correctly categorized by glapi.py
#define MG_GLES_VERSION_MAJOR 3
#define MG_GLES_VERSION_MINOR 0
#define mg_gl_load_gles mg_gl_load_gles30
#else
#define MG_EGL_PLATFORM_ANGLE_TYPE EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE
#define MG_GLES_VERSION_MAJOR 3
#define MG_GLES_VERSION_MINOR 1
#define mg_gl_load_gles mg_gl_load_gles31
#endif
typedef struct mg_egl_surface typedef struct mg_egl_surface
{ {
mg_surface_data interface; mg_surface_data interface;
@ -121,13 +137,6 @@ mg_surface mg_egl_surface_create_for_window(mp_window window)
mp_layer_init_for_window(&surface->layer, windowData); mp_layer_init_for_window(&surface->layer, windowData);
#if OS_MACOS
//NOTE: using EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE on osx defaults to CGL backend, which doesn't handle SwapInterval correctly
#define MG_EGL_PLATFORM_ANGLE_TYPE EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE
#else
#define MG_EGL_PLATFORM_ANGLE_TYPE EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE
#endif
EGLAttrib displayAttribs[] = { EGLAttrib displayAttribs[] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE, MG_EGL_PLATFORM_ANGLE_TYPE, EGL_PLATFORM_ANGLE_TYPE_ANGLE, MG_EGL_PLATFORM_ANGLE_TYPE,
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,
@ -160,8 +169,8 @@ 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, MG_GLES_VERSION_MAJOR,
EGL_CONTEXT_MINOR_VERSION_KHR, 0, EGL_CONTEXT_MINOR_VERSION_KHR, MG_GLES_VERSION_MINOR,
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,
@ -170,7 +179,7 @@ mg_surface mg_egl_surface_create_for_window(mp_window window)
surface->eglContext = eglCreateContext(surface->eglDisplay, surface->eglConfig, EGL_NO_CONTEXT, contextAttributes); surface->eglContext = eglCreateContext(surface->eglDisplay, surface->eglConfig, EGL_NO_CONTEXT, contextAttributes);
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext); eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);
mg_gl_load_gles32(&surface->api, (mg_gl_load_proc)eglGetProcAddress); mg_gl_load_gles(&surface->api, (mg_gl_load_proc)eglGetProcAddress);
eglSwapInterval(surface->eglDisplay, 1); eglSwapInterval(surface->eglDisplay, 1);

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
* *
* @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: 21/022023 * @date: 22/022023
* *
*********************************************************/ *********************************************************/
#include"gl_loader.h" #include"gl_loader.h"
@ -1038,7 +1038,7 @@ void mg_gl_load_gl43(mg_gl_api* api, mg_gl_load_proc loadProc)
api->GetPointerv = loadProc("glGetPointerv"); api->GetPointerv = loadProc("glGetPointerv");
} }
void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc) void mg_gl_load_gles30(mg_gl_api* api, mg_gl_load_proc loadProc)
{ {
api->ActiveTexture = loadProc("glActiveTexture"); api->ActiveTexture = loadProc("glActiveTexture");
api->AttachShader = loadProc("glAttachShader"); api->AttachShader = loadProc("glAttachShader");
@ -1356,7 +1356,7 @@ void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc)
api->VertexBindingDivisor = loadProc("glVertexBindingDivisor"); api->VertexBindingDivisor = loadProc("glVertexBindingDivisor");
} }
void mg_gl_load_gles32(mg_gl_api* api, mg_gl_load_proc loadProc) void mg_gl_load_gles31(mg_gl_api* api, mg_gl_load_proc loadProc)
{ {
api->ActiveTexture = loadProc("glActiveTexture"); api->ActiveTexture = loadProc("glActiveTexture");
api->AttachShader = loadProc("glAttachShader"); api->AttachShader = loadProc("glAttachShader");

View File

@ -2,7 +2,7 @@
* *
* @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: 21/022023 * @date: 22/022023
* *
*********************************************************/ *********************************************************/
#ifndef __GL_LOADER_H__ #ifndef __GL_LOADER_H__
@ -14,8 +14,8 @@ 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_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_gl43(mg_gl_api* api, mg_gl_load_proc loadProc);
void mg_gl_load_gles30(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_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); void mg_gl_select_api(mg_gl_api* 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: 21/022023 * date: 22/022023
* *
**********************************************************************/ **********************************************************************/
#ifndef __GLSL_SHADERS_H__ #ifndef __GLSL_SHADERS_H__

View File

@ -101,7 +101,6 @@ MP_API void mg_surface_set_frame(mg_surface surface, mp_rect frame);
MP_API bool mg_surface_get_hidden(mg_surface surface); MP_API bool mg_surface_get_hidden(mg_surface surface);
MP_API void mg_surface_set_hidden(mg_surface surface, bool hidden); MP_API void mg_surface_set_hidden(mg_surface surface, bool hidden);
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
//NOTE(martin): graphics canvas structs //NOTE(martin): graphics canvas structs
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------