Mercurial > hg > Game > Cerium
comparison Renderer/Engine/task/DrawSpan.cc @ 1163:b417abf82193 draft
use Segment API for spackload
author | Yutaka_Kinjyo |
---|---|
date | Tue, 10 May 2011 14:58:24 +0900 |
parents | 42f5958ab74e |
children | 880f989ce52a e92f00ed2fc0 |
comparison
equal
deleted
inserted
replaced
1162:8917aff8629c | 1163:b417abf82193 |
---|---|
326 */ | 326 */ |
327 static int | 327 static int |
328 drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) | 328 drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) |
329 { | 329 { |
330 | 330 |
331 | |
332 #ifdef PIPE_TILE | |
333 | |
331 int cur = 0; | 334 int cur = 0; |
332 DrawParam param[2]; | 335 DrawParam param[2]; |
333 | 336 |
334 int rangex = endx - startx + 1; | 337 int rangex = endx - startx + 1; |
335 | 338 |
338 | 341 |
339 int localy = getLocalY(span->y-1); | 342 int localy = getLocalY(span->y-1); |
340 | 343 |
341 int ret = je+1; | 344 int ret = je+1; |
342 int index = 1; | 345 int index = 1; |
346 | |
343 | 347 |
344 getDrawParam(smanager, g, span, localy, startx, endx, index, je, ¶m[cur]); | 348 getDrawParam(smanager, g, span, localy, startx, endx, index, je, ¶m[cur]); |
345 | 349 |
346 //for (int j = je; j >= js; j--) { <-もとはこうで、一度先にtextureをloadしておくから、je-1にしてる | 350 //for (int j = je; j >= js; j--) { <-もとはこうで、一度先にtextureをloadしておくから、je-1にしてる |
347 for (int j = je-1; j >= js; j--) { | 351 for (int j = je-1; j >= js; j--) { |
372 param[cur].x, span->y, param[cur].world_z, smanager); | 376 param[cur].x, span->y, param[cur].world_z, smanager); |
373 | 377 |
374 } | 378 } |
375 */ | 379 */ |
376 | 380 |
381 | |
382 #else | |
383 | |
384 | |
385 int x = span->x; | |
386 int rangex = endx - startx + 1; | |
387 int x_len = span->length_x; | |
388 | |
389 float normal_x = span->normal_x; | |
390 float normal_y = span->normal_y; | |
391 float normal_z = span->normal_z; | |
392 | |
393 int js = (x < startx) ? startx - x : 0; | |
394 int je = (x + x_len > endx) ? endx - x : x_len; | |
395 | |
396 // span の始点に対応する座標 (tex1, tey1) | |
397 float tex1 = span->tex_x1; | |
398 float tey1 = span->tex_y1; | |
399 | |
400 // span の終点に対応する座標 (tex2, tey2) | |
401 float tex2 = span->tex_x2; | |
402 float tey2 = span->tex_y2; | |
403 | |
404 // span の始点、終点に対応する z 座標 | |
405 float zpos1 = span->start_z; | |
406 float zpos2 = span->end_z; | |
407 | |
408 //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 | |
409 float z_inclination = (zpos2 - zpos1) / x_len; | |
410 float world_z = zpos2; | |
411 | |
412 // Tile 内での座標 | |
413 int localx, localy = getLocalY(span->y-1); | |
414 | |
415 int ret = je+1; | |
416 | |
417 //for (int j = js; j <= je; j++) { | |
418 for (int j = je; j >= js; j--) { | |
419 | |
420 float tex_z; | |
421 | |
422 world_z -= z_inclination; | |
423 localx = getLocalX(x-1+j); | |
424 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); | |
425 | |
426 if (tex_z < g->zRow[localx + (rangex*localy)]) { | |
427 | |
428 float tex_x, tex_y; | |
429 | |
430 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); | |
431 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
432 | |
433 if (tex_x > 1) tex_x = 1; | |
434 if (tex_x < 0) tex_x = 0; | |
435 if (tex_y > 1) tex_y = 1; | |
436 if (tex_y < 0) tex_y = 0; | |
437 | |
438 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
439 int tex_xpos, tex_ypos; | |
440 | |
441 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
442 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
443 | |
444 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
445 // そのブロックのアドレス(MainMemory) | |
446 memaddr tex_addr; | |
447 int tex_localx; | |
448 int tex_localy; | |
449 | |
450 if (!span->tex_addr) return -1; // broken case, I'd like to write some thing... | |
451 tex_addr = getTile(tex_xpos, tex_ypos, | |
452 span->tex_width, (memaddr)span->tex_addr); | |
453 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
454 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
455 | |
456 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); | |
457 smanager->wait_segment(tile); | |
458 | |
459 updateBuffer(g, tex_z, rangex, localx, localy, | |
460 tex_localx, tex_localy, | |
461 normal_x, normal_y, normal_z, tile, | |
462 span->x+j, span->y, world_z, smanager); | |
463 } | |
464 } | |
465 | |
466 | |
467 | |
468 #endif | |
469 | |
377 return ret; | 470 return ret; |
378 } | 471 } |
379 | 472 |
380 static int | 473 static int |
381 getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param) { | 474 getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param) { |