annotate TaskManager/Test/test_render/spe/DrawSpan.cpp @ 109:5c194c71eca8

Cerium cvs version
author gongo@gendarme.local
date Wed, 12 Nov 2008 17:39:33 +0900
parents
children a52e193f9a42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdlib.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include "DrawSpan.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include "polygon_pack.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "SpanPack.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "texture.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 #include "viewer_types.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 #define SPAN_PACK_LOAD 0
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 SchedDefineTask(DrawSpan);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13 void
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 DrawSpan::linebuf_init(int *buf, int x, int rgb)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 for (int i = 0; i < x; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 buf[i] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 float*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 DrawSpan::zRow_init(int w, int h)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 float *zRow = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 float z = 65535.0f;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 int length = w*h;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 zRow = (float*)smanager->allocate(sizeof(float)*length);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 for (int i = 0; i < length; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 zRow[i] = z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 return zRow;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 char*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 DrawSpan::get_pixel(int tx, int ty, void *texture_image)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 return (char*)texture_image+(3*((128)*ty+tx));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 Uint32
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 DrawSpan::get_rgb(int tx, int ty, void *texture)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 Uint8 red, green, blue, alpha;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 if (tx<0) tx = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 if (128-1< tx) tx = 128-1 ;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 if (ty<0) ty = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 if (128-1< ty) ty = 128-1 ;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 char *p = get_pixel(tx,ty,texture);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 blue = (Uint8) p[0];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 green = (Uint8) p[1];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 red = (Uint8) p[2];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 alpha = 255;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 return (red & 0xff) * 0x10000 + (green & 0xff) * 0x100
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 + (blue & 0xff) + (alpha << 24);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 int
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 DrawSpan::run(void *rbuf, void *wbuf)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 SpanPack *sp = (SpanPack*)smanager->get_input(0);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 SpanPack *next_sp =
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 (SpanPack*)smanager->allocate(sizeof(SpanPack));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 SpanPack *free_sp = next_sp; // next_sp の free() 用
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72 SpanPack *tmp_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 Span *span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 int render_y = sp->info.y_top;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 void *texture_image = global_get(TEXTURE_ID);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 int rangex_start = get_param(0); // このタスクが担当する x の範囲の始点
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 int rangex_end = get_param(1); // 終点 (start <= x <= end)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 int rangey = get_param(2); // y の範囲 (render_y + rangey - 1)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 int rangex = rangex_end - rangex_start + 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 float *zRow = zRow_init(rangex, rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 for (int i = 0; i < rangey; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 linebuf[i] = (int*)smanager->get_output(i);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 linebuf_init(linebuf[i], rangex, 0x00ff00ff);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 do {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 /**
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94 * SpanPack->next が存在する場合、
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 * 現在の SpanPack を処理してる間に
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 * 次の SpanPack の DMA 転送を行う
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98 if (sp->next != NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99 smanager->dma_load(next_sp, (uint32)sp->next,
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 sizeof(SpanPack), SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 next_sp = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
103 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
104
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
105 for (int t = 0; t < sp->info.size; t++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 span = &sp->span[t];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 int end = span->length_x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 Uint32 rgb = 0x00ff00;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
110 float tex1 = span->tex_x1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 float tex2 = span->tex_x2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
112 float tey1 = span->tex_y1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113 float tey2 = span->tex_y2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 int tex_xpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115 int tex_ypos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
116 int tex_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
117 int x = span->x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
118 int y = span->y;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
119 float z = span->start_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
120 float zpos = span->end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
121
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
122 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
123 int localx = getLocalX(x-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
124 int localy = getLocalY(y-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
125
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
126 if (end == 1) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
127 if (x < rangex_start || rangex_end < x) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
128 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
129 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
130
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
131 tex_xpos = (int)((span->tex_height-1) * tex1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
132 tex_ypos = (int)((span->tex_width-1) * tey1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
133 tex_zpos = (int)z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
134
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
135 if (zpos < zRow[localx + (rangex * localy)]) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
136 rgb = get_rgb(tex_xpos, tex_ypos, texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
137 zRow[localx + (rangex * localy)] = zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
138 linebuf[localy][localx] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
139 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
140 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
141 float tex_x, tex_y, tex_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
142 int js = (x < rangex_start) ? rangex_start - x : 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
143 int je = (x + end > rangex_end) ? rangex_end - x : end;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
144
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
145 for (int j = js; j <= je; j++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
146 localx = getLocalX(x-1+j);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
147
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
148 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
150 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
151 if (tex_x > 1) tex_x = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
152 if (tex_y > 1) tex_y = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
153 tex_xpos = (int)((span->tex_height-1) * tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
154 tex_ypos = (int)((span->tex_width-1) * tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
155
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
156 if (tex_z < zRow[localx + (rangex*localy)]) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
157 rgb = get_rgb(tex_xpos, tex_ypos, texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
158 zRow[localx + (rangex*localy)] = tex_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
159 linebuf[localy][localx] = rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
160 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
161 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
162 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
163 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
164
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165 smanager->dma_wait(SPAN_PACK_LOAD);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
166
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
167 tmp_sp = sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
168 sp = next_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
169 next_sp = tmp_sp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
170 } while (sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
171
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
172
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
173 FINISH:
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
174 free(free_sp);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 free(linebuf);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176 free(zRow);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 return 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179 }