Mercurial > hg > Game > Cerium
annotate Renderer/Engine/viewerPS3.cc @ 984:dbebc7afd08e draft
minor fix
author | root@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 01 Oct 2010 01:25:45 +0900 |
parents | fdb36a9c5030 |
children | 37bd2b0694e2 |
rev | line source |
---|---|
981
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
1 #include "viewerPS3.h" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
2 #include "fb.h" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
3 #include "types.h" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
4 #include "ps3fb/cp_vt.h" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
5 #include "ps3fb/cp_fb.h" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
6 #include <stdio.h> |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
7 |
fdb36a9c5030
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 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
9 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
10 ViewerPS3::ViewerPS3() {} |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
11 ViewerPS3::~ViewerPS3() {} |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
12 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
13 #if defined(__linux__) |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
14 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
15 #define DEVICE_NAME "/dev/fb0" |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
16 #define DIV_BYTE 8 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
17 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
18 ScreenInfo |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
19 ViewerPS3::get_fbdev_addr() |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
20 { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
21 ScreenInfo info; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
22 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
23 cp_vt_open_graphics(&vt); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
24 cp_fb_open(&fb); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
25 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
26 info.xres = fb.w; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
27 info.yres = fb.h; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
28 info.vbpp = 32; |
fdb36a9c5030
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 ]; |
fdb36a9c5030
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 ]; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
31 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
32 return info; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
33 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
34 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
35 #else /* !defined(__linux__) */ |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
36 ScreenInfo get_fbdev_addr(void) { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
37 ScreenInfo tmp = {0,0,0,0}; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
38 return tmp; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
39 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
40 #endif /* defined(__linux__) */ |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
41 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
42 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
43 Uint32 * |
fdb36a9c5030
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) |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
45 { |
fdb36a9c5030
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; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
47 Uint32 sdl_flag = default_sdl_flag ; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
48 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
49 if (SDL_Init(sdl_flag) < 0) { |
fdb36a9c5030
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()); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
51 exit(1); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
52 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
53 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
54 screen_info = get_fbdev_addr(); |
984 | 55 |
981
fdb36a9c5030
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]; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
57 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
58 if (pixels == 0) { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
59 fprintf(stderr, "Cannot get frame buffer!\n"); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
60 pixels = (new Uint32[width*height*32/8]); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
61 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
62 this->width = screen_info.xres; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
63 this->height = screen_info.yres; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
64 this->bpp = screen_info.vbpp; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
65 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
66 return pixels; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
67 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
68 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
69 void |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
70 ViewerPS3::clean_pixels() |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
71 { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
72 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
73 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
74 void |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
75 ViewerPS3::clear_screen() |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
76 { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
77 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
78 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
79 uint32_t * |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
80 ViewerPS3::flip_screen(uint32_t *old) |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
81 { |
fdb36a9c5030
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 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
83 cp_fb_wait_vsync( &fb ); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
84 |
fdb36a9c5030
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 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
86 cp_fb_flip( &fb, frame_ndx ); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
87 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
88 frame_ndx = frame_ndx ^ 0x01; |
fdb36a9c5030
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 ]; |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
90 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
91 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
92 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
93 void |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
94 ViewerPS3::free_device() |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
95 { |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
96 cp_vt_close(&vt); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
97 cp_fb_close(&fb); |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
98 } |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
99 |
fdb36a9c5030
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
100 /* end */ |