annotate Renderer/Engine/viewerPS3.cc @ 1002:c79651141045

many changes.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Oct 2010 19:00:47 +0900
parents 0b6f8c82625a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include "viewerPS3.h"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include "fb.h"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include "types.h"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 #include "ps3fb/cp_vt.h"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 #include "ps3fb/cp_fb.h"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 #include <stdio.h>
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 ViewerPS3::ViewerPS3() {}
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 ViewerPS3::~ViewerPS3() {}
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 #if defined(__linux__)
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 #define DEVICE_NAME "/dev/fb0"
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 #define DIV_BYTE 8
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 ScreenInfo
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 ViewerPS3::get_fbdev_addr()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 ScreenInfo info;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
22
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 cp_vt_open_graphics(&vt);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
24 cp_fb_open(&fb);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
25
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
26 info.xres = fb.w;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27 info.yres = fb.h;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 info.vbpp = 32;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 info.fbptr[0] = (uint32_t *)fb.draw_addr[ 0 ];
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
30 info.fbptr[1] = (uint32_t *)fb.draw_addr[ 1 ];
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
31
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
32 return info;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 #else /* !defined(__linux__) */
988
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
36 ScreenInfo
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
37 ViewerPS3::get_fbdev_addr(void) {
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 ScreenInfo tmp = {0,0,0,0};
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 return tmp;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 #endif /* defined(__linux__) */
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 Uint32 *
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 ViewerPS3::video_init(TaskManager *manager, int bpp, int width, int height)
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 // Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 Uint32 sdl_flag = default_sdl_flag ;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 if (SDL_Init(sdl_flag) < 0) {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 exit(1);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 screen_info = get_fbdev_addr();
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 981
diff changeset
56
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 uint32_t *pixels = screen_info.fbptr[frame_ndx];
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 if (pixels == 0) {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 fprintf(stderr, "Cannot get frame buffer!\n");
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 pixels = (new Uint32[width*height*32/8]);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 this->width = screen_info.xres;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 this->height = screen_info.yres;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 this->bpp = screen_info.vbpp;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 return pixels;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
69
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 ViewerPS3::clean_pixels()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
74
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 ViewerPS3::clear_screen()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
77 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
79
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 uint32_t *
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 ViewerPS3::flip_screen(uint32_t *old)
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
82 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
83 // At the vsync, the previous frame is finished sending to the CRT
985
e40dd2384357 fix light data update
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 984
diff changeset
84 // cp_fb_wait_vsync( &fb );
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
85
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
86 // Send the frame just drawn to the CRT by the next vblank
988
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
87 #ifdef __linux__
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 cp_fb_flip( &fb, frame_ndx );
988
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
89 #endif
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 frame_ndx = frame_ndx ^ 0x01;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92 return (uint32_t*)fb.draw_addr[ frame_ndx ];
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
94
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
95
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
96 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
97 ViewerPS3::free_device()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
98 {
988
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
99 #ifdef __linux__
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
100 cp_vt_close(&vt);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
101 cp_fb_close(&fb);
988
0b6f8c82625a fix for double buffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 985
diff changeset
102 #endif
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 /* end */