Skip to content

Commit

Permalink
ogc: add OpenGL 1.1 support via opengx (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy authored Jul 2, 2024
1 parent 9ca06e0 commit c56247f
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,13 @@ elseif(OGC)
list(APPEND SOURCE_FILES ${OGC_VIDEO_SOURCES})
set(SDL_VIDEO_OPENGL 0)
set(HAVE_SDL_VIDEO TRUE)
if(SDL_OPENGL)
pkg_search_module(OPENGX opengl REQUIRED IMPORTED_TARGET)
set(SDL_VIDEO_OPENGL 1)
set(HAVE_OPENGL TRUE)
list(APPEND EXTRA_LIBS "opengx")
target_include_directories(sdl-build-options INTERFACE ${OPENGX_INCLUDE_DIRS})
endif()
endif()

if(NOT SDL2_DISABLE_SDL2MAIN)
Expand Down
101 changes: 101 additions & 0 deletions src/video/ogc/SDL_ogcgl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"

#if defined(SDL_VIDEO_DRIVER_OGC) && defined(SDL_VIDEO_OPENGL)

#include "../SDL_sysvideo.h"

#include "SDL_ogcgl.h"
#include "SDL_ogcvideo.h"

#include <opengx.h>

typedef struct
{
SDL_Window *window;
int swap_interval;
} OGC_GL_Context;

int SDL_OGC_GL_LoadLibrary(_THIS, const char *path)
{
return 0;
}

void *SDL_OGC_GL_GetProcAddress(_THIS, const char *proc)
{
return ogx_get_proc_address(proc);
}

void SDL_OGC_GL_UnloadLibrary(_THIS)
{
// nothing to do
}

SDL_GLContext SDL_OGC_GL_CreateContext(_THIS, SDL_Window * window)
{
OGC_GL_Context *context = SDL_calloc(1, sizeof(*context));
context->window = window;
context->swap_interval = 1;
ogx_initialize();
return context;
}

int SDL_OGC_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
return 0;
}

int SDL_OGC_GL_SetSwapInterval(_THIS, int interval)
{
OGC_GL_Context *context = _this->current_glctx;
context->swap_interval = interval;
return 0;
}

int SDL_OGC_GL_GetSwapInterval(_THIS)
{
OGC_GL_Context *context = _this->current_glctx;
return context->swap_interval;
}

int SDL_OGC_GL_SwapWindow(_THIS, SDL_Window * window)
{
OGC_GL_Context *context = _this->current_glctx;

bool vsync = context->swap_interval == 1;
OGC_video_flip(_this, vsync);
return 0;
}

void SDL_OGC_GL_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_free(context);
}

void SDL_OGC_GL_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
{
*mask = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY;
*major = 1;
*minor = 1;
}

#endif /* SDL_VIDEO_DRIVER_OGC */
44 changes: 44 additions & 0 deletions src/video/ogc/SDL_ogcgl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

#ifndef SDL_OGC_gl_h_
#define SDL_OGC_gl_h_

#ifdef SDL_VIDEO_OPENGL

#include "../SDL_sysvideo.h"

int SDL_OGC_GL_LoadLibrary(_THIS, const char *path);
void *SDL_OGC_GL_GetProcAddress(_THIS, const char *proc);
void SDL_OGC_GL_UnloadLibrary(_THIS);
SDL_GLContext SDL_OGC_GL_CreateContext(_THIS, SDL_Window * window);
int SDL_OGC_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
int SDL_OGC_GL_SetSwapInterval(_THIS, int interval);
int SDL_OGC_GL_GetSwapInterval(_THIS);
int SDL_OGC_GL_SwapWindow(_THIS, SDL_Window * window);
void SDL_OGC_GL_DeleteContext(_THIS, SDL_GLContext context);
void SDL_OGC_GL_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);

#endif /* SDL_VIDEO_OPENGL */

#endif /* SDL_OGC_gl_h_ */

/* vi: set ts=4 sw=4 expandtab: */
14 changes: 14 additions & 0 deletions src/video/ogc/SDL_ogcvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "SDL_hints.h"
#include "SDL_ogcevents_c.h"
#include "SDL_ogcframebuffer_c.h"
#include "SDL_ogcgl.h"
#include "SDL_ogcgxcommon.h"
#include "SDL_ogcmouse.h"
#include "SDL_ogcvideo.h"
Expand Down Expand Up @@ -241,6 +242,19 @@ static SDL_VideoDevice *OGC_CreateDevice(void)
device->UpdateWindowFramebuffer = SDL_OGC_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = SDL_OGC_DestroyWindowFramebuffer;

#ifdef SDL_VIDEO_OPENGL
device->GL_LoadLibrary = SDL_OGC_GL_LoadLibrary;
device->GL_GetProcAddress = SDL_OGC_GL_GetProcAddress;
device->GL_UnloadLibrary = SDL_OGC_GL_UnloadLibrary;
device->GL_CreateContext = SDL_OGC_GL_CreateContext;
device->GL_MakeCurrent = SDL_OGC_GL_MakeCurrent;
device->GL_SetSwapInterval = SDL_OGC_GL_SetSwapInterval;
device->GL_GetSwapInterval = SDL_OGC_GL_GetSwapInterval;
device->GL_SwapWindow = SDL_OGC_GL_SwapWindow;
device->GL_DeleteContext = SDL_OGC_GL_DeleteContext;
device->GL_DefaultProfileConfig = SDL_OGC_GL_DefaultProfileConfig;
#endif

device->free = OGC_DeleteDevice;

return device;
Expand Down

0 comments on commit c56247f

Please sign in to comment.