Mercurial > sdl-ios-xcode
comparison src/video/qnxgf/SDL_qnxgf.c @ 3087:0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
From: "Mike Gorchak"
Subject: Re: About QNX support in SDL 1.3
Here is another batch of patches.
1) Makefile.in - added SDL_opengles.h header as header to install.
2) configure.in - Added special define to detect Common Lite OpenGL ES
library in case if Common library is not installed. Added check for
clock_gettime in libc (in QNX it is in libc).
3) SDL_config.h.in - Added SDL_VIDEO_RENDER_OPENGL_ES and
SDL_VIDEO_OPENGL_ES declarations for configure script autodetection.
4) SDL_opengles.h - Added GL_API definition if it is not defined. Added
extension GL_OES_draw_texture because OpenGL ES Renderer uses it without
declaration. Added GL_OES_vertex_buffer_object extension, which is supported
under QNX OpenGL ES. Added GL_OES_single_precision extension.
5) To the test directory I've added building OpenGL ES test applications
through the autotools suite. Was support for iPhone IDE building only.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 04 Mar 2009 15:10:47 +0000 |
parents | 0bc41e0361d3 |
children | cad1aefa2ed9 |
comparison
equal
deleted
inserted
replaced
3086:0102ed19c21a | 3087:0b6f51c29267 |
---|---|
21 */ | 21 */ |
22 | 22 |
23 #include "SDL_config.h" | 23 #include "SDL_config.h" |
24 | 24 |
25 #include "../SDL_sysvideo.h" | 25 #include "../SDL_sysvideo.h" |
26 #include "SDL_version.h" | |
27 #include "SDL_syswm.h" | |
28 | |
29 /* Include QNX Graphics Framework declarations */ | |
30 #include <gf/gf.h> | |
31 | |
32 #include "SDL_qnxgf.h" | |
33 #include "SDL_gf_pixelfmt.h" | |
34 | |
35 /******************************************************************************/ | |
36 /* SDL Generic video modes, which could provide GF */ | |
37 /* This is real pain in the ass. GF is just wrapper around a selected driver */ | |
38 /* some drivers could support double scan modes, like 320x200, 512x384, etc */ | |
39 /* but some drivers are not. Later we can distinguish one driver from another */ | |
40 /* Feel free to add any new custom graphics mode */ | |
41 /******************************************************************************/ | |
42 static SDL_DisplayMode generic_mode[]= | |
43 { | |
44 {0, 320, 200, 70, NULL}, /* 320x200 modes are 70Hz and 85Hz */ | |
45 {0, 320, 200, 85, NULL}, | |
46 {0, 320, 240, 70, NULL}, /* 320x240 modes are 70Hz and 85Hz */ | |
47 {0, 320, 240, 85, NULL}, | |
48 {0, 512, 384, 60, NULL}, /* 512x384 modes are 60Hz and 70Hz */ | |
49 {0, 512, 384, 70, NULL}, | |
50 {0, 640, 480, 60, NULL}, /* 640x480 modes are 60Hz, 75Hz, 85Hz */ | |
51 {0, 640, 480, 75, NULL}, | |
52 {0, 640, 480, 85, NULL}, | |
53 {0, 800, 600, 60, NULL}, /* 800x600 modes are 60Hz, 75Hz, 85Hz */ | |
54 {0, 800, 600, 75, NULL}, | |
55 {0, 800, 600, 85, NULL}, | |
56 {0, 800, 480, 60, NULL}, /* 800x480 mode is 60Hz only */ | |
57 {0, 1024, 640, 60, NULL}, /* 1024x640 mode is 60Hz only */ | |
58 {0, 1024, 768, 60, NULL}, /* 1024x768 modes are 60Hz, 70Hz, 75Hz */ | |
59 {0, 1024, 768, 70, NULL}, | |
60 {0, 1024, 768, 75, NULL}, | |
61 {0, 1280, 720, 60, NULL}, /* 1280x720 mode is 60Hz only */ | |
62 {0, 1280, 768, 60, NULL}, /* 1280x768 mode is 60Hz only */ | |
63 {0, 1280, 800, 60, NULL}, /* 1280x800 mode is 60Hz only */ | |
64 {0, 1280, 960, 60, NULL}, /* 1280x960 mode is 60Hz only */ | |
65 {0, 1280, 1024, 60, NULL}, /* 1280x1024 mode is 60Hz only */ | |
66 {0, 1400, 1050, 60, NULL}, /* 1400x1050 mode is 60Hz only */ | |
67 {0, 1440, 900, 60, NULL}, /* 1440x900 mode is 60Hz only */ | |
68 {0, 1440, 960, 60, NULL}, /* 1440x960 mode is 60Hz only */ | |
69 {0, 1600, 1200, 60, NULL}, /* 1600x1200 mode is 60Hz only */ | |
70 {0, 1680, 1050, 60, NULL}, /* 1680x1050 mode is 60Hz only */ | |
71 {0, 1920, 1080, 60, NULL}, /* 1920x1080 mode is 60Hz only */ | |
72 {0, 1920, 1200, 60, NULL}, /* 1920x1200 mode is 60Hz only */ | |
73 {0, 2048, 1536, 60, NULL}, /* 2048x1536 mode is 60Hz only */ | |
74 {0, 2048, 1080, 60, NULL}, /* 2048x1080 mode is 60Hz only */ | |
75 {0, 0, 0, 0, NULL} /* End of generic mode list */ | |
76 }; | |
77 | |
78 /*****************************************************************************/ | |
79 /* SDL Video Device initialization functions */ | |
80 /*****************************************************************************/ | |
81 | |
82 static int qnxgf_available(void) | |
83 { | |
84 gf_dev_t gfdev; | |
85 gf_dev_info_t gfdev_info; | |
86 int status; | |
87 | |
88 /* Try to attach to graphics device driver */ | |
89 status=gf_dev_attach(&gfdev, GF_DEVICE_INDEX(0), &gfdev_info); | |
90 if (status!=GF_ERR_OK) | |
91 { | |
92 return 0; | |
93 } | |
94 | |
95 /* Detach from graphics device driver for now */ | |
96 gf_dev_detach(gfdev); | |
97 | |
98 return 1; | |
99 } | |
100 | |
101 static void qnxgf_destroy(SDL_VideoDevice* device) | |
102 { | |
103 SDL_VideoData* gfdata=(SDL_VideoData*) device->driverdata; | |
104 | |
105 /* Detach from graphics device driver, if it was initialized */ | |
106 if (gfdata->gfinitialized!=SDL_FALSE) | |
107 { | |
108 gf_dev_detach(gfdata->gfdev); | |
109 } | |
110 | |
111 if (device->driverdata!=NULL) | |
112 { | |
113 SDL_free(device->driverdata); | |
114 device->driverdata=NULL; | |
115 } | |
116 SDL_free(device); | |
117 } | |
118 | |
119 static SDL_VideoDevice* qnxgf_create(int devindex) | |
120 { | |
121 SDL_VideoDevice* device; | |
122 SDL_VideoData* gfdata; | |
123 int status; | |
124 | |
125 /* Initialize SDL_VideoDevice structure */ | |
126 device = (SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice)); | |
127 if (device==NULL) | |
128 { | |
129 SDL_OutOfMemory(); | |
130 return NULL; | |
131 } | |
132 | |
133 /* Initialize internal GF specific data */ | |
134 gfdata = (SDL_VideoData*)SDL_calloc(1, sizeof(SDL_VideoData)); | |
135 if (gfdata==NULL) | |
136 { | |
137 SDL_OutOfMemory(); | |
138 SDL_free(device); | |
139 return NULL; | |
140 } | |
141 device->driverdata=gfdata; | |
142 | |
143 /* Try to attach to graphics device driver */ | |
144 status=gf_dev_attach(&gfdata->gfdev, GF_DEVICE_INDEX(devindex), &gfdata->gfdev_info); | |
145 if (status!=GF_ERR_OK) | |
146 { | |
147 SDL_OutOfMemory(); | |
148 SDL_free(gfdata); | |
149 SDL_free(device); | |
150 return NULL; | |
151 } | |
152 | |
153 /* Setup amount of available displays and current display */ | |
154 device->num_displays=0; | |
155 device->current_display=0; | |
156 | |
157 /* Setup device shutdown function */ | |
158 gfdata->gfinitialized=SDL_TRUE; | |
159 device->free=qnxgf_destroy; | |
160 | |
161 /* Setup all functions which we can handle */ | |
162 device->VideoInit=qnxgf_videoinit; | |
163 device->VideoQuit=qnxgf_videoquit; | |
164 device->GetDisplayModes=qnxgf_getdisplaymodes; | |
165 device->SetDisplayMode=qnxgf_setdisplaymode; | |
166 device->SetDisplayPalette=qnxgf_setdisplaypalette; | |
167 device->GetDisplayPalette=qnxgf_getdisplaypalette; | |
168 device->SetDisplayGammaRamp=qnxgf_setdisplaygammaramp; | |
169 device->GetDisplayGammaRamp=qnxgf_getdisplaygammaramp; | |
170 device->CreateWindow=qnxgf_createwindow; | |
171 device->CreateWindowFrom=qnxgf_createwindowfrom; | |
172 device->SetWindowTitle=qnxgf_setwindowtitle; | |
173 device->SetWindowIcon=qnxgf_setwindowicon; | |
174 device->SetWindowPosition=qnxgf_setwindowposition; | |
175 device->SetWindowSize=qnxgf_setwindowsize; | |
176 device->ShowWindow=qnxgf_showwindow; | |
177 device->HideWindow=qnxgf_hidewindow; | |
178 device->RaiseWindow=qnxgf_raisewindow; | |
179 device->MaximizeWindow=qnxgf_maximizewindow; | |
180 device->MinimizeWindow=qnxgf_minimizewindow; | |
181 device->RestoreWindow=qnxgf_restorewindow; | |
182 device->SetWindowGrab=qnxgf_setwindowgrab; | |
183 device->DestroyWindow=qnxgf_destroywindow; | |
184 device->GetWindowWMInfo=qnxgf_getwindowwminfo; | |
185 device->GL_LoadLibrary=qnxgf_gl_loadlibrary; | |
186 device->GL_GetProcAddress=qnxgf_gl_getprocaddres; | |
187 device->GL_UnloadLibrary=qnxgf_gl_unloadlibrary; | |
188 device->GL_CreateContext=qnxgf_gl_createcontext; | |
189 device->GL_MakeCurrent=qnxgf_gl_makecurrent; | |
190 device->GL_SetSwapInterval=qnxgf_gl_setswapinterval; | |
191 device->GL_GetSwapInterval=qnxgf_gl_getswapinterval; | |
192 device->GL_SwapWindow=qnxgf_gl_swapwindow; | |
193 device->GL_DeleteContext=qnxgf_gl_deletecontext; | |
194 device->PumpEvents=qnxgf_pumpevents; | |
195 device->SuspendScreenSaver=qnxgf_suspendscreensaver; | |
196 | |
197 return device; | |
198 } | |
26 | 199 |
27 VideoBootStrap qnxgf_bootstrap= | 200 VideoBootStrap qnxgf_bootstrap= |
28 { | 201 { |
29 "QNXGF", | 202 "qnxgf", |
30 "QNX Graphics Framework", | 203 "SDL QNX Graphics Framework (GF) video driver", |
31 NULL, | 204 qnxgf_available, |
32 NULL | 205 qnxgf_create |
33 }; | 206 }; |
34 | 207 |
208 /*****************************************************************************/ | |
209 /* SDL Video and Display initialization/handling functions */ | |
210 /*****************************************************************************/ | |
211 int qnxgf_videoinit(_THIS) | |
212 { | |
213 SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; | |
214 uint32_t it; | |
215 | |
216 /* Add each detected output to SDL */ | |
217 for (it=0; it<gfdata->gfdev_info.ndisplays; it++) | |
218 { | |
219 SDL_VideoDisplay display; | |
220 SDL_DisplayMode current_mode; | |
221 SDL_DisplayData* didata; | |
222 int status; | |
223 | |
224 didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData)); | |
225 if (didata==NULL) | |
226 { | |
227 /* memory allocation problem */ | |
228 SDL_OutOfMemory(); | |
229 return -1; | |
230 } | |
231 | |
232 status=gf_display_query(gfdata->gfdev, it, &didata->display_info); | |
233 if (status==GF_ERR_OK) | |
234 { | |
235 SDL_zero(current_mode); | |
236 current_mode.w=didata->display_info.xres; | |
237 current_mode.h=didata->display_info.yres; | |
238 current_mode.refresh_rate=didata->display_info.refresh; | |
239 current_mode.format=qnxgf_gf_to_sdl_pixelformat(didata->display_info.format); | |
240 current_mode.driverdata=NULL; | |
241 } | |
242 else | |
243 { | |
244 /* video initialization problem */ | |
245 SDL_free(didata); | |
246 SDL_SetError("Display query failed"); | |
247 return -1; | |
248 } | |
249 | |
250 /* Attach GF to selected display */ | |
251 status=gf_display_attach(&didata->display, gfdata->gfdev, it, NULL); | |
252 if (status!=GF_ERR_OK) | |
253 { | |
254 /* video initialization problem */ | |
255 SDL_free(didata); | |
256 SDL_SetError("Couldn't not attach to display"); | |
257 return -1; | |
258 } | |
259 | |
260 SDL_zero(display); | |
261 display.desktop_mode = current_mode; | |
262 display.current_mode = current_mode; | |
263 display.driverdata = didata; | |
264 SDL_AddVideoDisplay(&display); | |
265 } | |
266 | |
267 /* video has been initialized successfully */ | |
268 return 1; | |
269 } | |
270 | |
271 void qnxgf_videoquit(_THIS) | |
272 { | |
273 SDL_DisplayData* didata; | |
274 uint32_t it; | |
275 | |
276 for(it=0; it<_this->num_displays; it++) | |
277 { | |
278 didata=_this->displays[it].driverdata; | |
279 | |
280 /* Detach from selected display */ | |
281 gf_display_detach(didata->display); | |
282 } | |
283 } | |
284 | |
285 void qnxgf_getdisplaymodes(_THIS) | |
286 { | |
287 SDL_DisplayData* didata = (SDL_DisplayData*)SDL_CurrentDisplay.driverdata; | |
288 SDL_DisplayMode mode; | |
289 gf_modeinfo_t modeinfo; | |
290 uint32_t it=0; | |
291 uint32_t jt=0; | |
292 uint32_t kt=0; | |
293 int status; | |
294 | |
295 do { | |
296 status=gf_display_query_mode(didata->display, it, &modeinfo); | |
297 if (status==GF_ERR_OK) | |
298 { | |
299 /* Parsing current mode */ | |
300 if ((modeinfo.flags & GF_MODE_GENERIC)==GF_MODE_GENERIC) | |
301 { | |
302 /* This mode is generic, so we can add to SDL our resolutions */ | |
303 /* Only pixel format is fixed, refresh rate could be any */ | |
304 jt=0; | |
305 do { | |
306 if (generic_mode[jt].w==0) | |
307 { | |
308 break; | |
309 } | |
310 | |
311 mode.w=generic_mode[jt].w; | |
312 mode.h=generic_mode[jt].h; | |
313 mode.refresh_rate=generic_mode[jt].refresh_rate; | |
314 mode.format=qnxgf_gf_to_sdl_pixelformat(modeinfo.primary_format); | |
315 mode.driverdata=NULL; | |
316 SDL_AddDisplayMode(_this->current_display, &mode); | |
317 | |
318 jt++; | |
319 } while(1); | |
320 } | |
321 else | |
322 { | |
323 /* Add this display mode as is in case if it is non-generic */ | |
324 /* But go through the each refresh rate, supported by gf */ | |
325 jt=0; | |
326 do { | |
327 if (modeinfo.refresh[jt]!=0) | |
328 { | |
329 mode.w=modeinfo.xres; | |
330 mode.h=modeinfo.yres; | |
331 mode.refresh_rate=modeinfo.refresh[jt]; | |
332 mode.format=qnxgf_gf_to_sdl_pixelformat(modeinfo.primary_format); | |
333 mode.driverdata=NULL; | |
334 SDL_AddDisplayMode(_this->current_display, &mode); | |
335 jt++; | |
336 } | |
337 else | |
338 { | |
339 break; | |
340 } | |
341 } while(1); | |
342 } | |
343 } | |
344 else | |
345 { | |
346 if (status==GF_ERR_PARM) | |
347 { | |
348 /* out of available modes, all are listed */ | |
349 break; | |
350 } | |
351 | |
352 /* Error occured during mode listing */ | |
353 break; | |
354 } | |
355 it++; | |
356 } while(1); | |
357 } | |
358 | |
359 int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) | |
360 { | |
361 SDL_DisplayData* didata = (SDL_DisplayData*)SDL_CurrentDisplay.driverdata; | |
362 int result; | |
363 | |
364 result=gf_display_set_mode(didata->display, mode->w, mode->h, mode->refresh_rate, | |
365 qnxgf_sdl_to_gf_pixelformat(mode->format), 0); | |
366 if (result!=GF_ERR_OK) | |
367 { | |
368 /* Display mode/resolution switch has been failed */ | |
369 SDL_SetError("Mode is not supported by qnxgf driver"); | |
370 return -1; | |
371 } | |
372 | |
373 return 0; | |
374 } | |
375 | |
376 int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette) | |
377 { | |
378 /* Palette must be set through the QNXGF renderer */ | |
379 /* It connected to surface, part of it */ | |
380 | |
381 /* Setting display palette operation has been failed */ | |
382 return -1; | |
383 } | |
384 | |
385 int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette) | |
386 { | |
387 /* We can give to upper level palette, which it set before */ | |
388 | |
389 /* Getting display palette operation has been failed */ | |
390 return -1; | |
391 } | |
392 | |
393 int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp) | |
394 { | |
395 SDL_DisplayData* didata = (SDL_DisplayData*)SDL_CurrentDisplay.driverdata; | |
396 int status; | |
397 | |
398 /* GF can set Color LUT independently for each color channel, but SDL */ | |
399 /* uses combined gamma ramp, set it to each channel */ | |
400 status=gf_display_set_color_lut16(didata->display, (uint16_t*)ramp, (uint16_t*)ramp, (uint16_t*)ramp); | |
401 if (status!=GF_ERR_OK) | |
402 { | |
403 /* Setting display gamma ramp operation has been failed */ | |
404 return -1; | |
405 } | |
406 | |
407 return 0; | |
408 } | |
409 | |
410 int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp) | |
411 { | |
412 /* We need to return previous gamma set */ | |
413 | |
414 /* Getting display gamma ramp operation has been failed */ | |
415 return -1; | |
416 } | |
417 | |
418 int qnxgf_createwindow(_THIS, SDL_Window* window) | |
419 { | |
420 /* Failed to create new window */ | |
421 return -1; | |
422 } | |
423 | |
424 int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data) | |
425 { | |
426 /* Failed to create window from another window */ | |
427 return -1; | |
428 } | |
429 | |
430 void qnxgf_setwindowtitle(_THIS, SDL_Window* window) | |
431 { | |
432 } | |
433 | |
434 void qnxgf_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon) | |
435 { | |
436 } | |
437 | |
438 void qnxgf_setwindowposition(_THIS, SDL_Window* window) | |
439 { | |
440 } | |
441 | |
442 void qnxgf_setwindowsize(_THIS, SDL_Window* window) | |
443 { | |
444 } | |
445 | |
446 void qnxgf_showwindow(_THIS, SDL_Window* window) | |
447 { | |
448 } | |
449 | |
450 void qnxgf_hidewindow(_THIS, SDL_Window* window) | |
451 { | |
452 } | |
453 | |
454 void qnxgf_raisewindow(_THIS, SDL_Window* window) | |
455 { | |
456 } | |
457 | |
458 void qnxgf_maximizewindow(_THIS, SDL_Window* window) | |
459 { | |
460 } | |
461 | |
462 void qnxgf_minimizewindow(_THIS, SDL_Window* window) | |
463 { | |
464 } | |
465 | |
466 void qnxgf_restorewindow(_THIS, SDL_Window* window) | |
467 { | |
468 } | |
469 | |
470 void qnxgf_setwindowgrab(_THIS, SDL_Window* window) | |
471 { | |
472 } | |
473 | |
474 void qnxgf_destroywindow(_THIS, SDL_Window* window) | |
475 { | |
476 printf("qnxgf_destroywindow()\n"); | |
477 } | |
478 | |
479 /*****************************************************************************/ | |
480 /* SDL Window Manager function */ | |
481 /*****************************************************************************/ | |
482 SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info) | |
483 { | |
484 if (info->version.major <= SDL_MAJOR_VERSION) | |
485 { | |
486 return SDL_TRUE; | |
487 } | |
488 else | |
489 { | |
490 SDL_SetError("Application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION); | |
491 return SDL_FALSE; | |
492 } | |
493 | |
494 /* Failed to get window manager information */ | |
495 return SDL_FALSE; | |
496 } | |
497 | |
498 /*****************************************************************************/ | |
499 /* SDL OpenGL/OpenGL ES functions */ | |
500 /*****************************************************************************/ | |
501 int qnxgf_gl_loadlibrary(_THIS, const char* path) | |
502 { | |
503 /* Failed to load new GL library */ | |
504 return -1; | |
505 } | |
506 | |
507 void* qnxgf_gl_getprocaddres(_THIS, const char* proc) | |
508 { | |
509 /* Failed to get GL function address pointer */ | |
510 return NULL; | |
511 } | |
512 | |
513 void qnxgf_gl_unloadlibrary(_THIS) | |
514 { | |
515 } | |
516 | |
517 SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) | |
518 { | |
519 /* Failed to create GL context */ | |
520 return NULL; | |
521 } | |
522 | |
523 int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context) | |
524 { | |
525 /* Failed to set current GL context */ | |
526 return -1; | |
527 } | |
528 | |
529 int qnxgf_gl_setswapinterval(_THIS, int interval) | |
530 { | |
531 /* Failed to set swap interval */ | |
532 return -1; | |
533 } | |
534 | |
535 int qnxgf_gl_getswapinterval(_THIS) | |
536 { | |
537 /* Failed to get default swap interval */ | |
538 return -1; | |
539 } | |
540 | |
541 void qnxgf_gl_swapwindow(_THIS, SDL_Window* window) | |
542 { | |
543 } | |
544 | |
545 void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context) | |
546 { | |
547 } | |
548 | |
549 /*****************************************************************************/ | |
550 /* SDL Event handling function */ | |
551 /*****************************************************************************/ | |
552 void qnxgf_pumpevents(_THIS) | |
553 { | |
554 } | |
555 | |
556 /*****************************************************************************/ | |
557 /* SDL screen saver related functions */ | |
558 /*****************************************************************************/ | |
559 void qnxgf_suspendscreensaver(_THIS) | |
560 { | |
561 /* There is no screensaver in pure console, it may exist when running */ | |
562 /* GF under Photon, but I do not know, how to disable screensaver */ | |
563 } | |
564 | |
35 /* vi: set ts=4 sw=4 expandtab: */ | 565 /* vi: set ts=4 sw=4 expandtab: */ |