src/video/bwindow/SDL_bopengl.cc
author Nathan Heisey <nathanheisey@gmail.com>
Mon, 22 Aug 2011 11:02:05 +0000
changeset 5939 d9e9c343d264
parent 5938 b85b6326c498
child 6037 2feab4874268
permissions -rw-r--r--
Partially cleaned out code
nathanheisey@5918
     1
/*
nathanheisey@5918
     2
  Simple DirectMedia Layer
nathanheisey@5918
     3
  Copyright (C) 1997-2011 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
*/
nathanheisey@5918
    21
nathanheisey@5918
    22
#include "SDL_bopengl.h"
nathanheisey@5918
    23
nathanheisey@5931
    24
#include <unistd.h>
nathanheisey@5931
    25
#include <KernelKit.h>
nathanheisey@5931
    26
#include <OpenGLKit.h>
nathanheisey@5931
    27
#include "SDL_BWin.h"
nathanheisey@5931
    28
#include "../../main/beos/SDL_BApp.h"
nathanheisey@5931
    29
nathanheisey@5919
    30
#ifdef __cplusplus
nathanheisey@5919
    31
extern "C" {
nathanheisey@5919
    32
#endif
nathanheisey@5918
    33
nathanheisey@5938
    34
nathanheisey@5938
    35
#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
nathanheisey@5938
    36
nathanheisey@5931
    37
static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
nathanheisey@5931
    38
	return ((SDL_BWin*)(window->driverdata));
nathanheisey@5931
    39
}
nathanheisey@5931
    40
nathanheisey@5931
    41
static inline SDL_BApp *_GetBeApp() {
nathanheisey@5931
    42
	return ((SDL_BApp*)be_app);
nathanheisey@5931
    43
}
nathanheisey@5931
    44
nathanheisey@5918
    45
/* Passing a NULL path means load pointers from the application */
nathanheisey@5918
    46
int BE_GL_LoadLibrary(_THIS, const char *path)
nathanheisey@5918
    47
{
nathanheisey@5939
    48
/* FIXME: Is this working correctly? */
nathanheisey@5935
    49
	image_info info;
nathanheisey@5935
    50
			int32 cookie = 0;
nathanheisey@5935
    51
	while (get_next_image_info(0, &cookie, &info) == B_OK) {
nathanheisey@5935
    52
		void *location = NULL;
nathanheisey@5935
    53
		if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
nathanheisey@5935
    54
				&location) == B_OK) {
nathanheisey@5936
    55
nathanheisey@5935
    56
			_this->gl_config.dll_handle = (void *) info.id;
nathanheisey@5935
    57
			_this->gl_config.driver_loaded = 1;
nathanheisey@5935
    58
			SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
nathanheisey@5935
    59
					SDL_arraysize(_this->gl_config.driver_path));
nathanheisey@5935
    60
		}
nathanheisey@5935
    61
	}
nathanheisey@5918
    62
}
nathanheisey@5918
    63
nathanheisey@5918
    64
void *BE_GL_GetProcAddress(_THIS, const char *proc)
nathanheisey@5918
    65
{
nathanheisey@5918
    66
	if (_this->gl_config.dll_handle != NULL) {
nathanheisey@5918
    67
		void *location = NULL;
nathanheisey@5918
    68
		status_t err;
nathanheisey@5918
    69
		if ((err =
nathanheisey@5918
    70
			get_image_symbol((image_id) _this->gl_config.dll_handle,
nathanheisey@5918
    71
                              proc, B_SYMBOL_TYPE_ANY,
nathanheisey@5918
    72
                              &location)) == B_OK) {
nathanheisey@5918
    73
            return location;
nathanheisey@5918
    74
        } else {
nathanheisey@5918
    75
                SDL_SetError("Couldn't find OpenGL symbol");
nathanheisey@5918
    76
                return NULL;
nathanheisey@5918
    77
        }
nathanheisey@5918
    78
	} else {
nathanheisey@5918
    79
		SDL_SetError("OpenGL library not loaded");
nathanheisey@5918
    80
		return NULL;
nathanheisey@5918
    81
	}
nathanheisey@5918
    82
}
nathanheisey@5918
    83
nathanheisey@5918
    84
nathanheisey@5934
    85
nathanheisey@5934
    86
nathanheisey@5934
    87
void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
nathanheisey@5934
    88
    _ToBeWin(window)->SwapBuffers();
nathanheisey@5934
    89
}
nathanheisey@5934
    90
nathanheisey@5934
    91
int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
nathanheisey@5934
    92
	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
nathanheisey@5934
    93
	return 0;
nathanheisey@5934
    94
}
nathanheisey@5934
    95
nathanheisey@5934
    96
nathanheisey@5934
    97
SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
nathanheisey@5934
    98
	/* FIXME: Not sure what flags should be included here; may want to have
nathanheisey@5934
    99
	   most of them */
nathanheisey@5934
   100
	SDL_BWin *bwin = _ToBeWin(window);
nathanheisey@5938
   101
	bwin->CreateGLView(BGL_FLAGS);
nathanheisey@5934
   102
	return (SDL_GLContext)(bwin);
nathanheisey@5934
   103
}
nathanheisey@5934
   104
nathanheisey@5934
   105
void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
nathanheisey@5934
   106
	/* Currently, automatically unlocks the view */
nathanheisey@5934
   107
	((SDL_BWin*)context)->RemoveGLView();
nathanheisey@5934
   108
}
nathanheisey@5934
   109
nathanheisey@5934
   110
nathanheisey@5934
   111
