Skip to content

Commit c56247f

Browse files
authored
ogc: add OpenGL 1.1 support via opengx (#74)
1 parent 9ca06e0 commit c56247f

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,13 @@ elseif(OGC)
29362936
list(APPEND SOURCE_FILES ${OGC_VIDEO_SOURCES})
29372937
set(SDL_VIDEO_OPENGL 0)
29382938
set(HAVE_SDL_VIDEO TRUE)
2939+
if(SDL_OPENGL)
2940+
pkg_search_module(OPENGX opengl REQUIRED IMPORTED_TARGET)
2941+
set(SDL_VIDEO_OPENGL 1)
2942+
set(HAVE_OPENGL TRUE)
2943+
list(APPEND EXTRA_LIBS "opengx")
2944+
target_include_directories(sdl-build-options INTERFACE ${OPENGX_INCLUDE_DIRS})
2945+
endif()
29392946
endif()
29402947

29412948
if(NOT SDL2_DISABLE_SDL2MAIN)

src/video/ogc/SDL_ogcgl.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
#include "../../SDL_internal.h"
22+
23+
#if defined(SDL_VIDEO_DRIVER_OGC) && defined(SDL_VIDEO_OPENGL)
24+
25+
#include "../SDL_sysvideo.h"
26+
27+
#include "SDL_ogcgl.h"
28+
#include "SDL_ogcvideo.h"
29+
30+
#include <opengx.h>
31+
32+
typedef struct
33+
{
34+
SDL_Window *window;
35+
int swap_interval;
36+
} OGC_GL_Context;
37+
38+
int SDL_OGC_GL_LoadLibrary(_THIS, const char *path)
39+
{
40+
return 0;
41+
}
42+
43+
void *SDL_OGC_GL_GetProcAddress(_THIS, const char *proc)
44+
{
45+
return ogx_get_proc_address(proc);
46+
}
47+
48+
void SDL_OGC_GL_UnloadLibrary(_THIS)
49+
{
50+
// nothing to do
51+
}
52+
53+
SDL_GLContext SDL_OGC_GL_CreateContext(_THIS, SDL_Window * window)
54+
{
55+
OGC_GL_Context *context = SDL_calloc(1, sizeof(*context));
56+
context->window = window;
57+
context->swap_interval = 1;
58+
ogx_initialize();
59+
return context;
60+
}
61+
62+
int SDL_OGC_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
63+
{
64+
return 0;
65+
}
66+
67+
int SDL_OGC_GL_SetSwapInterval(_THIS, int interval)
68+
{
69+
OGC_GL_Context *context = _this->current_glctx;
70+
context->swap_interval = interval;
71+
return 0;
72+
}
73+
74+
int SDL_OGC_GL_GetSwapInterval(_THIS)
75+
{
76+
OGC_GL_Context *context = _this->current_glctx;
77+
return context->swap_interval;
78+
}
79+
80+
int SDL_OGC_GL_SwapWindow(_THIS, SDL_Window * window)
81+
{
82+
OGC_GL_Context *context = _this->current_glctx;
83+
84+
bool vsync = context->swap_interval == 1;
85+
OGC_video_flip(_this, vsync);
86+
return 0;
87+
}
88+
89+
void SDL_OGC_GL_DeleteContext(_THIS, SDL_GLContext context)
90+
{
91+
SDL_free(context);
92+
}
93+
94+
void SDL_OGC_GL_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
95+
{
96+
*mask = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY;
97+
*major = 1;
98+
*minor = 1;
99+
}
100+
101+
#endif /* SDL_VIDEO_DRIVER_OGC */

src/video/ogc/SDL_ogcgl.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#ifndef SDL_OGC_gl_h_
23+
#define SDL_OGC_gl_h_
24+
25+
#ifdef SDL_VIDEO_OPENGL
26+
27+
#include "../SDL_sysvideo.h"
28+
29+
int SDL_OGC_GL_LoadLibrary(_THIS, const char *path);
30+
void *SDL_OGC_GL_GetProcAddress(_THIS, const char *proc);
31+
void SDL_OGC_GL_UnloadLibrary(_THIS);
32+
SDL_GLContext SDL_OGC_GL_CreateContext(_THIS, SDL_Window * window);
33+
int SDL_OGC_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
34+
int SDL_OGC_GL_SetSwapInterval(_THIS, int interval);
35+
int SDL_OGC_GL_GetSwapInterval(_THIS);
36+
int SDL_OGC_GL_SwapWindow(_THIS, SDL_Window * window);
37+
void SDL_OGC_GL_DeleteContext(_THIS, SDL_GLContext context);
38+
void SDL_OGC_GL_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);
39+
40+
#endif /* SDL_VIDEO_OPENGL */
41+
42+
#endif /* SDL_OGC_gl_h_ */
43+
44+
/* vi: set ts=4 sw=4 expandtab: */

src/video/ogc/SDL_ogcvideo.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "SDL_hints.h"
3232
#include "SDL_ogcevents_c.h"
3333
#include "SDL_ogcframebuffer_c.h"
34+
#include "SDL_ogcgl.h"
3435
#include "SDL_ogcgxcommon.h"
3536
#include "SDL_ogcmouse.h"
3637
#include "SDL_ogcvideo.h"
@@ -241,6 +242,19 @@ static SDL_VideoDevice *OGC_CreateDevice(void)
241242
device->UpdateWindowFramebuffer = SDL_OGC_UpdateWindowFramebuffer;
242243
device->DestroyWindowFramebuffer = SDL_OGC_DestroyWindowFramebuffer;
243244

245+
#ifdef SDL_VIDEO_OPENGL
246+
device->GL_LoadLibrary = SDL_OGC_GL_LoadLibrary;
247+
device->GL_GetProcAddress = SDL_OGC_GL_GetProcAddress;
248+
device->GL_UnloadLibrary = SDL_OGC_GL_UnloadLibrary;
249+
device->GL_CreateContext = SDL_OGC_GL_CreateContext;
250+
device->GL_MakeCurrent = SDL_OGC_GL_MakeCurrent;
251+
device->GL_SetSwapInterval = SDL_OGC_GL_SetSwapInterval;
252+
device->GL_GetSwapInterval = SDL_OGC_GL_GetSwapInterval;
253+
device->GL_SwapWindow = SDL_OGC_GL_SwapWindow;
254+
device->GL_DeleteContext = SDL_OGC_GL_DeleteContext;
255+
device->GL_DefaultProfileConfig = SDL_OGC_GL_DefaultProfileConfig;
256+
#endif
257+
244258
device->free = OGC_DeleteDevice;
245259

246260
return device;

0 commit comments

Comments
 (0)