src/video/haiku/SDL_bopengl.cc
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 18 Jun 2017 23:00:42 +0200
changeset 11109 5f33dc4d399e
parent 11107 a5fe51ef0877
child 11130 898db1eb3e3a
permissions -rw-r--r--
haiku: Removed unused internal function.

Its functionality is already in SDL_GL_GetAttribute().
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
slouken@7860
    38
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
slouken@10690
    39
    return ((SDL_BWin*)(window->driverdata));
nathanheisey@5931
    40
}
nathanheisey@5931
    41
slouken@7860
    42
static SDL_INLINE SDL_BApp *_GetBeApp() {
slouken@10690
    43
    return ((SDL_BApp*)be_app);
nathanheisey@5931
    44
}
nathanheisey@5931
    45
nathanheisey@5918
    46
/* Passing a NULL path means load pointers from the application */
nathanheisey@5918
    47
int BE_GL_LoadLibrary(_THIS, const char *path)
nathanheisey@5918
    48
{
nathanheisey@5939
    49
/* FIXME: Is this working correctly? */
slouken@10690
    50
    image_info info;
slouken@10690
    51
            int32 cookie = 0;
slouken@10690
    52
    while (get_next_image_info(0, &cookie, &info) == B_OK) {
slouken@10690
    53
        void *location = NULL;
slouken@10690
    54
        if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
slouken@10690
    55
                &location) == B_OK) {
nathanheisey@5936
    56
slouken@10690
    57
            _this->gl_config.dll_handle = (void *) info.id;
slouken@10690
    58
            _this->gl_config.driver_loaded = 1;
slouken@10690
    59
            SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
slouken@10690
    60
                    SDL_arraysize(_this->gl_config.driver_path));
slouken@10690
    61
        }
slouken@10690
    62
    }
slouken@10690
    63
    return 0;
nathanheisey@5918
    64
}
nathanheisey@5918
    65
nathanheisey@5918
    66
void *BE_GL_GetProcAddress(_THIS, const char *proc)
nathanheisey@5918
    67
{
slouken@10690
    68
    if (_this->gl_config.dll_handle != NULL) {
slouken@10690
    69
        void *location = NULL;
slouken@10690
    70
        status_t err;
slouken@10690
    71
        if ((err =
slouken@10690
    72
            get_image_symbol((image_id) _this->gl_config.dll_handle,
nathanheisey@5918
    73
                              proc, B_SYMBOL_TYPE_ANY,
nathanheisey@5918
    74
                              &location)) == B_OK) {
nathanheisey@5918
    75
            return location;
nathanheisey@5918
    76
        } else {
nathanheisey@5918
    77
                SDL_SetError("Couldn't find OpenGL symbol");
nathanheisey@5918
    78
                return NULL;
nathanheisey@5918
    79
        }
slouken@10690
    80
    } else {
slouken@10690
    81
        SDL_SetError("OpenGL library not loaded");
slouken@10690
    82
        return NULL;
slouken@10690
    83
    }
nathanheisey@5918
    84
}
nathanheisey@5918
    85
nathanheisey@5918
    86
nathanheisey@5934
    87
nathanheisey@5934
    88
slouken@10690
    89
int BE_GL_SwapWindow(_THIS, SDL_Window * window) {
nathanheisey@5934
    90
    _ToBeWin(window)->SwapBuffers();
slouken@10690
    91
    return 0;
nathanheisey@5934
    92
}
nathanheisey@5934
    93
nathanheisey@5934
    94
int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
icculus@10983
    95
    SDL_BWin* win = (SDL_BWin*)context;
icculus@10983
    96
    _GetBeApp()->SetCurrentContext(win ? win->GetGLView() : NULL);
slouken@10690
    97
    return 0;
nathanheisey@5934
    98
}
nathanheisey@5934
    99
nathanheisey@5934
   100
nathanheisey@5934
   101
SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
slouken@10690
   102
    /* FIXME: Not sure what flags should be included here; may want to have
slouken@10690
   103
       most of them */
slouken@10690
   104
    SDL_BWin *bwin = _ToBeWin(window);
