comparison src/video/photon/SDL_ph_image.c @ 701:aaf3b8af6616

Date: Sat, 30 Aug 2003 16:28:10 +0300 From: "Mike Gorchak" Subject: Re: SDL 1.2.6 - minor changes about shared library building under QNX6 into README.QNX - added forgotten libSDLmain.a into distribution, SDL.qpg.in - added header guards to the all headers. - fixed fullscreen double buffered mode. - fixed Photon crashes after/during using fullscreen OpenGL modes. - added GL_MakeCurrent function. - added SDL_VIDEOEXPOSE event, when OpenGL window have been resized - added more HAVE_OPENGL checks to avoid dead code compilation without using OpenGL - finished code reorganization (began into previous patches).
author Sam Lantinga <slouken@libsdl.org>
date Sat, 30 Aug 2003 17:07:59 +0000
parents 04dd6c6d7c30
children b8d311d90021
comparison
equal deleted inserted replaced
700:c35edafc84d1 701:aaf3b8af6616
184 this->UpdateRects = ph_OCUpdate; 184 this->UpdateRects = ph_OCUpdate;
185 185
186 return 0; 186 return 0;
187 } 187 }
188 188
189 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
190 {
191 this->UpdateRects = ph_OpenGLUpdate;
192
193 return 0;
194 }
195
196 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen) 189 int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
197 { 190 {
198 OCImage.flags = screen->flags; 191 OCImage.flags = screen->flags;
199 192
200 /* Begin direct mode */ 193 /* Begin direct mode */
208 { 201 {
209 PgGetPalette(savedpal); 202 PgGetPalette(savedpal);
210 PgGetPalette(syspalph); 203 PgGetPalette(syspalph);
211 } 204 }
212 205
213 OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY); 206 OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY | Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
214 if (OCImage.offscreen_context == NULL) 207 if (OCImage.offscreen_context == NULL)
215 { 208 {
216 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n"); 209 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
217 return -1; 210 return -1;
218 } 211 }
219 212
220 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) 213 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
221 { 214 {
222 OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE); 215 OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE | Pg_OSC_MEM_PAGE_ALIGN);
223 if (OCImage.offscreen_backcontext == NULL) 216 if (OCImage.offscreen_backcontext == NULL)
224 { 217 {
225 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n"); 218 SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
226 return -1; 219 return -1;
227 } 220 }
270 PgFlush(); 263 PgFlush();
271 264
272 return 0; 265 return 0;
273 } 266 }
274 267
275 void ph_DestroyImage(_THIS, SDL_Surface *screen) 268 #ifdef HAVE_OPENGL
276 { 269
270 static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)
271 {
272 PhDim_t dim;
273 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
274 int exposepost=0;
275 int OGLargc;
276
277 dim.w=width;
278 dim.h=height;
279
280 if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp))
281 {
282 PdOpenGLContextResize(oglctx, &dim);
283 PhDCSetCurrent(oglctx);
284 return 0;
285 }
286 else
287 {
288 if (oglctx!=NULL)
289 {
290 PhDCSetCurrent(NULL);
291 PhDCRelease(oglctx);
292 oglctx=NULL;
293 exposepost=1;
294 }
295 }
296
297 OGLargc=0;
298 if (this->gl_config.depth_size)
299 {
300 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
301 OGLAttrib[OGLargc++]=this->gl_config.depth_size;
302 }
303 if (this->gl_config.stencil_size)
304 {
305 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
306 OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
307 }
308 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
309 if (flags & SDL_FULLSCREEN)
310 {
311 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;
312 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;
313 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;
314 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;
315 }
316 OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
317
318 if (this->gl_config.double_buffer)
319 {
320 oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
321 }
322 else
323 {
324 oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
325 }
326
327 if (oglctx==NULL)
328 {
329 SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
330 return (-1);
331 }
332
333 PhDCSetCurrent(oglctx);
334
335 PtFlush();
336
337 oglflags=flags;
338 oglbpp=bpp;
339
340 if (exposepost!=0)
341 {
342 /* OpenGL context has been recreated, so report about this fact */
343 SDL_PrivateExpose();
344 }
345
346 return 0;
347 }
348
349 int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
350 {
351 this->UpdateRects = ph_OpenGLUpdate;
352 screen->pixels=NULL;
353 screen->pitch=NULL;
354
355 if (ph_SetupOpenGLContext(this, screen->w, screen->h, screen->format->BitsPerPixel, screen->flags)!=0)
356 {
357 screen->flags &= ~SDL_OPENGL;
358 return -1;
359 }
360
361 return 0;
362 }
363
364 #endif /* HAVE_OPENGL */
365
366 void ph_DestroyImage(_THIS, SDL_Surface* screen)
367 {
368
369 #ifdef HAVE_OPENGL
370 if ((screen->flags & SDL_OPENGL)==SDL_OPENGL)
371 {
372 if (oglctx)
373 {
374 PhDCSetCurrent(NULL);
375 PhDCRelease(oglctx);
376 oglctx=NULL;
377 oglflags=0;
378 oglbpp=0;
379 }
380 return;
381 }
382 #endif /* HAVE_OPENGL */
383
277 if (currently_fullscreen) 384 if (currently_fullscreen)
278 { 385 {
279 /* if we right now in 8bpp fullscreen we must release palette */ 386 /* if we right now in 8bpp fullscreen we must release palette */
280 if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8)) 387 if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
281 { 388 {
318 { 425 {
319 screen->pixels = NULL; 426 screen->pixels = NULL;
320 } 427 }
321 } 428 }
322 429
323 int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags) 430 int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags)
324 { 431 {
325 ph_DestroyImage(this, screen); 432 ph_DestroyImage(this, screen);
326 433
434 #ifdef HAVE_OPENGL
435 if ((flags & SDL_OPENGL)==SDL_OPENGL)
436 {
437 return ph_SetupOpenGLImage(this, screen);
438 }
439 #endif /* HAVE_OPENGL */
327 if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) 440 if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
328 { 441 {
329 return ph_SetupFullScreenImage(this, screen); 442 return ph_SetupFullScreenImage(this, screen);
330 } 443 }
331 if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE) 444 if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
332 { 445 {
333 return ph_SetupOCImage(this, screen); 446 return ph_SetupOCImage(this, screen);
334 } 447 }
335 if ((flags & SDL_OPENGL)==SDL_OPENGL)
336 {
337 return ph_SetupOpenGLImage(this, screen);
338 }
339 448
340 return ph_SetupImage(this, screen); 449 return ph_SetupImage(this, screen);
341 } 450 }
342 451
343 int ph_AllocHWSurface(_THIS, SDL_Surface *surface) 452 int ph_AllocHWSurface(_THIS, SDL_Surface* surface)
344 { 453 {
345 return(-1); 454 return(-1);
346 } 455 }
347 456
348 void ph_FreeHWSurface(_THIS, SDL_Surface *surface) 457 void ph_FreeHWSurface(_THIS, SDL_Surface* surface)
349 { 458 {
350 return; 459 return;
351 } 460 }
352 461
353 int ph_FlipHWSurface(_THIS, SDL_Surface *screen) 462 int ph_FlipHWSurface(_THIS, SDL_Surface* screen)
354 { 463 {
355 PhArea_t area;
356
357 area.pos.x=0;
358 area.pos.y=0;
359 area.size.w=screen->w;
360 area.size.h=screen->h;
361
362 if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) 464 if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
363 { 465 {
466 PgWaitHWIdle();
364 if (OCImage.current==0) 467 if (OCImage.current==0)
365 { 468 {
366 PgSwapDisplay(OCImage.offscreen_context, 0); 469 PgSwapDisplay(OCImage.offscreen_context, 0);
367 OCImage.current=1; 470 OCImage.current=1;
368 screen->pitch = OCImage.offscreen_backcontext->pitch; 471 screen->pitch = OCImage.offscreen_backcontext->pitch;
369 screen->pixels = OCImage.FrameData1; 472 screen->pixels = OCImage.FrameData1;
370 // memcpy(OCImage.FrameData1, OCImage.FrameData0, OCImage.offscreen_context->shared_size);
371 PgContextBlitArea(OCImage.offscreen_context, &area, OCImage.offscreen_backcontext, &area);
372 PhDCSetCurrent(OCImage.offscreen_backcontext); 473 PhDCSetCurrent(OCImage.offscreen_backcontext);
373 PgFlush(); 474 PgFlush();
374 } 475 }
375 else 476 else
376 { 477 {
377 PgSwapDisplay(OCImage.offscreen_backcontext, 0); 478 PgSwapDisplay(OCImage.offscreen_backcontext, 0);
378 OCImage.current=0; 479 OCImage.current=0;
379 screen->pitch = OCImage.offscreen_context->pitch; 480 screen->pitch = OCImage.offscreen_context->pitch;
380 screen->pixels = OCImage.FrameData0; 481 screen->pixels = OCImage.FrameData0;
381 // memcpy(OCImage.FrameData0, OCImage.FrameData1, OCImage.offscreen_context->shared_size);
382 PgContextBlitArea(OCImage.offscreen_backcontext, &area, OCImage.offscreen_context, &area);
383 PhDCSetCurrent(OCImage.offscreen_context); 482 PhDCSetCurrent(OCImage.offscreen_context);
384 PgFlush(); 483 PgFlush();
385 } 484 }
386 } 485 }
387 return 0; 486 return 0;
395 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) 494 void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
396 { 495 {
397 return; 496 return;
398 } 497 }
399 498
499 #ifdef HAVE_OPENGL
400 void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) 500 void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
401 { 501 {
402 this->GL_SwapBuffers(this); 502 this->GL_SwapBuffers(this);
403 503
404 return; 504 return;
405 } 505 }
506 #endif /* HAVE_OPENGL */
406 507
407 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 508 void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
408 { 509 {
409 PhPoint_t ph_pos; 510 PhPoint_t ph_pos;
410 PhRect_t ph_rect; 511 PhRect_t ph_rect;