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.
nathanheisey@5918
     1
/*
nathanheisey@5918
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
nathanheisey@5918
     4
nathanheisey@5918
     5
  This software is provided 'as-is', without any express or implied
nathanheisey@5918
     6
  warranty.  In no event will the authors be held liable for any damages
nathanheisey@5918
     7
  arising from the use of this software.
nathanheisey@5918
     8
nathanheisey@5918
     9
  Permission is granted to anyone to use this software for any purpose,
nathanheisey@5918
    10
  including commercial applications, and to alter it and redistribute it
nathanheisey@5918
    11
  freely, subject to the following restrictions:
nathanheisey@5918
    12
nathanheisey@5918
    13
  1. The origin of this software must not be misrepresented; you must not
nathanheisey@5918
    14
     claim that you wrote the original software. If you use this software
nathanheisey@5918
    15
     in a product, an acknowledgment in the product documentation would be
nathanheisey@5918
    16
     appreciated but is not required.
nathanheisey@5918
    17
  2. Altered source versions must be plainly marked as such, and must not be
nathanheisey@5918
    18
     misrepresented as being the original software.
nathanheisey@5918
    19
  3. This notice may not be removed or altered from any source distribution.
nathanheisey@5918
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@6044
    22
icculus@7981
    23
#if SDL_VIDEO_DRIVER_HAIKU
nathanheisey@5918
    24
nathanheisey@5918
    25
#include "SDL_bopengl.h"
nathanheisey@5918
    26
nathanheisey@5931
    27
#include <unistd.h>
nathanheisey@5931
    28
#include <KernelKit.h>
nathanheisey@5931
    29
#include <OpenGLKit.h>
nathanheisey@5931
    30
#include "SDL_BWin.h"
icculus@7981
    31
#include "../../main/haiku/SDL_BApp.h"
nathanheisey@5931
    32
nathanheisey@5919
    33
#ifdef __cplusplus
nathanheisey@5919
    34
extern "C" {
nathanheisey@5919
    35
#endif
nathanheisey@5918
    36
nathanheisey@5938
    37
nathanheisey@5938
    38
#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
nathanheisey@5938
    39
slouken@7860
    40
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
slouken@10690
    41
    return ((SDL_BWin*)(window->driverdata));
nathanheisey@5931
    42
}
nathanheisey@5931
    43
slouken@7860
    44
static SDL_INLINE SDL_BApp *_GetBeApp() {
slouken@10690
    45
    return ((SDL_BApp*)be_app);
nathanheisey@5931
    46
}
nathanheisey@5931
    47
nathanheisey@5918
    48
/* Passing a NULL path means load pointers from the application */
nathanheisey@5918
    49
int BE_GL_LoadLibrary(_THIS, const char *path)
nathanheisey@5918
    50
{
nathanheisey@5939
    51
/* FIXME: Is this working correctly? */
slouken@10690
    52
    image_info info;
slouken@10690
    53
            int32 cookie = 0;
slouken@10690
    54
    while (get_next_image_info(0, &cookie, &info) == B_OK) {
slouken@10690
    55
        void *location = NULL;
slouken@10690
    56
        if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
slouken@10690
    57
                &location) == B_OK) {
nathanheisey@5936
    58
slouken@10690
    59
            _this->gl_config.dll_handle = (void *) info.id;
slouken@10690
    60
            _this->gl_config.driver_loaded = 1;
slouken@10690
    61
            SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
slouken@10690
    62
                    SDL_arraysize(_this->gl_config.driver_path));
slouken@10690
    63
        }
slouken@10690
    64
    }
slouken@10690
    65
    return 0;
nathanheisey@5918
    66
}
nathanheisey@5918
    67
nathanheisey@5918
    68
