Mercurial > hg > Members > kono > Cerium
comparison old/simple_pack/task/spu_draw.cpp @ 507:735f76483bb2
Reorganization..
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 12 Oct 2009 09:39:35 +0900 |
parents | TaskManager/Test/simple_pack/task/spu_draw.cpp@459f54b49648 |
children |
comparison
equal
deleted
inserted
replaced
506:1d4a8a86f26b | 507:735f76483bb2 |
---|---|
1 #include <iostream> | |
2 #include "polygon_pack.h" | |
3 #include "span_pack.h" | |
4 #include "spu_span.h" | |
5 using namespace std; | |
6 | |
7 #define PIXELSIZE 11520 //32 line pixel size | |
8 | |
9 int linebuf[2][8][IMG_MAX_Y]; | |
10 | |
11 | |
12 | |
13 void linebuf_init(int j) { | |
14 int i; | |
15 for(int t= 0; t < 8; t++) { | |
16 for(i = 0; i < IMG_MAX_Y; i++) { | |
17 linebuf[j][t][i] = 0; | |
18 } | |
19 } | |
20 } | |
21 char *get_pixel(int tx, int ty, void *texture_image) | |
22 { | |
23 //return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx)); | |
24 return (char*)texture_image+(3*((128)*ty+tx)); | |
25 } | |
26 | |
27 Uint32 Polygon::get_rgb(int tx, int ty, void *texture) | |
28 { | |
29 Uint8 red, green, blue; | |
30 | |
31 if (tx<0) tx = 0; | |
32 if (128-1< tx) tx = 128-1 ; | |
33 if (ty<0) ty = 0; | |
34 if (128-1< ty) ty = 128-1 ; | |
35 | |
36 char *p = get_pixel(tx,ty,texture); | |
37 | |
38 blue = (Uint8) p[0]; | |
39 green = (Uint8) p[1]; | |
40 red = (Uint8) p[2]; | |
41 | |
42 SDL_PixelFormat pf; | |
43 pf.BitsPerPixel = 32; | |
44 pf.BytesPerPixel = 4; | |
45 alpha = 255; | |
46 | |
47 return SDL_MapRGB(pf, red, green, blue); | |
48 } | |
49 | |
50 void write_pixel(int x, int y, float z, Uint32 rgb) | |
51 { | |
52 | |
53 } | |
54 | |
55 void zRow_init() { | |
56 int i; | |
57 //printf("zRow_init?n"); | |
58 for(int t = 0; t < 8; t++) { | |
59 for(i = 0; i < IMG_MAX_Y; i++) { | |
60 zRow[t][i] = 65535; | |
61 } | |
62 } | |
63 } | |
64 | |
65 int spu_draw(SPUSPAN *ss, unsigned int fbdev_addr) | |
66 { | |
67 void *texture = new void[128*128*3]; | |
68 long *addr = ss->sp[0].tex_addr; | |
69 GLushort zRow[8][IMG_MAX_Y]; | |
70 static int j = 0; | |
71 int render_y = 0; | |
72 spu_mfcdma32(texture, addr, PIXELSIZE, 17, MFC_GET_CMD); | |
73 spu_mfcdma32(texture+PIXELSIZE, addr+PIXELSIZE, PIXELSIZE, 18, MFC_GET_CMD); | |
74 spu_mfcdma32(texture+PIXELSIZE*2, addr+PIXELSIZE*2, PIXELSIZE, 19, MFC_GET_CMD); | |
75 spu_mfcdma32(texture+PIXELSIZE*3, addr+PIXELSIZE*3, PIXELSIZE, 20, MFC_GET_CMD); | |
76 spu_writech(MFC_WrTagMask, 1 << 17); | |
77 spu_mfcstat(MFC_TAG_UPDATE_ALL); | |
78 spu_writech(MFC_WrTagMask, 1 << 18); | |
79 spu_mfcstat(MFC_TAG_UPDATE_ALL); | |
80 spu_writech(MFC_WrTagMask, 1 << 19); | |
81 spu_mfcstat(MFC_TAG_UPDATE_ALL); | |
82 spu_writech(MFC_WrTagMask, 1 << 20); | |
83 spu_mfcstat(MFC_TAG_UPDATE_ALL); | |
84 zRow_init(); | |
85 linebuf_init(j); | |
86 render_y = ss->sp[0].span[0].y; | |
87 for(int i; i<ss->length; i++) | |
88 { | |
89 for(int t; t<ss->sp[i].info.size; t++) | |
90 { | |
91 int end = sp->span[n].length_x; | |
92 Uint32 rgb; | |
93 float tex1 = sp->span[n].tex_x1; | |
94 float tex2= sp->span[n].tex_x2; | |
95 float tey1 = sp->span[n].tex_y1; | |
96 float tey2= sp->span[n].tex_y2; | |
97 int tex_xpos; | |
98 int tex_ypos; | |
99 int tex_zpos; | |
100 int x = sp->span[n].x; | |
101 int y = sp->span[n].y; | |
102 float z = sp->span[n].start_z; | |
103 float zpos = sp->span[n].end_z; | |
104 float tex_x,tex_y,tex_z; | |
105 | |
106 if(end == 1) { | |
107 //printf("end == 1\n"); | |
108 //printf("tex_x:%f tex_y:%f\n",tex1,tex2); | |
109 //if(tex1 > 1) tex1 = 1; | |
110 //if(tey1 > 1) tey1 = 1; | |
111 tex_xpos = (int)((sp->span[n].tex_height-1) * tex1); | |
112 tex_ypos = (int)((sp->span[n].tex_width-1) * tey1); | |
113 tex_zpos = (int)z; | |
114 //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); | |
115 //printf("image->h:%d tex_x:%f\n",(int)sp->span[n].tex_height,tex1); | |
116 if(z < zRow[x][y%8]) { | |
117 rgb = get_rgb(tex_xpos,tex_ypos); | |
118 //viewer->write_pixel(x,y,zpos,rgb); | |
119 linebuf[j][x][y%8] = rgb; | |
120 } | |
121 | |
122 }else { | |
123 //printf("end != 1\n"); | |
124 for(int j = 0; j < end; j++) { | |
125 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); | |
126 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); | |
127 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); | |
128 if(tex_x > 1) tex_x = 1; | |
129 if(tex_y > 1) tex_y = 1; | |
130 tex_xpos = (int)((sp->span[n].tex_height-1) * tex_x); | |
131 tex_ypos = (int)((sp->span[n].tex_width-1) * tex_y); | |
132 //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); | |
133 //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); | |
134 //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); | |
135 if(z < zRow[x][y%8]) { | |
136 rgb = get_rgb(tex_xpos,tex_ypos); | |
137 linebuf[j][x][y%8] = rgb; | |
138 //viewer->write_pixel(j+x,y,tex_z,rgb); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 writebuffer(j,fbdev_addr,render_y); | |
144 } | |
145 j ^= 1; | |
146 } | |
147 | |
148 void writebuffer(int i,fbdev_addr,int y) { | |
149 spu_mfcdma32(&linebuf[0][0],fbdev_addr,PIXELSIZE,21,MFC_PUT_CMD); | |
150 } |