forked from libsdl-org/SDL
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSDL_ogcgl.c
More file actions
135 lines (111 loc) · 3.65 KB
/
SDL_ogcgl.c
File metadata and controls
135 lines (111 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
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;
/* Weak symbols for the opengx functions used by SDL, so that the client does
* not need to link to opengx, unless it actually uses OpenGL. */
void __attribute__((weak)) ogx_initialize(void)
{
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
"%s() called but opengx not used in build!", __func__);
}
void __attribute__((weak)) ogx_stencil_create(OgxStencilFlags)
{
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
"%s() called but opengx not used in build!", __func__);
}
void __attribute__((weak)) *ogx_get_proc_address(const char *)
{
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
"%s() called but opengx not used in build!", __func__);
return NULL;
}
int __attribute__((weak)) ogx_prepare_swap_buffers()
{
SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO,
"%s() called but opengx not used in build!", __func__);
return 0;
}
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();
glViewport(0, 0, window->w, window->h);
if (_this->gl_config.stencil_size > 0) {
OgxStencilFlags flags = 0; /* Don't care if Z gets dirty on discarded fragments */
if (_this->gl_config.stencil_size > 4) flags |= OGX_STENCIL_8BIT;
ogx_stencil_create(flags);
}
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 */