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