src/video/haiku/SDL_bopengl.cc
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 17 Jun 2017 22:30:28 +0200
changeset 11107 a5fe51ef0877
parent 11063 43d5a039018f
child 11109 5f33dc4d399e
permissions -rw-r--r--
haiku: Added support for some values set with SDL_GL_SetAttribute().
     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 static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
    39     return ((SDL_BWin*)(window->driverdata));
    40 }
    41 
    42 static SDL_INLINE SDL_BApp *_GetBeApp() {
    43     return ((SDL_BApp*)be_app);
    44 }
    45 
    46 /* Passing a NULL path means load pointers from the application */
    47 int BE_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 *) info.id;
    58             _this->gl_config.driver_loaded = 1;
    59             SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
    60                     SDL_arraysize(_this->gl_config.driver_path));
    61         }
    62     }
    63     return 0;
    64 }
    65 
    66 void *BE_GL_GetProcAddress(_THIS, const char *proc)
    67 {
    68     if (_this->gl_config.dll_handle != NULL) {
    69         void *location = NULL;
    70         status_t err;
    71         if ((err =
    72             get_image_symbol((image_id) _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 
    89 int BE_GL_SwapWindow(_THIS, SDL_Window * window) {
    90     _ToBeWin(window)->SwapBuffers();
    91     return 0;
    92 }
    93 
    94 int BE_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 
   101 SDL_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     Uint32 gl_flags = BGL_RGB;
   106     if (_this->gl_config.alpha_size) {
   107         gl_flags |= BGL_ALPHA;
   108     }
   109     if (_this->gl_config.depth_size) {
   110         gl_flags |= BGL_DEPTH;
   111     }
   112     if (_this->gl_config.stencil_size) {
   113         gl_flags |= BGL_STENCIL;
   114     }
   115     if (_this->gl_config.double_buffer) {
   116         gl_flags |= BGL_DOUBLE;
   117     } else {
   118         gl_flags |= BGL_SINGLE;
   119     }
   120     if (_this->gl_config.accum_red_size ||
   121             _this->gl_config.accum_green_size ||
   122             _this->gl_config.accum_blue_size ||
   123             _this->gl_config.accum_alpha_size) {
   124         gl_flags |= BGL_ACCUM;
   125     }
   126     bwin->CreateGLView(gl_flags);
   127     return (SDL_GLContext)(bwin);
   128 }
   129 
   130 void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
   131     /* Currently, automatically unlocks the view */
   132     ((SDL_BWin*)context)->RemoveGLView();
   133 }
   134 
   135 
   136 int BE_GL_SetSwapInterval(_THIS, int interval) {
   137     /* TODO: Implement this, if necessary? */
   138     return SDL_Unsupported();
   139 }
   140 
   141 int BE_GL_GetSwapInterval(_THIS) {
   142     /* TODO: Implement this, if necessary? */
   143     return 0;
   144 }
   145 
   146 
   147 void BE_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. */
   155 void BE_GL_RebootContexts(_THIS) {
   156     SDL_Window *window = _this->windows;
   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 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
   171 
   172     int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
   173     {
   174         /*
   175            FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
   176          */
   177         switch (attrib) {
   178         case SDL_GL_RED_SIZE:
   179             glGetIntegerv(GL_RED_BITS, (GLint *) value);
   180             break;
   181         case SDL_GL_GREEN_SIZE:
   182             glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
   183             break;
   184         case SDL_GL_BLUE_SIZE:
   185             glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
   186             break;
   187         case SDL_GL_ALPHA_SIZE:
   188             glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
   189             break;
   190         case SDL_GL_DOUBLEBUFFER:
   191             glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
   192             break;
   193         case SDL_GL_BUFFER_SIZE:
   194             int v;
   195             glGetIntegerv(GL_RED_BITS, (GLint *) & v);
   196             *value = v;
   197             glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
   198             *value += v;
   199             glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
   200             *value += v;
   201             glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
   202             *value += v;
   203             break;
   204         case SDL_GL_DEPTH_SIZE:
   205             glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
   206             break;
   207         case SDL_GL_STENCIL_SIZE:
   208             glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
   209             break;
   210         case SDL_GL_ACCUM_RED_SIZE:
   211             glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
   212             break;
   213         case SDL_GL_ACCUM_GREEN_SIZE:
   214             glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
   215             break;
   216         case SDL_GL_ACCUM_BLUE_SIZE:
   217             glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
   218             break;
   219         case SDL_GL_ACCUM_ALPHA_SIZE:
   220             glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
   221             break;
   222         case SDL_GL_STEREO:
   223         case SDL_GL_MULTISAMPLEBUFFERS:
   224         case SDL_GL_MULTISAMPLESAMPLES:
   225         default:
   226             *value = 0;
   227             return (-1);
   228         }
   229         return 0;
   230     }
   231 
   232 #endif
   233 
   234 
   235 
   236 #ifdef __cplusplus
   237 }
   238 #endif
   239 
   240 #endif /* SDL_VIDEO_DRIVER_HAIKU */
   241 
   242 /* vi: set ts=4 sw=4 expandtab: */