src/video/haiku/SDL_bopengl.cc
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 04 Jun 2017 23:15:13 +0200
changeset 11063 43d5a039018f
parent 10983 9f9160df4f1f
child 11107 a5fe51ef0877
permissions -rw-r--r--
Fixed SDL_GL_SetSwapInterval() returning success on two unsupported platforms.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2017 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
    34 extern "C" {
    35 #endif
    36 
    37 
    38 #define BGL_FLAGS BGL_RGB | BGL_DOUBLE
    39 
    40 static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
    41     return ((SDL_BWin*)(window->driverdata));
    42 }
    43 
    44 static SDL_INLINE SDL_BApp *_GetBeApp() {
    45     return ((SDL_BApp*)be_app);
    46 }
    47 
    48 /* Passing a NULL path means load pointers from the application */
    49 int 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 
    68 void *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 
    91 int BE_GL_SwapWindow(_THIS, SDL_Window * window) {
    92     _ToBeWin(window)->SwapBuffers();
    93     return 0;
    94 }
    95 
    96 int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
    97     SDL_BWin* win = (SDL_BWin*)context;
    98     _GetBeApp()->SetCurrentContext(win ? win->GetGLView() : NULL);
    99     return 0;
   100 }
   101 
   102 
   103 SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
   104     /* FIXME: Not sure what flags should be included here; may want to have
   105        most of them */
   106     SDL_BWin *bwin = _ToBeWin(window);
   107     bwin->CreateGLView(BGL_FLAGS);
   108     return (SDL_GLContext)(bwin);
   109 }
   110 
   111 void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
   112     /* Currently, automatically unlocks the view */
   113     ((SDL_BWin*)context)->RemoveGLView();
   114 }
   115 
   116 
   117 int BE_GL_SetSwapInterval(_THIS, int interval) {
   118     /* TODO: Implement this, if necessary? */
   119     return SDL_Unsupported();
   120 }
   121 
   122 int BE_GL_GetSwapInterval(_THIS) {
   123     /* TODO: Implement this, if necessary? */
   124     return 0;
   125 }
   126 
   127 
   128 void BE_GL_UnloadLibrary(_THIS) {
   129     /* TODO: Implement this, if necessary? */
   130 }
   131 
   132 
   133 /* FIXME: This function is meant to clear the OpenGL context when the video
   134    mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
   135    currently in use. */
   136 void BE_GL_RebootContexts(_THIS) {
   137     SDL_Window *window = _this->windows;
   138     while(window) {
   139         SDL_BWin *bwin = _ToBeWin(window);
   140         if(bwin->GetGLView()) {
   141             bwin->LockLooper();
   142             bwin->RemoveGLView();
   143             bwin->CreateGLView(BGL_FLAGS);
   144             bwin->UnlockLooper();
   145         }
   146         window = window->next;
   147     }
   148 }
   149 
   150 
   151 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
   152 
   153     int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
   154     {
   155         /*
   156            FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
   157          */
   158         switch (attrib) {
   159         case SDL_GL_RED_SIZE:
   160             glGetIntegerv(GL_RED_BITS, (GLint *) value);
   161             break;
   162         case SDL_GL_GREEN_SIZE:
   163             glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
   164             break;
   165         case SDL_GL_BLUE_SIZE:
   166             glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
   167             break;
   168         case SDL_GL_ALPHA_SIZE:
   169             glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
   170             break;
   171         case SDL_GL_DOUBLEBUFFER:
   172             glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
   173             break;
   174         case SDL_GL_BUFFER_SIZE:
   175             int v;
   176             glGetIntegerv(GL_RED_BITS, (GLint *) & v);
   177             *value = v;
   178             glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
   179             *value += v;
   180             glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
   181             *value += v;
   182             glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
   183             *value += v;
   184             break;
   185         case SDL_GL_DEPTH_SIZE:
   186             glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
   187             break;
   188         case SDL_GL_STENCIL_SIZE:
   189             glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
   190             break;
   191         case SDL_GL_ACCUM_RED_SIZE:
   192             glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
   193             break;
   194         case SDL_GL_ACCUM_GREEN_SIZE:
   195             glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
   196             break;
   197         case SDL_GL_ACCUM_BLUE_SIZE:
   198             glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
   199             break;
   200         case SDL_GL_ACCUM_ALPHA_SIZE:
   201             glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
   202             break;
   203         case SDL_GL_STEREO:
   204         case SDL_GL_MULTISAMPLEBUFFERS:
   205         case SDL_GL_MULTISAMPLESAMPLES:
   206         default:
   207             *value = 0;
   208             return (-1);
   209         }
   210         return 0;
   211     }
   212 
   213 #endif
   214 
   215 
   216 
   217 #ifdef __cplusplus
   218 }
   219 #endif
   220 
   221 #endif /* SDL_VIDEO_DRIVER_HAIKU */
   222 
   223 /* vi: set ts=4 sw=4 expandtab: */