From 46c9e3c84328b29a24b067bddef67a1f2f386359 Mon Sep 17 00:00:00 2001 From: TothBenoit Date: Fri, 26 Jul 2024 15:29:29 +0200 Subject: [PATCH] Added hasExtension and glMultiDrawElementsIndirectCount support for SDL --- libs/sdl/GLImports.h | 1 + libs/sdl/gl.c | 24 ++++++++++++++++++++++++ libs/sdl/sdl/GL.hx | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/libs/sdl/GLImports.h b/libs/sdl/GLImports.h index c6e1222e5..50be901ee 100644 --- a/libs/sdl/GLImports.h +++ b/libs/sdl/GLImports.h @@ -58,6 +58,7 @@ GL_IMPORT(glBindFragDataLocation, BINDFRAGDATALOCATION); GL_IMPORT(glGenVertexArrays, GENVERTEXARRAYS); GL_IMPORT(glBindVertexArray, BINDVERTEXARRAY); GL_IMPORT(glDeleteVertexArrays, DELETEVERTEXARRAYS); +GL_IMPORT(glGetStringi, GETSTRINGI); GL_IMPORT(glBeginQuery, BEGINQUERY); GL_IMPORT(glEndQuery, ENDQUERY); diff --git a/libs/sdl/gl.c b/libs/sdl/gl.c index 88c1fb2d4..4888c12bb 100644 --- a/libs/sdl/gl.c +++ b/libs/sdl/gl.c @@ -52,6 +52,10 @@ #include "GLImports.h" #undef GL_IMPORT #define GL_IMPORT(fun,t) fun = (PFNGL##t##PROC)SDL_GL_GetProcAddress(#fun); if( fun == NULL ) return 1 +#define GL_IMPORT_OPT(fun, t) PFNGL##t##PROC fun = NULL; if ( !fun ) { fun = (PFNGL##t##PROC)SDL_GL_GetProcAddress(#fun); if( fun == NULL ) hl_error("function not resolved"); } +#else +#define GL_IMPORT_OPT(fun, t) +#define glMultiDrawElementsIndirectCountARB(...) hl_error("function not resolved"); #endif static int GLLoadAPI() { @@ -576,6 +580,11 @@ HL_PRIM void HL_NAME(gl_multi_draw_elements_indirect)( int mode, int type, vbyte # endif } +HL_PRIM void HL_NAME(gl_multi_draw_elements_indirect_count)(int mode, int type, vbyte* data, vbyte* drawcount, int maxdrawcount, int stride) { + GL_IMPORT_OPT(glMultiDrawElementsIndirectCountARB, MULTIDRAWELEMENTSINDIRECTCOUNTARB) + glMultiDrawElementsIndirectCountARB(mode, type, data, drawcount, maxdrawcount, stride); +} + HL_PRIM int HL_NAME(gl_get_config_parameter)( int feature ) { switch( feature ) { case 0: @@ -595,6 +604,19 @@ HL_PRIM int HL_NAME(gl_get_config_parameter)( int feature ) { return -1; } +HL_PRIM bool HL_NAME(gl_has_extension)(vstring *name) { + const char* cname = hl_to_utf8(name->bytes); + GLint numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + for (int i = 0; i < numExtensions; i++) { + const char* ext = (const char*)glGetStringi(GL_EXTENSIONS, i); + if (ext && strcmp(cname, ext) == 0) { + return true; + } + } + return false; +} + // queries HL_PRIM vdynamic *HL_NAME(gl_create_query)() { @@ -784,6 +806,7 @@ DEFINE_PRIM(_VOID,gl_draw_elements_instanced,_I32 _I32 _I32 _I32 _I32); DEFINE_PRIM(_VOID,gl_draw_arrays,_I32 _I32 _I32); DEFINE_PRIM(_VOID,gl_draw_arrays_instanced,_I32 _I32 _I32 _I32); DEFINE_PRIM(_VOID,gl_multi_draw_elements_indirect, _I32 _I32 _BYTES _I32 _I32); +DEFINE_PRIM(_VOID,gl_multi_draw_elements_indirect_count, _I32 _I32 _BYTES _BYTES _I32 _I32); DEFINE_PRIM(_NULL(_I32),gl_create_vertex_array,_NO_ARG); DEFINE_PRIM(_VOID,gl_bind_vertex_array,_NULL(_I32)); DEFINE_PRIM(_VOID,gl_delete_vertex_array,_NULL(_I32)); @@ -803,3 +826,4 @@ DEFINE_PRIM(_I32, gl_get_program_resource_index, _NULL(_I32) _I32 _STRING); DEFINE_PRIM(_VOID, gl_shader_storage_block_binding, _NULL(_I32) _I32 _I32); DEFINE_PRIM(_I32, gl_get_config_parameter, _I32); +DEFINE_PRIM(_BOOL, gl_has_extension, _STRING); diff --git a/libs/sdl/sdl/GL.hx b/libs/sdl/sdl/GL.hx index 25a8d041e..3e1155645 100644 --- a/libs/sdl/sdl/GL.hx +++ b/libs/sdl/sdl/GL.hx @@ -39,6 +39,10 @@ class GL { return 0; } + public static function hasExtension( name : String ) : Bool { + return false; + } + public static function isContextLost() : Bool { return false; } @@ -405,6 +409,9 @@ class GL { public static function multiDrawElementsIndirect( mode : Int, type : Int, data : hl.Bytes, count : Int, stride : Int ) { } + public static function multiDrawElementsIndirectCount( mode : Int, type : Int, data : hl.Bytes, drawcount : hl.Bytes, maxdrawcount : Int, stride : Int ) { + } + // queries public static function createQuery() : Query { @@ -917,6 +924,7 @@ class GL { public static inline var READ_FRAMEBUFFER = 0x8CA8; public static inline var DRAW_FRAMEBUFFER = 0x8CA9; public static inline var DRAW_INDIRECT_BUFFER = 0x8F3F; + public static inline var PARAMETER_BUFFER = 0x80ee; public static inline var RGBA4 = 0x8056; public static inline var RGB5_A1 = 0x8057;