annotate Renderer/Engine/viewerSDL.cc @ 996:78ebcdaae8bc

add sdl_test file
author yutaka@charles.cr.ie.u-ryukyu.ac.jp
date Mon, 11 Oct 2010 18:56:51 +0900
parents 33616b2789de
children 625be5ca53ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "viewerSDL.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "Func.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "TaskManager.h"
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
4 #include "viewer_types.h"
993
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
5 #include "fb.h"
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
7 #define UGA 1
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
8
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 extern void post2runLoop(void *);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
11 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
13 ViewerSDL::ViewerSDL() {}
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
14 ViewerSDL::~ViewerSDL() {}
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
15
993
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
16 #define DEVICE_NAME "/dev/fb0"
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
17 #define DIV_BYTE 8
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
18
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
19 Uint32 *
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 {
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
22
993
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
23 int fd_framebuffer ;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
24 struct fb_var_screeninfo vinfo;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
25 struct fb_fix_screeninfo finfo;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
26
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
27 int xres,yres,vbpp;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
28
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
29 // 読み書き用にファイルを開く
993
8024a3a44832 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);
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
31 if ( !fd_framebuffer ) {
8024a3a44832 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 !");
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
33 exit(1);
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
34 }
8024a3a44832 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 !");
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
36
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
37 // 固定スクリーン情報取得
993
8024a3a44832 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 ) ) {
8024a3a44832 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 !");
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
40 exit(2);
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
41 }
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
42
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
43 // 変動スクリーン情報取得
993
8024a3a44832 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 ) ) {
8024a3a44832 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 !");
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
46 exit(3);
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
47 }
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
48
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
49 close(fd_framebuffer);
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
50
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
51 xres = vinfo.xres;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
52 yres = vinfo.yres;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
53 vbpp = vinfo.bits_per_pixel;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
54
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
55 width = xres;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
56 height = yres;
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
57 bpp = vbpp;
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
58
993
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
59
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 Uint32 *p;
993
8024a3a44832 sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 988
diff changeset
62
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 if (SDL_Init(sdl_flag) < 0) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 exit(1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
996
78ebcdaae8bc add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
68 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE);
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if (screen == NULL) {
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
70 fprintf(stderr, "Couldn't set SDL mode: %s\n", SDL_GetError());
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 SDL_Quit();
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 exit(1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
996
78ebcdaae8bc add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
74
895
bed529c55eda add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
75 this->width = screen->w;
bed529c55eda add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
76 this->height = screen->h;
bed529c55eda add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 728
diff changeset
77 this->bpp = screen->format->BitsPerPixel;
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 p = (Uint32*)manager->allocate(screen->pitch*height);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
81 return p;
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 void
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 ViewerSDL::clean_pixels()
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 //bzero(pixels, sizeof(int)*width*height);
996
78ebcdaae8bc add sdl_test file
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 994
diff changeset
88
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
89 //SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 void
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
93 ViewerSDL::clear_screen()
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 {
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
95
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
96 #if !UGA
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 SDL_BlitSurface(bitmap, NULL, screen, NULL);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 SDL_UpdateRect(screen, 0, 0, 0, 0);
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
99 #endif
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
100
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
101 }
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
102
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
103 uint32_t *
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
104 ViewerSDL::flip_screen(uint32_t *old)
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
105 {
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
106 #if UGA
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
107
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
108 bitmap = SDL_CreateRGBSurfaceFrom((void *)old,
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
109 screen->w, screen->h,
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
110 screen->format->BitsPerPixel,
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
111 screen->pitch,
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
112 //redMask, greenMask, blueMask, alphaMask);
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
113 redMask, greenMask, blueMask, 0);
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
114
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
115 SDL_BlitSurface(bitmap,NULL,screen,NULL);
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
116 SDL_UpdateRect(screen,0,0,0,0);
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
117
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
118 #endif
994
33616b2789de SDL mode fix
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents: 993
diff changeset
119
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 895
diff changeset
120 return old;
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 void
728
4f77768d7a7f add Engine/ViewerDevice , SgRootChange not work
aaa
parents: 507
diff changeset
124 ViewerSDL::free_device()
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 free(bitmap->pixels);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 SDL_FreeSurface(bitmap);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }