SDL_bopengl.cc (6258B)
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2014 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 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 38#define BGL_FLAGS BGL_RGB | BGL_DOUBLE 39 40static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { 41 return ((SDL_BWin*)(window->driverdata)); 42} 43 44static SDL_INLINE SDL_BApp *_GetBeApp() { 45 return ((SDL_BApp*)be_app); 46} 47 48/* Passing a NULL path means load pointers from the application */ 49int BE_GL_LoadLibrary(_THIS, const char *path) 50{ 51/* FIXME: Is this working correctly? */ 52 image_info info; 53 int32 cookie = 0; 54 while (get_next_image_info(0, &cookie, &info) == B_OK) { 55 void *location = NULL; 56 if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY, 57 &location) == B_OK) { 58 59 _this->gl_config.dll_handle = (void *) info.id; 60 _this->gl_config.driver_loaded = 1; 61 SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", 62 SDL_arraysize(_this->gl_config.driver_path)); 63 } 64 } 65 return 0; 66} 67 68void *BE_GL_GetProcAddress(_THIS, const char *proc) 69{ 70 if (_this->gl_config.dll_handle != NULL) { 71 void *location = NULL; 72 status_t err; 73 if ((err = 74 get_image_symbol((image_id) _this->gl_config.dll_handle, 75 proc, B_SYMBOL_TYPE_ANY, 76 &location)) == B_OK) { 77 return location; 78 } else { 79 SDL_SetError("Couldn't find OpenGL symbol"); 80 return NULL; 81 } 82 } else { 83 SDL_SetError("OpenGL library not loaded"); 84 return NULL; 85 } 86} 87 88 89 90 91void BE_GL_SwapWindow(_THIS, SDL_Window * window) { 92 _ToBeWin(window)->SwapBuffers(); 93} 94 95int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) { 96 _GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView()); 97 return 0; 98} 99 100 101SDL_GLContext BE_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 bwin->CreateGLView(BGL_FLAGS); 106 return (SDL_GLContext)(bwin); 107} 108 109void BE_GL_DeleteContext(_THIS, SDL_GLContext context) { 110 /* Currently, automatically unlocks the view */ 111 ((SDL_BWin*)context)->RemoveGLView(); 112} 113 114 115int BE_GL_SetSwapInterval(_THIS, int interval) { 116 /* TODO: Implement this, if necessary? */ 117 return 0; 118} 119 120int BE_GL_GetSwapInterval(_THIS) { 121 /* TODO: Implement this, if necessary? */ 122 return 0; 123} 124 125 126void BE_GL_UnloadLibrary(_THIS) { 127 /* TODO: Implement this, if necessary? */ 128} 129 130 131/* FIXME: This function is meant to clear the OpenGL context when the video 132 mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not 133 currently in use. */ 134void BE_GL_RebootContexts(_THIS) { 135 SDL_Window *window = _this->windows; 136 while(window) { 137 SDL_BWin *bwin = _ToBeWin(window); 138 if(bwin->GetGLView()) { 139 bwin->LockLooper(); 140 bwin->RemoveGLView(); 141 bwin->CreateGLView(BGL_FLAGS); 142 bwin->UnlockLooper(); 143 } 144 window = window->next; 145 } 146} 147 148 149#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */ 150 151 int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) 152 { 153 /* 154 FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values 155 */ 156 switch (attrib) { 157 case SDL_GL_RED_SIZE: 158 glGetIntegerv(GL_RED_BITS, (GLint *) value); 159 break; 160 case SDL_GL_GREEN_SIZE: 161 glGetIntegerv(GL_GREEN_BITS, (GLint *) value); 162 break; 163 case SDL_GL_BLUE_SIZE: 164 glGetIntegerv(GL_BLUE_BITS, (GLint *) value); 165 break; 166 case SDL_GL_ALPHA_SIZE: 167 glGetIntegerv(GL_ALPHA_BITS, (GLint *) value); 168 break; 169 case SDL_GL_DOUBLEBUFFER: 170 glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value); 171 break; 172 case SDL_GL_BUFFER_SIZE: 173 int v; 174 glGetIntegerv(GL_RED_BITS, (GLint *) & v); 175 *value = v; 176 glGetIntegerv(GL_GREEN_BITS, (GLint *) & v); 177 *value += v; 178 glGetIntegerv(GL_BLUE_BITS, (GLint *) & v); 179 *value += v; 180 glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v); 181 *value += v; 182 break; 183 case SDL_GL_DEPTH_SIZE: 184 glGetIntegerv(GL_DEPTH_BITS, (GLint *) value); /* Mesa creates 16 only? r5 always 32 */ 185 break; 186 case SDL_GL_STENCIL_SIZE: 187 glGetIntegerv(GL_STENCIL_BITS, (GLint *) value); 188 break; 189 case SDL_GL_ACCUM_RED_SIZE: 190 glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value); 191 break; 192 case SDL_GL_ACCUM_GREEN_SIZE: 193 glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value); 194 break; 195 case SDL_GL_ACCUM_BLUE_SIZE: 196 glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value); 197 break; 198 case SDL_GL_ACCUM_ALPHA_SIZE: 199 glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value); 200 break; 201 case SDL_GL_STEREO: 202 case SDL_GL_MULTISAMPLEBUFFERS: 203 case SDL_GL_MULTISAMPLESAMPLES: 204 default: 205 *value = 0; 206 return (-1); 207 } 208 return 0; 209 } 210 211#endif 212 213 214 215#ifdef __cplusplus 216} 217#endif 218 219#endif /* SDL_VIDEO_DRIVER_HAIKU */