src/video/bwindow/SDL_bopengl.cc
author Nathan Heisey <nathanheisey@gmail.com>
Wed, 13 Jul 2011 09:37:00 +0000
changeset 5919 e19c4c44f224
parent 5918 2063df37190b
child 5931 edf9a8e68b34
permissions -rw-r--r--
Fixed video compile(?)
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@5919
    24
#ifdef __cplusplus
nathanheisey@5919
    25
extern "C" {
nathanheisey@5919
    26
#endif
nathanheisey@5918
    27
nathanheisey@5918
    28
/* Passing a NULL path means load pointers from the application */
nathanheisey@5918
    29
int BE_GL_LoadLibrary(_THIS, const char *path)
nathanheisey@5918
    30
{
nathanheisey@5918
    31
#if 0
nathanheisey@5918
    32
	if (path == NULL) {
nathanheisey@5918
    33
		if (_this->gl_config.dll_handle == NULL) {
nathanheisey@5918
    34
			image_info info;
nathanheisey@5918
    35
			int32 cookie = 0;
nathanheisey@5918
    36
			while (get_next_image_info(0, &cookie, &info) == B_OK) {
nathanheisey@5918
    37
				void *location = NULL;
nathanheisey@5918
    38
				if (get_image_symbol
nathanheisey@5918
    39
				((image_id) cookie, "glBegin",
nathanheisey@5918
    40
				B_SYMBOL_TYPE_ANY, &location) == B_OK) {
nathanheisey@5918
    41
					_this->gl_config.dll_handle = (void *) cookie;
nathanheisey@5918
    42
					_this->gl_config.driver_loaded = 1;
nathanheisey@5918
    43
					SDL_strlcpy(_this->gl_config.driver_path,
nathanheisey@5918
    44
					"libGL.so",
nathanheisey@5918
    45
					SDL_arraysize(_this->
nathanheisey@5918
    46
					gl_config.driver_path));
nathanheisey@5918
    47
				}
nathanheisey@5918
    48
			}
nathanheisey@5918
    49
		}
nathanheisey@5918
    50
	} else {
nathanheisey@5918
    51
        /*
nathanheisey@5918
    52
           FIXME None of BeOS libGL.so implementations have exported functions 
nathanheisey@5918
    53
           to load BGLView, which should be reloaded from new lib.
nathanheisey@5918
    54
           So for now just "load" linked libGL.so :(
nathanheisey@5918
    55
        */
nathanheisey@5918
    56
        if (_this->gl_config.dll_handle == NULL) {
nathanheisey@5918
    57
        	return BE_GL_LoadLibrary(_this, NULL);
nathanheisey@5918
    58
        }
nathanheisey@5918
    59
nathanheisey@5918
    60
            /* Unload old first */
nathanheisey@5918
    61
            /*if (_this->gl_config.dll_handle != NULL) { */
nathanheisey@5918
    62
            /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */
nathanheisey@5918
    63
            /*      image_info info;
nathanheisey@5918
    64
               if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) {
nathanheisey@5918
    65
               if (info.type != B_APP_IMAGE) {
nathanheisey@5918
    66
               unload_add_on((image_id)_this->gl_config.dll_handle);
nathanheisey@5918
    67
               }
nathanheisey@5918
    68
               }
nathanheisey@5918
    69
nathanheisey@5918
    70
               }
nathanheisey@5918
    71
nathanheisey@5918
    72
               if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
nathanheisey@5918
    73
               _this->gl_config.driver_loaded = 1;
nathanheisey@5918
    74
               SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
nathanheisey@5918
    75
               } */
nathanheisey@5918
    76
	}
nathanheisey@5918
    77
	
nathanheisey@5918
    78
	if (_this->gl_config.dll_handle != NULL) {
nathanheisey@5918
    79
		return 0;
nathanheisey@5918
    80
	} else {
nathanheisey@5918
    81
		_this->gl_config.dll_handle = NULL;
nathanheisey@5918
    82
		_this->gl_config.driver_loaded = 0;
nathanheisey@5918
    83
		*_this->gl_config.driver_path = '\0';
nathanheisey@5918
    84
		return -1;
nathanheisey@5918
    85
	}
nathanheisey@5918
    86
#endif
nathanheisey@5918
    87
}
nathanheisey@5918
    88
nathanheisey@5918
    89
void *BE_GL_GetProcAddress(_THIS, const char *proc)
nathanheisey@5918
    90
{
nathanheisey@5918
    91
#if 0
nathanheisey@5918
    92
	if (_this->gl_config.dll_handle != NULL) {
nathanheisey@5918
    93
		void *location = NULL;
nathanheisey@5918
    94
		status_t err;
nathanheisey@5918
    95
		if ((err =
nathanheisey@5918
    96
			get_image_symbol((image_id) _this->gl_config.dll_handle,
nathanheisey@5918
    97
                              proc, B_SYMBOL_TYPE_ANY,
nathanheisey@5918
    98
                              &location)) == B_OK) {
nathanheisey@5918
    99
            return location;
nathanheisey@5918
   100
        } else {
nathanheisey@5918
   101
                SDL_SetError("Couldn't find OpenGL symbol");
nathanheisey@5918
   102
                return NULL;
nathanheisey@5918
   103
        }
nathanheisey@5918
   104
	} else {
nathanheisey@5918
   105
		SDL_SetError("OpenGL library not loaded");
nathanheisey@5918
   106
		return NULL;
nathanheisey@5918
   107
	}
nathanheisey@5918
   108
#endif
nathanheisey@5918
   109
}
nathanheisey@5918
   110
nathanheisey@5918
   111
nathanheisey@5918
   112
nathanheisey@5918
   113
nathanheisey@5918
   114
int BE_GL_MakeCurrent(_THIS)
nathanheisey@5918
   115
{
nathanheisey@5918
   116
	/* FIXME: should we glview->unlock and then glview->lock()? */
nathanheisey@5918
   117
	return 0;
nathanheisey@5918
   118
}
nathanheisey@5918
   119
nathanheisey@5918
   120
nathanheisey@5918
   121
nathanheisey@5918
   122
nathanheisey@5918
   123
nathanheisey@5918
   124
nathanheisey@5918
   125
nathanheisey@5918
   126
nathanheisey@5918
   127
nathanheisey@5918
   128
nathanheisey@5918
   129
nathanheisey@5918
   130
nathanheisey@5918
   131
#if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
nathanheisey@5918
   132
nathanheisey@5918
   133
    int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
nathanheisey@5918
   134
    {
nathanheisey@5918
   135
        /*
nathanheisey@5918
   136
           FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
nathanheisey@5918
   137
         */
nathanheisey@5918
   138
        switch (attrib) {
nathanheisey@5918
   139
        case SDL_GL_RED_SIZE:
nathanheisey@5918
   140
            glGetIntegerv(GL_RED_BITS, (GLint *) value);
nathanheisey@5918
   141
            break;
nathanheisey@5918
   142
        case SDL_GL_GREEN_SIZE:
nathanheisey@5918
   143
            glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   144
            break;
nathanheisey@5918
   145
        case SDL_GL_BLUE_SIZE:
nathanheisey@5918
   146
            glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   147
            break;
nathanheisey@5918
   148
        case SDL_GL_ALPHA_SIZE:
nathanheisey@5918
   149
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   150
            break;
nathanheisey@5918
   151
        case SDL_GL_DOUBLEBUFFER:
nathanheisey@5918
   152
            glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
nathanheisey@5918
   153
            break;
nathanheisey@5918
   154
        case SDL_GL_BUFFER_SIZE:
nathanheisey@5918
   155
            int v;
nathanheisey@5918
   156
            glGetIntegerv(GL_RED_BITS, (GLint *) & v);
nathanheisey@5918
   157
            *value = v;
nathanheisey@5918
   158
            glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
nathanheisey@5918
   159
            *value += v;
nathanheisey@5918
   160
            glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
nathanheisey@5918
   161
            *value += v;
nathanheisey@5918
   162
            glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
nathanheisey@5918
   163
            *value += v;
nathanheisey@5918
   164
            break;
nathanheisey@5918
   165
        case SDL_GL_DEPTH_SIZE:
nathanheisey@5918
   166
            glGetIntegerv(GL_DEPTH_BITS, (GLint *) value);      /* Mesa creates 16 only? r5 always 32 */
nathanheisey@5918
   167
            break;
nathanheisey@5918
   168
        case SDL_GL_STENCIL_SIZE:
nathanheisey@5918
   169
            glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
nathanheisey@5918
   170
            break;
nathanheisey@5918
   171
        case SDL_GL_ACCUM_RED_SIZE:
nathanheisey@5918
   172
            glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
nathanheisey@5918
   173
            break;
nathanheisey@5918
   174
        case SDL_GL_ACCUM_GREEN_SIZE:
nathanheisey@5918
   175
            glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
nathanheisey@5918
   176
            break;
nathanheisey@5918
   177
        case SDL_GL_ACCUM_BLUE_SIZE:
nathanheisey@5918
   178
            glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
nathanheisey@5918
   179
            break;
nathanheisey@5918
   180
        case SDL_GL_ACCUM_ALPHA_SIZE:
nathanheisey@5918
   181
            glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
nathanheisey@5918
   182
            break;
nathanheisey@5918
   183
        case SDL_GL_STEREO:
nathanheisey@5918
   184
        case SDL_GL_MULTISAMPLEBUFFERS:
nathanheisey@5918
   185
        case SDL_GL_MULTISAMPLESAMPLES:
nathanheisey@5918
   186
        default:
nathanheisey@5918
   187
            *value = 0;
nathanheisey@5918
   188
            return (-1);
nathanheisey@5918
   189
        }
nathanheisey@5918
   190
        return 0;
nathanheisey@5918
   191
    }
nathanheisey@5918
   192
nathanheisey@5918
   193
    void BE_GL_SwapBuffers(_THIS)
nathanheisey@5918
   194
    {
nathanheisey@5918
   195
        SDL_Win->SwapBuffers();
nathanheisey@5918
   196
    }
nathanheisey@5918
   197
#endif
nathanheisey@5919
   198
nathanheisey@5919
   199
#ifdef __cplusplus
nathanheisey@5919
   200
}
nathanheisey@5919
   201
#endif