src/video/haiku/SDL_bopengl.cc
author Sam Lantinga <slouken@libsdl.org>
Fri, 09 Dec 2016 01:47:43 -0800
changeset 10690 23a825f341e6
parent 9998 f67cf37e9cd4
child 10737 3406a0f8b041
permissions -rw-r--r--
Fixed bug 3513 - SDL_GL_SwapWindow does not return error status

Return an error code from SDL_GL_SwapWindow(), like the other SDL APIs.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2016 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     _GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
    98     return 0;
    99 }
   100 
   101 
   102 SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
   103     /* FIXME: Not sure what flags should be included here; may want to have
   104        most of them */
   105     SDL_BWin *bwin = _ToBeWin(window);
   106     bwin->CreateGLView(BGL_FLAGS);
   107     return (SDL_GLContext)(bwin);
   108 }
   109 
   110 void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
   111     /* Currently, automatically unlocks the view */
   112     ((SDL_BWin*)context)->RemoveGLView();
   113 }
   114 
   115 
   116 int BE_GL_SetSwapInterval(_THIS, int interval) {
   117     /* TODO: Implement this, if necessary? */
   118     return 0;
   119 }
   120 
   121 int BE_GL_GetSwapInterval(_THIS) {
   122     /* TODO: Implement this, if necessary? */
   123     return 0;
   124 }
   125 
   126 
   127 void BE_GL_UnloadLibrary(_THIS) {
   128     /* TODO: Implement this, if necessary? */
   129 }
   130 
   131 
   132 /* FIXME: This function is meant to clear the OpenGL context when the video
   133    mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
   134    currently in use. */
   135 void BE_GL_RebootContexts(_THIS) {
   136     SDL_Window *window = _this->windows;
   137     while(window) {
   138         SDL_BWin *bwin = _ToBeWin(window);
   139         if(bwin->GetGLView()) {
   140             bwin->LockLooper();
   141             bwin->RemoveGLView();
   142             bwin->CreateGLView(BGL_FLAGS);
   143             bwin->UnlockLooper();
   144         }
   145         window = window->next;
   146     }
   147 }
   148 
   149 
   150 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
   151 
   152     int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
   153     {
   154         /*
   155            FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
   156          */
   157         switch (attrib) {
   158         case SDL_GL_RED_SIZE:
   159             glGetIntegerv(GL_RED_BITS, (GLint *) value);
   160             break;
   161         case SDL_GL_GREEN_SIZE:
   162             glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
   163             break;
   164         case SDL_GL_BLUE_SIZE:
   165             glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
   166             break;
   167         case SDL_GL_ALPHA_SIZE:
   168             glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
   169             break;
   170         case SDL_GL_DOUBLEBUFFER:
   171             glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
   172             break;
   173         case SDL_GL_BUFFER_SIZE:
   174             int v;
   175             glGetIntegerv(GL_RED_BITS, (GLint *) & v);
   176             *value = v;
   177             glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
   178             *value += v;
   179             glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
   180             *value += v;
   181             glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
   182             *value += v;
   183             break;
   184         case SDL_GL_DEPTH_SIZE:
   185             glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
   186             break;
   187         case SDL_GL_STENCIL_SIZE:
   188             glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
   189             break;
   190         case SDL_GL_ACCUM_RED_SIZE:
   191             glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
   192             break;
   193         case SDL_GL_ACCUM_GREEN_SIZE:
   194             glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
   195             break;
   196         case SDL_GL_ACCUM_BLUE_SIZE:
   197             glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
   198             break;
   199         case SDL_GL_ACCUM_ALPHA_SIZE:
   200             glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
   201             break;
   202         case SDL_GL_STEREO:
   203         case SDL_GL_MULTISAMPLEBUFFERS:
   204         case SDL_GL_MULTISAMPLESAMPLES:
   205         default:
   206             *value = 0;
   207             return (-1);
   208         }
   209         return 0;
   210     }
   211 
   212 #endif
   213 
   214 
   215 
   216 #ifdef __cplusplus
   217 }
   218 #endif
   219 
   220 #endif /* SDL_VIDEO_DRIVER_HAIKU */
   221 
   222 /* vi: set ts=4 sw=4 expandtab: */