src/video/haiku/SDL_bopengl.cc
changeset 7981 6d538bc1b395
parent 7860 2b0bcdea3a79
child 8093 b43765095a6f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/haiku/SDL_bopengl.cc	Thu Nov 14 11:51:24 2013 -0500
     1.3 @@ -0,0 +1,219 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_HAIKU
    1.27 +
    1.28 +#include "SDL_bopengl.h"
    1.29 +
    1.30 +#include <unistd.h>
    1.31 +#include <KernelKit.h>
    1.32 +#include <OpenGLKit.h>
    1.33 +#include "SDL_BWin.h"
    1.34 +#include "../../main/haiku/SDL_BApp.h"
    1.35 +
    1.36 +#ifdef __cplusplus
    1.37 +extern "C" {
    1.38 +#endif
    1.39 +
    1.40 +
    1.41 +#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
    1.42 +
    1.43 +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
    1.44 +	return ((SDL_BWin*)(window->driverdata));
    1.45 +}
    1.46 +
    1.47 +static SDL_INLINE SDL_BApp *_GetBeApp() {
    1.48 +	return ((SDL_BApp*)be_app);
    1.49 +}
    1.50 +
    1.51 +/* Passing a NULL path means load pointers from the application */
    1.52 +int BE_GL_LoadLibrary(_THIS, const char *path)
    1.53 +{
    1.54 +/* FIXME: Is this working correctly? */
    1.55 +	image_info info;
    1.56 +			int32 cookie = 0;
    1.57 +	while (get_next_image_info(0, &cookie, &info) == B_OK) {
    1.58 +		void *location = NULL;
    1.59 +		if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
    1.60 +				&location) == B_OK) {
    1.61 +
    1.62 +			_this->gl_config.dll_handle = (void *) info.id;
    1.63 +			_this->gl_config.driver_loaded = 1;
    1.64 +			SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
    1.65 +					SDL_arraysize(_this->gl_config.driver_path));
    1.66 +		}
    1.67 +	}
    1.68 +	return 0;
    1.69 +}
    1.70 +
    1.71 +void *BE_GL_GetProcAddress(_THIS, const char *proc)
    1.72 +{
    1.73 +	if (_this->gl_config.dll_handle != NULL) {
    1.74 +		void *location = NULL;
    1.75 +		status_t err;
    1.76 +		if ((err =
    1.77 +			get_image_symbol((image_id) _this->gl_config.dll_handle,
    1.78 +                              proc, B_SYMBOL_TYPE_ANY,
    1.79 +                              &location)) == B_OK) {
    1.80 +            return location;
    1.81 +        } else {
    1.82 +                SDL_SetError("Couldn't find OpenGL symbol");
    1.83 +                return NULL;
    1.84 +        }
    1.85 +	} else {
    1.86 +		SDL_SetError("OpenGL library not loaded");
    1.87 +		return NULL;
    1.88 +	}
    1.89 +}
    1.90 +
    1.91 +
    1.92 +
    1.93 +
    1.94 +void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
    1.95 +    _ToBeWin(window)->SwapBuffers();
    1.96 +}
    1.97 +
    1.98 +int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
    1.99 +	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
   1.100 +	return 0;
   1.101 +}
   1.102 +
   1.103 +
   1.104 +SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
   1.105 +	/* FIXME: Not sure what flags should be included here; may want to have
   1.106 +	   most of them */
   1.107 +	SDL_BWin *bwin = _ToBeWin(window);
   1.108 +	bwin->CreateGLView(BGL_FLAGS);
   1.109 +	return (SDL_GLContext)(bwin);
   1.110 +}
   1.111 +
   1.112 +void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
   1.113 +	/* Currently, automatically unlocks the view */
   1.114 +	((SDL_BWin*)context)->RemoveGLView();
   1.115 +}
   1.116 +
   1.117 +
   1.118 +int BE_GL_SetSwapInterval(_THIS, int interval) {
   1.119 +	/* TODO: Implement this, if necessary? */
   1.120 +	return 0;
   1.121 +}
   1.122 +
   1.123 +int BE_GL_GetSwapInterval(_THIS) {
   1.124 +	/* TODO: Implement this, if necessary? */
   1.125 +	return 0;
   1.126 +}
   1.127 +
   1.128 +
   1.129 +void BE_GL_UnloadLibrary(_THIS) {
   1.130 +	/* TODO: Implement this, if necessary? */
   1.131 +}
   1.132 +
   1.133 +
   1.134 +/* FIXME: This function is meant to clear the OpenGL context when the video
   1.135 +   mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
   1.136 +   currently in use. */
   1.137 +void BE_GL_RebootContexts(_THIS) {
   1.138 +	SDL_Window *window = _this->windows;
   1.139 +	while(window) {
   1.140 +		SDL_BWin *bwin = _ToBeWin(window);
   1.141 +		if(bwin->GetGLView()) {
   1.142 +			bwin->LockLooper();
   1.143 +			bwin->RemoveGLView();
   1.144 +			bwin->CreateGLView(BGL_FLAGS);
   1.145 +			bwin->UnlockLooper();
   1.146 +		}
   1.147 +		window = window->next;
   1.148 +	}
   1.149 +}
   1.150 +
   1.151 +
   1.152 +#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
   1.153 +
   1.154 +    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
   1.155 +    {
   1.156 +        /*
   1.157 +           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
   1.158 +         */
   1.159 +        switch (attrib) {
   1.160 +        case SDL_GL_RED_SIZE:
   1.161 +            glGetIntegerv(GL_RED_BITS, (GLint *) value);
   1.162 +            break;
   1.163 +        case SDL_GL_GREEN_SIZE:
   1.164 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
   1.165 +            break;
   1.166 +        case SDL_GL_BLUE_SIZE:
   1.167 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
   1.168 +            break;
   1.169 +        case SDL_GL_ALPHA_SIZE:
   1.170 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
   1.171 +            break;
   1.172 +        case SDL_GL_DOUBLEBUFFER:
   1.173 +            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
   1.174 +            break;
   1.175 +        case SDL_GL_BUFFER_SIZE:
   1.176 +            int v;
   1.177 +            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
   1.178 +            *value = v;
   1.179 +            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
   1.180 +            *value += v;
   1.181 +            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
   1.182 +            *value += v;
   1.183 +            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
   1.184 +            *value += v;
   1.185 +            break;
   1.186 +        case SDL_GL_DEPTH_SIZE:
   1.187 +            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
   1.188 +            break;
   1.189 +        case SDL_GL_STENCIL_SIZE:
   1.190 +            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
   1.191 +            break;
   1.192 +        case SDL_GL_ACCUM_RED_SIZE:
   1.193 +            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
   1.194 +            break;
   1.195 +        case SDL_GL_ACCUM_GREEN_SIZE:
   1.196 +            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
   1.197 +            break;
   1.198 +        case SDL_GL_ACCUM_BLUE_SIZE:
   1.199 +            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
   1.200 +            break;
   1.201 +        case SDL_GL_ACCUM_ALPHA_SIZE:
   1.202 +            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
   1.203 +            break;
   1.204 +        case SDL_GL_STEREO:
   1.205 +        case SDL_GL_MULTISAMPLEBUFFERS:
   1.206 +        case SDL_GL_MULTISAMPLESAMPLES:
   1.207 +        default:
   1.208 +            *value = 0;
   1.209 +            return (-1);
   1.210 +        }
   1.211 +        return 0;
   1.212 +    }
   1.213 +
   1.214 +#endif
   1.215 +
   1.216 +
   1.217 +
   1.218 +#ifdef __cplusplus
   1.219 +}
   1.220 +#endif
   1.221 +
   1.222 +#endif /* SDL_VIDEO_DRIVER_HAIKU */