Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/viewerSDL.cc @ 993:8024a3a44832
sdl mode not worked yet.
author | yutaka@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Sat, 09 Oct 2010 19:11:45 +0900 |
parents | 0b6f8c82625a |
children | 33616b2789de |
rev | line source |
---|---|
507 | 1 #include "viewerSDL.h" |
2 #include "Func.h" | |
3 #include "TaskManager.h" | |
728 | 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 | 6 |
984 | 7 #define UGA 1 |
8 | |
507 | 9 extern void post2runLoop(void *); |
10 | |
728 | 11 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
507 | 12 |
728 | 13 ViewerSDL::ViewerSDL() {} |
14 ViewerSDL::~ViewerSDL() {} | |
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 | 19 Uint32 * |
20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height) | |
507 | 21 { |
993
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
22 |
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 |
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
29 /* 読み書き用にファイルを開く */ |
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 |
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
37 /* 固定スクリーン情報取得 */ |
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 |
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
43 /* 変動スクリーン情報取得 */ |
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; |
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
58 |
507 | 59 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; |
60 Uint32 *p; | |
993
8024a3a44832
sdl mode not worked yet.
yutaka@charles.cr.ie.u-ryukyu.ac.jp
parents:
988
diff
changeset
|
61 |
507 | 62 if (SDL_Init(sdl_flag) < 0) { |
63 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); | |
64 exit(1); | |
65 } | |
66 | |
984 | 67 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); |
507 | 68 if (screen == NULL) { |
69 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); | |
70 SDL_Quit(); | |
71 exit(1); | |
72 } | |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
73 this->width = screen->w; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
74 this->height = screen->h; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
728
diff
changeset
|
75 this->bpp = screen->format->BitsPerPixel; |
507 | 76 |
77 p = (Uint32*)manager->allocate(screen->pitch*height); | |
78 bitmap = SDL_CreateRGBSurfaceFrom((void *)p, | |
79 screen->w, screen->h, | |
80 screen->format->BitsPerPixel, | |
81 screen->pitch, | |
82 redMask, greenMask, blueMask, alphaMask); | |
83 | |
728 | 84 return p; |
507 | 85 } |
86 | |
87 void | |
88 ViewerSDL::clean_pixels() | |
89 { | |
90 //bzero(pixels, sizeof(int)*width*height); | |
91 SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); | |
92 } | |
93 | |
94 void | |
728 | 95 ViewerSDL::clear_screen() |
507 | 96 { |
984 | 97 #if !UGA |
507 | 98 SDL_BlitSurface(bitmap, NULL, screen, NULL); |
99 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
984 | 100 #endif |
101 } | |
102 | |
103 uint32_t * | |
104 ViewerSDL::flip_screen(uint32_t *old) | |
105 { | |
106 #if UGA | |
107 SDL_BlitSurface(bitmap,NULL,screen,NULL); | |
108 SDL_UpdateRect(screen,0,0,0,0); | |
109 #endif | |
110 return old; | |
507 | 111 } |
112 | |
113 void | |
728 | 114 ViewerSDL::free_device() |
507 | 115 { |
116 free(bitmap->pixels); | |
117 SDL_FreeSurface(bitmap); | |
118 } |