philipp@11107
   105
    Uint32 gl_flags = BGL_RGB;
philipp@11107
   106
    if (_this->gl_config.alpha_size) {
philipp@11107
   107
        gl_flags |= BGL_ALPHA;
philipp@11107
   108
    }
philipp@11107
   109
    if (_this->gl_config.depth_size) {
philipp@11107
   110
        gl_flags |= BGL_DEPTH;
philipp@11107
   111
    }
philipp@11107
   112
    if (_this->gl_config.stencil_size) {
philipp@11107
   113
        gl_flags |= BGL_STENCIL;
philipp@11107
   114
    }
philipp@11107
   115
    if (_this->gl_config.double_buffer) {
philipp@11107
   116
        gl_flags |= BGL_DOUBLE;
philipp@11107
   117
    } else {
philipp@11107
   118
        gl_flags |= BGL_SINGLE;
philipp@11107
   119
    }
philipp@11107
   120
    if (_this->gl_config.accum_red_size ||
philipp@11107
   121
            _this->gl_config.accum_green_size ||
philipp@11107
   122
            _this->gl_config.accum_blue_size ||
philipp@11107
   123
            _this->gl_config.accum_alpha_size) {
philipp@11107
   124
        gl_flags |= BGL_ACCUM;
philipp@11107
   125
    }
philipp@11107
   126
    bwin->CreateGLView(gl_flags);
slouken@10690
   127
    return (SDL_GLContext)(bwin);
nathanheisey@5934
   128
}
nathanheisey@5934
   129
nathanheisey@5934
   130
void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
slouken@10690
   131
    /* Currently, automatically unlocks the view */
slouken@10690
   132
    ((SDL_BWin*)context)->RemoveGLView();
nathanheisey@5934
   133
}
nathanheisey@5934
   134
nathanheisey@5934
   135
nathanheisey@5934
   136
int BE_GL_SetSwapInterval(_THIS, int interval) {
slouken@10690
   137
    /* TODO: Implement this, if necessary? */
philipp@11063
   138
    return SDL_Unsupported();
nathanheisey@5934
   139
}
nathanheisey@5934
   140
nathanheisey@5934
   141
int BE_GL_GetSwapInterval(_THIS) {
slouken@10690
   142
    /* TODO: Implement this, if necessary? */
slouken@10690
   143
    return 0;
nathanheisey@5934
   144
}
nathanheisey@5934
   145
nathanheisey@5934
   146
nathanheisey@5934
   147
void BE_GL_UnloadLibrary(_THIS) {
slouken@10690
   148
    /* TODO: Implement this, if necessary? */
nathanheisey@5934
   149
}
nathanheisey@5934
   150
nathanheisey@5934
   151
nathanheisey@5939
   152
/* FIXME: This function is meant to clear the OpenGL context when the video
nathanheisey@5939
   153
   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
nathanheisey@5939
   154
   currently in use. */
nathanheisey@5938
   155
void BE_GL_RebootContexts(_THIS) {
slouken@10690
   156
    SDL_Window *window = _this->windows;
slouken@10690
   157
    while(window) {
slouken@10690
   158
        SDL_BWin *bwin = _ToBeWin(window);
slouken@10690
   159
        if(bwin->GetGLView()) {
slouken@10690
   160
            bwin->LockLooper();
slouken@10690
   161
            bwin->RemoveGLView();
philipp@11107
   162
            bwin->CreateGLView(bwin->GetGLType());
slouken@10690
   163
            bwin->UnlockLooper();
slouken@10690
   164
        }
slouken@10690
   165
        window = window->next;
slouken@10690
   166
    }
nathanheisey@5938
   167
}
nathanheisey@5934
   168
nathanheisey@5934
   169
nathanheisey@5919
   170
#ifdef __cplusplus
nathanheisey@5919
   171
}
nathanheisey@5919
   172
#endif
slouken@6044
   173
icculus@7981
   174
#endif /* SDL_VIDEO_DRIVER_HAIKU */
slouken@10690
   175
slouken@10690
   176
/* vi: set ts=4 sw=4 expandtab: */