annotate Renderer/Engine/viewerSDL.cc @ 1079:7823233584da draft

single cpu run on Mac OS X
author one@zeus.cr.ie.u-ryukyu.ac.jp
date Sat, 18 Dec 2010 11:04:58 +0900
parents 78552463c06a
children
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"
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
5 #include "fb.h"
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
7 #define UGA 1
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
8
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 extern void post2runLoop(void *);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
11 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
728
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 ViewerSDL::~ViewerSDL() {}
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
15
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
16 #define DEVICE_NAME "/dev/fb0"
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
17 #define DIV_BYTE 8
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
18
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
19 Uint32 *
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
20 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
21 {
997
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
22
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
23 #if defined(__linux__)
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
24
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
25 int fd_framebuffer ;
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
26 struct fb_var_screeninfo vinfo;
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
27 struct fb_fix_screeninfo finfo;
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
28
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
29 // 読み書き用にファイルを開く
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
30 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
31 if ( !fd_framebuffer ) {
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
32 send_current_error_msg("Framebuffer device open error !");
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
33 exit(1);
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
34 }
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
35 send_current_information("The framebuffer device was opened !");
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
36
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
37 // 固定スクリーン情報取得
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
38 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
39 send_current_error_msg("Fixed information not gotton !");
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
40 exit(2);
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
41 }
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
42
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
43 // 変動スクリーン情報取得
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
44 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
45 send_current_error_msg("Variable information not gotton !");
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
46 exit(3);
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
47 }
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
48
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
49 close(fd_framebuffer);
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
50
997
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
51 width = vinfo.xres;
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
52 height = vinfo.yres;
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
53 bpp = vinfo.bits_per_pixel;
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
54
997
78552463c06a minor fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 996
diff changeset
55 #endif
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
56
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 Uint32 *p;
993
d3b20d63057e sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
59
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 if (SDL_Init(sdl_flag) < 0) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
996
bac3b0afc3e8 add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
65 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if (screen == NULL) {
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
67 fprintf(stderr, "Couldn't set SDL mode: %s\n", SDL_GetError());
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 SDL_Quit();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 exit(1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
996
bac3b0afc3e8 add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
71
895
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
72 this->width = screen->w;
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
73 this->height = screen->h;
b662e9dd26b0 add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
74 this->bpp = screen->format->BitsPerPixel;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 p = (Uint32*)manager->allocate(screen->pitch*height);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
78 return p;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 ViewerSDL::clean_pixels()
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 //bzero(pixels, sizeof(int)*width*height);
996
bac3b0afc3e8 add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
85
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
86 //SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 void
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
90 ViewerSDL::clear_screen()
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 {
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
92
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
93 #if !UGA
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 SDL_BlitSurface(bitmap, NULL, screen, NULL);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 SDL_UpdateRect(screen, 0, 0, 0, 0);
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
96 #endif
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
97
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
98 }
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
99
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
100 uint32_t *
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
101 ViewerSDL::flip_screen(uint32_t *old)
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
102 {
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
103 #if UGA
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
104
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
105 bitmap = SDL_CreateRGBSurfaceFrom((void *)old,
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
106 screen->w, screen->h,
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
107 screen->format->BitsPerPixel,
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
108 screen->pitch,
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
109 //redMask, greenMask, blueMask, alphaMask);
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
110 redMask, greenMask, blueMask, 0);
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
111
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
112 SDL_BlitSurface(bitmap,NULL,screen,NULL);
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
113 SDL_UpdateRect(screen,0,0,0,0);
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
114
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
115 #endif
994
56c3b9dd37a7 SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
116
984
dbebc7afd08e minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
117 return old;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 void
728
c7afc21e448d add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 539
diff changeset
121 ViewerSDL::free_device()
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 free(bitmap->pixels);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 SDL_FreeSurface(bitmap);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 }