comparison TaskManager/Test/test_render/spe/DrawSpan.cpp @ 147:4636153abc9f draft

fix
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 02 Dec 2008 15:47:25 +0900
parents 8f1419174cdf
children 74341c8bf935
comparison
equal deleted inserted replaced
146:a98dbb81db5c 147:4636153abc9f
6 #include "texture.h" 6 #include "texture.h"
7 #include "viewer_types.h" 7 #include "viewer_types.h"
8 8
9 #define SPAN_PACK_LOAD 0 9 #define SPAN_PACK_LOAD 0
10 #define TEX_LOAD 1 10 #define TEX_LOAD 1
11 #define TILE_INFO_LOAD 2
11 12
12 SchedDefineTask(DrawSpan); 13 SchedDefineTask(DrawSpan);
13 14
14 static const int hashsize = 263; 15 static const int hashsize = 263;
15 16
173 SpanPack *next_sp = 174 SpanPack *next_sp =
174 (SpanPack*)smanager->allocate(sizeof(SpanPack)); 175 (SpanPack*)smanager->allocate(sizeof(SpanPack));
175 SpanPack *free_sp = next_sp; // next_sp の free() 用 176 SpanPack *free_sp = next_sp; // next_sp の free() 用
176 SpanPack *tmp_sp = NULL; 177 SpanPack *tmp_sp = NULL;
177 Span *span; 178 Span *span;
179
180 TileInfoListPtr tilist =
181 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
182 TileInfoListPtr next_tilist =
183 (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
184 TileInfoListPtr tmp_tilist = NULL;
185 TileInfoPtr tinfo;
186
178 187
179 tileList = (TileListPtr)smanager->allocate(sizeof(TileList)); 188 tileList = (TileListPtr)smanager->allocate(sizeof(TileList));
180 tileList->init(); 189 tileList->init();
181 190
182 int render_y = sp->info.y_top; 191 int render_y = sp->info.y_top;
211 next_sp = NULL; 220 next_sp = NULL;
212 } 221 }
213 222
214 for (int t = 0; t < sp->info.size; t++) { 223 for (int t = 0; t < sp->info.size; t++) {
215 span = &sp->span[t]; 224 span = &sp->span[t];
225
226 smanager->dma_load(tilist, (uint32)span->tilelist,
227 sizeof(TileInfoList), TILE_INFO_LOAD);
216 228
217 Uint32 rgb = 0x00ff00; 229 Uint32 rgb = 0x00ff00;
218 float tex1 = span->tex_x1; 230 float tex1 = span->tex_x1;
219 float tex2 = span->tex_x2; 231 float tex2 = span->tex_x2;
220 float tey1 = span->tex_y1; 232 float tey1 = span->tex_y1;
230 242
231 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 243 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1
232 int localx = getLocalX(x-1); 244 int localx = getLocalX(x-1);
233 int localy = getLocalY(y-1); 245 int localy = getLocalY(y-1);
234 246
247 smanager->dma_wait(TILE_INFO_LOAD);
248
235 if (x_len == 1) { 249 if (x_len == 1) {
236 if (x < rangex_start || rangex_end < x) { 250 if (x < rangex_start || rangex_end < x) {
237 continue; 251 continue;
238 } 252 }
239 tex_xpos = (int)((span->tex_width-1) * tex1); 253 tex_xpos = (int)((span->tex_width-1) * tex1);
245 span->tex_height, texture_image); 259 span->tex_height, texture_image);
246 zRow[localx + (rangex * localy)] = zpos; 260 zRow[localx + (rangex * localy)] = zpos;
247 linebuf[localy][localx] = rgb; 261 linebuf[localy][localx] = rgb;
248 } 262 }
249 } else { 263 } else {
250 float tex_x, tex_y, tex_z;
251 int js = (x < rangex_start) ? rangex_start - x : 0; 264 int js = (x < rangex_start) ? rangex_start - x : 0;
252 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; 265 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len;
253 266
254 for (int j = js; j <= je; j++) { 267 if (js > je) continue;
255 localx = getLocalX(x-1+j); 268
256 269 int cur_x = 0;
257 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); 270 int max_x = je;
258 271 int len;
259 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); 272
260 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); 273 while (cur_x + MAX_TILE_LIST < js) {
261 if (tex_x > 1) tex_x = 1; 274 smanager->dma_wait(TILE_INFO_LOAD);
262 if (tex_y > 1) tex_y = 1; 275 smanager->dma_load(tilist, (uint32)tilist->next,
263 tex_xpos = (int)((span->tex_width-1) * tex_x); 276 sizeof(TileInfoList), TILE_INFO_LOAD);
264 tex_ypos = (int)((span->tex_height-1) * tex_y); 277 cur_x += MAX_TILE_LIST;
265 278 }
266 if (tex_z < zRow[localx + (rangex*localy)]) { 279
267 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width, 280 cur_x = js;
268 span->tex_height, texture_image); 281
269 zRow[localx + (rangex*localy)] = tex_z; 282 while (cur_x < max_x) {
270 linebuf[localy][localx] = rgb; 283 smanager->dma_wait(TILE_INFO_LOAD);
284
285 if (cur_x + MAX_TILE_LIST < max_x) {
286 smanager->dma_load(next_tilist, (uint32)tilist->next,
287 sizeof(TileInfoList), TILE_INFO_LOAD);
288 len = MAX_TILE_LIST;
289 } else {
290 len = max_x - cur_x;
271 } 291 }
292
293 float tex_x, tex_y, tex_z;
294
295 for (int j = cur_x; j <= cur_x + len; j++) {
296 localx = getLocalX(x-1+j);
297
298 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1);
299
300 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1);
301 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1);
302 if (tex_x > 1) tex_x = 1;
303 if (tex_y > 1) tex_y = 1;
304 tex_xpos = (int)((span->tex_width-1) * tex_x);
305 tex_ypos = (int)((span->tex_height-1) * tex_y);
306
307 if (tex_z < zRow[localx + (rangex*localy)]) {
308 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width,
309 span->tex_height, texture_image);
310 zRow[localx + (rangex*localy)] = tex_z;
311 linebuf[localy][localx] = rgb;
312 }
313 }
314
315 smanager->dma_wait(TILE_INFO_LOAD);
316
317 TileInfoListPtr tmp = tilist;
318 tilist = next_tilist;
319 next_tilist = tmp;
320
321 cur_x += MAX_TILE_LIST;
272 } 322 }
273 } 323 }
274 } 324 }
275 325
276 smanager->dma_wait(SPAN_PACK_LOAD); 326 smanager->dma_wait(SPAN_PACK_LOAD);
277 327
278 tmp_sp = sp; 328 tmp_sp = sp;
279 sp = next_sp; 329 sp = next_sp;
280 next_sp = tmp_sp; 330 next_sp = tmp_sp;
282 332
283 free(free_sp); 333 free(free_sp);
284 free(linebuf); 334 free(linebuf);
285 free(zRow); 335 free(zRow);
286 free(tileList); 336 free(tileList);
337 free(tilist);
338 free(next_tilist);
287 339
288 return 0; 340 return 0;
289 } 341 }