Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_video.c @ 288:2f5a6062db86
Updated for Watcom C++ and LCC compilers
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 28 Feb 2002 00:28:26 +0000 |
parents | 3d8b6b9f1e18 |
children | 68a8a8237c09 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
204
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
30 #include <unistd.h> | |
31 #include <string.h> | |
32 #include <sys/ioctl.h> | |
33 | |
34 #include "SDL.h" | |
35 #include "SDL_error.h" | |
36 #include "SDL_timer.h" | |
37 #include "SDL_thread.h" | |
38 #include "SDL_video.h" | |
39 #include "SDL_mouse.h" | |
40 #include "SDL_endian.h" | |
41 #include "SDL_sysvideo.h" | |
42 #include "SDL_pixels_c.h" | |
43 #include "SDL_events_c.h" | |
44 #include "SDL_ph_video.h" | |
45 #include "SDL_ph_modes_c.h" | |
46 #include "SDL_ph_image_c.h" | |
47 #include "SDL_ph_events_c.h" | |
48 #include "SDL_ph_mouse_c.h" | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
49 #include "SDL_ph_wm_c.h" |
0 | 50 #include "SDL_phyuv_c.h" |
51 #include "blank_cursor.h" | |
52 | |
53 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | |
55 int width, int height, int bpp, Uint32 flags); | |
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
57 static void ph_VideoQuit(_THIS); | |
58 static void ph_DeleteDevice(SDL_VideoDevice *device); | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
59 static void ph_GL_SwapBuffers(_THIS); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
60 |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
61 #ifdef HAVE_OPENGL |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
62 PdOpenGLContext_t* OGLContext=NULL; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
63 #endif /* HAVE_OPENGL */ |
0 | 64 |
65 static int ph_Available(void) | |
66 { | |
67 return 1; | |
68 } | |
69 | |
70 static SDL_VideoDevice *ph_CreateDevice(int devindex) | |
71 { | |
72 SDL_VideoDevice *device; | |
73 | |
74 /* Initialize all variables that we clean on shutdown */ | |
75 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
76 if ( device ) { | |
77 memset(device, 0, (sizeof *device)); | |
78 device->hidden = (struct SDL_PrivateVideoData *) | |
79 malloc((sizeof *device->hidden)); | |
80 device->gl_data = NULL; | |
81 } | |
82 if ( (device == NULL) || (device->hidden == NULL) ) { | |
83 SDL_OutOfMemory(); | |
84 ph_DeleteDevice(device); | |
85 return(0); | |
86 } | |
87 memset(device->hidden, 0, (sizeof *device->hidden)); | |
88 | |
89 /* Set the driver flags */ | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
90 device->handles_any_size = 1; /* JB not true for fullscreen */ |
0 | 91 |
92 /* Set the function pointers */ | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
93 device->CreateYUVOverlay = ph_CreateYUVOverlay; |
0 | 94 device->VideoInit = ph_VideoInit; |
95 device->ListModes = ph_ListModes; | |
96 device->SetVideoMode = ph_SetVideoMode; | |
97 device->ToggleFullScreen = ph_ToggleFullScreen; | |
98 device->UpdateMouse = NULL; | |
99 device->SetColors = ph_SetColors; | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
100 device->UpdateRects = NULL; /* ph_ResizeImage; */ |
0 | 101 device->VideoQuit = ph_VideoQuit; |
102 device->AllocHWSurface = ph_AllocHWSurface; | |
103 device->CheckHWBlit = NULL; | |
104 device->FillHWRect = NULL; | |
105 device->SetHWColorKey = NULL; | |
106 device->SetHWAlpha = NULL; | |
107 device->LockHWSurface = ph_LockHWSurface; | |
108 device->UnlockHWSurface = ph_UnlockHWSurface; | |
109 device->FlipHWSurface = ph_FlipHWSurface; | |
110 device->FreeHWSurface = ph_FreeHWSurface; | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
111 device->SetCaption = ph_SetCaption; |
0 | 112 device->SetIcon = NULL; |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
113 device->IconifyWindow = ph_IconifyWindow; |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
279
diff
changeset
|
114 device->GrabInput = ph_GrabInput; |
0 | 115 device->GetWMInfo = NULL; |
116 device->FreeWMCursor = ph_FreeWMCursor; | |
117 device->CreateWMCursor = ph_CreateWMCursor; | |
118 device->ShowWMCursor = ph_ShowWMCursor; | |
119 device->WarpWMCursor = ph_WarpWMCursor; | |
120 device->CheckMouseMode = ph_CheckMouseMode; | |
121 device->InitOSKeymap = ph_InitOSKeymap; | |
122 device->PumpEvents = ph_PumpEvents; | |
123 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
124 /* OpenGL support. */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 device->GL_LoadLibrary = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
126 device->GL_GetProcAddress = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
127 device->GL_GetAttribute = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 device->GL_MakeCurrent = NULL; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
129 #ifdef HAVE_OPENGL |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
130 device->GL_SwapBuffers = ph_GL_SwapBuffers; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
131 #else |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
132 device->GL_SwapBuffers = NULL; |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
133 #endif /* HAVE_OPENGL */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
134 |
0 | 135 device->free = ph_DeleteDevice; |
136 | |
137 return device; | |
138 } | |
139 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
140 VideoBootStrap ph_bootstrap = { |
0 | 141 "photon", "QNX Photon video output", |
142 ph_Available, ph_CreateDevice | |
143 }; | |
144 | |
145 static void ph_DeleteDevice(SDL_VideoDevice *device) | |
146 { | |
147 | |
148 if ( device ) { | |
149 if ( device->hidden ) { | |
150 free(device->hidden); | |
151 device->hidden = NULL; | |
152 } | |
153 if ( device->gl_data ) { | |
154 free(device->gl_data); | |
155 device->gl_data = NULL; | |
156 } | |
157 free(device); | |
158 device = NULL; | |
159 } | |
160 } | |
161 | |
162 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
163 { | |
164 PtArg_t arg[1]; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
165 PhDim_t dim; |
0 | 166 PgColor_t ph_palette[_Pg_MAX_PALETTE]; |
167 int i; | |
168 unsigned long *tempptr; | |
169 int rtnval; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
170 // PgDisplaySettings_t mysettings; |
0 | 171 PgVideoModeInfo_t my_mode_info; |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
172 PgHWCaps_t my_hwcaps; |
0 | 173 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
174 if( NULL == ( event = malloc( EVENT_SIZE ) ) ) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
175 exit( EXIT_FAILURE ); |
0 | 176 |
177 /* Create a widget 'window' to capture events */ | |
178 dim.w=0; //JB test320; | |
179 dim.h=0; //JB test240; | |
180 //We need to return BytesPerPixel as it in used by CreateRGBsurface | |
181 | |
182 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); | |
183 | |
184 /* | |
185 PtSetArg(&arg[1], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED); | |
186 PtSetArg(&arg[2], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | | |
187 Ph_WM_STATE_ISMAX | | |
188 Ph_WM_STATE_ISFOCUS); | |
189 | |
190 PtSetArg(&arg[3], Pt_ARG_WINDOW_RENDER_FLAGS,Pt_FALSE,~0); | |
191 PtSetArg(&arg[4], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, | |
192 Ph_WM_FFRONT | | |
193 Ph_WM_CLOSE | | |
194 Ph_WM_TOFRONT | | |
195 Ph_WM_CONSWITCH); | |
196 */ | |
197 | |
198 | |
199 window=PtAppInit(NULL, NULL, NULL, 1, arg); | |
200 | |
201 if(window == NULL) | |
202 { | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
203 printf("Photon application init failed, probably Photon is not running.\n"); |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 exit( EXIT_FAILURE ); |
0 | 205 } |
206 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
207 //PgSetDrawBufferSize(16 *1024); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
208 PgSetRegion(PtWidgetRid(window)); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
209 PgSetClipping(0,NULL); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
210 PtRealizeWidget(window); |
0 | 211 |
212 | |
213 /* Get the available video modes */ | |
214 // if(ph_GetVideoModes(this) < 0) | |
215 // return -1; | |
216 | |
217 /* Create the blank cursor */ | |
218 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, | |
219 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, | |
220 (int)BLANK_CHOTX, (int)BLANK_CHOTY); | |
221 | |
222 if(SDL_BlankCursor == NULL) | |
223 printf("could not create blank cursor\n"); | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
224 |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
225 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
226 { |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
227 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
228 } |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
229 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
230 { |
0 | 231 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
232 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
233 |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
234 //We need to return BytesPerPixel as it in used by CreateRGBsurface |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
235 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
236 vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
237 |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
238 //return a palette if we are in 256 color mode |
0 | 239 if(vformat->BitsPerPixel == 8) |
240 { | |
241 vformat->palette = malloc(sizeof(SDL_Palette)); | |
242 memset(vformat->palette, 0, sizeof(SDL_Palette)); | |
243 vformat->palette->ncolors = 256; | |
244 vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | |
245 | |
246 //fill the palette | |
247 rtnval = PgGetPalette(ph_palette); | |
248 if(rtnval < 0) | |
249 printf("ph_VideoInit: PgGetPalette failed\n"); | |
250 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
251 tempptr = (unsigned long *)vformat->palette->colors; |
0 | 252 |
253 for(i=0;i<256; i++) | |
254 { | |
255 *tempptr = (((unsigned long)ph_palette[i]) << 8); | |
256 tempptr++; | |
257 | |
258 } | |
259 | |
260 } | |
261 | |
262 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
263 currently_fullscreen = 0; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
264 |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
265 this->info.wm_available = 1; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
266 |
0 | 267 return 0; |
268 } | |
269 | |
270 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | |
271 int width, int height, int bpp, Uint32 flags) | |
272 { | |
273 PgDisplaySettings_t settings; | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
274 /* |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
275 PgHWCaps_t my_hwcaps; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
276 PgVideoModeInfo_t mode_info; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
277 */ |
0 | 278 int mode, actual_width, actual_height; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
279 PtArg_t arg[5]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
280 PhDim_t dim; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
281 int rtnval; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
282 PgColor_t ph_palette[_Pg_MAX_PALETTE]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
283 int i; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
284 unsigned long *tempptr; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
285 |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
286 #ifdef HAVE_OPENGL |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
288 #endif // HAVE_OPENGL |
0 | 289 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
290 actual_width = width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
291 actual_height = height; |
0 | 292 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
293 dim.w=width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
294 dim.h=height; |
0 | 295 |
296 /* Lock the event thread, in multi-threading environments */ | |
297 SDL_Lock_EventThread(); | |
298 | |
299 /* Initialize the window */ | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
300 if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */ |
0 | 301 { |
302 /* Get the video mode and set it */ | |
303 if (flags & SDL_ANYFORMAT) | |
304 { | |
305 if ((mode = get_mode_any_format(width, height, bpp)) == 0) | |
306 { | |
307 fprintf(stderr,"error: get_mode_any_format failed\n"); | |
308 exit(1); | |
309 } | |
310 } | |
311 else | |
312 { | |
313 if ((mode = get_mode(width, height, bpp)) == 0) | |
314 { | |
315 fprintf(stderr,"error: get_mode failed\n"); | |
316 exit(1); | |
317 } | |
318 | |
319 | |
320 } | |
321 settings.mode = mode; | |
322 settings.refresh = 0; | |
323 settings.flags = 0; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
324 |
0 | 325 if (PgSetVideoMode( &settings ) < 0) |
326 { | |
327 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
328 } | |
329 | |
330 /* Get the true height and width */ | |
331 | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
279
diff
changeset
|
332 current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */ |
0 | 333 |
334 /* Begin direct mode */ | |
335 ph_EnterFullScreen(this); | |
336 | |
337 | |
338 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
339 } /* end fullscreen flag */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
340 else |
0 | 341 { |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
342 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
343 { |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
344 /* Hardware surface is Offsceen Context. ph_ResizeImage handles the switch */ |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
279
diff
changeset
|
345 current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
346 } |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
347 else /* must be SDL_SWSURFACE */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
348 { |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
279
diff
changeset
|
349 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
350 } |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
351 |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
352 #ifdef HAVE_OPENGL |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
353 if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
354 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
355 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
356 OGLAttrib[1]=bpp; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
357 OGLAttrib[2]=PHOGL_ATTRIB_NONE; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
358 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
359 if (OGLContext==NULL) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
360 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
361 fprintf(stderr,"error: cannot create OpenGL context\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
362 exit(1); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
363 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
364 PhDCSetCurrent(OGLContext); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
365 } |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
366 #endif /* HAVE_OPENGL */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
367 |
0 | 368 } |
369 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
370 /* If we are setting video to use the palette make sure we have allocated memory for it */ |
0 | 371 if(bpp == 8) |
372 { | |
373 current->format->palette = malloc(sizeof(SDL_Palette)); | |
374 memset(current->format->palette, 0, sizeof(SDL_Palette)); | |
375 current->format->palette->ncolors = 256; | |
376 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
377 /* fill the palette */ |
0 | 378 rtnval = PgGetPalette(ph_palette); |
379 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
380 tempptr = (unsigned long *)current->format->palette->colors; |
0 | 381 |
382 for(i=0;i<256; i++) | |
383 { | |
384 *tempptr = (((unsigned long)ph_palette[i]) << 8); | |
385 tempptr++; | |
386 | |
387 } | |
388 } | |
389 | |
390 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
391 /* Current window dimensions */ |
0 | 392 PtGetResource( window, Pt_ARG_DIM, &dim, 0 ); |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
393 |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
394 /* If we need to resize the window */ |
0 | 395 if((dim.w != width)||(dim.h != height)) |
396 { | |
397 dim.w=width; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
398 dim.h=height; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
399 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
400 PtSetResources( window, 1, arg ); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
401 current->w = width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
402 current->h = height; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
403 current->format->BitsPerPixel = bpp; |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
404 current->format->BytesPerPixel = (bpp+7)/8; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
405 current->pitch = SDL_CalculatePitch(current); |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
406 /* Must call at least once it setup image planes */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
407 ph_ResizeImage(this, current, flags); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
408 } |
0 | 409 |
410 SDL_Unlock_EventThread(); | |
411 | |
412 /* We're done! */ | |
413 return(current); | |
414 } | |
415 | |
416 static void ph_VideoQuit(_THIS) | |
417 { | |
283
3d8b6b9f1e18
Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents:
279
diff
changeset
|
418 ph_DestroyImage(this, SDL_VideoSurface); |
0 | 419 |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
420 if (currently_fullscreen) |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
421 { |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
422 PdDirectStop( directContext ); |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
423 PdReleaseDirectContext( directContext ); |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
424 directContext=0; |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
425 currently_fullscreen = 0; |
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
426 } |
0 | 427 } |
428 | |
429 | |
430 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
431 { | |
432 PgColor_t *in, *out; | |
433 int i, j; | |
434 int alloct_all = 1; | |
435 | |
436 colors = this->screen->format->palette->colors; | |
437 | |
438 in = alloca( ncolors*sizeof(PgColor_t) ); | |
439 if ( in == NULL ) { | |
440 return 0; | |
441 } | |
442 memset(in,0,ncolors*sizeof(PgColor_t)); | |
443 | |
444 out = alloca( ncolors*sizeof(PgColor_t) ); | |
445 if ( out == NULL ) { | |
446 return 0; | |
447 } | |
448 | |
449 for (i=0,j=firstcolor;i<ncolors;i++,j++) | |
450 { | |
451 in[i] |= colors[j].r<<16 ; | |
452 in[i] |= colors[j].g<<8 ; | |
453 in[i] |= colors[j].b ; | |
454 } | |
455 | |
456 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) | |
457 { | |
458 if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 ) | |
459 { | |
460 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD) failed\n"); | |
461 return 0; | |
462 } | |
463 } | |
464 else | |
465 { | |
466 if ( PgColorMatch(ncolors, in, out) < 0 ) | |
467 { | |
468 fprintf(stderr,"error: PgColorMatch failed\n"); | |
469 return 0; | |
470 } | |
471 for (i=0;i<ncolors;i++) | |
472 { | |
473 if (memcmp(&in[i],&out[i],sizeof(PgColor_t))) | |
474 { | |
475 alloct_all = 0; | |
476 break; | |
477 } | |
478 } | |
479 if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 ) | |
480 { | |
481 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n"); | |
482 return 0; | |
483 } | |
484 } | |
485 return alloct_all; | |
486 } | |
487 | |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
488 #ifdef HAVE_OPENGL |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
489 void ph_GL_SwapBuffers(_THIS) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
490 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
491 PgSetRegion(PtWidgetRid(window)); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
492 PdOpenGLContextSwapBuffers(OGLContext); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
493 } |
279
04351f59b051
Mike Gorchak added some QNX tweaks, including OpenGL support
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
494 #endif // HAVE_OPENGL |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
495 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
496 /* |
0 | 497 static int ph_ResizeWindow(_THIS, |
498 SDL_Surface *screen, int w, int h, Uint32 flags) | |
499 { | |
500 PhWindowEvent_t winevent; | |
501 | |
502 memset( &winevent, 0, sizeof(winevent) ); | |
503 winevent.event_f = Ph_WM_RESIZE; | |
504 winevent.size.w = w; | |
505 winevent.size.h = h; | |
506 winevent.rid = PtWidgetRid( window ); | |
507 if (PtForwardWindowEvent( &winevent ) < 0) | |
508 { | |
509 fprintf(stderr,"error: PtForwardWindowEvent failed.\n"); | |
510 } | |
511 current_w = w; | |
512 current_h = h; | |
513 return(0); | |
514 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
515 */ |