annotate Renderer/Engine/viewerSDL.cc @ 988:da1cec21f0c9 draft akira

fix for double buffer
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 02 Oct 2010 03:48:39 +0900
parents dbebc7afd08e
children d3b20d63057e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "viewerSDL.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "Func.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "TaskManager.h"
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
4 #include "viewer_types.h"
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
6 #define UGA 1
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
7
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern void post2runLoop(void *);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
10 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
12 ViewerSDL::ViewerSDL() {}
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
13 ViewerSDL::~ViewerSDL() {}
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
14
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
15 Uint32 *
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
16 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 Uint32 *p;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 if (SDL_Init(sdl_flag) < 0) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
26 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 if (screen == NULL) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 SDL_Quit();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 }
895
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
32 this->width = screen->w;
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
33 this->height = screen->h;
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
34 this->bpp = screen->format->BitsPerPixel;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 p = (Uint32*)manager->allocate(screen->pitch*height);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 bitmap = SDL_CreateRGBSurfaceFrom((void *)p,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 screen->w, screen->h,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 screen->format->BitsPerPixel,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 screen->pitch,
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 redMask, greenMask, blueMask, alphaMask);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
43 return p;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 ViewerSDL::clean_pixels()
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 //bzero(pixels, sizeof(int)*width*height);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
54 ViewerSDL::clear_screen()
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 {
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
56 #if !UGA
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 SDL_BlitSurface(bitmap, NULL, screen, NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 SDL_UpdateRect(screen, 0, 0, 0, 0);
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
59 #endif
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
60 }
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
61
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
62 uint32_t *
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
63 ViewerSDL::flip_screen(uint32_t *old)
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
64 {
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
65 #if UGA
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
66 SDL_BlitSurface(bitmap,NULL,screen,NULL);
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
67 SDL_UpdateRect(screen,0,0,0,0);
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
68 #endif
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
69 return old;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 void
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
73 ViewerSDL::free_device()
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 free(bitmap->pixels);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 SDL_FreeSurface(bitmap);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 }