diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/haiku/SDL_bopengl.cc')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/haiku/SDL_bopengl.cc | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/haiku/SDL_bopengl.cc b/contrib/SDL-3.2.8/src/video/haiku/SDL_bopengl.cc new file mode 100644 index 0000000..469b7f6 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/haiku/SDL_bopengl.cc | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 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 defined(SDL_VIDEO_DRIVER_HAIKU) && defined(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 "../../core/haiku/SDL_BApp.h" | ||
| 32 | |||
| 33 | #ifdef __cplusplus | ||
| 34 | extern "C" { | ||
| 35 | #endif | ||
| 36 | |||
| 37 | |||
| 38 | static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) | ||
| 39 | { | ||
| 40 | return (SDL_BWin *)(window->internal); | ||
| 41 | } | ||
| 42 | |||
| 43 | static SDL_INLINE SDL_BLooper *_GetBeLooper() | ||
| 44 | { | ||
| 45 | return SDL_Looper; | ||
| 46 | } | ||
| 47 | |||
| 48 | // Passing a NULL path means load pointers from the application | ||
| 49 | bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_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 = (SDL_SharedObject *) (addr_t) 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 true; | ||
| 66 | } | ||
| 67 | |||
| 68 | SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) | ||
| 69 | { | ||
| 70 | if (_this->gl_config.dll_handle) { | ||
| 71 | void *location = NULL; | ||
| 72 | status_t err; | ||
| 73 | if ((err = | ||
| 74 | get_image_symbol((image_id) (addr_t) _this->gl_config.dll_handle, | ||
| 75 | proc, B_SYMBOL_TYPE_ANY, | ||
| 76 | &location)) == B_OK) { | ||
| 77 | return (SDL_FunctionPointer)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 | bool HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 90 | { | ||
| 91 | _ToBeWin(window)->SwapBuffers(); | ||
| 92 | return true; | ||
| 93 | } | ||
| 94 | |||
| 95 | bool HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context) | ||
| 96 | { | ||
| 97 | BGLView* glView = (BGLView*)context; | ||
| 98 | // printf("HAIKU_GL_MakeCurrent(%llx), win = %llx, thread = %d\n", (uint64)context, (uint64)window, find_thread(NULL)); | ||
| 99 | if (glView) { | ||
| 100 | if ((glView->Window() == NULL) || (!window) || (_ToBeWin(window)->GetGLView() != glView)) { | ||
| 101 | return SDL_SetError("MakeCurrent failed"); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | _GetBeLooper()->SetCurrentContext(glView); | ||
| 105 | return true; | ||
| 106 | } | ||
| 107 | |||
| 108 | |||
| 109 | SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window) | ||
| 110 | { | ||
| 111 | /* FIXME: Not sure what flags should be included here; may want to have | ||
| 112 | most of them */ | ||
| 113 | SDL_BWin *bwin = _ToBeWin(window); | ||
| 114 | // printf("HAIKU_GL_CreateContext, win = %llx, thread = %d\n", (uint64)window, find_thread(NULL)); | ||
| 115 | if (bwin->GetGLView() != NULL) { | ||
| 116 | SDL_SetError("Context already creaded"); | ||
| 117 | return NULL; | ||
| 118 | } | ||
| 119 | Uint32 gl_flags = BGL_RGB; | ||
| 120 | if (_this->gl_config.alpha_size) { | ||
| 121 | gl_flags |= BGL_ALPHA; | ||
| 122 | } | ||
| 123 | if (_this->gl_config.depth_size) { | ||
| 124 | gl_flags |= BGL_DEPTH; | ||
| 125 | } | ||
| 126 | if (_this->gl_config.stencil_size) { | ||
| 127 | gl_flags |= BGL_STENCIL; | ||
| 128 | } | ||
| 129 | if (_this->gl_config.double_buffer) { | ||
| 130 | gl_flags |= BGL_DOUBLE; | ||
| 131 | } else { | ||
| 132 | gl_flags |= BGL_SINGLE; | ||
| 133 | } | ||
| 134 | if (_this->gl_config.accum_red_size || | ||
| 135 | _this->gl_config.accum_green_size || | ||
| 136 | _this->gl_config.accum_blue_size || | ||
| 137 | _this->gl_config.accum_alpha_size) { | ||
| 138 | gl_flags |= BGL_ACCUM; | ||
| 139 | } | ||
| 140 | #if __GNUC__ > 3 | ||
| 141 | if (_this->gl_config.share_with_current_context) { | ||
| 142 | gl_flags |= BGL_SHARE_CONTEXT; | ||
| 143 | } | ||
| 144 | #endif | ||
| 145 | bwin->CreateGLView(gl_flags); | ||
| 146 | _GetBeLooper()->SetCurrentContext(bwin->GetGLView()); | ||
| 147 | return (SDL_GLContext)(bwin->GetGLView()); | ||
| 148 | } | ||
| 149 | |||
| 150 | bool HAIKU_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) | ||
| 151 | { | ||
| 152 | // printf("HAIKU_GL_DestroyContext(%llx), thread = %d\n", (uint64)context, find_thread(NULL)); | ||
| 153 | BGLView* glView = (BGLView*)context; | ||
| 154 | SDL_BWin *bwin = (SDL_BWin*)glView->Window(); | ||
| 155 | if (!bwin) { | ||
| 156 | delete glView; | ||
| 157 | } else { | ||
| 158 | bwin->RemoveGLView(); | ||
| 159 | } | ||
| 160 | return true; | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | bool HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) | ||
| 165 | { | ||
| 166 | // TODO: Implement this, if necessary? | ||
| 167 | return SDL_Unsupported(); | ||
| 168 | } | ||
| 169 | |||
| 170 | bool HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) | ||
| 171 | { | ||
| 172 | return SDL_Unsupported(); | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) | ||
| 177 | { | ||
| 178 | // TODO: Implement this, if necessary? | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | /* FIXME: This function is meant to clear the OpenGL context when the video | ||
| 183 | mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not | ||
| 184 | currently in use. */ | ||
| 185 | void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this) | ||
| 186 | { | ||
| 187 | SDL_Window *window = _this->windows; | ||
| 188 | while (window) { | ||
| 189 | SDL_BWin *bwin = _ToBeWin(window); | ||
| 190 | if (bwin->GetGLView()) { | ||
| 191 | bwin->LockLooper(); | ||
| 192 | bwin->RemoveGLView(); | ||
| 193 | bwin->CreateGLView(bwin->GetGLType()); | ||
| 194 | bwin->UnlockLooper(); | ||
| 195 | } | ||
| 196 | window = window->next; | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | |||
| 201 | #ifdef __cplusplus | ||
| 202 | } | ||
| 203 | #endif | ||
| 204 | |||
| 205 | #endif // SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL | ||