int BE_GL_SetSwapInterval(_THIS, int interval) {
nathanheisey@5939
   112
	/* TODO: Implement this, if necessary? */
nathanheisey@5934
   113
	return 0;
nathanheisey@5934
   114
}
nathanheisey@5934
   115
nathanheisey@5934
   116
int BE_GL_GetSwapInterval(_THIS) {
nathanheisey@5939
   117
	/* TODO: Implement this, if necessary? */
nathanheisey@5934
   118
	return 0;
nathanheisey@5934
   119
}
nathanheisey@5934
   120
nathanheisey@5934
   121
nathanheisey@5934
   122
void BE_GL_UnloadLibrary(_THIS) {
nathanheisey@5939
   123
	/* TODO: Implement this, if necessary? */
nathanheisey@5934
   124
}
nathanheisey@5934
   125
nathanheisey@5934
   126
nathanheisey@5939
   127
/* FIXME: This function is meant to clear the OpenGL context when the video
nathanheisey@5939
   128
   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
nathanheisey@5939
   129
   currently in use. */
nathanheisey@5938
   130
void BE_GL_RebootContexts(_THIS) {
nathanheisey@5938
   131
	SDL_Window *window = _this->windows;
nathanheisey@5938
   132
	while(window) {
nathanheisey@5938
   133
		SDL_BWin *bwin = _ToBeWin(window);
nathanheisey@5938
   134
		if(bwin->GetGLView()) {
nathanheisey@5938
   135
			bwin->LockLooper();
nathanheisey@5938
   136
			bwin->RemoveGLView();
nathanheisey@5938
   137
			bwin->CreateGLView(BGL_FLAGS);
nathanheisey@5938
   138
			bwin->UnlockLooper();
nathanheisey@5938
   139
		}
nathanheisey@5938
   140
		window = window->next;
nathanheisey@5938
   141
	}
nathanheisey@5938
   142
}
nathanheisey@5934
   143
nathanheisey@5934
   144
nathanheisey@5918
   145
#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
nathanheisey@5918
   146
nathanheisey@5918
   147
    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
nathanheisey@5918
   148
    {
nathanheisey@5918
   149
        /*
nathanheisey@5918
   150
           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
nathanheisey@5918
   151
         */
nathanheisey@5918
   152
        switch (attrib) {
nathanheisey@5918
   153
        case SDL_GL_RED_SIZE:
nathanheisey@5918
   154
            glGetIntegerv(GL_RED_BITS, (GLint *) value);
nathanheisey@5918
   155
            break;
nathanheisey@5918
   156
        case SDL_GL_GREEN_SIZE:
nathanheisey@5918
   157
            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   158
            break;
nathanheisey@5918
   159
        case SDL_GL_BLUE_SIZE:
nathanheisey@5918
   160
            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   161
            break;
nathanheisey@5918
   162
        case SDL_GL_ALPHA_SIZE:
nathanheisey@5918
   163
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   164
            break;
nathanheisey@5918
   165
        case SDL_GL_DOUBLEBUFFER:
nathanheisey@5918
   166
            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
nathanheisey@5918
   167
            break;
nathanheisey@5918
   168
        case SDL_GL_BUFFER_SIZE:
nathanheisey@5918
   169
            int v;
nathanheisey@5918
   170
            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
nathanheisey@5918
   171
            *value = v;
nathanheisey@5918
   172
            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
nathanheisey@5918
   173
            *value += v;
nathanheisey@5918
   174
            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
nathanheisey@5918
   175
            *value += v;
nathanheisey@5918
   176
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
nathanheisey@5918
   177
            *value += v;
nathanheisey@5918
   178
            break;
nathanheisey@5918
   179
        case SDL_GL_DEPTH_SIZE:
nathanheisey@5918
   180
            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
nathanheisey@5918
   181
            break;
nathanheisey@5918
   182
        case SDL_GL_STENCIL_SIZE:
nathanheisey@5918
   183
            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
nathanheisey@5918
   184
            break;
nathanheisey@5918
   185
        case SDL_GL_ACCUM_RED_SIZE:
nathanheisey@5918
   186
            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
nathanheisey@5918
   187
            break;
nathanheisey@5918
   188
        case SDL_GL_ACCUM_GREEN_SIZE:
nathanheisey@5918
   189
            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   190
            break;
nathanheisey@5918
   191
        case SDL_GL_ACCUM_BLUE_SIZE:
nathanheisey@5918
   192
            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   193
            break;
nathanheisey@5918
   194
        case SDL_GL_ACCUM_ALPHA_SIZE:
nathanheisey@5918
   195
            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   196
            break;
nathanheisey@5918
   197
        case SDL_GL_STEREO:
nathanheisey@5918
   198
        case SDL_GL_MULTISAMPLEBUFFERS:
nathanheisey@5918
   199
        case SDL_GL_MULTISAMPLESAMPLES:
nathanheisey@5918
   200
        default:
nathanheisey@5918
   201
            *value = 0;
nathanheisey@5918
   202
            return (-1);
nathanheisey@5918
   203
        }
nathanheisey@5918
   204
        return 0;
nathanheisey@5918
   205
    }
nathanheisey@5918
   206
nathanheisey@5931
   207
#endif
nathanheisey@5931
   208
nathanheisey@5931
   209
nathanheisey@5931
   210
nathanheisey@5931
   211
nathanheisey@5931
   212
nathanheisey@5931
   213
nathanheisey@5931
   214
nathanheisey@5919
   215
nathanheisey@5919
   216
#ifdef __cplusplus
nathanheisey@5919
   217
}
nathanheisey@5919
   218
#endif