Skip to content

Commit

Permalink
Added a userdata parameter for EGL attribute callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 1, 2024
1 parent 798c957 commit eced9f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
9 changes: 5 additions & 4 deletions include/SDL3/SDL_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ typedef int SDL_EGLint;
*
* \since This datatype is available since SDL 3.0.0.
*/
typedef SDL_EGLAttrib *(SDLCALL *SDL_EGLAttribArrayCallback)(void);
typedef SDL_EGLint *(SDLCALL *SDL_EGLIntArrayCallback)(void);
typedef SDL_EGLAttrib *(SDLCALL *SDL_EGLAttribArrayCallback)(void *userdata);
typedef SDL_EGLint *(SDLCALL *SDL_EGLIntArrayCallback)(void *userdata);

/**
* An enumeration of OpenGL configuration attributes.
Expand Down Expand Up @@ -2756,13 +2756,14 @@ extern SDL_DECLSPEC SDL_EGLSurface SDLCALL SDL_EGL_GetWindowSurface(SDL_Window *
* \param surfaceAttribCallback callback for attributes to pass to
* eglCreateSurface.
* \param contextAttribCallback callback for attributes to pass to
* eglCreateContext.
* eglCreateContext.
* \param userdata a pointer that is passed to the callbacks.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC void SDLCALL SDL_EGL_SetAttributeCallbacks(SDL_EGLAttribArrayCallback platformAttribCallback,
SDL_EGLIntArrayCallback surfaceAttribCallback,
SDL_EGLIntArrayCallback contextAttribCallback);
SDL_EGLIntArrayCallback contextAttribCallback, void *userdata);

/**
* Set the swap interval for the current OpenGL context.
Expand Down
2 changes: 1 addition & 1 deletion src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentConfig,(void),(),return)
SDL_DYNAPI_PROC(SDL_EGLDisplay,SDL_EGL_GetCurrentDisplay,(void),(),return)
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_EGL_GetProcAddress,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_EGLSurface,SDL_EGL_GetWindowSurface,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_EGL_SetAttributeCallbacks,(SDL_EGLAttribArrayCallback a, SDL_EGLIntArrayCallback b, SDL_EGLIntArrayCallback c),(a,b,c),)
SDL_DYNAPI_PROC(void,SDL_EGL_SetAttributeCallbacks,(SDL_EGLAttribArrayCallback a, SDL_EGLIntArrayCallback b, SDL_EGLIntArrayCallback c, void *d),(a,b,c,d),)
SDL_DYNAPI_PROC(bool,SDL_EnableScreenSaver,(void),(),return)
SDL_DYNAPI_PROC(void,SDL_EndGPUComputePass,(SDL_GPUComputePass *a),(a),)
SDL_DYNAPI_PROC(void,SDL_EndGPUCopyPass,(SDL_GPUCopyPass *a),(a),)
Expand Down
6 changes: 3 additions & 3 deletions src/video/SDL_egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ bool SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDis
if (_this->egl_data->eglGetPlatformDisplay) {
EGLAttrib *attribs = NULL;
if (_this->egl_platformattrib_callback) {
attribs = _this->egl_platformattrib_callback();
attribs = _this->egl_platformattrib_callback(_this->egl_attrib_callback_userdata);
if (!attribs) {
_this->gl_config.driver_loaded = 0;
*_this->gl_config.driver_path = '\0';
Expand Down Expand Up @@ -1038,7 +1038,7 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa
if (_this->egl_contextattrib_callback) {
const int maxAttribs = sizeof(attribs) / sizeof(attribs[0]);
EGLint *userAttribs, *userAttribP;
userAttribs = _this->egl_contextattrib_callback();
userAttribs = _this->egl_contextattrib_callback(_this->egl_attrib_callback_userdata);
if (!userAttribs) {
_this->gl_config.driver_loaded = 0;
*_this->gl_config.driver_path = '\0';
Expand Down Expand Up @@ -1264,7 +1264,7 @@ EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, Nat
if (_this->egl_surfaceattrib_callback) {
const int maxAttribs = sizeof(attribs) / sizeof(attribs[0]);
EGLint *userAttribs, *userAttribP;
userAttribs = _this->egl_surfaceattrib_callback();
userAttribs = _this->egl_surfaceattrib_callback(_this->egl_attrib_callback_userdata);
if (!userAttribs) {
_this->gl_config.driver_loaded = 0;
*_this->gl_config.driver_path = '\0';
Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_sysvideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ struct SDL_VideoDevice
SDL_EGLAttribArrayCallback egl_platformattrib_callback;
SDL_EGLIntArrayCallback egl_surfaceattrib_callback;
SDL_EGLIntArrayCallback egl_contextattrib_callback;
void *egl_attrib_callback_userdata;

/* * * */
// Cache current GL context; don't call the OS when it hasn't changed.
Expand Down
7 changes: 5 additions & 2 deletions src/video/SDL_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -4448,15 +4448,17 @@ void SDL_GL_DeduceMaxSupportedESProfile(int *major, int *minor)
}

void SDL_EGL_SetAttributeCallbacks(SDL_EGLAttribArrayCallback platformAttribCallback,
SDL_EGLIntArrayCallback surfaceAttribCallback,
SDL_EGLIntArrayCallback contextAttribCallback)
SDL_EGLIntArrayCallback surfaceAttribCallback,
SDL_EGLIntArrayCallback contextAttribCallback,
void *userdata)
{
if (!_this) {
return;
}
_this->egl_platformattrib_callback = platformAttribCallback;
_this->egl_surfaceattrib_callback = surfaceAttribCallback;
_this->egl_contextattrib_callback = contextAttribCallback;
_this->egl_attrib_callback_userdata = userdata;
}

void SDL_GL_ResetAttributes(void)
Expand All @@ -4468,6 +4470,7 @@ void SDL_GL_ResetAttributes(void)
_this->egl_platformattrib_callback = NULL;
_this->egl_surfaceattrib_callback = NULL;
_this->egl_contextattrib_callback = NULL;
_this->egl_attrib_callback_userdata = NULL;

_this->gl_config.red_size = 8;
_this->gl_config.green_size = 8;
Expand Down

0 comments on commit eced9f5

Please sign in to comment.