void *BE_GL_GetProcAddress(_THIS, const char *proc)
nathanheisey@5918
    69
{
slouken@10690
    70
    if (_this->gl_config.dll_handle != NULL) {
slouken@10690
    71
        void *location = NULL;
slouken@10690
    72
        status_t err;
slouken@10690
    73
        if ((err =
slouken@10690
    74
            get_image_symbol((image_id) _this->gl_config.dll_handle,
nathanheisey@5918
    75
                              proc, B_SYMBOL_TYPE_ANY,
nathanheisey@5918
    76
                              &location)) == B_OK) {
nathanheisey@5918
    77
            return location;
nathanheisey@5918
    78
        } else {
nathanheisey@5918
    79
                SDL_SetError("Couldn't find OpenGL symbol");
nathanheisey@5918
    80
                return NULL;
nathanheisey@5918
    81
        }
slouken@10690
    82
    } else {
slouken@10690
    83
        SDL_SetError("OpenGL library not loaded");
slouken@10690
    84
        return NULL;
slouken@10690
    85
    }
nathanheisey@5918
    86
}
nathanheisey@5918
    87
nathanheisey@5918
    88
nathanheisey@5934
    89
nathanheisey@5934
    90
slouken@10690
    91
int BE_GL_SwapWindow(_THIS, SDL_Window * window) {
nathanheisey@5934
    92
    _ToBeWin(window)->SwapBuffers();
slouken@10690
    93
    return 0;
nathanheisey@5934
    94
}
nathanheisey@5934
    95
nathanheisey@5934
    96
int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
icculus@10983
    97
    SDL_BWin* win = (SDL_BWin*)context;
icculus@10983
    98
    _GetBeApp()->SetCurrentContext(win ? win->GetGLView() : NULL);
slouken@10690
    99
    return 0;
nathanheisey@5934
   100
}
nathanheisey@5934
   101
nathanheisey@5934
   102
nathanheisey@5934
   103
SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
slouken@10690
   104
    /* FIXME: Not sure what flags should be included here; may want to have
slouken@10690
   105
       most of them */
slouken@10690
   106
    SDL_BWin *bwin = _ToBeWin(window);
slouken@10690
   107
    bwin->CreateGLView(BGL_FLAGS);
slouken@10690
   108
    return (SDL_GLContext)(bwin);
nathanheisey@5934
   109
}
nathanheisey@5934
   110
nathanheisey@5934
   111
void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
slouken@10690
   112
    /* Currently, automatically unlocks the view */
slouken@10690
   113
    ((SDL_BWin*)context)->RemoveGLView();
nathanheisey@5934
   114
}
nathanheisey@5934
   115
nathanheisey@5934
   116
nathanheisey@5934
   117
int BE_GL_SetSwapInterval(_THIS, int interval) {
slouken@10690
   118
    /* TODO: Implement this, if necessary? */
philipp@11063
   119
    return SDL_Unsupported();
nathanheisey@5934
   120
}
nathanheisey@5934
   121
nathanheisey@5934
   122
int BE_GL_GetSwapInterval(_THIS) {
slouken@10690
   123
    /* TODO: Implement this, if necessary? */
slouken@10690
   124
    return 0;
nathanheisey@5934
   125
}
nathanheisey@5934
   126
nathanheisey@5934
   127
nathanheisey@5934
   128
void BE_GL_UnloadLibrary(_THIS) {
slouken@10690
   129
    /* TODO: Implement this, if necessary? */
nathanheisey@5934
   130
}
nathanheisey@5934
   131
nathanheisey@5934
   132
nathanheisey@5939
   133
/* FIXME: This function is meant to clear the OpenGL context when the video
nathanheisey@5939
   134
   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
nathanheisey@5939
   135
   currently in use. */
nathanheisey@5938
   136
void BE_GL_RebootContexts(_THIS) {
slouken@10690
   137
    SDL_Window *window = _this->windows;
slouken@10690
   138
    while(window) {
slouken@10690
   139
        SDL_BWin *bwin = _ToBeWin(window);
slouken@10690
   140
        if(bwin->GetGLView()) {
slouken@10690
   141
            bwin->LockLooper();
slouken@10690
   142
            bwin->RemoveGLView();
slouken@10690
   143
            bwin->CreateGLView(BGL_FLAGS);
slouken@10690
   144
            bwin->UnlockLooper();
slouken@10690
   145
        }
slouken@10690
   146
        window = window->next;
slouken@10690
   147
    }
nathanheisey@5938
   148
}
nathanheisey@5934
   149
