SDL 2.0
SDL_bopengl.cc
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
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 SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL
24
25#include "SDL_bopengl.h"
26
27#include <unistd.h>
28#include <KernelKit.h>
29#include <OpenGLKit.h>
30#include "SDL_BWin.h"
31#include "../../main/haiku/SDL_BApp.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37
38static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
39 return ((SDL_BWin*)(window->driverdata));
40}
41
42static SDL_INLINE SDL_BApp *_GetBeApp() {
43 return ((SDL_BApp*)be_app);
44}
45
46/* Passing a NULL path means load pointers from the application */
47int HAIKU_GL_LoadLibrary(_THIS, const char *path)
48{
49/* FIXME: Is this working correctly? */
50 image_info info;
51 int32 cookie = 0;
52 while (get_next_image_info(0, &cookie, &info) == B_OK) {
53 void *location = NULL;
54 if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
55 &location) == B_OK) {
56
57 _this->gl_config.dll_handle = (void *) (size_t) info.id;
61 }
62 }
63 return 0;
64}
65
66void *HAIKU_GL_GetProcAddress(_THIS, const char *proc)
67{
69 void *location = NULL;
70 status_t err;
71 if ((err =
72 get_image_symbol((image_id) (size_t) _this->gl_config.dll_handle,
73 proc, B_SYMBOL_TYPE_ANY,
74 &location)) == B_OK) {
75 return location;
76 } else {
77 SDL_SetError("Couldn't find OpenGL symbol");
78 return NULL;
79 }
80 } else {
81 SDL_SetError("OpenGL library not loaded");
82 return NULL;
83 }
84}
85
86
87
88
89int HAIKU_GL_SwapWindow(_THIS, SDL_Window * window) {
90 _ToBeWin(window)->SwapBuffers();
91 return 0;
92}
93
94int HAIKU_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
95 SDL_BWin* win = (SDL_BWin*)context;
96 _GetBeApp()->SetCurrentContext(win ? win->GetGLView() : NULL);
97 return 0;
98}
99
100
101SDL_GLContext HAIKU_GL_CreateContext(_THIS, SDL_Window * window) {
102 /* FIXME: Not sure what flags should be included here; may want to have
103 most of them */
104 SDL_BWin *bwin = _ToBeWin(window);
105 Uint32 gl_flags = BGL_RGB;
107 gl_flags |= BGL_ALPHA;
108 }
110 gl_flags |= BGL_DEPTH;
111 }
113 gl_flags |= BGL_STENCIL;
114 }
116 gl_flags |= BGL_DOUBLE;
117 } else {
118 gl_flags |= BGL_SINGLE;
119 }
124 gl_flags |= BGL_ACCUM;
125 }
126 bwin->CreateGLView(gl_flags);
127 return (SDL_GLContext)(bwin);
128}
129
130void HAIKU_GL_DeleteContext(_THIS, SDL_GLContext context) {
131 /* Currently, automatically unlocks the view */
132 ((SDL_BWin*)context)->RemoveGLView();
133}
134
135
136int HAIKU_GL_SetSwapInterval(_THIS, int interval) {
137 /* TODO: Implement this, if necessary? */
138 return SDL_Unsupported();
139}
140
141int HAIKU_GL_GetSwapInterval(_THIS) {
142 /* TODO: Implement this, if necessary? */
143 return 0;
144}
145
146
147void HAIKU_GL_UnloadLibrary(_THIS) {
148 /* TODO: Implement this, if necessary? */
149}
150
151
152/* FIXME: This function is meant to clear the OpenGL context when the video
153 mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
154 currently in use. */
155void HAIKU_GL_RebootContexts(_THIS) {
157 while(window) {
158 SDL_BWin *bwin = _ToBeWin(window);
159 if(bwin->GetGLView()) {
160 bwin->LockLooper();
161 bwin->RemoveGLView();
162 bwin->CreateGLView(bwin->GetGLType());
163 bwin->UnlockLooper();
164 }
165 window = window->next;
166 }
167}
168
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL */
175
176/* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_SetError
#define SDL_strlcpy
#define SDL_Unsupported()
Definition: SDL_error.h:53
GLint location
GLsizei const GLchar *const * path
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
uint32_t Uint32
Definition: SDL_stdinc.h:203
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:193
#define NULL
Definition: begin_code.h:167
#define SDL_INLINE
Definition: begin_code.h:134
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
char driver_path[256]
Definition: SDL_sysvideo.h:354
struct SDL_VideoDevice::@262 gl_config
SDL_Window * windows
Definition: SDL_sysvideo.h:317
The type used to identify a window.
Definition: SDL_sysvideo.h:74
static screen_context_t context
Definition: video.c:25