src/video/bwindow/SDL_bopengl.cc
author Nathan Heisey <nathanheisey@gmail.com>
Mon, 08 Aug 2011 17:00:38 +0000
changeset 5934 01531d8d1e01
parent 5931 edf9a8e68b34
child 5935 d52ded852194
permissions -rw-r--r--
Some video fixes
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 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 
    22 #include "SDL_bopengl.h"
    23 
    24 #include <unistd.h>
    25 #include <KernelKit.h>
    26 #include <OpenGLKit.h>
    27 #include "SDL_BWin.h"
    28 #include "../../main/beos/SDL_BApp.h"
    29 
    30 #ifdef __cplusplus
    31 extern "C" {
    32 #endif
    33 
    34 static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    35 	return ((SDL_BWin*)(window->driverdata));
    36 }
    37 
    38 static inline SDL_BApp *_GetBeApp() {
    39 	return ((SDL_BApp*)be_app);
    40 }
    41 
    42 /* Passing a NULL path means load pointers from the application */
    43 int BE_GL_LoadLibrary(_THIS, const char *path)
    44 {
    45 	if (path == NULL) {
    46 		if (_this->gl_config.dll_handle == NULL) {
    47 			image_info info;
    48 			int32 cookie = 0;
    49 			while (get_next_image_info(0, &cookie, &info) == B_OK) {
    50 				void *location = NULL;
    51 				if (get_image_symbol
    52 				((image_id) cookie, "glBegin",
    53 				B_SYMBOL_TYPE_ANY, &location) == B_OK) {
    54 					_this->gl_config.dll_handle = (void *) cookie;
    55 					_this->gl_config.driver_loaded = 1;
    56 					SDL_strlcpy(_this->gl_config.driver_path,
    57 					"libGL.so",
    58 					SDL_arraysize(_this->
    59 					gl_config.driver_path));
    60 				}
    61 			}
    62 		}
    63 	} else {
    64         /*
    65            FIXME None of BeOS libGL.so implementations have exported functions 
    66            to load BGLView, which should be reloaded from new lib.
    67            So for now just "load" linked libGL.so :(
    68         */
    69         if (_this->gl_config.dll_handle == NULL) {
    70         	return BE_GL_LoadLibrary(_this, NULL);
    71         }
    72 
    73             /* Unload old first */
    74             /*if (_this->gl_config.dll_handle != NULL) { */
    75             /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */
    76             /*      image_info info;
    77                if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) {
    78                if (info.type != B_APP_IMAGE) {
    79                unload_add_on((image_id)_this->gl_config.dll_handle);
    80                }
    81                }
    82 
    83                }
    84 
    85                if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
    86                _this->gl_config.driver_loaded = 1;
    87                SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
    88                } */
    89 	}
    90 	
    91 	if (_this->gl_config.dll_handle != NULL) {
    92 		return 0;
    93 	} else {
    94 		_this->gl_config.dll_handle = NULL;
    95 		_this->gl_config.driver_loaded = 0;
    96 		*_this->gl_config.driver_path = '\0';
    97 		return -1;
    98 	}
    99 }
   100 
   101 void *BE_GL_GetProcAddress(_THIS, const char *proc)
   102 {
   103 	if (_this->gl_config.dll_handle != NULL) {
   104 		void *location = NULL;
   105 		status_t err;
   106 		if ((err =
   107 			get_image_symbol((image_id) _this->gl_config.dll_handle,
   108                               proc, B_SYMBOL_TYPE_ANY,
   109                               &location)) == B_OK) {
   110             return location;
   111         } else {
   112                 SDL_SetError("Couldn't find OpenGL symbol");
   113                 return NULL;
   114         }
   115 	} else {
   116 		SDL_SetError("OpenGL library not loaded");
   117 		return NULL;
   118 	}
   119 }
   120 
   121 
   122 
   123 
   124 void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
   125     _ToBeWin(window)->SwapBuffers();
   126 }
   127 
   128 int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
   129 	_GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
   130 	return 0;
   131 }
   132 
   133 
   134 SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
   135 	/* FIXME: Not sure what flags should be included here; may want to have
   136 	   most of them */
   137 	SDL_BWin *bwin = _ToBeWin(window);
   138 	bwin->CreateGLView(BGL_RGB | BGL_DOUBLE);
   139 	return (SDL_GLContext)(bwin);
   140 }
   141 
   142 void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
   143 	/* Currently, automatically unlocks the view */
   144 	((SDL_BWin*)context)->RemoveGLView();
   145 }
   146 
   147 
   148 int BE_GL_SetSwapInterval(_THIS, int interval) {
   149 	printf(__FILE__": %d- swap interval set\n", __LINE__);
   150 	return 0;
   151 }
   152 
   153 int BE_GL_GetSwapInterval(_THIS) {
   154 	printf(__FILE__": %d- swap interval requested\n", __LINE__);
   155 	return 0;
   156 }
   157 
   158 
   159 void BE_GL_UnloadLibrary(_THIS) {
   160 	printf(__FILE__": %d- Library unloaded\n", __LINE__);
   161 }
   162 
   163 
   164 
   165 
   166 
   167 
   168 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
   169 
   170     int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
   171     {
   172         /*
   173            FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
   174          */
   175         switch (attrib) {
   176         case SDL_GL_RED_SIZE:
   177             glGetIntegerv(GL_RED_BITS, (GLint *) value);
   178             break;
   179         case SDL_GL_GREEN_SIZE:
   180             glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
   181             break;
   182         case SDL_GL_BLUE_SIZE:
   183             glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
   184             break;
   185         case SDL_GL_ALPHA_SIZE:
   186             glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
   187             break;
   188         case SDL_GL_DOUBLEBUFFER:
   189             glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
   190             break;
   191         case SDL_GL_BUFFER_SIZE:
   192             int v;
   193             glGetIntegerv(GL_RED_BITS, (GLint *) & v);
   194             *value = v;
   195             glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
   196             *value += v;
   197             glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
   198             *value += v;
   199             glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
   200             *value += v;
   201             break;
   202         case SDL_GL_DEPTH_SIZE:
   203             glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
   204             break;
   205         case SDL_GL_STENCIL_SIZE:
   206             glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
   207             break;
   208         case SDL_GL_ACCUM_RED_SIZE:
   209             glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
   210             break;
   211         case SDL_GL_ACCUM_GREEN_SIZE:
   212             glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
   213             break;
   214         case SDL_GL_ACCUM_BLUE_SIZE:
   215             glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
   216             break;
   217         case SDL_GL_ACCUM_ALPHA_SIZE:
   218             glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
   219             break;
   220         case SDL_GL_STEREO:
   221         case SDL_GL_MULTISAMPLEBUFFERS:
   222         case SDL_GL_MULTISAMPLESAMPLES:
   223         default:
   224             *value = 0;
   225             return (-1);
   226         }
   227         return 0;
   228     }
   229 
   230 #endif
   231 
   232 
   233 
   234 
   235 
   236 
   237 
   238 
   239 #ifdef __cplusplus
   240 }
   241 #endif