Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_photon.c @ 3754:09d4fa3a787a gsoc2009_unit_tests
Added README.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Thu, 06 Aug 2009 16:58:24 +0000 |
parents | 7f684f249ec9 |
children | 44d5474c2c8a |
rev | line source |
---|---|
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
21 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
22 QNX Photon GUI SDL driver |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
23 Copyright (C) 2009 Mike Gorchak |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
24 (mike@malva.ua, lestat@i.com.ua) |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 */ |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
27 /* SDL internals */ |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "SDL_config.h" |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "../SDL_sysvideo.h" |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
30 #include "SDL_version.h" |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
31 #include "SDL_syswm.h" |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
32 #include "SDL_loadso.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
33 #include "SDL_events.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
34 #include "../../events/SDL_mouse_c.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
35 #include "../../events/SDL_keyboard_c.h" |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
36 |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
37 /* Photon declarations */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
38 #include "SDL_photon.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
39 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
40 /* Pixel format conversion routines */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
41 #include "SDL_photon_pixelfmt.h" |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
42 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
43 /* Use GF's pixel format functions for OpenGL ES context creation */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
44 #if defined(SDL_VIDEO_OPENGL_ES) |
3139 | 45 #include "../qnxgf/SDL_gf_pixelfmt.h" |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
46 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
47 /* If GF driver is not compiled in, include some of usefull functions */ |
3139 | 48 #if !defined(SDL_VIDEO_DRIVER_QNXGF) |
49 #include "../qnxgf/SDL_gf_pixelfmt.c" | |
50 #endif /* SDL_VIDEO_DRIVER_QNXGF */ | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
51 #endif /* SDL_VIDEO_OPENGL_ES */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
52 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
53 /* Use GF's OpenGL ES 1.1 functions emulation */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
54 #if defined(SDL_VIDEO_OPENGL_ES) |
3139 | 55 #include "../qnxgf/SDL_gf_opengles.h" |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
56 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
57 /* If GF driver is not compiled in, include some of usefull functions */ |
3139 | 58 #if !defined(SDL_VIDEO_DRIVER_QNXGF) |
59 #include "../qnxgf/SDL_gf_opengles.c" | |
60 #endif /* SDL_VIDEO_DRIVER_QNXGF */ | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
61 #endif /* SDL_VIDEO_OPENGL_ES */ |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
62 |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
63 /* Low level device graphics driver names, which they are reporting */ |
3139 | 64 Photon_DeviceCaps photon_devicename[] = { |
65 /* ATI Rage 128 graphics driver (devg-ati_rage128) */ | |
66 {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
67 , | |
68 /* Fujitsu Carmine graphics driver (devg-carmine.so) */ | |
69 {"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
70 , | |
71 /* C&T graphics driver (devg-chips.so) */ | |
72 {"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
73 , | |
74 /* Fujitsu Coral graphics driver (devg-coral.so) */ | |
75 {"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
76 , | |
77 /* Intel integrated graphics driver (devg-extreme2.so) */ | |
78 {"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
79 , | |
80 /* Unaccelerated FB driver (devg-flat.so) */ | |
81 {"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
82 , | |
83 /* NS Geode graphics driver (devg-geode.so) */ | |
84 {"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
85 , | |
86 /* Geode LX graphics driver (devg-geodelx.so) */ | |
87 {"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
88 , | |
89 /* Intel integrated graphics driver (devg-gma9xx.so) */ | |
90 {"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
91 , | |
92 /* Intel integrated graphics driver (devg-i810.so) */ | |
93 {"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
94 , | |
95 /* Intel integrated graphics driver (devg-i830.so) */ | |
96 {"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
97 , | |
98 /* Geode LX graphics driver (devg-lx800.so) */ | |
99 {"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
100 , | |
101 /* Matrox Gxx graphics driver (devg-matroxg.so) */ | |
102 {"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
103 , | |
104 /* Intel Poulsbo graphics driver (devg-poulsbo.so) */ | |
105 {"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
106 , | |
107 /* ATI Radeon driver (devg-radeon.so) */ | |
108 {"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
109 , | |
110 /* ATI Rage driver (devg-rage.so) */ | |
111 {"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
112 , | |
113 /* S3 Savage graphics driver (devg-s3_savage.so) */ | |
114 {"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
115 , | |
116 /* SiS630 integrated graphics driver (devg-sis630.so) */ | |
117 {"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
118 , | |
119 /* PowerVR SGX 535 graphics driver (devg-poulsbo.so) */ | |
120 {"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D} | |
121 , | |
122 /* SM Voyager GX graphics driver (devg-smi5xx.so) */ | |
123 {"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
124 , | |
125 /* Silicon Motion graphics driver (devg-smi7xx.so) */ | |
126 {"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
127 , | |
128 /* SVGA unaccelerated gfx driver (devg-svga.so) */ | |
129 {"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
130 , | |
131 /* nVidia TNT graphics driver (devg-tnt.so) */ | |
132 {"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
133 , | |
134 /* VIA integrated graphics driver (devg-tvia.so) */ | |
135 {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
136 , | |
137 /* VIA UniChrome graphics driver (devg-unichrome.so) */ | |
138 {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
139 , | |
140 /* VESA unaccelerated gfx driver (devg-vesa.so) */ | |
141 {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
142 , | |
143 /* VmWare graphics driver (devg-volari.so) */ | |
144 {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
145 , | |
146 /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5 */ | |
147 {"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D} | |
148 , | |
149 /* End of list */ | |
150 {NULL, 0x00000000} | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
151 }; |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
3139 | 153 static SDL_bool photon_initialized = SDL_FALSE; |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
3139 | 155 static int |
156 photon_available(void) | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 { |
3139 | 158 int status; |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
3139 | 160 /* Check if Photon was initialized before */ |
161 if (photon_initialized == SDL_FALSE) { | |
162 /* Initialize Photon widget library and open channel to Photon */ | |
163 status = PtInit(NULL); | |
164 if (status == 0) { | |
165 photon_initialized = SDL_TRUE; | |
166 return 1; | |
167 } else { | |
168 photon_initialized = SDL_FALSE; | |
169 return 0; | |
170 } | |
171 } | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
3139 | 173 return 1; |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 } |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
3139 | 176 static void |
177 photon_destroy(SDL_VideoDevice * device) | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 { |
3139 | 179 SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
180 |
3139 | 181 #if defined(SDL_VIDEO_OPENGL_ES) |
182 if (phdata->gfinitialized != SDL_FALSE) { | |
183 gf_dev_detach(phdata->gfdev); | |
184 } | |
185 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
186 |
3139 | 187 if (device->driverdata != NULL) { |
188 device->driverdata = NULL; | |
189 } | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 } |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
3139 | 192 static SDL_VideoDevice * |
193 photon_create(int devindex) | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 { |
3139 | 195 SDL_VideoDevice *device; |
196 SDL_VideoData *phdata; | |
197 int status; | |
198 | |
199 /* Check if photon could be initialized */ | |
200 status = photon_available(); | |
201 if (status == 0) { | |
202 /* Photon could not be used */ | |
203 return NULL; | |
204 } | |
205 | |
206 /* Photon agregates all video devices to one with multiple heads */ | |
207 if (devindex != 0) { | |
208 /* devindex could be zero only in Photon SDL driver */ | |
209 return NULL; | |
210 } | |
211 | |
212 /* Initialize SDL_VideoDevice structure */ | |
213 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); | |
214 if (device == NULL) { | |
215 SDL_OutOfMemory(); | |
216 return NULL; | |
217 } | |
218 | |
219 /* Initialize internal photon specific data */ | |
220 phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); | |
221 if (phdata == NULL) { | |
222 SDL_OutOfMemory(); | |
223 SDL_free(device); | |
224 return NULL; | |
225 } | |
226 device->driverdata = phdata; | |
227 | |
228 /* Get all photon display devices */ | |
229 phdata->avail_rids = | |
230 PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS); | |
231 if (phdata->avail_rids > SDL_VIDEO_PHOTON_MAX_RIDS) { | |
232 phdata->avail_rids = SDL_VIDEO_PHOTON_MAX_RIDS; | |
233 } | |
234 #if defined(SDL_VIDEO_OPENGL_ES) | |
235 /* TODO: add real device detection versus multiple heads */ | |
236 status = | |
237 gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0), | |
238 &phdata->gfdev_info); | |
239 if (status != GF_ERR_OK) { | |
240 /* Do not fail right now, if GF can't be attached */ | |
241 phdata->gfinitialized = SDL_FALSE; | |
242 } else { | |
243 phdata->gfinitialized = SDL_TRUE; | |
244 } | |
245 #endif /* SDL_VIDEO_OPENGL_ES */ | |
246 | |
247 /* Set default target device */ | |
248 status = PdSetTargetDevice(NULL, phdata->rid[0]); | |
249 if (status == -1) { | |
250 SDL_SetError("Photon: Can't set default target device"); | |
251 #if defined(SDL_VIDEO_OPENGL_ES) | |
252 gf_dev_detach(phdata->gfdev); | |
253 #endif /* SDL_VIDEO_OPENGL_ES */ | |
254 SDL_free(phdata); | |
255 SDL_free(device); | |
256 return NULL; | |
257 } | |
258 phdata->current_device_id = 0; | |
259 | |
260 /* Setup amount of available displays and current display */ | |
261 device->num_displays = 0; | |
262 device->current_display = 0; | |
263 | |
264 /* Set device free function */ | |
265 device->free = photon_destroy; | |
266 | |
267 /* Setup all functions which we can handle */ | |
268 device->VideoInit = photon_videoinit; | |
269 device->VideoQuit = photon_videoquit; | |
270 device->GetDisplayModes = photon_getdisplaymodes; | |
271 device->SetDisplayMode = photon_setdisplaymode; | |
272 device->SetDisplayPalette = photon_setdisplaypalette; | |
273 device->GetDisplayPalette = photon_getdisplaypalette; | |
274 device->SetDisplayGammaRamp = photon_setdisplaygammaramp; | |
275 device->GetDisplayGammaRamp = photon_getdisplaygammaramp; | |
276 device->CreateWindow = photon_createwindow; | |
277 device->CreateWindowFrom = photon_createwindowfrom; | |
278 device->SetWindowTitle = photon_setwindowtitle; | |
279 device->SetWindowIcon = photon_setwindowicon; | |
280 device->SetWindowPosition = photon_setwindowposition; | |
281 device->SetWindowSize = photon_setwindowsize; | |
282 device->ShowWindow = photon_showwindow; | |
283 device->HideWindow = photon_hidewindow; | |
284 device->RaiseWindow = photon_raisewindow; | |
285 device->MaximizeWindow = photon_maximizewindow; | |
286 device->MinimizeWindow = photon_minimizewindow; | |
287 device->RestoreWindow = photon_restorewindow; | |
288 device->SetWindowGrab = photon_setwindowgrab; | |
289 device->DestroyWindow = photon_destroywindow; | |
290 device->GetWindowWMInfo = photon_getwindowwminfo; | |
291 device->GL_LoadLibrary = photon_gl_loadlibrary; | |
292 device->GL_GetProcAddress = photon_gl_getprocaddres; | |
293 device->GL_UnloadLibrary = photon_gl_unloadlibrary; | |
294 device->GL_CreateContext = photon_gl_createcontext; | |
295 device->GL_MakeCurrent = photon_gl_makecurrent; | |
296 device->GL_SetSwapInterval = photon_gl_setswapinterval; | |
297 device->GL_GetSwapInterval = photon_gl_getswapinterval; | |
298 device->GL_SwapWindow = photon_gl_swapwindow; | |
299 device->GL_DeleteContext = photon_gl_deletecontext; | |
300 device->PumpEvents = photon_pumpevents; | |
301 device->SuspendScreenSaver = photon_suspendscreensaver; | |
302 | |
303 return device; | |
304 } | |
305 | |
306 VideoBootStrap photon_bootstrap = { | |
307 "photon", | |
308 "SDL QNX Photon video driver", | |
309 photon_available, | |
310 photon_create | |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 }; |
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
313 /*****************************************************************************/ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
314 /* SDL Video and Display initialization/handling functions */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
315 /*****************************************************************************/ |
3139 | 316 int |
317 photon_videoinit(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
318 { |
3139 | 319 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
320 PgHWCaps_t hwcaps; | |
321 PgVideoModeInfo_t modeinfo; | |
322 int32_t status; | |
323 SDL_VideoDisplay display; | |
324 SDL_DisplayMode current_mode; | |
325 SDL_DisplayData *didata; | |
326 uint32_t it; | |
327 uint32_t jt; | |
328 char *override; | |
329 | |
330 /* By default Photon do not uses swap on VSYNC */ | |
331 phdata->swapinterval = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
332 |
3139 | 333 for (it = 0; it < phdata->avail_rids; it++) { |
334 didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); | |
335 if (didata == NULL) { | |
336 /* memory allocation error */ | |
337 SDL_OutOfMemory(); | |
338 return -1; | |
339 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
340 |
3139 | 341 /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */ |
342 /* and 128 bytes of spare place */ | |
343 didata->cursor_size = | |
344 ((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE * 4) >> 3) + 128; | |
345 didata->cursor = (PhCursorDef_t *) SDL_calloc(1, didata->cursor_size); | |
346 if (didata->cursor == NULL) { | |
347 /* memory allocation error */ | |
348 SDL_OutOfMemory(); | |
349 SDL_free(didata); | |
350 return -1; | |
351 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
352 |
3139 | 353 /* Initialize GF in case of OpenGL ES support is compiled in */ |
354 #if defined(SDL_VIDEO_OPENGL_ES) | |
355 /* TODO: add real device detection versus multiple heads */ | |
356 if (phdata->gfinitialized == SDL_TRUE) { | |
357 status = | |
358 gf_display_attach(&didata->display, phdata->gfdev, it, | |
359 &didata->display_info); | |
360 if (status != GF_ERR_OK) { | |
361 /* Just shutdown GF, do not fail */ | |
362 gf_dev_detach(phdata->gfdev); | |
363 phdata->gfinitialized = SDL_FALSE; | |
364 } | |
365 } | |
366 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
367 |
3139 | 368 /* Check if current device is not the same as target */ |
369 if (phdata->current_device_id != it) { | |
370 /* Set target device as default for Pd and Pg functions */ | |
371 status = PdSetTargetDevice(NULL, phdata->rid[it]); | |
372 if (status != 0) { | |
373 SDL_SetError("Photon: Can't set default target device\n"); | |
374 SDL_free(didata->cursor); | |
375 SDL_free(didata); | |
376 return -1; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
377 } |
3139 | 378 phdata->current_device_id = it; |
379 } | |
380 | |
381 /* Store device id */ | |
382 didata->device_id = it; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
383 |
3139 | 384 /* Query photon about graphics hardware caps and current video mode */ |
385 status = PgGetGraphicsHWCaps(&hwcaps); | |
386 if (status != 0) { | |
387 SDL_SetError("Photon: Can't get graphics capabilities"); | |
388 SDL_free(didata->cursor); | |
389 SDL_free(didata); | |
390 return -1; | |
391 } | |
392 | |
393 /* Get current video mode details */ | |
394 status = PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo); | |
395 if (status != 0) { | |
396 SDL_SetError("Photon: Can't get current video mode information"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
397 SDL_free(didata->cursor); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
398 SDL_free(didata); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
399 return -1; |
3139 | 400 } |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
401 |
3139 | 402 /* Setup current desktop mode for SDL */ |
403 SDL_zero(current_mode); | |
404 current_mode.w = modeinfo.width; | |
405 current_mode.h = modeinfo.height; | |
406 current_mode.refresh_rate = hwcaps.current_rrate; | |
407 current_mode.format = photon_image_to_sdl_pixelformat(modeinfo.type); | |
408 current_mode.driverdata = NULL; | |
409 | |
410 /* Copy device name */ | |
411 SDL_strlcpy(didata->description, hwcaps.chip_name, | |
412 SDL_VIDEO_PHOTON_DEVICENAME_MAX - 1); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
413 |
3139 | 414 /* Search device capabilities and possible workarounds */ |
415 jt = 0; | |
416 do { | |
417 if (photon_devicename[jt].name == NULL) { | |
418 break; | |
419 } | |
420 if (SDL_strncmp | |
421 (photon_devicename[jt].name, didata->description, | |
422 SDL_strlen(photon_devicename[jt].name)) == 0) { | |
423 didata->caps = photon_devicename[jt].caps; | |
424 } | |
425 jt++; | |
426 } while (1); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
427 |
3139 | 428 /* Initialize display structure */ |
429 SDL_zero(display); | |
430 display.desktop_mode = current_mode; | |
431 display.current_mode = current_mode; | |
432 display.driverdata = didata; | |
433 didata->current_mode = current_mode; | |
434 SDL_AddVideoDisplay(&display); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
435 |
3139 | 436 /* Check for environment variables which could override some SDL settings */ |
437 didata->custom_refresh = 0; | |
438 override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE"); | |
439 if (override != NULL) { | |
440 if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) { | |
441 didata->custom_refresh = 0; | |
442 } | |
443 } | |
444 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
445 |
3139 | 446 /* Add photon input devices */ |
447 status = photon_addinputdevices(_this); | |
448 if (status != 0) { | |
449 /* SDL error is set by photon_addinputdevices() function */ | |
450 return -1; | |
451 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
452 |
3139 | 453 /* Add photon renderer to SDL */ |
454 photon_addrenderdriver(_this); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
455 |
3139 | 456 /* video has been initialized successfully */ |
457 return 1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
458 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
459 |
3139 | 460 void |
461 photon_videoquit(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
462 { |
3139 | 463 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
464 SDL_DisplayData *didata; | |
465 uint32_t it; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
466 |
3139 | 467 /* SDL will restore our desktop mode on exit */ |
468 for (it = 0; it < _this->num_displays; it++) { | |
469 didata = _this->displays[it].driverdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
470 |
3139 | 471 if (didata->cursor != NULL) { |
472 SDL_free(didata->cursor); | |
473 } | |
474 #if defined(SDL_VIDEO_OPENGL_ES) | |
475 if (phdata->gfinitialized == SDL_TRUE) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
476 /* Detach GF display */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
477 gf_display_detach(didata->display); |
3139 | 478 } |
479 #endif /* SDL_VIDEO_OPENGL_ES */ | |
480 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
481 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
482 |
3139 | 483 void |
484 photon_getdisplaymodes(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
485 { |
3139 | 486 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
487 SDL_DisplayData *didata = | |
488 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
489 SDL_DisplayMode mode; | |
490 PgVideoModes_t modes; | |
491 PgVideoModeInfo_t modeinfo; | |
492 int32_t status; | |
493 uint32_t it; | |
494 uint32_t jt; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
495 |
3139 | 496 /* Check if current device is not the same as target */ |
497 if (phdata->current_device_id != didata->device_id) { | |
498 /* Set target device as default for Pd and Pg functions */ | |
499 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); | |
500 if (status != 0) { | |
501 SDL_SetError("Photon: Can't set default target device\n"); | |
502 return; | |
503 } | |
504 phdata->current_device_id = didata->device_id; | |
505 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
506 |
3139 | 507 /* Get array of available video modes */ |
508 status = PgGetVideoModeList(&modes); | |
509 if (status != 0) { | |
510 SDL_SetError("Photon: Can't get video mode list"); | |
511 return; | |
512 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
513 |
3139 | 514 for (it = 0; it < modes.num_modes; it++) { |
515 status = PgGetVideoModeInfo(modes.modes[it], &modeinfo); | |
516 if (status != 0) { | |
517 /* Maybe something wrong with this particular mode, skip it */ | |
518 continue; | |
519 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
520 |
3139 | 521 jt = 0; |
522 do { | |
523 if (modeinfo.refresh_rates[jt] != 0) { | |
524 mode.w = modeinfo.width; | |
525 mode.h = modeinfo.height; | |
526 mode.refresh_rate = modeinfo.refresh_rates[jt]; | |
527 mode.format = photon_image_to_sdl_pixelformat(modeinfo.type); | |
528 mode.driverdata = NULL; | |
529 SDL_AddDisplayMode(_this->current_display, &mode); | |
530 jt++; | |
531 } else { | |
532 break; | |
533 } | |
534 } while (1); | |
535 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
536 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
537 |
3139 | 538 int |
539 photon_setdisplaymode(_THIS, SDL_DisplayMode * mode) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
540 { |
3139 | 541 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
542 SDL_DisplayData *didata = | |
543 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
544 PgVideoModes_t modes; | |
545 PgVideoModeInfo_t modeinfo; | |
546 PgDisplaySettings_t modesettings; | |
547 uint32_t refresh_rate = 0; | |
548 int32_t status; | |
549 uint32_t it; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
550 |
3139 | 551 /* Check if current device is not the same as target */ |
552 if (phdata->current_device_id != didata->device_id) { | |
553 /* Set target device as default for Pd and Pg functions */ | |
554 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); | |
555 if (status != 0) { | |
556 SDL_SetError("Photon: Can't set default target device\n"); | |
557 return; | |
558 } | |
559 phdata->current_device_id = didata->device_id; | |
560 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
561 |
3139 | 562 /* Get array of available video modes */ |
563 status = PgGetVideoModeList(&modes); | |
564 if (status != 0) { | |
565 SDL_SetError("Photon: Can't get video mode list"); | |
566 return; | |
567 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
568 |
3139 | 569 /* Current display dimension and bpp are no more valid */ |
570 didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN; | |
571 didata->current_mode.w = 0; | |
572 didata->current_mode.h = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
573 |
3139 | 574 /* Check if custom refresh rate requested */ |
575 if (didata->custom_refresh != 0) { | |
576 refresh_rate = didata->custom_refresh; | |
577 } else { | |
578 refresh_rate = mode->refresh_rate; | |
579 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
580 |
3139 | 581 /* Check if SDL GF driver needs to find appropriate refresh rate itself */ |
582 if (refresh_rate == 0) { | |
583 SDL_DisplayMode tempmode; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
584 |
3139 | 585 /* Clear display mode structure */ |
586 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode)); | |
587 tempmode.refresh_rate = 0x0000FFFF; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
588 |
3139 | 589 /* Check if window width and height matches one of our modes */ |
590 for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) { | |
591 if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) && | |
592 (SDL_CurrentDisplay.display_modes[it].h == mode->h) && | |
593 (SDL_CurrentDisplay.display_modes[it].format == mode->format)) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
594 { |
3139 | 595 /* Find the lowest refresh rate available */ |
596 if (tempmode.refresh_rate > | |
597 SDL_CurrentDisplay.display_modes[it].refresh_rate) { | |
598 tempmode = SDL_CurrentDisplay.display_modes[it]; | |
599 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
600 } |
3139 | 601 } |
602 if (tempmode.refresh_rate != 0x0000FFFF) { | |
603 refresh_rate = tempmode.refresh_rate; | |
604 } else { | |
605 /* Let video driver decide what to do with this */ | |
606 refresh_rate = 0; | |
607 } | |
608 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
609 |
3139 | 610 /* Check if SDL GF driver needs to check custom refresh rate */ |
611 if (didata->custom_refresh != 0) { | |
612 SDL_DisplayMode tempmode; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
613 |
3139 | 614 /* Clear display mode structure */ |
615 SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode)); | |
616 tempmode.refresh_rate = 0x0000FFFF; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
617 |
3139 | 618 /* Check if window width and height matches one of our modes */ |
619 for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) { | |
620 if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) && | |
621 (SDL_CurrentDisplay.display_modes[it].h == mode->h) && | |
622 (SDL_CurrentDisplay.display_modes[it].format == mode->format)) | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
623 { |
3139 | 624 /* Find the lowest refresh rate available */ |
625 if (tempmode.refresh_rate > | |
626 SDL_CurrentDisplay.display_modes[it].refresh_rate) { | |
627 tempmode = SDL_CurrentDisplay.display_modes[it]; | |
628 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
629 |
3139 | 630 /* Check if requested refresh rate found */ |
631 if (refresh_rate == | |
632 SDL_CurrentDisplay.display_modes[it].refresh_rate) { | |
633 tempmode = SDL_CurrentDisplay.display_modes[it]; | |
634 break; | |
635 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
636 } |
3139 | 637 } |
638 if (tempmode.refresh_rate != 0x0000FFFF) { | |
639 refresh_rate = tempmode.refresh_rate; | |
640 } else { | |
641 /* Let video driver decide what to do with this */ | |
642 refresh_rate = 0; | |
643 } | |
644 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
645 |
3139 | 646 /* Find photon's video mode number */ |
647 for (it = 0; it < modes.num_modes; it++) { | |
648 uint32_t jt; | |
649 uint32_t foundrefresh; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
650 |
3139 | 651 /* Get current video mode details */ |
652 status = PgGetVideoModeInfo(modes.modes[it], &modeinfo); | |
653 if (status != 0) { | |
654 /* Maybe something wrong with this particular mode, skip it */ | |
655 continue; | |
656 } | |
657 if ((modeinfo.width == mode->w) && (modeinfo.height == mode->h) && | |
658 (modeinfo.type == photon_sdl_to_image_pixelformat(mode->format))) | |
659 { | |
660 /* Mode is found, find requested refresh rate, this case is for */ | |
661 /* video drivers, which provide non-generic video modes. */ | |
662 jt = 0; | |
663 foundrefresh = 0; | |
664 do { | |
665 if (modeinfo.refresh_rates[jt] != 0) { | |
666 if (modeinfo.refresh_rates[jt] == refresh_rate) { | |
667 foundrefresh = 1; | |
668 break; | |
669 } | |
670 jt++; | |
671 } else { | |
672 break; | |
673 } | |
674 } while (1); | |
675 if (foundrefresh != 0) { | |
676 break; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
677 } |
3139 | 678 } |
679 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
680 |
3139 | 681 /* Check if video mode has not been found */ |
682 if (it == modes.num_modes) { | |
683 SDL_SetError("Photon: Can't find appropriate video mode"); | |
684 return -1; | |
685 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
686 |
3139 | 687 /* Fill mode settings */ |
688 modesettings.flags = 0x00000000; | |
689 modesettings.mode = modes.modes[it]; | |
690 modesettings.refresh = refresh_rate; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
691 |
3139 | 692 /* Finally set new video mode */ |
693 status = PgSetVideoMode(&modesettings); | |
694 if (status != 0) { | |
695 SDL_SetError("Photon: Can't set new video mode"); | |
696 return -1; | |
697 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
698 |
3139 | 699 /* Store new video mode parameters */ |
700 didata->current_mode = *mode; | |
701 didata->current_mode.refresh_rate = refresh_rate; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
702 |
3139 | 703 return 0; |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
704 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
705 |
3139 | 706 int |
707 photon_setdisplaypalette(_THIS, SDL_Palette * palette) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
708 { |
3139 | 709 SDL_DisplayData *didata = |
710 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
711 |
3139 | 712 /* Setting display palette operation has been failed */ |
713 return -1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
714 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
715 |
3139 | 716 int |
717 photon_getdisplaypalette(_THIS, SDL_Palette * palette) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
718 { |
3139 | 719 SDL_DisplayData *didata = |
720 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
721 |
3139 | 722 /* Getting display palette operation has been failed */ |
723 return -1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
724 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
725 |
3139 | 726 int |
727 photon_setdisplaygammaramp(_THIS, Uint16 * ramp) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
728 { |
3139 | 729 SDL_DisplayData *didata = |
730 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
731 |
3139 | 732 /* Setting display gamma ramp operation has been failed */ |
733 return -1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
734 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
735 |
3139 | 736 int |
737 photon_getdisplaygammaramp(_THIS, Uint16 * ramp) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
738 { |
3139 | 739 /* Getting display gamma ramp operation has been failed */ |
740 return -1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
741 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
742 |
3139 | 743 int |
744 photon_createwindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
745 { |
3139 | 746 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
747 SDL_DisplayData *didata = | |
748 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
749 SDL_WindowData *wdata; | |
750 PhDim_t winsize; | |
751 PhPoint_t winpos; | |
752 PtArg_t winargs[32]; | |
753 uint32_t winargc = 0; | |
754 int32_t status; | |
755 PhRegion_t wregion; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
756 |
3139 | 757 /* Allocate window internal data */ |
758 wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData)); | |
759 if (wdata == NULL) { | |
760 SDL_OutOfMemory(); | |
761 return -1; | |
762 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
763 |
3139 | 764 /* Setup driver data for this window */ |
765 window->driverdata = wdata; | |
766 | |
767 /* Set initial window title */ | |
768 if (window->title != NULL) { | |
769 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0); | |
770 } else { | |
771 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0); | |
772 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
773 |
3139 | 774 /* TODO: handle SDL_WINDOW_INPUT_GRABBED */ |
775 | |
776 /* Disable default window filling on redraw */ | |
777 PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, | |
778 Pt_BASIC_PREVENT_FILL); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
779 |
3139 | 780 /* Reset default managed flags to disabled state */ |
781 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, | |
782 Ph_WM_APP_DEF_MANAGED); | |
783 /* Set which events we will not handle, let WM to handle them */ | |
784 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, | |
785 Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT | | |
786 Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX | | |
787 Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR | | |
788 Ph_WM_TOBACK | Ph_WM_RESIZE); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
789 |
3139 | 790 /* Reset default notify events to disable */ |
791 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, | |
792 Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP); | |
793 /* Set which events we will handle */ | |
794 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, | |
795 Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX | | |
796 Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
797 |
3139 | 798 /* Borderless window can't be resizeable */ |
799 if ((window->flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS) { | |
800 window->flags &= ~(SDL_WINDOW_RESIZABLE); | |
801 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
802 |
3139 | 803 /* Reset all default decorations */ |
804 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, | |
805 Ph_WM_APP_DEF_RENDER); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
806 |
3139 | 807 /* Fullscreen window has its own decorations */ |
808 if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) { | |
809 window->flags |= SDL_WINDOW_BORDERLESS; | |
810 window->flags &= ~(SDL_WINDOW_RESIZABLE); | |
811 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, | |
812 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE); | |
813 } else { | |
814 uint32_t decorations = | |
815 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN | | |
816 Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
817 |
3139 | 818 if ((window->flags & SDL_WINDOW_RESIZABLE) == SDL_WINDOW_RESIZABLE) { |
819 decorations |= | |
820 Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX; | |
821 PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, | |
822 Pt_RESIZE_XY_AS_REQUIRED); | |
823 } | |
824 if ((window->flags & SDL_WINDOW_BORDERLESS) != SDL_WINDOW_BORDERLESS) { | |
825 decorations |= Ph_WM_RENDER_BORDER; | |
826 } | |
827 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, | |
828 decorations); | |
829 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
830 |
3139 | 831 /* Set initial window state */ |
832 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, | |
833 Ph_WM_STATE_ISFOCUS); | |
834 PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, | |
835 Ph_WM_STATE_ISALTKEY); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
836 |
3139 | 837 /* Set window dimension */ |
838 winsize.w = window->w; | |
839 winsize.h = window->h; | |
840 PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
841 |
3139 | 842 /* Check if upper level requests WM to position window */ |
843 if ((window->x == SDL_WINDOWPOS_UNDEFINED) | |
844 && (window->y == SDL_WINDOWPOS_UNDEFINED)) { | |
845 /* Do not set widget position, let WM to set it */ | |
846 } else { | |
847 if (window->x == SDL_WINDOWPOS_UNDEFINED) { | |
848 window->x = 0; | |
849 } | |
850 if (window->y == SDL_WINDOWPOS_UNDEFINED) { | |
851 window->y = 0; | |
852 } | |
853 if (window->x == SDL_WINDOWPOS_CENTERED) { | |
854 window->x = (didata->current_mode.w - window->w) / 2; | |
855 } | |
856 if (window->y == SDL_WINDOWPOS_CENTERED) { | |
857 window->y = (didata->current_mode.h - window->h) / 2; | |
858 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
859 |
3139 | 860 /* Now set window position */ |
861 winpos.x = window->x; | |
862 winpos.y = window->y; | |
863 PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0); | |
864 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
865 |
3139 | 866 /* Check if window must support OpenGL ES rendering */ |
867 if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) { | |
868 #if defined(SDL_VIDEO_OPENGL_ES) | |
869 EGLBoolean initstatus; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
870 |
3139 | 871 /* Check if GF was initialized correctly */ |
872 if (phdata->gfinitialized == SDL_FALSE) { | |
873 SDL_SetError | |
874 ("Photon: GF initialization failed, no OpenGL ES support"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
875 return -1; |
3139 | 876 } |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
877 |
3139 | 878 /* Mark this window as OpenGL ES compatible */ |
879 wdata->uses_gles = SDL_TRUE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
880 |
3139 | 881 /* Create connection to OpenGL ES */ |
882 if (phdata->egldisplay == EGL_NO_DISPLAY) { | |
883 phdata->egldisplay = eglGetDisplay(phdata->gfdev); | |
884 if (phdata->egldisplay == EGL_NO_DISPLAY) { | |
885 SDL_SetError("Photon: Can't get connection to OpenGL ES"); | |
886 return -1; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
887 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
888 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
889 /* Initialize OpenGL ES library, ignore EGL version */ |
3139 | 890 initstatus = eglInitialize(phdata->egldisplay, NULL, NULL); |
891 if (initstatus != EGL_TRUE) { | |
892 SDL_SetError("Photon: Can't init OpenGL ES library"); | |
893 return -1; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
894 } |
3139 | 895 } |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
896 |
3139 | 897 /* Increment GL ES reference count usage */ |
898 phdata->egl_refcount++; | |
899 #else | |
900 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
901 return -1; | |
902 #endif /* SDL_VIDEO_OPENGL_ES */ | |
903 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
904 |
3139 | 905 /* Finally create the window */ |
906 wdata->window = PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs); | |
907 if (wdata->window == NULL) { | |
908 SDL_SetError("Photon: Can't create window widget"); | |
909 SDL_free(wdata); | |
910 return -1; | |
911 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
912 |
3139 | 913 /* Show widget */ |
914 status = PtRealizeWidget(wdata->window); | |
915 if (status != 0) { | |
916 SDL_SetError("Photon: Can't realize window widget"); | |
917 PtDestroyWidget(wdata->window); | |
918 SDL_free(wdata); | |
919 return; | |
920 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
921 |
3139 | 922 /* Just created SDL window always gets focus */ |
923 window->flags |= SDL_WINDOW_INPUT_FOCUS; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
924 |
3139 | 925 /* Create window-specific cursor after creation */ |
926 if (didata->cursor_visible == SDL_TRUE) { | |
927 /* Setup cursor type. shape and default color */ | |
928 PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, | |
929 Ph_CURSOR_DEFAULT_COLOR, 0); | |
930 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0); | |
931 PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor, | |
932 didata->cursor->hdr.len + sizeof(PhRegionDataHdr_t)); | |
933 } else { | |
934 PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0); | |
935 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
936 |
3139 | 937 /* Set window region sensible to mouse motion events */ |
938 status = | |
939 PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0); | |
940 if (status != 0) { | |
941 SDL_SetError | |
942 ("Photon: Can't set region sensivity to mouse motion events"); | |
943 PtDestroyWidget(wdata->window); | |
944 SDL_free(wdata); | |
945 return -1; | |
946 } | |
947 wregion.events_sense |= | |
948 Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; | |
949 status = PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL); | |
950 if (status < 0) { | |
951 SDL_SetError("Photon: Can't change region sensivity"); | |
952 PtDestroyWidget(wdata->window); | |
953 SDL_free(wdata); | |
954 return -1; | |
955 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
956 |
3139 | 957 /* Flush all widget operations again */ |
958 PtFlush(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
959 |
3139 | 960 /* By default last created window got a input focus */ |
961 SDL_SetKeyboardFocus(0, window->id); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
962 |
3139 | 963 /* Window has been successfully created */ |
964 return 0; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
965 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
966 |
3139 | 967 int |
968 photon_createwindowfrom(_THIS, SDL_Window * window, const void *data) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
969 { |
3139 | 970 /* TODO: it is possible */ |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
971 |
3139 | 972 /* Failed to create window from another window */ |
973 return -1; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
974 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
975 |
3139 | 976 void |
977 photon_setwindowtitle(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
978 { |
3139 | 979 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
980 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
981 |
3139 | 982 /* Set window title */ |
983 if (window->title != NULL) { | |
984 status = | |
985 PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title, | |
986 0); | |
987 } else { | |
988 status = PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0); | |
989 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
990 |
3139 | 991 if (status != 0) { |
992 SDL_SetError("Photon: Can't set window title"); | |
993 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
994 |
3139 | 995 /* Flush all widget operations */ |
996 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
997 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
998 |
3139 | 999 void |
1000 photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1001 { |
3139 | 1002 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1003 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1004 |
3139 | 1005 /* TODO: Use iconify ? */ |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1006 |
3139 | 1007 /* Flush all widget operations */ |
1008 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1009 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1010 |
3139 | 1011 void |
1012 photon_setwindowposition(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1013 { |
3139 | 1014 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1015 SDL_DisplayData *didata = | |
1016 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
1017 PhPoint_t winpos; | |
1018 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1019 |
3139 | 1020 /* Check if upper level requests WM to position window */ |
1021 if ((window->x == SDL_WINDOWPOS_UNDEFINED) | |
1022 && (window->y == SDL_WINDOWPOS_UNDEFINED)) { | |
1023 /* Do not set widget position, let WM to set it */ | |
1024 } else { | |
1025 if (window->x == SDL_WINDOWPOS_UNDEFINED) { | |
1026 window->x = 0; | |
1027 } | |
1028 if (window->y == SDL_WINDOWPOS_UNDEFINED) { | |
1029 window->y = 0; | |
1030 } | |
1031 if (window->x == SDL_WINDOWPOS_CENTERED) { | |
1032 window->x = (didata->current_mode.w - window->w) / 2; | |
1033 } | |
1034 if (window->y == SDL_WINDOWPOS_CENTERED) { | |
1035 window->y = (didata->current_mode.h - window->h) / 2; | |
1036 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1037 |
3139 | 1038 /* Now set window position */ |
1039 winpos.x = window->x; | |
1040 winpos.y = window->y; | |
1041 status = PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0); | |
1042 if (status != 0) { | |
1043 SDL_SetError("Photon: Can't set window position"); | |
1044 } | |
1045 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1046 |
3139 | 1047 /* Flush all widget operations */ |
1048 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1049 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1050 |
3139 | 1051 void |
1052 photon_setwindowsize(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1053 { |
3139 | 1054 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1055 PhDim_t winsize; | |
1056 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1057 |
3139 | 1058 winsize.w = window->w; |
1059 winsize.h = window->h; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1060 |
3139 | 1061 status = PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0); |
1062 if (status != 0) { | |
1063 SDL_SetError("Photon: Can't set window size"); | |
1064 } | |
1065 | |
1066 /* Flush all widget operations */ | |
1067 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1068 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1069 |
3139 | 1070 void |
1071 photon_showwindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1072 { |
3139 | 1073 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1074 int32_t status; | |
1075 | |
1076 /* Bring focus to window and put it in front of others */ | |
1077 PtWindowToFront(wdata->window); | |
1078 | |
1079 /* Flush all widget operations */ | |
1080 PtFlush(); | |
1081 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1082 |
3139 | 1083 void |
1084 photon_hidewindow(_THIS, SDL_Window * window) | |
1085 { | |
1086 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; | |
1087 PhWindowEvent_t winevent; | |
1088 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1089 |
3139 | 1090 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t)); |
1091 winevent.event_f = Ph_WM_HIDE; | |
1092 winevent.rid = PtWidgetRid(wdata->window); | |
1093 winevent.event_state = Ph_WM_EVSTATE_HIDE; | |
1094 | |
1095 status = PtForwardWindowEvent(&winevent); | |
1096 if (status != 0) { | |
1097 SDL_SetError("Photon: Can't hide window"); | |
1098 } | |
1099 | |
1100 /* Flush all widget operations */ | |
1101 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1102 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1103 |
3139 | 1104 void |
1105 photon_raisewindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1106 { |
3139 | 1107 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1108 PhWindowEvent_t winevent; | |
1109 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1110 |
3139 | 1111 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t)); |
1112 winevent.event_f = Ph_WM_HIDE; | |
1113 winevent.rid = PtWidgetRid(wdata->window); | |
1114 winevent.event_state = Ph_WM_EVSTATE_UNHIDE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1115 |
3139 | 1116 status = PtForwardWindowEvent(&winevent); |
1117 if (status != 0) { | |
1118 SDL_SetError("Photon: Can't hide window"); | |
1119 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1120 |
3139 | 1121 /* Flush all widget operations */ |
1122 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1123 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1124 |
3139 | 1125 void |
1126 photon_maximizewindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1127 { |
3139 | 1128 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1129 PhWindowEvent_t winevent; | |
1130 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1131 |
3139 | 1132 /* Flush all widget operations */ |
1133 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1134 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1135 |
3139 | 1136 void |
1137 photon_minimizewindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1138 { |
3139 | 1139 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1140 PhWindowEvent_t winevent; | |
1141 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1142 |
3139 | 1143 SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t)); |
1144 winevent.event_f = Ph_WM_HIDE; | |
1145 winevent.rid = PtWidgetRid(wdata->window); | |
1146 winevent.event_state = Ph_WM_EVSTATE_HIDE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1147 |
3139 | 1148 status = PtForwardWindowEvent(&winevent); |
1149 if (status != 0) { | |
1150 SDL_SetError("Photon: Can't hide window"); | |
1151 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1152 |
3139 | 1153 /* Flush all widget operations */ |
1154 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1155 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1156 |
3139 | 1157 void |
1158 photon_restorewindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1159 { |
3139 | 1160 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1161 PhWindowEvent_t winevent; | |
1162 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1163 |
3139 | 1164 /* Flush all widget operations */ |
1165 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1166 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1167 |
3139 | 1168 void |
1169 photon_setwindowgrab(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1170 { |
3139 | 1171 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; |
1172 PhWindowEvent_t winevent; | |
1173 int32_t status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1174 |
3139 | 1175 /* Flush all widget operations */ |
1176 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1177 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1178 |
3139 | 1179 void |
1180 photon_destroywindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1181 { |
3139 | 1182 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; |
1183 SDL_DisplayData *didata = | |
1184 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
1185 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; | |
1186 int32_t status; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1187 |
3139 | 1188 if (wdata != NULL) { |
1189 status = PtDestroyWidget(wdata->window); | |
1190 if (status != 0) { | |
1191 SDL_SetError("Photon: Can't destroy window widget"); | |
1192 } | |
1193 wdata->window = NULL; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1194 |
3139 | 1195 #if defined(SDL_VIDEO_OPENGL_ES) |
1196 if (phdata->gfinitialized == SDL_TRUE) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1197 /* Destroy OpenGL ES surface if it was created */ |
3139 | 1198 if (wdata->gles_surface != EGL_NO_SURFACE) { |
1199 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1200 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1201 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1202 /* Free OpenGL ES target surface */ |
3139 | 1203 if (wdata->gfsurface != NULL) { |
1204 gf_surface_free(wdata->gfsurface); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1205 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1206 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1207 phdata->egl_refcount--; |
3139 | 1208 if (phdata->egl_refcount == 0) { |
1209 /* Terminate connection to OpenGL ES */ | |
1210 if (phdata->egldisplay != EGL_NO_DISPLAY) { | |
1211 eglTerminate(phdata->egldisplay); | |
1212 phdata->egldisplay = EGL_NO_DISPLAY; | |
1213 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1214 } |
3139 | 1215 } |
1216 #endif /* SDL_VIDEO_OPENGL_ES */ | |
1217 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1218 |
3139 | 1219 /* Flush all widget operations */ |
1220 PtFlush(); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1221 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1222 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1223 /*****************************************************************************/ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1224 /* SDL Window Manager function */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1225 /*****************************************************************************/ |
3139 | 1226 SDL_bool |
1227 photon_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1228 { |
3139 | 1229 if (info->version.major <= SDL_MAJOR_VERSION) { |
1230 return SDL_TRUE; | |
1231 } else { | |
1232 SDL_SetError("application not compiled with SDL %d.%d\n", | |
1233 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); | |
1234 return SDL_FALSE; | |
1235 } | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1236 |
3139 | 1237 /* Failed to get window manager information */ |
1238 return SDL_FALSE; | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1239 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1240 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1241 /*****************************************************************************/ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1242 /* SDL OpenGL/OpenGL ES functions */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1243 /*****************************************************************************/ |
3139 | 1244 int |
1245 photon_gl_loadlibrary(_THIS, const char *path) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1246 { |
3139 | 1247 #if defined(SDL_VIDEO_OPENGL_ES) |
1248 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1249 |
3139 | 1250 if (phdata->gfinitialized != SDL_TRUE) { |
1251 SDL_SetError | |
1252 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1253 return NULL; | |
1254 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1255 |
3139 | 1256 /* Check if OpenGL ES library is specified for GF driver */ |
1257 if (path == NULL) { | |
1258 path = SDL_getenv("SDL_OPENGL_LIBRARY"); | |
1259 if (path == NULL) { | |
1260 path = SDL_getenv("SDL_OPENGLES_LIBRARY"); | |
1261 } | |
1262 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1263 |
3139 | 1264 /* Check if default library loading requested */ |
1265 if (path == NULL) { | |
1266 /* Already linked with GF library which provides egl* subset of */ | |
1267 /* functions, use Common profile of OpenGL ES library by default */ | |
1268 path = "/usr/lib/libGLES_CM.so.1"; | |
1269 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1270 |
3139 | 1271 /* Load dynamic library */ |
1272 _this->gl_config.dll_handle = SDL_LoadObject(path); | |
1273 if (!_this->gl_config.dll_handle) { | |
1274 /* Failed to load new GL ES library */ | |
1275 SDL_SetError("Photon: Failed to locate OpenGL ES library"); | |
1276 return -1; | |
1277 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1278 |
3139 | 1279 /* Store OpenGL ES library path and name */ |
1280 SDL_strlcpy(_this->gl_config.driver_path, path, | |
1281 SDL_arraysize(_this->gl_config.driver_path)); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1282 |
3139 | 1283 /* New OpenGL ES library is loaded */ |
1284 return 0; | |
1285 #else | |
1286 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1287 return -1; | |
1288 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1289 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1290 |
3139 | 1291 void * |
1292 photon_gl_getprocaddres(_THIS, const char *proc) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1293 { |
3139 | 1294 #if defined(SDL_VIDEO_OPENGL_ES) |
1295 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1296 void *function_address; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1297 |
3139 | 1298 if (phdata->gfinitialized != SDL_TRUE) { |
1299 SDL_SetError | |
1300 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1301 return NULL; | |
1302 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1303 |
3139 | 1304 /* Try to get function address through the egl interface */ |
1305 function_address = eglGetProcAddress(proc); | |
1306 if (function_address != NULL) { | |
1307 return function_address; | |
1308 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1309 |
3139 | 1310 /* Then try to get function in the OpenGL ES library */ |
1311 if (_this->gl_config.dll_handle) { | |
1312 function_address = | |
1313 SDL_LoadFunction(_this->gl_config.dll_handle, proc); | |
1314 if (function_address != NULL) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1315 return function_address; |
3139 | 1316 } |
1317 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1318 |
3139 | 1319 /* Add emulated OpenGL ES 1.1 functions */ |
1320 if (SDL_strcmp(proc, "glTexParameteri") == 0) { | |
1321 return glTexParameteri; | |
1322 } | |
1323 if (SDL_strcmp(proc, "glTexParameteriv") == 0) { | |
1324 return glTexParameteriv; | |
1325 } | |
1326 if (SDL_strcmp(proc, "glColor4ub") == 0) { | |
1327 return glColor4ub; | |
1328 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1329 |
3139 | 1330 /* Failed to get GL ES function address pointer */ |
1331 SDL_SetError("Photon: Cannot locate OpenGL ES function name"); | |
1332 return NULL; | |
1333 #else | |
1334 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1335 return NULL; | |
1336 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1337 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1338 |
3139 | 1339 void |
1340 photon_gl_unloadlibrary(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1341 { |
3139 | 1342 #if defined(SDL_VIDEO_OPENGL_ES) |
1343 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1344 |
3139 | 1345 if (phdata->gfinitialized == SDL_TRUE) { |
1346 /* Unload OpenGL ES library */ | |
1347 if (_this->gl_config.dll_handle) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1348 SDL_UnloadObject(_this->gl_config.dll_handle); |
3139 | 1349 _this->gl_config.dll_handle = NULL; |
1350 } | |
1351 } else { | |
1352 SDL_SetError | |
1353 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1354 } | |
1355 #else | |
1356 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1357 return; | |
1358 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1359 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1360 |
3139 | 1361 SDL_GLContext |
1362 photon_gl_createcontext(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1363 { |
3139 | 1364 #if defined(SDL_VIDEO_OPENGL_ES) |
1365 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1366 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; | |
1367 SDL_DisplayData *didata = | |
1368 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
1369 EGLBoolean status; | |
1370 int32_t gfstatus; | |
1371 EGLint configs; | |
1372 uint32_t attr_pos; | |
1373 EGLint attr_value; | |
1374 EGLint cit; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1375 |
3139 | 1376 /* Check if GF was initialized */ |
1377 if (phdata->gfinitialized != SDL_TRUE) { | |
1378 SDL_SetError | |
1379 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1380 return NULL; | |
1381 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1382 |
3139 | 1383 /* Prepare attributes list to pass them to OpenGL ES */ |
1384 attr_pos = 0; | |
1385 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID; | |
1386 wdata->gles_attributes[attr_pos++] = | |
1387 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); | |
1388 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE; | |
1389 wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size; | |
1390 wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE; | |
1391 wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size; | |
1392 wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE; | |
1393 wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size; | |
1394 wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1395 |
3139 | 1396 /* Setup alpha size in bits */ |
1397 if (_this->gl_config.alpha_size) { | |
1398 wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size; | |
1399 } else { | |
1400 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1401 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1402 |
3139 | 1403 /* Setup color buffer size */ |
1404 if (_this->gl_config.buffer_size) { | |
1405 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; | |
1406 wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size; | |
1407 } else { | |
1408 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; | |
1409 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1410 } | |
1411 | |
1412 /* Setup depth buffer bits */ | |
1413 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; | |
1414 wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1415 |
3139 | 1416 /* Setup stencil bits */ |
1417 if (_this->gl_config.stencil_size) { | |
1418 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; | |
1419 wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size; | |
1420 } else { | |
1421 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; | |
1422 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1423 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1424 |
3139 | 1425 /* Set number of samples in multisampling */ |
1426 if (_this->gl_config.multisamplesamples) { | |
1427 wdata->gles_attributes[attr_pos++] = EGL_SAMPLES; | |
1428 wdata->gles_attributes[attr_pos++] = | |
1429 _this->gl_config.multisamplesamples; | |
1430 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1431 |
3139 | 1432 /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */ |
1433 if (_this->gl_config.multisamplebuffers) { | |
1434 wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS; | |
1435 wdata->gles_attributes[attr_pos++] = | |
1436 _this->gl_config.multisamplebuffers; | |
1437 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1438 |
3139 | 1439 /* Finish attributes list */ |
1440 wdata->gles_attributes[attr_pos] = EGL_NONE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1441 |
3139 | 1442 /* Request first suitable framebuffer configuration */ |
1443 status = eglChooseConfig(phdata->egldisplay, wdata->gles_attributes, | |
1444 wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, | |
1445 &configs); | |
1446 if (status != EGL_TRUE) { | |
1447 SDL_SetError | |
1448 ("Photon: Can't find closest configuration for OpenGL ES"); | |
1449 return NULL; | |
1450 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1451 |
3139 | 1452 /* Check if nothing has been found, try "don't care" settings */ |
1453 if (configs == 0) { | |
1454 int32_t it; | |
1455 int32_t jt; | |
1456 GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE }; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1457 |
3139 | 1458 for (it = 0; it < 4; it++) { |
1459 for (jt = 16; jt >= 0; jt--) { | |
1460 /* Don't care about color buffer bits, use what exist */ | |
1461 /* Replace previous set data with EGL_DONT_CARE */ | |
1462 attr_pos = 0; | |
1463 wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID; | |
1464 wdata->gles_attributes[attr_pos++] = | |
1465 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); | |
1466 wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE; | |
1467 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1468 wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE; | |
1469 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1470 wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE; | |
1471 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1472 wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE; | |
1473 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1474 wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE; | |
1475 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1476 |
3139 | 1477 /* Try to find requested or smallest depth */ |
1478 if (_this->gl_config.depth_size) { | |
1479 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; | |
1480 wdata->gles_attributes[attr_pos++] = depthbits[it]; | |
1481 } else { | |
1482 wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE; | |
1483 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1484 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1485 |
3139 | 1486 if (_this->gl_config.stencil_size) { |
1487 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; | |
1488 wdata->gles_attributes[attr_pos++] = jt; | |
1489 } else { | |
1490 wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE; | |
1491 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1492 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1493 |
3139 | 1494 wdata->gles_attributes[attr_pos++] = EGL_SAMPLES; |
1495 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1496 wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS; | |
1497 wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE; | |
1498 wdata->gles_attributes[attr_pos] = EGL_NONE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1499 |
3139 | 1500 /* Request first suitable framebuffer configuration */ |
1501 status = | |
1502 eglChooseConfig(phdata->egldisplay, | |
1503 wdata->gles_attributes, | |
1504 wdata->gles_configs, | |
1505 SDL_VIDEO_GF_OPENGLES_CONFS, &configs); | |
1506 if (status != EGL_TRUE) { | |
1507 SDL_SetError | |
1508 ("Photon: Can't find closest configuration for OpenGL ES"); | |
1509 return NULL; | |
1510 } | |
1511 if (configs != 0) { | |
1512 break; | |
1513 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1514 } |
3139 | 1515 if (configs != 0) { |
1516 break; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1517 } |
3139 | 1518 } |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1519 |
3139 | 1520 /* No available configs */ |
1521 if (configs == 0) { | |
1522 SDL_SetError | |
1523 ("Photon: Can't find any configuration for OpenGL ES"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1524 return NULL; |
3139 | 1525 } |
1526 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1527 |
3139 | 1528 /* Initialize config index */ |
1529 wdata->gles_config = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1530 |
3139 | 1531 /* Now check each configuration to find out the best */ |
1532 for (cit = 0; cit < configs; cit++) { | |
1533 uint32_t stencil_found; | |
1534 uint32_t depth_found; | |
1535 | |
1536 stencil_found = 0; | |
1537 depth_found = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1538 |
3139 | 1539 if (_this->gl_config.stencil_size) { |
1540 status = | |
1541 eglGetConfigAttrib(phdata->egldisplay, | |
1542 wdata->gles_configs[cit], EGL_STENCIL_SIZE, | |
1543 &attr_value); | |
1544 if (status == EGL_TRUE) { | |
1545 if (attr_value != 0) { | |
1546 stencil_found = 1; | |
1547 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1548 } |
3139 | 1549 } else { |
1550 stencil_found = 1; | |
1551 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1552 |
3139 | 1553 if (_this->gl_config.depth_size) { |
1554 status = | |
1555 eglGetConfigAttrib(phdata->egldisplay, | |
1556 wdata->gles_configs[cit], EGL_DEPTH_SIZE, | |
1557 &attr_value); | |
1558 if (status == EGL_TRUE) { | |
1559 if (attr_value != 0) { | |
1560 depth_found = 1; | |
1561 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1562 } |
3139 | 1563 } else { |
1564 depth_found = 1; | |
1565 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1566 |
3139 | 1567 /* Exit from loop if found appropriate configuration */ |
1568 if ((depth_found != 0) && (stencil_found != 0)) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1569 break; |
3139 | 1570 } |
1571 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1572 |
3139 | 1573 /* If best could not be found, use first */ |
1574 if (cit == configs) { | |
1575 cit = 0; | |
1576 } | |
1577 wdata->gles_config = cit; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1578 |
3139 | 1579 /* Create OpenGL ES context */ |
1580 wdata->gles_context = | |
1581 eglCreateContext(phdata->egldisplay, | |
1582 wdata->gles_configs[wdata->gles_config], | |
1583 EGL_NO_CONTEXT, NULL); | |
1584 if (wdata->gles_context == EGL_NO_CONTEXT) { | |
1585 SDL_SetError("Photon: OpenGL ES context creation has been failed"); | |
1586 return NULL; | |
1587 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1588 |
3139 | 1589 /* Check if surface is exist */ |
1590 if (wdata->gfsurface != NULL) { | |
1591 gf_surface_free(wdata->gfsurface); | |
1592 wdata->gfsurface = NULL; | |
1593 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1594 |
3139 | 1595 /* Create GF surface */ |
1596 gfstatus = | |
1597 gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w, | |
1598 window->h, | |
1599 qnxgf_sdl_to_gf_pixelformat(didata->current_mode. | |
1600 format), NULL, | |
1601 GF_SURFACE_CREATE_2D_ACCESSIBLE | | |
1602 GF_SURFACE_CREATE_3D_ACCESSIBLE | | |
1603 GF_SURFACE_CREATE_SHAREABLE); | |
1604 if (gfstatus != GF_ERR_OK) { | |
1605 eglDestroyContext(phdata->egldisplay, wdata->gles_context); | |
1606 wdata->gles_context = EGL_NO_CONTEXT; | |
1607 SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus); | |
1608 return NULL; | |
1609 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1610 |
3139 | 1611 /* Create pixmap 3D target surface */ |
1612 wdata->gles_surface = | |
1613 eglCreatePixmapSurface(phdata->egldisplay, | |
1614 wdata->gles_configs[wdata->gles_config], | |
1615 wdata->gfsurface, NULL); | |
1616 if (wdata->gles_surface == EGL_NO_SURFACE) { | |
1617 gf_surface_free(wdata->gfsurface); | |
1618 eglDestroyContext(phdata->egldisplay, wdata->gles_context); | |
1619 wdata->gles_context = EGL_NO_CONTEXT; | |
1620 SDL_SetError("Photon: Can't create EGL pixmap surface"); | |
1621 return NULL; | |
1622 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1623 |
3139 | 1624 /* Make just created context current */ |
1625 status = | |
1626 eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, | |
1627 wdata->gles_surface, wdata->gles_context); | |
1628 if (status != EGL_TRUE) { | |
1629 /* Destroy OpenGL ES surface */ | |
1630 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); | |
1631 gf_surface_free(wdata->gfsurface); | |
1632 eglDestroyContext(phdata->egldisplay, wdata->gles_context); | |
1633 wdata->gles_context = EGL_NO_CONTEXT; | |
1634 SDL_SetError("Photon: Can't set OpenGL ES context on creation"); | |
1635 return NULL; | |
1636 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1637 |
3139 | 1638 /* Setup into SDL internals state of OpenGL ES: */ |
1639 /* it is accelerated or not */ | |
1640 if ((didata->caps & SDL_PHOTON_ACCELERATED_3D) == | |
1641 SDL_PHOTON_ACCELERATED_3D) { | |
1642 _this->gl_config.accelerated = 1; | |
1643 } else { | |
1644 _this->gl_config.accelerated = 0; | |
1645 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1646 |
3139 | 1647 /* Always clear stereo enable, since OpenGL ES do not supports stereo */ |
1648 _this->gl_config.stereo = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1649 |
3139 | 1650 /* Get back samples and samplebuffers configurations. Rest framebuffer */ |
1651 /* parameters could be obtained through the OpenGL ES API */ | |
1652 status = | |
1653 eglGetConfigAttrib(phdata->egldisplay, | |
1654 wdata->gles_configs[wdata->gles_config], | |
1655 EGL_SAMPLES, &attr_value); | |
1656 if (status == EGL_TRUE) { | |
1657 _this->gl_config.multisamplesamples = attr_value; | |
1658 } | |
1659 status = | |
1660 eglGetConfigAttrib(phdata->egldisplay, | |
1661 wdata->gles_configs[wdata->gles_config], | |
1662 EGL_SAMPLE_BUFFERS, &attr_value); | |
1663 if (status == EGL_TRUE) { | |
1664 _this->gl_config.multisamplebuffers = attr_value; | |
1665 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1666 |
3139 | 1667 /* Get back stencil and depth buffer sizes */ |
1668 status = | |
1669 eglGetConfigAttrib(phdata->egldisplay, | |
1670 wdata->gles_configs[wdata->gles_config], | |
1671 EGL_DEPTH_SIZE, &attr_value); | |
1672 if (status == EGL_TRUE) { | |
1673 _this->gl_config.depth_size = attr_value; | |
1674 } | |
1675 status = | |
1676 eglGetConfigAttrib(phdata->egldisplay, | |
1677 wdata->gles_configs[wdata->gles_config], | |
1678 EGL_STENCIL_SIZE, &attr_value); | |
1679 if (status == EGL_TRUE) { | |
1680 _this->gl_config.stencil_size = attr_value; | |
1681 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1682 |
3139 | 1683 /* Under Photon OpenGL ES output can't be double buffered */ |
1684 _this->gl_config.double_buffer = 0; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1685 |
3139 | 1686 /* Check if current device is not the same as target */ |
1687 if (phdata->current_device_id != didata->device_id) { | |
1688 /* Set target device as default for Pd and Pg functions */ | |
1689 status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]); | |
1690 if (status != 0) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1691 /* Destroy OpenGL ES surface */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1692 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1693 gf_surface_free(wdata->gfsurface); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1694 eglDestroyContext(phdata->egldisplay, wdata->gles_context); |
3139 | 1695 wdata->gles_context = EGL_NO_CONTEXT; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1696 SDL_SetError("Photon: Can't set default target device\n"); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1697 return NULL; |
3139 | 1698 } |
1699 phdata->current_device_id = didata->device_id; | |
1700 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1701 |
3139 | 1702 wdata->phsurface = PdCreateOffscreenContextGF(wdata->gfsurface); |
1703 if (wdata->phsurface == NULL) { | |
1704 /* Destroy OpenGL ES surface */ | |
1705 eglDestroySurface(phdata->egldisplay, wdata->gles_surface); | |
1706 gf_surface_free(wdata->gfsurface); | |
1707 eglDestroyContext(phdata->egldisplay, wdata->gles_context); | |
1708 wdata->gles_context = EGL_NO_CONTEXT; | |
1709 SDL_SetError("Photon: Can't bind GF surface to Photon\n"); | |
1710 return NULL; | |
1711 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1712 |
3139 | 1713 /* GL ES context was successfully created */ |
1714 return wdata->gles_context; | |
1715 #else | |
1716 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1717 return NULL; | |
1718 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1719 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1720 |
3139 | 1721 int |
1722 photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1723 { |
3139 | 1724 #if defined(SDL_VIDEO_OPENGL_ES) |
1725 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1726 SDL_WindowData *wdata; | |
1727 EGLBoolean status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1728 |
3139 | 1729 if (phdata->gfinitialized != SDL_TRUE) { |
1730 SDL_SetError | |
1731 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1732 return -1; | |
1733 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1734 |
3139 | 1735 if ((window == NULL) && (context == NULL)) { |
1736 status = | |
1737 eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, | |
1738 EGL_NO_CONTEXT); | |
1739 if (status != EGL_TRUE) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1740 /* Failed to set current GL ES context */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1741 SDL_SetError("Photon: Can't set OpenGL ES context"); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1742 return -1; |
3139 | 1743 } |
1744 } else { | |
1745 wdata = (SDL_WindowData *) window->driverdata; | |
1746 if (wdata->gles_surface == EGL_NO_SURFACE) { | |
1747 SDL_SetError | |
1748 ("Photon: OpenGL ES surface is not initialized for this window"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1749 return -1; |
3139 | 1750 } |
1751 if (wdata->gles_context == EGL_NO_CONTEXT) { | |
1752 SDL_SetError | |
1753 ("Photon: OpenGL ES context is not initialized for this window"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1754 return -1; |
3139 | 1755 } |
1756 if (wdata->gles_context != context) { | |
1757 SDL_SetError | |
1758 ("Photon: OpenGL ES context is not belong to this window"); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1759 return -1; |
3139 | 1760 } |
1761 status = | |
1762 eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, | |
1763 wdata->gles_surface, wdata->gles_context); | |
1764 if (status != EGL_TRUE) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1765 /* Failed to set current GL ES context */ |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1766 SDL_SetError("Photon: Can't set OpenGL ES context"); |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1767 return -1; |
3139 | 1768 } |
1769 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1770 |
3139 | 1771 return 0; |
1772 #else | |
1773 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1774 return -1; | |
1775 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1776 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1777 |
3139 | 1778 int |
1779 photon_gl_setswapinterval(_THIS, int interval) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1780 { |
3139 | 1781 #if defined(SDL_VIDEO_OPENGL_ES) |
1782 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1783 EGLBoolean status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1784 |
3139 | 1785 if (phdata->gfinitialized != SDL_TRUE) { |
1786 SDL_SetError | |
1787 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1788 return -1; | |
1789 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1790 |
3139 | 1791 /* Check if OpenGL ES connection has been initialized */ |
1792 if (phdata->egldisplay != EGL_NO_DISPLAY) { | |
1793 /* Set swap OpenGL ES interval */ | |
1794 status = eglSwapInterval(phdata->egldisplay, interval); | |
1795 if (status == EGL_TRUE) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1796 /* Return success to upper level */ |
3139 | 1797 phdata->swapinterval = interval; |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1798 return 0; |
3139 | 1799 } |
1800 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1801 |
3139 | 1802 /* Failed to set swap interval */ |
1803 SDL_SetError("Photon: Cannot set swap interval"); | |
1804 return -1; | |
1805 #else | |
1806 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1807 return -1; | |
1808 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1809 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1810 |
3139 | 1811 int |
1812 photon_gl_getswapinterval(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1813 { |
3139 | 1814 #if defined(SDL_VIDEO_OPENGL_ES) |
1815 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1816 |
3139 | 1817 if (phdata->gfinitialized != SDL_TRUE) { |
1818 SDL_SetError | |
1819 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1820 return -1; | |
1821 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1822 |
3139 | 1823 /* Return default swap interval value */ |
1824 return phdata->swapinterval; | |
1825 #else | |
1826 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1827 return -1; | |
1828 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1829 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1830 |
3139 | 1831 void |
1832 photon_gl_swapwindow(_THIS, SDL_Window * window) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1833 { |
3139 | 1834 #if defined(SDL_VIDEO_OPENGL_ES) |
1835 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1836 SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata; | |
1837 SDL_DisplayData *didata = | |
1838 (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; | |
1839 PhRect_t dst_rect; | |
1840 PhRect_t src_rect; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1841 |
3139 | 1842 if (phdata->gfinitialized != SDL_TRUE) { |
1843 SDL_SetError | |
1844 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1845 return; | |
1846 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1847 |
3139 | 1848 /* Many applications do not uses glFinish(), so we call it for them */ |
1849 glFinish(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1850 |
3139 | 1851 /* Wait until OpenGL ES rendering is completed */ |
1852 eglWaitGL(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1853 |
3139 | 1854 /* Wait for VSYNC manually, if it was enabled */ |
1855 if (phdata->swapinterval != 0) { | |
1856 /* Wait for VSYNC, we use GF function, since Photon requires */ | |
1857 /* to enter to the Direct mode to call PgWaitVSync() */ | |
1858 gf_display_wait_vsync(didata->display); | |
1859 } | |
1860 | |
1861 /* Set blit area */ | |
1862 dst_rect = *PtGetCanvas(wdata->window); | |
1863 src_rect.ul.x = 0; | |
1864 src_rect.ul.y = 0; | |
1865 src_rect.lr.x = window->w - 1; | |
1866 src_rect.lr.y = window->h - 1; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1867 |
3139 | 1868 /* Blit OpenGL ES pixmap surface directly to window region */ |
1869 PgFFlush(Ph_START_DRAW); | |
1870 PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window)); | |
1871 PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent())); | |
1872 PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect); | |
1873 PgFFlush(Ph_DONE_DRAW); | |
1874 PgWaitHWIdle(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1875 |
3139 | 1876 eglSwapBuffers(phdata->egldisplay, wdata->gles_surface); |
1877 #else | |
1878 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1879 return; | |
1880 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1881 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1882 |
3139 | 1883 void |
1884 photon_gl_deletecontext(_THIS, SDL_GLContext context) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1885 { |
3139 | 1886 #if defined(SDL_VIDEO_OPENGL_ES) |
1887 SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata; | |
1888 EGLBoolean status; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1889 |
3139 | 1890 if (phdata->gfinitialized != SDL_TRUE) { |
1891 SDL_SetError | |
1892 ("Photon: GF initialization failed, no OpenGL ES support"); | |
1893 return; | |
1894 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1895 |
3139 | 1896 /* Check if OpenGL ES connection has been initialized */ |
1897 if (phdata->egldisplay != EGL_NO_DISPLAY) { | |
1898 if (context != EGL_NO_CONTEXT) { | |
1899 status = eglDestroyContext(phdata->egldisplay, context); | |
1900 if (status != EGL_TRUE) { | |
1901 /* Error during OpenGL ES context destroying */ | |
1902 SDL_SetError("Photon: OpenGL ES context destroy error"); | |
1903 return; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1904 } |
3139 | 1905 } |
1906 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1907 |
3139 | 1908 return; |
1909 #else | |
1910 SDL_SetError("Photon: OpenGL ES support is not compiled in"); | |
1911 return; | |
1912 #endif /* SDL_VIDEO_OPENGL_ES */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1913 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1914 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1915 /*****************************************************************************/ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1916 /* SDL Event handling function */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1917 /*****************************************************************************/ |
3139 | 1918 void |
1919 photon_pumpevents(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
1920 { |
3139 | 1921 uint8_t eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE]; |
1922 PhEvent_t *event = (PhEvent_t *) eventbuffer; | |
1923 int32_t status; | |
1924 uint32_t finish = 0; | |
1925 uint32_t it; | |
1926 SDL_Window *window; | |
1927 SDL_WindowData *wdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1928 |
3139 | 1929 do { |
1930 status = PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE); | |
1931 switch (status) { | |
1932 case Ph_RESIZE_MSG: | |
1933 { | |
1934 SDL_SetError("Photon: Event size too much for buffer"); | |
1935 return; | |
1936 } | |
1937 break; | |
1938 case Ph_EVENT_MSG: | |
1939 { | |
1940 /* Find a window, to which this handle destinated */ | |
1941 status = 0; | |
1942 for (it = 0; it < SDL_CurrentDisplay.num_windows; it++) { | |
1943 wdata = | |
1944 (SDL_WindowData *) SDL_CurrentDisplay.windows[it]. | |
1945 driverdata; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1946 |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1947 /* Find the proper window */ |
3139 | 1948 if (wdata->window != NULL) { |
1949 if (PtWidgetRid(wdata->window) == | |
1950 event->collector.rid) { | |
1951 window = | |
1952 (SDL_Window *) & SDL_CurrentDisplay. | |
1953 windows[it]; | |
1954 status = 1; | |
1955 break; | |
1956 } | |
1957 } else { | |
1958 continue; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1959 } |
3139 | 1960 } |
1961 if (status == 0) { | |
1962 window = NULL; | |
1963 wdata = NULL; | |
1964 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1965 |
3139 | 1966 /* Event is ready */ |
1967 switch (event->type) { | |
1968 case Ph_EV_BOUNDARY: | |
1969 { | |
1970 switch (event->subtype) { | |
1971 case Ph_EV_PTR_ENTER: | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1972 { |
3139 | 1973 /* Mouse cursor over handled window */ |
1974 if (window != NULL) { | |
1975 SDL_SendWindowEvent(window->id, | |
1976 SDL_WINDOWEVENT_ENTER, | |
1977 0, 0); | |
1978 SDL_SetMouseFocus(0, window->id); | |
1979 } | |
1980 } | |
1981 break; | |
1982 case Ph_EV_PTR_LEAVE: | |
1983 { | |
1984 /* Mouse cursor out of handled window */ | |
1985 if (window != NULL) { | |
1986 SDL_SendWindowEvent(window->id, | |
1987 SDL_WINDOWEVENT_LEAVE, | |
1988 0, 0); | |
1989 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
1990 } |
3139 | 1991 break; |
1992 } | |
1993 } | |
1994 break; | |
1995 case Ph_EV_PTR_MOTION_BUTTON: | |
1996 case Ph_EV_PTR_MOTION_NOBUTTON: | |
1997 { | |
1998 PhPointerEvent_t *pevent = NULL; | |
1999 PhRect_t *prects = NULL; | |
2000 | |
2001 /* Get event data */ | |
2002 pevent = PhGetData(event); | |
2003 /* Get associated event rectangles */ | |
2004 prects = PhGetRects(event); | |
2005 if ((pevent != NULL) && (prects != NULL)) { | |
2006 SDL_SendMouseMotion(0, 0, prects->ul.x, | |
2007 prects->ul.y, 0); | |
2008 } | |
2009 } | |
2010 break; | |
2011 case Ph_EV_BUT_PRESS: | |
2012 { | |
2013 /* Button press event */ | |
2014 PhPointerEvent_t *pevent = NULL; | |
2015 uint32_t sdlbutton = 0x00000000; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2016 |
3139 | 2017 /* Get event data */ |
2018 pevent = PhGetData(event); | |
2019 if (pevent != NULL) { | |
2020 for (it = 0; it < sizeof(pevent->buttons) * 8; | |
2021 it++) { | |
2022 if ((pevent->buttons & (0x0001 << it)) == | |
2023 (0x0001 << it)) { | |
2024 switch (it) { | |
2025 case 0: | |
2026 { | |
2027 sdlbutton = SDL_BUTTON_RIGHT; | |
2028 } | |
2029 break; | |
2030 case 1: | |
2031 { | |
2032 sdlbutton = SDL_BUTTON_MIDDLE; | |
2033 } | |
2034 break; | |
2035 case 2: | |
2036 { | |
2037 sdlbutton = SDL_BUTTON_LEFT; | |
2038 } | |
2039 break; | |
2040 default: | |
2041 { | |
2042 sdlbutton = it + 1; | |
2043 } | |
2044 break; | |
2045 } | |
2046 SDL_SendMouseButton(0, SDL_PRESSED, | |
2047 sdlbutton); | |
2048 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2049 } |
3139 | 2050 } |
2051 } | |
2052 break; | |
2053 case Ph_EV_BUT_RELEASE: | |
2054 { | |
2055 /* Button press event */ | |
2056 PhPointerEvent_t *pevent = NULL; | |
2057 uint32_t sdlbutton = 0x00000000; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2058 |
3139 | 2059 /* Get event data */ |
2060 pevent = PhGetData(event); | |
2061 if (pevent != NULL) { | |
2062 for (it = 0; it < sizeof(pevent->buttons) * 8; | |
2063 it++) { | |
2064 if ((pevent->buttons & (0x0001 << it)) == | |
2065 (0x0001 << it)) { | |
2066 switch (it) { | |
2067 case 0: | |
2068 { | |
2069 sdlbutton = SDL_BUTTON_RIGHT; | |
2070 } | |
2071 break; | |
2072 case 1: | |
2073 { | |
2074 sdlbutton = SDL_BUTTON_MIDDLE; | |
2075 } | |
2076 break; | |
2077 case 2: | |
2078 { | |
2079 sdlbutton = SDL_BUTTON_LEFT; | |
2080 } | |
2081 break; | |
2082 default: | |
2083 { | |
2084 sdlbutton = it + 1; | |
2085 } | |
2086 break; | |
2087 } | |
2088 } | |
2089 } | |
2090 } | |
2091 | |
2092 switch (event->subtype) { | |
2093 case Ph_EV_RELEASE_REAL: | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2094 { |
3139 | 2095 /* Real release button event */ |
2096 SDL_SendMouseButton(0, SDL_RELEASED, | |
2097 sdlbutton); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2098 } |
3139 | 2099 break; |
2100 case Ph_EV_RELEASE_PHANTOM: | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2101 { |
3139 | 2102 /* We will get phantom button release */ |
2103 /* event in case if it was unpressed */ | |
2104 /* outside of window */ | |
2105 if (window != NULL) { | |
2106 if ((window-> | |
2107 flags & SDL_WINDOW_MOUSE_FOCUS) != | |
2108 SDL_WINDOW_MOUSE_FOCUS) { | |
2109 /* Send phantom button release */ | |
2110 SDL_SendMouseButton(0, SDL_RELEASED, | |
2111 sdlbutton); | |
2112 } | |
2113 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2114 } |
3139 | 2115 break; |
2116 } | |
2117 } | |
2118 break; | |
2119 case Ph_EV_EXPOSE: | |
2120 { | |
2121 switch (event->subtype) { | |
2122 case Ph_NORMAL_EXPOSE: | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2123 { |
3139 | 2124 PhRect_t *rects = NULL; |
2125 | |
2126 /* Get array of rectangles to be updated */ | |
2127 rects = PhGetRects(event); | |
2128 if (rects == NULL) { | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2129 break; |
3139 | 2130 } |
2131 | |
2132 /* Check if expose come to one of the our windows */ | |
2133 if ((wdata != NULL) && (window != NULL)) { | |
2134 /* Check if window uses OpenGL ES */ | |
2135 if (wdata->uses_gles == SDL_TRUE) { | |
2136 PhRect_t dst_rect; | |
2137 PhRect_t src_rect; | |
2138 | |
2139 /* Cycle through each rectangle */ | |
2140 for (it = 0; it < event->num_rects; | |
2141 it++) { | |
2142 /* Blit OpenGL ES pixmap surface directly to window region */ | |
2143 PgFFlush(Ph_START_DRAW); | |
2144 PgSetRegionCx(PhDCGetCurrent(), | |
2145 PtWidgetRid(wdata-> | |
2146 window)); | |
2147 PgClearTranslationCx(PgGetGCCx | |
2148 (PhDCGetCurrent | |
2149 ())); | |
2150 PgContextBlit(wdata->phsurface, | |
2151 &rects[it], NULL, | |
2152 &rects[it]); | |
2153 PgFFlush(Ph_DONE_DRAW); | |
2154 PgWaitHWIdle(); | |
2155 } | |
2156 } else { | |
2157 /* Normal window */ | |
2158 /* TODO: update the damaged rectangles */ | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2159 } |
3139 | 2160 } |
2161 | |
2162 /* Flush all blittings */ | |
2163 PgFlush(); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2164 } |
3139 | 2165 break; |
2166 case Ph_CAPTURE_EXPOSE: | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2167 { |
3139 | 2168 /* Check if expose come to one of the our windows */ |
2169 if ((wdata != NULL) && (window != NULL)) { | |
2170 /* Check if window uses OpenGL ES */ | |
2171 if (wdata->uses_gles == SDL_TRUE) { | |
2172 PhRect_t dst_rect; | |
2173 PhRect_t src_rect; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2174 |
3139 | 2175 /* Set blit area */ |
2176 dst_rect = | |
2177 *PtGetCanvas(wdata->window); | |
2178 src_rect.ul.x = 0; | |
2179 src_rect.ul.y = 0; | |
2180 src_rect.lr.x = window->w - 1; | |
2181 src_rect.lr.y = window->h - 1; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2182 |
3139 | 2183 /* We need to redraw entire window */ |
2184 PgFFlush(Ph_START_DRAW); | |
2185 PgSetRegionCx(PhDCGetCurrent(), | |
2186 PtWidgetRid(wdata-> | |
2187 window)); | |
2188 PgClearTranslationCx(PgGetGCCx | |
2189 (PhDCGetCurrent | |
2190 ())); | |
2191 PgContextBlit(wdata->phsurface, | |
2192 &src_rect, NULL, | |
2193 &dst_rect); | |
2194 PgFFlush(Ph_DONE_DRAW); | |
2195 PgWaitHWIdle(); | |
2196 } else { | |
2197 /* Normal window */ | |
2198 /* TODO: update the damaged rectangles */ | |
3115
1102a3305928
Added handler for all window events.
Mike Gorchak <lestat@i.com.ua>
parents:
3108
diff
changeset
|
2199 |
3139 | 2200 /* We need to redraw entire window */ |
2201 } | |
2202 } | |
2203 } | |
2204 break; | |
2205 case Ph_GRAPHIC_EXPOSE: | |
2206 { | |
2207 /* TODO: What this event means ? */ | |
2208 } | |
2209 break; | |
2210 } | |
2211 } | |
2212 break; | |
2213 case Ph_EV_INFO: | |
2214 { | |
2215 } | |
2216 break; | |
2217 case Ph_EV_KEY: | |
2218 { | |
2219 PhKeyEvent_t *keyevent = NULL; | |
2220 SDL_scancode scancode = SDL_SCANCODE_UNKNOWN; | |
2221 SDL_bool pressed = SDL_FALSE; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2222 |
3139 | 2223 keyevent = PhGetData(event); |
2224 if (keyevent == NULL) { | |
2225 break; | |
2226 } | |
2227 | |
2228 /* Check if key is repeated */ | |
2229 if ((keyevent->key_flags & Pk_KF_Key_Repeat) == | |
2230 Pk_KF_Key_Repeat) { | |
2231 /* Ignore such events */ | |
2232 break; | |
2233 } | |
2234 | |
2235 /* Check if key has its own scancode */ | |
2236 if ((keyevent->key_flags & Pk_KF_Scan_Valid) == | |
2237 Pk_KF_Scan_Valid) { | |
2238 if ((keyevent->key_flags & Pk_KF_Key_Down) == | |
2239 Pk_KF_Key_Down) { | |
2240 pressed = SDL_TRUE; | |
2241 } else { | |
2242 pressed = SDL_FALSE; | |
2243 } | |
2244 scancode = | |
2245 photon_to_sdl_keymap(keyevent->key_scan); | |
2246 | |
2247 /* Add details for the pressed key */ | |
2248 if ((keyevent->key_flags & Pk_KF_Cap_Valid) == | |
2249 Pk_KF_Cap_Valid) { | |
2250 switch (keyevent->key_cap) { | |
2251 case Pk_Hyper_R: /* Right windows flag key */ | |
2252 scancode = SDL_SCANCODE_RGUI; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2253 break; |
3139 | 2254 case Pk_Control_R: /* Right Ctrl key */ |
2255 scancode = SDL_SCANCODE_RCTRL; | |
2256 break; | |
2257 case Pk_Alt_R: /* Right Alt key */ | |
2258 scancode = SDL_SCANCODE_RALT; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2259 break; |
3139 | 2260 case Pk_Up: /* Up key but with invalid scan */ |
2261 if (scancode != SDL_SCANCODE_UP) { | |
2262 /* This is a mouse wheel event */ | |
2263 SDL_SendMouseWheel(0, 0, 1); | |
2264 return; | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2265 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2266 break; |
3139 | 2267 case Pk_KP_8: /* Up arrow or 8 on keypad */ |
2268 scancode = SDL_SCANCODE_KP_8; | |
2269 break; | |
2270 case Pk_Down: /* Down key but with invalid scan */ | |
2271 if (scancode != SDL_SCANCODE_DOWN) { | |
2272 /* This is a mouse wheel event */ | |
2273 SDL_SendMouseWheel(0, 0, -1); | |
2274 return; | |
2275 } | |
2276 break; | |
2277 case Pk_KP_2: /* Down arrow or 2 on keypad */ | |
2278 scancode = SDL_SCANCODE_KP_2; | |
2279 break; | |
2280 case Pk_Left: /* Left arrow key */ | |
2281 scancode = SDL_SCANCODE_LEFT; | |
2282 break; | |
2283 case Pk_KP_4: /* Left arrow or 4 on keypad */ | |
2284 scancode = SDL_SCANCODE_KP_4; | |
2285 break; | |
2286 case Pk_Right: /* Right arrow key */ | |
2287 scancode = SDL_SCANCODE_RIGHT; | |
2288 break; | |
2289 case Pk_KP_6: /* Right arrow or 6 on keypad */ | |
2290 scancode = SDL_SCANCODE_KP_6; | |
2291 break; | |
2292 case Pk_Insert: /* Insert key */ | |
2293 scancode = SDL_SCANCODE_INSERT; | |
2294 break; | |
2295 case Pk_KP_0: /* Insert or 0 on keypad */ | |
2296 scancode = SDL_SCANCODE_KP_0; | |
2297 break; | |
2298 case Pk_Home: /* Home key */ | |
2299 scancode = SDL_SCANCODE_HOME; | |
2300 break; | |
2301 case Pk_KP_7: /* Home or 7 on keypad */ | |
2302 scancode = SDL_SCANCODE_KP_7; | |
2303 break; | |
2304 case Pk_Pg_Up: /* PageUp key */ | |
2305 scancode = SDL_SCANCODE_PAGEUP; | |
2306 break; | |
2307 case Pk_KP_9: /* PgUp or 9 on keypad */ | |
2308 scancode = SDL_SCANCODE_KP_9; | |
2309 break; | |
2310 case Pk_Delete: /* Delete key */ | |
2311 scancode = SDL_SCANCODE_DELETE; | |
2312 break; | |
2313 case Pk_KP_Decimal: /* Del or . on keypad */ | |
2314 scancode = SDL_SCANCODE_KP_PERIOD; | |
2315 break; | |
2316 case Pk_End: /* End key */ | |
2317 scancode = SDL_SCANCODE_END; | |
2318 break; | |
2319 case Pk_KP_1: /* End or 1 on keypad */ | |
2320 scancode = SDL_SCANCODE_KP_1; | |
2321 break; | |
2322 case Pk_Pg_Down: /* PageDown key */ | |
2323 scancode = SDL_SCANCODE_PAGEDOWN; | |
2324 break; | |
2325 case Pk_KP_3: /* PgDn or 3 on keypad */ | |
2326 scancode = SDL_SCANCODE_KP_3; | |
2327 break; | |
2328 case Pk_KP_5: /* 5 on keypad */ | |
2329 scancode = SDL_SCANCODE_KP_5; | |
2330 break; | |
2331 case Pk_KP_Enter: | |
2332 scancode = SDL_SCANCODE_KP_ENTER; | |
2333 break; | |
2334 case Pk_KP_Add: | |
2335 scancode = SDL_SCANCODE_KP_PLUS; | |
2336 break; | |
2337 case Pk_KP_Subtract: | |
2338 scancode = SDL_SCANCODE_KP_MINUS; | |
2339 break; | |
2340 case Pk_KP_Multiply: | |
2341 scancode = SDL_SCANCODE_KP_MULTIPLY; | |
2342 break; | |
2343 case Pk_KP_Divide: | |
2344 scancode = SDL_SCANCODE_KP_DIVIDE; | |
2345 break; | |
2346 case Pk_Pause: | |
2347 scancode = SDL_SCANCODE_PAUSE; | |
2348 break; | |
2349 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2350 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2351 |
3139 | 2352 /* Finally check if scancode has been decoded */ |
2353 if (scancode == SDL_SCANCODE_UNKNOWN) { | |
2354 /* Something was pressed, which is not supported */ | |
2355 break; | |
2356 } | |
2357 | |
2358 /* Report pressed/released key to SDL */ | |
2359 if (pressed == SDL_TRUE) { | |
2360 SDL_SendKeyboardKey(0, SDL_PRESSED, scancode); | |
2361 } else { | |
2362 SDL_SendKeyboardKey(0, SDL_RELEASED, | |
2363 scancode); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2364 } |
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2365 |
3139 | 2366 /* Photon doesn't send a release event for PrnScr key */ |
2367 if ((scancode == SDL_SCANCODE_PRINTSCREEN) | |
2368 && (pressed)) { | |
2369 SDL_SendKeyboardKey(0, SDL_RELEASED, | |
2370 scancode); | |
2371 } | |
2372 } | |
2373 } | |
2374 break; | |
2375 case Ph_EV_SERVICE: | |
2376 { | |
2377 } | |
2378 break; | |
2379 case Ph_EV_SYSTEM: | |
2380 { | |
2381 } | |
2382 break; | |
2383 case Ph_EV_WM: | |
2384 { | |
2385 PhWindowEvent_t *wmevent = NULL; | |
2386 | |
2387 /* Get associated event data */ | |
2388 wmevent = PhGetData(event); | |
2389 if (wmevent == NULL) { | |
2390 break; | |
2391 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2392 |
3139 | 2393 switch (wmevent->event_f) { |
2394 case Ph_WM_CLOSE: | |
2395 { | |
2396 if (window != NULL) { | |
2397 SDL_SendWindowEvent(window->id, | |
2398 SDL_WINDOWEVENT_CLOSE, | |
2399 0, 0); | |
2400 } | |
2401 } | |
2402 break; | |
2403 case Ph_WM_FOCUS: | |
2404 { | |
2405 if (wmevent->event_state == | |
2406 Ph_WM_EVSTATE_FOCUS) { | |
2407 if (window != NULL) { | |
2408 PhRegion_t wregion; | |
2409 | |
2410 SDL_SendWindowEvent(window->id, | |
2411 SDL_WINDOWEVENT_FOCUS_GAINED, | |
2412 0, 0); | |
2413 SDL_SetKeyboardFocus(0, window->id); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2414 |
3139 | 2415 /* Set window region sensible to mouse motion events */ |
2416 PhRegionQuery(PtWidgetRid | |
2417 (wdata->window), | |
2418 &wregion, NULL, NULL, | |
2419 0); | |
2420 wregion.events_sense |= | |
2421 Ph_EV_PTR_MOTION_BUTTON | | |
2422 Ph_EV_PTR_MOTION_NOBUTTON; | |
2423 PhRegionChange(Ph_REGION_EV_SENSE, 0, | |
2424 &wregion, NULL, NULL); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2425 |
3139 | 2426 /* If window got a focus, the it is visible */ |
2427 SDL_SendWindowEvent(window->id, | |
2428 SDL_WINDOWEVENT_SHOWN, | |
2429 0, 0); | |
2430 } | |
2431 } | |
2432 if (wmevent->event_state == | |
2433 Ph_WM_EVSTATE_FOCUSLOST) { | |
2434 if (window != NULL) { | |
2435 PhRegion_t wregion; | |
2436 | |
2437 SDL_SendWindowEvent(window->id, | |
2438 SDL_WINDOWEVENT_FOCUS_LOST, | |
2439 0, 0); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2440 |
3139 | 2441 /* Set window region ignore mouse motion events */ |
2442 PhRegionQuery(PtWidgetRid | |
2443 (wdata->window), | |
2444 &wregion, NULL, NULL, | |
2445 0); | |
2446 wregion.events_sense &= | |
2447 ~(Ph_EV_PTR_MOTION_BUTTON | | |
2448 Ph_EV_PTR_MOTION_NOBUTTON); | |
2449 PhRegionChange(Ph_REGION_EV_SENSE, 0, | |
2450 &wregion, NULL, NULL); | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2451 } |
3139 | 2452 } |
2453 } | |
2454 break; | |
2455 case Ph_WM_MOVE: | |
2456 { | |
2457 if (window != NULL) { | |
2458 SDL_SendWindowEvent(window->id, | |
2459 SDL_WINDOWEVENT_MOVED, | |
2460 wmevent->pos.x, | |
2461 wmevent->pos.y); | |
2462 } | |
2463 } | |
2464 break; | |
2465 case Ph_WM_RESIZE: | |
2466 { | |
2467 if (window != NULL) { | |
2468 /* Set new window position after resize */ | |
2469 SDL_SendWindowEvent(window->id, | |
2470 SDL_WINDOWEVENT_MOVED, | |
2471 wmevent->pos.x, | |
2472 wmevent->pos.y); | |
2473 /* Set new window size after resize */ | |
2474 SDL_SendWindowEvent(window->id, | |
2475 SDL_WINDOWEVENT_RESIZED, | |
2476 wmevent->size.w, | |
2477 wmevent->size.h); | |
2478 } | |
2479 } | |
2480 break; | |
2481 case Ph_WM_HIDE: | |
2482 { | |
2483 if (window != NULL) { | |
2484 /* Send new window state: minimized */ | |
2485 SDL_SendWindowEvent(window->id, | |
2486 SDL_WINDOWEVENT_MINIMIZED, | |
2487 0, 0); | |
2488 /* In case window is minimized, then it is hidden */ | |
2489 SDL_SendWindowEvent(window->id, | |
2490 SDL_WINDOWEVENT_HIDDEN, | |
2491 0, 0); | |
2492 } | |
3108
aa1897bee1e9
Continue working on QNX Photon with OpenGL ES support
Mike Gorchak <lestat@i.com.ua>
parents:
3092
diff
changeset
|
2493 } |
3139 | 2494 break; |
2495 case Ph_WM_MAX: | |
2496 { | |
2497 if (window != NULL) { | |
2498 SDL_SendWindowEvent(window->id, | |
2499 SDL_WINDOWEVENT_MAXIMIZED, | |
2500 0, 0); | |
2501 } | |
2502 } | |
2503 break; | |
2504 case Ph_WM_RESTORE: | |
2505 { | |
2506 if (window != NULL) { | |
2507 SDL_SendWindowEvent(window->id, | |
2508 SDL_WINDOWEVENT_RESTORED, | |
2509 0, 0); | |
2510 } | |
2511 } | |
2512 break; | |
2513 } | |
2514 } | |
2515 break; | |
2516 } | |
2517 PtEventHandler(event); | |
2518 } | |
2519 break; | |
2520 case 0: | |
2521 { | |
2522 /* All events are read */ | |
2523 finish = 1; | |
2524 break; | |
2525 } | |
2526 case -1: | |
2527 { | |
2528 /* Error occured in event reading */ | |
2529 SDL_SetError("Photon: Can't read event"); | |
2530 return; | |
2531 } | |
2532 break; | |
2533 } | |
2534 if (finish != 0) { | |
2535 break; | |
2536 } | |
2537 } while (1); | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2538 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2539 |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2540 /*****************************************************************************/ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2541 /* SDL screen saver related functions */ |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2542 /*****************************************************************************/ |
3139 | 2543 void |
2544 photon_suspendscreensaver(_THIS) | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2545 { |
3139 | 2546 /* There is no screensaver in pure console, it may exist when running */ |
2547 /* GF under Photon, but I do not know, how to disable screensaver */ | |
3092
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2548 } |
cad1aefa2ed9
Date: Thu, 12 Mar 2009 15:14:38 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
3087
diff
changeset
|
2549 |
3087
0b6f51c29267
Date: Wed, 4 Mar 2009 15:38:22 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2550 /* vi: set ts=4 sw=4 expandtab: */ |