zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_bopengl.cc
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 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 #include "SDL_config.h"
22 
23 #if SDL_VIDEO_DRIVER_BWINDOW
24 
25 #include "SDL_bopengl.h"
26 
27 #include <unistd.h>
28 #include <KernelKit.h>
29 #include <OpenGLKit.h>
30 #include "SDL_BWin.h"
31 #include "../../main/beos/SDL_BApp.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 
38 #define BGL_FLAGS BGL_RGB | BGL_DOUBLE
39 
40 static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
41  return ((SDL_BWin*)(window->driverdata));
42 }
43 
44 static inline SDL_BApp *_GetBeApp() {
45  return ((SDL_BApp*)be_app);
46 }
47 
48 /* Passing a NULL path means load pointers from the application */
49 int BE_GL_LoadLibrary(_THIS, const char *path)
50 {
51 /* FIXME: Is this working correctly? */
52  image_info info;
53  int32 cookie = 0;
54  while (get_next_image_info(0, &cookie, &info) == B_OK) {
55  void *location = NULL;
56  if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
57  &location) == B_OK) {
58 
59  _this->gl_config.dll_handle = (void *) info.id;
63  }
64  }
65  return 0;
66 }
67 
68 void *BE_GL_GetProcAddress(_THIS, const char *proc)
69 {
70  if (_this->gl_config.dll_handle != NULL) {
71  void *location = NULL;
72  status_t err;
73  if ((err =
74  get_image_symbol((image_id) _this->gl_config.dll_handle,
75  proc, B_SYMBOL_TYPE_ANY,
76  &location)) == B_OK) {
77  return location;
78  } else {
79  SDL_SetError("Couldn't find OpenGL symbol");
80  return NULL;
81  }
82  } else {
83  SDL_SetError("OpenGL library not loaded");
84  return NULL;
85  }
86 }
87 
88 
89 
90 
91 void BE_GL_SwapWindow(_THIS, SDL_Window * window) {
92  _ToBeWin(window)->SwapBuffers();
93 }
94 
96  _GetBeApp()->SetCurrentContext(((SDL_BWin*)context)->GetGLView());
97  return 0;
98 }
99 
100 
102  /* FIXME: Not sure what flags should be included here; may want to have
103  most of them */
104  SDL_BWin *bwin = _ToBeWin(window);
105  bwin->CreateGLView(BGL_FLAGS);
106  return (SDL_GLContext)(bwin);
107 }
108 
109 void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
110  /* Currently, automatically unlocks the view */
111  ((SDL_BWin*)context)->RemoveGLView();
112 }
113 
114 
115 int BE_GL_SetSwapInterval(_THIS, int interval) {
116  /* TODO: Implement this, if necessary? */
117  return 0;
118 }
119 
121  /* TODO: Implement this, if necessary? */
122  return 0;
123 }
124 
125 
127  /* TODO: Implement this, if necessary? */
128 }
129 
130 
131 /* FIXME: This function is meant to clear the OpenGL context when the video
132  mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
133  currently in use. */
135  SDL_Window *window = _this->windows;
136  while(window) {
137  SDL_BWin *bwin = _ToBeWin(window);
138  if(bwin->GetGLView()) {
139  bwin->LockLooper();
140  bwin->RemoveGLView();
141  bwin->CreateGLView(BGL_FLAGS);
142  bwin->UnlockLooper();
143  }
144  window = window->next;
145  }
146 }
147 
148 
149 #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
150 
151  int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
152  {
153  /*
154  FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
155  */
156  switch (attrib) {
157  case SDL_GL_RED_SIZE:
158  glGetIntegerv(GL_RED_BITS, (GLint *) value);
159  break;
160  case SDL_GL_GREEN_SIZE:
161  glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
162  break;
163  case SDL_GL_BLUE_SIZE:
164  glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
165  break;
166  case SDL_GL_ALPHA_SIZE:
167  glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
168  break;
169  case SDL_GL_DOUBLEBUFFER:
171  break;
172  case SDL_GL_BUFFER_SIZE:
173  int v;
174  glGetIntegerv(GL_RED_BITS, (GLint *) & v);
175  *value = v;
177  *value += v;
178  glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
179  *value += v;
181  *value += v;
182  break;
183  case SDL_GL_DEPTH_SIZE:
184  glGetIntegerv(GL_DEPTH_BITS, (GLint *) value); /* Mesa creates 16 only? r5 always 32 */
185  break;
186  case SDL_GL_STENCIL_SIZE:
187  glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
188  break;
191  break;
194  break;
197  break;
200  break;
201  case SDL_GL_STEREO:
204  default:
205  *value = 0;
206  return (-1);
207  }
208  return 0;
209  }
210 
211 #endif
212 
213 
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* SDL_VIDEO_DRIVER_BWINDOW */
SDL_Window * next
Definition: SDL_sysvideo.h:102
#define GL_DEPTH_BITS
Definition: gl2.h:206
int BE_GL_LoadLibrary(_THIS, const char *path)
void BE_GL_UnloadLibrary(_THIS)
#define NULL
Definition: ftobjs.h:61
#define GL_GREEN_BITS
Definition: gl2.h:203
unsigned char GLboolean
Definition: gl2.h:24
GLint location
Definition: gl2ext.h:1164
void * BE_GL_GetProcAddress(_THIS, const char *proc)
void BE_GL_DeleteContext(_THIS, SDL_GLContext context)
void BE_GL_RebootContexts(_THIS)
#define glGetIntegerv
Definition: gl_mangle.h:679
SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window *window)
#define GL_ACCUM_GREEN_BITS
Definition: glew_head.h:495
SDL_GLattr
OpenGL configuration attributes.
Definition: SDL_video.h:166
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:161
GLsizei const GLchar *const * path
Definition: glew.h:5828
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
const GLdouble * v
Definition: glew.h:1377
#define GL_ACCUM_ALPHA_BITS
Definition: glew_head.h:497
#define glGetBooleanv
Definition: gl_mangle.h:601
#define _THIS
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
Definition: SDL_string.c:448
#define GL_ACCUM_BLUE_BITS
Definition: glew_head.h:496
char driver_path[256]
Definition: SDL_sysvideo.h:298
#define GL_ACCUM_RED_BITS
Definition: glew_head.h:494
int BE_GL_GetSwapInterval(_THIS)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
#define GL_STENCIL_BITS
Definition: gl2.h:207
SDL_Window * windows
Definition: SDL_sysvideo.h:266
#define GL_BLUE_BITS
Definition: gl2.h:204
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:83
int GLint
Definition: gl2.h:28
EGLSurface EGLint void ** value
Definition: eglext.h:301
int BE_GL_SetSwapInterval(_THIS, int interval)
int BE_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
#define GL_RED_BITS
Definition: gl2.h:202
void * driverdata
Definition: SDL_sysvideo.h:99
TParseContext * context
void BE_GL_SwapWindow(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@87 gl_config
#define GL_ALPHA_BITS
Definition: gl2.h:205
#define GL_DOUBLEBUFFER
Definition: glew_head.h:414