nathanheisey@5934
   150
nathanheisey@5918
   151
#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
nathanheisey@5918
   152
nathanheisey@5918
   153
    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
nathanheisey@5918
   154
    {
nathanheisey@5918
   155
        /*
nathanheisey@5918
   156
           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
nathanheisey@5918
   157
         */
nathanheisey@5918
   158
        switch (attrib) {
nathanheisey@5918
   159
        case SDL_GL_RED_SIZE:
nathanheisey@5918
   160
            glGetIntegerv(GL_RED_BITS, (GLint *) value);
nathanheisey@5918
   161
            break;
nathanheisey@5918
   162
        case SDL_GL_GREEN_SIZE:
nathanheisey@5918
   163
            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   164
            break;
nathanheisey@5918
   165
        case SDL_GL_BLUE_SIZE:
nathanheisey@5918
   166
            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   167
            break;
nathanheisey@5918
   168
        case SDL_GL_ALPHA_SIZE:
nathanheisey@5918
   169
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   170
            break;
nathanheisey@5918
   171
        case SDL_GL_DOUBLEBUFFER:
nathanheisey@5918
   172
            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
nathanheisey@5918
   173
            break;
nathanheisey@5918
   174
        case SDL_GL_BUFFER_SIZE:
nathanheisey@5918
   175
            int v;
nathanheisey@5918
   176
            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
nathanheisey@5918
   177
            *value = v;
nathanheisey@5918
   178
            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
nathanheisey@5918
   179
            *value += v;
nathanheisey@5918
   180
            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
nathanheisey@5918
   181
            *value += v;
nathanheisey@5918
   182
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
nathanheisey@5918
   183
            *value += v;
nathanheisey@5918
   184
            break;
nathanheisey@5918
   185
        case SDL_GL_DEPTH_SIZE:
nathanheisey@5918
   186
            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
nathanheisey@5918
   187
            break;
nathanheisey@5918
   188
        case SDL_GL_STENCIL_SIZE:
nathanheisey@5918
   189
            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
nathanheisey@5918
   190
            break;
nathanheisey@5918
   191
        case SDL_GL_ACCUM_RED_SIZE:
nathanheisey@5918
   192
            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
nathanheisey@5918
   193
            break;
nathanheisey@5918
   194
        case SDL_GL_ACCUM_GREEN_SIZE:
nathanheisey@5918
   195
            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   196
            break;
nathanheisey@5918
   197
        case SDL_GL_ACCUM_BLUE_SIZE:
nathanheisey@5918
   198
            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   199
            break;
nathanheisey@5918
   200
        case SDL_GL_ACCUM_ALPHA_SIZE:
nathanheisey@5918
   201
            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   202
            break;
nathanheisey@5918
   203
        case SDL_GL_STEREO:
nathanheisey@5918
   204
        case SDL_GL_MULTISAMPLEBUFFERS:
nathanheisey@5918
   205
        case SDL_GL_MULTISAMPLESAMPLES:
nathanheisey@5918
   206
        default:
nathanheisey@5918
   207
            *value = 0;
nathanheisey@5918
   208
            return (-1);
nathanheisey@5918
   209
        }
nathanheisey@5918
   210
        return 0;
nathanheisey@5918
   211
    }
nathanheisey@5918
   212
nathanheisey@5931
   213
#endif
nathanheisey@5931
   214
nathanheisey@5931
   215
nathanheisey@5931
   216
nathanheisey@5919
   217
#ifdef __cplusplus
nathanheisey@5919
   218
}
nathanheisey@5919
   219
#endif
slouken@6044
   220
icculus@7981
   221
#endif /* SDL_VIDEO_DRIVER_HAIKU */
slouken@10690
   222
slouken@10690
   223
/* vi: set ts=4 sw=4 expandtab: */