Mercurial > hg > Members > kono > Cerium
view TaskManager/Test/test_render/spe/CreateSpan.cpp @ 109:5c194c71eca8
Cerium cvs version
author | gongo@gendarme.local |
---|---|
date | Wed, 12 Nov 2008 17:39:33 +0900 |
parents | |
children | 6ba88fa28df6 |
line wrap: on
line source
#include "CreateSpan.h" #include "viewer_types.h" static const int SPAN_PACK_LOAD = 5; static const int SPAN_PACK_STORE = 6; static const int POLYGON_PACK_LOAD = 7; static SpanPackPtr spack = NULL; static SpanPackPtr send_spack = NULL; static int prev_index = 0; SchedDefineTask(CreateSpan); static float calc(float f1, float f2,int i, float base) { float ans; ans = f1/f2*i + base; return ans; } /** * TrianglePack から、vMin, vMid, vMax を求める * * @param [triPack] TrianglePack * @param [vMin] [vMid] [vMax] */ static void make_vertex(TrianglePack *triPack, VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax) { if (triPack->ver1.y <= triPack->ver2.y) { if (triPack->ver2.y <= triPack->ver3.y) { *vMin = &triPack->ver1; *vMid = &triPack->ver2; *vMax = &triPack->ver3; } else if (triPack->ver3.y <= triPack->ver1.y) { *vMin = &triPack->ver3; *vMid = &triPack->ver1; *vMax = &triPack->ver2; } else { *vMin = &triPack->ver1; *vMid = &triPack->ver3; *vMax = &triPack->ver2; } } else { if (triPack->ver1.y <= triPack->ver3.y) { *vMin = &triPack->ver2; *vMid = &triPack->ver1; *vMax = &triPack->ver3; } else if (triPack->ver3.y <= triPack->ver2.y) { *vMin = &triPack->ver3; *vMid = &triPack->ver2; *vMax = &triPack->ver1; } else { *vMin = &triPack->ver2; *vMid = &triPack->ver3; *vMax = &triPack->ver1; } } } static void make_vMid10(VertexPack *v, VertexPack *vMin, VertexPack *vMid, VertexPack *vMax) { int d, d1; d = (int)(vMax->y - vMin->y); d1 = (int)(vMid->y - vMin->y); v->tex_x = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x); v->tex_y = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y); v->x = calc(vMax->x - vMin->x, d, d1, vMin->x); v->y = vMid->y; v->z = calc(vMax->z - vMin->z, d, d1, vMin->z); } void CreateSpan::half_triangle(SpanPackPtr *spackList, int charge_y_top, int charge_y_end, long *tex_addr, long tex_width, long tex_height, VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10) { float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; float tmp_xpos,tmp_end,tmp_zpos; float start_z, end_z; float start_tex_x, end_tex_x, start_tex_y, end_tex_y; int x, y, length; int start_y = (int)vMid->y; int end_y = (int)vMin->y; float div_y = start_y - end_y; int k = 0; int l = 1; SpanPackPtr tmp_spack; if (div_y < 0) { div_y = -div_y; k = 1; l = -1; } for (int i = k; i < div_y+1; i++) { y = (int)vMin->y + i*l; /** * 担当 y 範囲内 */ if (charge_y_top <= y && y <= charge_y_end) { // 1..8 を index0, 9..16 を index1 にするために y を -1 int index = (y-1) / split_screen_h; /** * 違う SpanPack を扱う場合、 * 現在の SpanPack をメインメモリに送り、 * 新しい SpanPack を取ってくる */ if (index != prev_index) { tmp_spack = spack; spack = send_spack; send_spack = tmp_spack; smanager->dma_wait(SPAN_PACK_STORE); smanager->dma_store(send_spack, (uint32)spackList[prev_index], sizeof(SpanPack), SPAN_PACK_STORE); smanager->dma_load(spack, (uint32)spackList[index], sizeof(SpanPack), SPAN_PACK_LOAD); prev_index = index; smanager->dma_wait(SPAN_PACK_LOAD); } /** * 書き込む SpanPack が満杯だったら * メインメモリで allocate した領域 (next) を持ってきて * 現在の spack->next につなぎ、next を次の spack とする。 */ if (spack->info.size >= MAX_SIZE_SPAN) { SpanPackPtr next; mainMem_alloc(0, sizeof(SpanPack)); mainMem_wait(); next = (SpanPackPtr)mainMem_get(0); spack->next = next; tmp_spack = spack; spack = send_spack; send_spack = tmp_spack; smanager->dma_wait(SPAN_PACK_STORE); smanager->dma_store(send_spack, (uint32)spackList[index], sizeof(SpanPack), SPAN_PACK_STORE); spackList[index] = next; smanager->dma_load(spack, (uint32)spackList[index], sizeof(SpanPack), SPAN_PACK_LOAD); smanager->dma_wait(SPAN_PACK_LOAD); spack->init((index+1)*split_screen_h); } } else { /** * 担当範囲外だったら無視 */ continue; } tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x); tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z); tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); tmp_tex1 =((i/(div_y)) * vMid10->tex_x) + ( ((div_y - i)/(div_y)) * vMin->tex_x); tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + ( ((div_y - i)/(div_y)) * vMin->tex_x); tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) + ( ((div_y - i)/(div_y)) * vMin->tex_y); tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + ( ((div_y - i)/(div_y)) * vMin->tex_y); if (tmp_xpos > tmp_end) { x = (int)tmp_end; length = (int)(tmp_xpos)-(int)(tmp_end)+1; start_z = tmp_zpos; end_z = tmp_z; start_tex_x = tmp_tex2; end_tex_x = tmp_tex1; start_tex_y = tmp_tey2; end_tex_y = tmp_tey1; } else { x = (int)tmp_xpos; length = (int)(tmp_end)-(int)(tmp_xpos)+1; start_z = tmp_z; end_z = tmp_zpos; start_tex_x = tmp_tex1; end_tex_x = tmp_tex2; start_tex_y = tmp_tey1; end_tex_y = tmp_tey2; } smanager->dma_wait(SPAN_PACK_LOAD); Span *span = &spack->span[spack->info.size++]; span->tex_addr = tex_addr; span->tex_width = tex_width; span->tex_height = tex_height; span->x = x; span->y = y; span->length_x = length; span->start_z = start_z; span->end_z = end_z; span->tex_x1 = start_tex_x; span->tex_x2 = end_tex_x; span->tex_y1 = start_tex_y; span->tex_y2 = end_tex_y; } } int CreateSpan::run(void *rbuf, void *wbuf) { PolygonPack *pp = (PolygonPack*)smanager->get_input(0); PolygonPack *next_pp = (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); PolygonPack *free_pp = next_pp; PolygonPack *tmp_pp; TrianglePackPtr triPack; VertexPackPtr vMin, vMid, vMax; VertexPackPtr vMid10 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); spack = (SpanPackPtr)smanager->get_input(2); send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); prev_index = get_param(0); // spack と send_spack は swap しながら DMA を繰り返すので // 自分で allocate した send_spack を覚えてないといけない SpanPackPtr free_spack = send_spack; int charge_y_top = get_param(1); int charge_y_end = get_param(2); do { if (pp->next != NULL) { smanager->dma_load(next_pp, (uint32)pp->next, sizeof(PolygonPack), POLYGON_PACK_LOAD); } else { next_pp = NULL; } for (int i = 0; i < pp->info.size; i++) { triPack = &pp->tri[i]; #if 0 make_vertex(triPack, &vMin, &vMid, &vMax); #else if (triPack->ver1.y <= triPack->ver2.y) { if (triPack->ver2.y <= triPack->ver3.y) { vMin = &triPack->ver1; vMid = &triPack->ver2; vMax = &triPack->ver3; } else if (triPack->ver3.y <= triPack->ver1.y) { vMin = &triPack->ver3; vMid = &triPack->ver1; vMax = &triPack->ver2; } else { vMin = &triPack->ver1; vMid = &triPack->ver3; vMax = &triPack->ver2; } } else { if (triPack->ver1.y <= triPack->ver3.y) { vMin = &triPack->ver2; vMid = &triPack->ver1; vMax = &triPack->ver3; } else if (triPack->ver3.y <= triPack->ver2.y) { vMin = &triPack->ver3; vMid = &triPack->ver2; vMax = &triPack->ver1; } else { vMin = &triPack->ver2; vMid = &triPack->ver3; vMax = &triPack->ver1; } } #endif make_vMid10(vMid10, vMin, vMid, vMax); half_triangle(spackList, charge_y_top, charge_y_end, triPack->tex_addr, triPack->tex_width, triPack->tex_height, vMin, vMid, vMid10); half_triangle(spackList, charge_y_top, charge_y_end, pp->tri[0].tex_addr, pp->tri[0].tex_width, pp->tri[0].tex_height, vMax, vMid, vMid10); } smanager->dma_wait(POLYGON_PACK_LOAD); tmp_pp = pp; pp = next_pp; next_pp = tmp_pp; } while (pp); smanager->dma_wait(SPAN_PACK_STORE); smanager->dma_store(spack, (uint32)spackList[prev_index], sizeof(SpanPack), SPAN_PACK_STORE); smanager->dma_wait(SPAN_PACK_STORE); free(free_pp); free(free_spack); free(vMid10); return 0; }