Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_gl.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
32 GLPH_DECLARE_FUNCS; | 32 GLPH_DECLARE_FUNCS; |
33 #endif /* 6.3.0 */ | 33 #endif /* 6.3.0 */ |
34 | 34 |
35 #if (_NTO_VERSION < 630) | 35 #if (_NTO_VERSION < 630) |
36 void | 36 void |
37 ph_GL_SwapBuffers (_THIS) | 37 ph_GL_SwapBuffers(_THIS) |
38 { | 38 { |
39 PgSetRegion (PtWidgetRid (window)); | 39 PgSetRegion(PtWidgetRid(window)); |
40 PdOpenGLContextSwapBuffers (oglctx); | 40 PdOpenGLContextSwapBuffers(oglctx); |
41 } | 41 } |
42 #else | 42 #else |
43 void | 43 void |
44 ph_GL_SwapBuffers (_THIS) | 44 ph_GL_SwapBuffers(_THIS) |
45 { | 45 { |
46 qnxgl_swap_buffers (oglbuffers); | 46 qnxgl_swap_buffers(oglbuffers); |
47 } | 47 } |
48 #endif /* 6.3.0 */ | 48 #endif /* 6.3.0 */ |
49 | 49 |
50 int | 50 int |
51 ph_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value) | 51 ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value) |
52 { | 52 { |
53 switch (attrib) { | 53 switch (attrib) { |
54 case SDL_GL_DOUBLEBUFFER: | 54 case SDL_GL_DOUBLEBUFFER: |
55 *value = this->gl_config.double_buffer; | 55 *value = this->gl_config.double_buffer; |
56 break; | 56 break; |
96 return 0; | 96 return 0; |
97 } | 97 } |
98 | 98 |
99 #if (_NTO_VERSION < 630) | 99 #if (_NTO_VERSION < 630) |
100 int | 100 int |
101 ph_GL_LoadLibrary (_THIS, const char *path) | 101 ph_GL_LoadLibrary(_THIS, const char *path) |
102 { | 102 { |
103 /* if code compiled with SDL_VIDEO_OPENGL, that mean that library already linked */ | 103 /* if code compiled with SDL_VIDEO_OPENGL, that mean that library already linked */ |
104 this->gl_config.driver_loaded = 1; | 104 this->gl_config.driver_loaded = 1; |
105 | 105 |
106 return 0; | 106 return 0; |
107 } | 107 } |
108 #else | 108 #else |
109 int | 109 int |
110 ph_GL_LoadLibrary (_THIS, const char *path) | 110 ph_GL_LoadLibrary(_THIS, const char *path) |
111 { | 111 { |
112 void *handle; | 112 void *handle; |
113 int dlopen_flags = RTLD_WORLD | RTLD_GROUP; | 113 int dlopen_flags = RTLD_WORLD | RTLD_GROUP; |
114 | 114 |
115 if (this->gl_config.dll_handle != NULL) { | 115 if (this->gl_config.dll_handle != NULL) { |
116 return 0; | 116 return 0; |
117 } | 117 } |
118 | 118 |
119 handle = dlopen (path, dlopen_flags); | 119 handle = dlopen(path, dlopen_flags); |
120 | 120 |
121 if (handle == NULL) { | 121 if (handle == NULL) { |
122 SDL_SetError ("ph_GL_LoadLibrary(): Could not load OpenGL library"); | 122 SDL_SetError("ph_GL_LoadLibrary(): Could not load OpenGL library"); |
123 return -1; | 123 return -1; |
124 } | 124 } |
125 | 125 |
126 this->gl_config.dll_handle = handle; | 126 this->gl_config.dll_handle = handle; |
127 this->gl_config.driver_loaded = 1; | 127 this->gl_config.driver_loaded = 1; |
128 | 128 |
129 SDL_strlcpy (this->gl_config.driver_path, path, | 129 SDL_strlcpy(this->gl_config.driver_path, path, |
130 SDL_arraysize (this->gl_config.driver_path)); | 130 SDL_arraysize(this->gl_config.driver_path)); |
131 | 131 |
132 return 0; | 132 return 0; |
133 } | 133 } |
134 #endif /* 6.3.0 */ | 134 #endif /* 6.3.0 */ |
135 | 135 |
136 #if (_NTO_VERSION < 630) | 136 #if (_NTO_VERSION < 630) |
137 void * | 137 void * |
138 ph_GL_GetProcAddress (_THIS, const char *proc) | 138 ph_GL_GetProcAddress(_THIS, const char *proc) |
139 { | 139 { |
140 return NULL; | 140 return NULL; |
141 } | 141 } |
142 #else | 142 #else |
143 void * | 143 void * |
144 ph_GL_GetProcAddress (_THIS, const char *proc) | 144 ph_GL_GetProcAddress(_THIS, const char *proc) |
145 { | 145 { |
146 void *function; | 146 void *function; |
147 | 147 |
148 if (this->gl_config.dll_handle == NULL) { | 148 if (this->gl_config.dll_handle == NULL) { |
149 ph_GL_LoadLibrary (this, DEFAULT_OPENGL); | 149 ph_GL_LoadLibrary(this, DEFAULT_OPENGL); |
150 if (this->gl_config.dll_handle == NULL) { | 150 if (this->gl_config.dll_handle == NULL) { |
151 return NULL; | 151 return NULL; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 function = qnxgl_get_func (proc, oglctx, 0); | 155 function = qnxgl_get_func(proc, oglctx, 0); |
156 if (function == NULL) { | 156 if (function == NULL) { |
157 function = dlsym (this->gl_config.dll_handle, proc); | 157 function = dlsym(this->gl_config.dll_handle, proc); |
158 } | 158 } |
159 | 159 |
160 return function; | 160 return function; |
161 } | 161 } |
162 #endif /* 6.3.0 */ | 162 #endif /* 6.3.0 */ |
163 | 163 |
164 #if (_NTO_VERSION < 630) | 164 #if (_NTO_VERSION < 630) |
165 int | 165 int |
166 ph_GL_MakeCurrent (_THIS) | 166 ph_GL_MakeCurrent(_THIS) |
167 { | 167 { |
168 PgSetRegion (PtWidgetRid (window)); | 168 PgSetRegion(PtWidgetRid(window)); |
169 | 169 |
170 if (oglctx != NULL) { | 170 if (oglctx != NULL) { |
171 PhDCSetCurrent (oglctx); | 171 PhDCSetCurrent(oglctx); |
172 } | 172 } |
173 | 173 |
174 return 0; | 174 return 0; |
175 } | 175 } |
176 #else | 176 #else |
177 int | 177 int |
178 ph_GL_MakeCurrent (_THIS) | 178 ph_GL_MakeCurrent(_THIS) |
179 { | 179 { |
180 PgSetRegion (PtWidgetRid (window)); | 180 PgSetRegion(PtWidgetRid(window)); |
181 | 181 |
182 if (oglctx != NULL) { | 182 if (oglctx != NULL) { |
183 if (qnxgl_set_current (oglctx) == -1) { | 183 if (qnxgl_set_current(oglctx) == -1) { |
184 return -1; | 184 return -1; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 return 0; | 188 return 0; |
192 #if (_NTO_VERSION < 630) | 192 #if (_NTO_VERSION < 630) |
193 | 193 |
194 /* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */ | 194 /* This code is actual for the Photon3D Runtime which was available prior to 6.3 only */ |
195 | 195 |
196 int | 196 int |
197 ph_SetupOpenGLContext (_THIS, int width, int height, int bpp, Uint32 flags) | 197 ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) |
198 { | 198 { |
199 PhDim_t dim; | 199 PhDim_t dim; |
200 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; | 200 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; |
201 int exposepost = 0; | 201 int exposepost = 0; |
202 int OGLargc; | 202 int OGLargc; |
203 | 203 |
204 dim.w = width; | 204 dim.w = width; |
205 dim.h = height; | 205 dim.h = height; |
206 | 206 |
207 if ((oglctx != NULL) && (oglflags == flags) && (oglbpp == bpp)) { | 207 if ((oglctx != NULL) && (oglflags == flags) && (oglbpp == bpp)) { |
208 PdOpenGLContextResize (oglctx, &dim); | 208 PdOpenGLContextResize(oglctx, &dim); |
209 PhDCSetCurrent (oglctx); | 209 PhDCSetCurrent(oglctx); |
210 return 0; | 210 return 0; |
211 } else { | 211 } else { |
212 if (oglctx != NULL) { | 212 if (oglctx != NULL) { |
213 PhDCSetCurrent (NULL); | 213 PhDCSetCurrent(NULL); |
214 PhDCRelease (oglctx); | 214 PhDCRelease(oglctx); |
215 oglctx = NULL; | 215 oglctx = NULL; |
216 exposepost = 1; | 216 exposepost = 1; |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
234 OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FULLSCREEN_CENTER; | 234 OGLAttrib[OGLargc++] = PHOGL_ATTRIB_FULLSCREEN_CENTER; |
235 } | 235 } |
236 OGLAttrib[OGLargc++] = PHOGL_ATTRIB_NONE; | 236 OGLAttrib[OGLargc++] = PHOGL_ATTRIB_NONE; |
237 | 237 |
238 if (this->gl_config.double_buffer) { | 238 if (this->gl_config.double_buffer) { |
239 oglctx = PdCreateOpenGLContext (2, &dim, 0, OGLAttrib); | 239 oglctx = PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); |
240 } else { | 240 } else { |
241 oglctx = PdCreateOpenGLContext (1, &dim, 0, OGLAttrib); | 241 oglctx = PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); |
242 } | 242 } |
243 | 243 |
244 if (oglctx == NULL) { | 244 if (oglctx == NULL) { |
245 SDL_SetError | 245 SDL_SetError |
246 ("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); | 246 ("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); |
247 return -1; | 247 return -1; |
248 } | 248 } |
249 | 249 |
250 PhDCSetCurrent (oglctx); | 250 PhDCSetCurrent(oglctx); |
251 | 251 |
252 PtFlush (); | 252 PtFlush(); |
253 | 253 |
254 oglflags = flags; | 254 oglflags = flags; |
255 oglbpp = bpp; | 255 oglbpp = bpp; |
256 | 256 |
257 if (exposepost != 0) { | 257 if (exposepost != 0) { |
258 /* OpenGL context has been recreated, so report about this fact */ | 258 /* OpenGL context has been recreated, so report about this fact */ |
259 SDL_PrivateExpose (); | 259 SDL_PrivateExpose(); |
260 } | 260 } |
261 | 261 |
262 return 0; | 262 return 0; |
263 } | 263 } |
264 | 264 |
265 #else /* _NTO_VERSION */ | 265 #else /* _NTO_VERSION */ |
266 | 266 |
267 /* This code is actual for the built-in PhGL support, which became available since 6.3 */ | 267 /* This code is actual for the built-in PhGL support, which became available since 6.3 */ |
268 | 268 |
269 int | 269 int |
270 ph_SetupOpenGLContext (_THIS, int width, int height, int bpp, Uint32 flags) | 270 ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) |
271 { | 271 { |
272 qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS]; | 272 qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS]; |
273 qnxgl_buf_attrib_t *qnxgl_attribs_slide; | 273 qnxgl_buf_attrib_t *qnxgl_attribs_slide; |
274 int num_interfaces = 0; | 274 int num_interfaces = 0; |
275 int num_buffers = 0; | 275 int num_buffers = 0; |
276 | 276 |
277 /* Initialize the OpenGL subsystem */ | 277 /* Initialize the OpenGL subsystem */ |
278 | 278 |
279 num_interfaces = qnxgl_init (NULL, NULL, 0); | 279 num_interfaces = qnxgl_init(NULL, NULL, 0); |
280 | 280 |
281 if (num_interfaces < 0) { | 281 if (num_interfaces < 0) { |
282 SDL_SetError | 282 SDL_SetError |
283 ("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n"); | 283 ("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n"); |
284 return -1; | 284 return -1; |
295 /* Initialize the OpenGL context attributes */ | 295 /* Initialize the OpenGL context attributes */ |
296 qnxgl_attribs_slide = qnxgl_attribs; | 296 qnxgl_attribs_slide = qnxgl_attribs; |
297 | 297 |
298 /* Depth size */ | 298 /* Depth size */ |
299 if (this->gl_config.depth_size) { | 299 if (this->gl_config.depth_size) { |
300 fprintf (stderr, "setted depth size %d\n", | 300 fprintf(stderr, "setted depth size %d\n", this->gl_config.depth_size); |
301 this->gl_config.depth_size); | |
302 qnxgl_attribs_slide = | 301 qnxgl_attribs_slide = |
303 qnxgl_attrib_set_depth (qnxgl_attribs_slide, | 302 qnxgl_attrib_set_depth(qnxgl_attribs_slide, |
304 this->gl_config.depth_size); | 303 this->gl_config.depth_size); |
305 } | 304 } |
306 | 305 |
307 /* Stencil size */ | 306 /* Stencil size */ |
308 if (this->gl_config.stencil_size) { | 307 if (this->gl_config.stencil_size) { |
309 qnxgl_attribs_slide = | 308 qnxgl_attribs_slide = |
310 qnxgl_attrib_set_stencil (qnxgl_attribs_slide, | 309 qnxgl_attrib_set_stencil(qnxgl_attribs_slide, |
311 this->gl_config.stencil_size); | 310 this->gl_config.stencil_size); |
312 } | 311 } |
313 | 312 |
314 /* The sum of the accum bits of each channel */ | 313 /* The sum of the accum bits of each channel */ |
315 if ((this->gl_config.accum_red_size != 0) | 314 if ((this->gl_config.accum_red_size != 0) |
316 && (this->gl_config.accum_blue_size != 0) | 315 && (this->gl_config.accum_blue_size != 0) |
317 && (this->gl_config.accum_green_size != 0)) { | 316 && (this->gl_config.accum_green_size != 0)) { |
318 qnxgl_attribs_slide = qnxgl_attrib_set_accum (qnxgl_attribs_slide, | 317 qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide, |
319 this->gl_config. | 318 this->gl_config. |
320 accum_red_size + | 319 accum_red_size + |
321 this->gl_config. | 320 this->gl_config. |
322 accum_blue_size + | 321 accum_blue_size + |
323 this->gl_config. | 322 this->gl_config. |
324 accum_green_size + | 323 accum_green_size + |
325 this->gl_config. | 324 this->gl_config. |
326 accum_alpha_size); | 325 accum_alpha_size); |
327 } | 326 } |
328 | 327 |
329 /* Stereo mode */ | 328 /* Stereo mode */ |
330 if (this->gl_config.stereo) { | 329 if (this->gl_config.stereo) { |
331 qnxgl_attribs_slide = qnxgl_attrib_set_stereo (qnxgl_attribs_slide); | 330 qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide); |
332 } | 331 } |
333 | 332 |
334 /* Fullscreen mode */ | 333 /* Fullscreen mode */ |
335 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { | 334 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { |
336 qnxgl_attribs_slide = | 335 qnxgl_attribs_slide = |
337 qnxgl_attrib_set_hint_fullscreen (qnxgl_attribs_slide); | 336 qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide); |
338 } | 337 } |
339 | 338 |
340 /* Double buffering mode */ | 339 /* Double buffering mode */ |
341 if (this->gl_config.double_buffer) { | 340 if (this->gl_config.double_buffer) { |
342 num_buffers = 2; | 341 num_buffers = 2; |
343 } else { | 342 } else { |
344 num_buffers = 1; | 343 num_buffers = 1; |
345 } | 344 } |
346 | 345 |
347 /* Loading the function pointers so we can use the extensions */ | 346 /* Loading the function pointers so we can use the extensions */ |
348 GLPH_LOAD_FUNCS_GC (oglctx); | 347 GLPH_LOAD_FUNCS_GC(oglctx); |
349 | 348 |
350 /* Set the buffers region to be that of our window's region */ | 349 /* Set the buffers region to be that of our window's region */ |
351 qnxgl_attribs_slide = | 350 qnxgl_attribs_slide = |
352 glph_attrib_set_region (qnxgl_attribs_slide, PtWidgetRid (window)); | 351 glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window)); |
353 | 352 |
354 /* End of the attributes array */ | 353 /* End of the attributes array */ |
355 qnxgl_attribs_slide = qnxgl_attrib_set_end (qnxgl_attribs_slide); | 354 qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide); |
356 | 355 |
357 /* Create the buffers with the specified color model */ | 356 /* Create the buffers with the specified color model */ |
358 fprintf (stderr, "ARGB: %d, %d, %d, %d\n", this->gl_config.alpha_size, | 357 fprintf(stderr, "ARGB: %d, %d, %d, %d\n", this->gl_config.alpha_size, |
359 this->gl_config.red_size, this->gl_config.green_size, | 358 this->gl_config.red_size, this->gl_config.green_size, |
360 this->gl_config.blue_size); | 359 this->gl_config.blue_size); |
361 oglbuffers = qnxgl_buffers_create (QNXGL_FORMAT_BEST_RGB, | 360 oglbuffers = qnxgl_buffers_create(QNXGL_FORMAT_BEST_RGB, |
362 /* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size, | 361 /* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size, |
363 this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */ | 362 this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */ |
364 num_buffers, width, height, | 363 num_buffers, width, height, |
365 qnxgl_attribs, -1); | 364 qnxgl_attribs, -1); |
366 | 365 |
367 | 366 |
368 if (oglbuffers == NULL) { | 367 if (oglbuffers == NULL) { |
369 SDL_SetError | 368 SDL_SetError |
370 ("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n"); | 369 ("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n"); |
371 qnxgl_finish (); | 370 qnxgl_finish(); |
372 return -1; | 371 return -1; |
373 } | 372 } |
374 | 373 |
375 /* Create a QNXGL context for the previously created buffer */ | 374 /* Create a QNXGL context for the previously created buffer */ |
376 oglctx = qnxgl_context_create (oglbuffers, NULL); | 375 oglctx = qnxgl_context_create(oglbuffers, NULL); |
377 | 376 |
378 if (oglctx == NULL) { | 377 if (oglctx == NULL) { |
379 SDL_SetError | 378 SDL_SetError |
380 ("ph_SetupOpenGLContext(): failed to create OpenGL context !\n"); | 379 ("ph_SetupOpenGLContext(): failed to create OpenGL context !\n"); |
381 qnxgl_buffers_destroy (oglbuffers); | 380 qnxgl_buffers_destroy(oglbuffers); |
382 qnxgl_finish (); | 381 qnxgl_finish(); |
383 return -1; | 382 return -1; |
384 } | 383 } |
385 | 384 |
386 /* Attempt to make the context current so we can use OpenGL commands */ | 385 /* Attempt to make the context current so we can use OpenGL commands */ |
387 if (qnxgl_set_current (oglctx) == -1) { | 386 if (qnxgl_set_current(oglctx) == -1) { |
388 SDL_SetError | 387 SDL_SetError |
389 ("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n"); | 388 ("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n"); |
390 qnxgl_context_destroy (oglctx); | 389 qnxgl_context_destroy(oglctx); |
391 qnxgl_buffers_destroy (oglbuffers); | 390 qnxgl_buffers_destroy(oglbuffers); |
392 qnxgl_finish (); | 391 qnxgl_finish(); |
393 return -1; | 392 return -1; |
394 } | 393 } |
395 | 394 |
396 PtFlush (); | 395 PtFlush(); |
397 | 396 |
398 oglflags = flags; | 397 oglflags = flags; |
399 oglbpp = bpp; | 398 oglbpp = bpp; |
400 | 399 |
401 return 0; | 400 return 0; |