Skip to content

Commit

Permalink
Added hasExtension and glMultiDrawElementsIndirectCount support for SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
TothBenoit committed Jul 26, 2024
1 parent 54e97e3 commit 46c9e3c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/sdl/GLImports.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions libs/sdl/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:
Expand All @@ -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)() {
Expand Down Expand Up @@ -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));
Expand All @@ -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);
8 changes: 8 additions & 0 deletions libs/sdl/sdl/GL.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class GL {
return 0;
}

public static function hasExtension( name : String ) : Bool {
return false;
}

public static function isContextLost() : Bool {
return false;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 46c9e3c

Please sign in to comment.