annotate Renderer/Engine/viewerPS3.cc @ 985:e40dd2384357

fix light data update
author root@henri.cr.ie.u-ryukyu.ac.jp
date Fri, 01 Oct 2010 02:49:38 +0900
parents df5185513c2d
children 0b6f8c82625a
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__) */
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 ScreenInfo get_fbdev_addr(void) {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 ScreenInfo tmp = {0,0,0,0};
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 return tmp;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 #endif /* defined(__linux__) */
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41
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 Uint32 *
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 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
45 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 // 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
47 Uint32 sdl_flag = default_sdl_flag ;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 if (SDL_Init(sdl_flag) < 0) {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 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
51 exit(1);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 }
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 screen_info = get_fbdev_addr();
984
df5185513c2d minor fix
root@henri.cr.ie.u-ryukyu.ac.jp
parents: 981
diff changeset
55
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 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
57
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 if (pixels == 0) {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 fprintf(stderr, "Cannot get frame buffer!\n");
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 pixels = (new Uint32[width*height*32/8]);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 this->width = screen_info.xres;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 this->height = screen_info.yres;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 this->bpp = screen_info.vbpp;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 return pixels;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
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 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 ViewerPS3::clean_pixels()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 {
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 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 ViewerPS3::clear_screen()
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 {
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 uint32_t *
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 ViewerPS3::flip_screen(uint32_t *old)
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 {
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
82 // 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
83 // cp_fb_wait_vsync( &fb );
981
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
84
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
85 // Send the frame just drawn to the CRT by the next vblank
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
86 cp_fb_flip( &fb, frame_ndx );
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
87
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 frame_ndx = frame_ndx ^ 0x01;
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89 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
90 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 void
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 ViewerPS3::free_device()
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 cp_vt_close(&vt);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
97 cp_fb_close(&fb);
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
98 }
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
99
a193a851b5e3 add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
100 /* end */