Mercurial > hg > Game > Cerium
changeset 1145:4e898dca4ab9 draft
light bug fix.
author | yutaka@localhost.localdomain |
---|---|
date | Mon, 21 Feb 2011 03:56:57 +0900 |
parents | e068c1269292 |
children | 1fd472cd1ee9 |
files | Renderer/Engine/spe/CreateSpan.cc Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/task/DrawSpan.cc Renderer/Engine/viewer.cc Renderer/Test/ball_bound.cc |
diffstat | 5 files changed, 108 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/spe/CreateSpan.cc Sat Feb 19 03:54:12 2011 +0900 +++ b/Renderer/Engine/spe/CreateSpan.cc Mon Feb 21 03:56:57 2011 +0900 @@ -1,5 +1,4 @@ // #define DEBUG -#include "error.h" #include "CreateSpan.h" #include "viewer_types.h" #include "matrix_calc.h" @@ -13,11 +12,9 @@ static const int TILE_LOAD = 9; static const int TILE_STORE = 10; -typedef struct g { - SpanPackPtr spack ; - SpanPackPtr send_spack ; - int prev_index; -} G, *Gptr; +static SpanPackPtr spack = NULL; +static SpanPackPtr send_spack = NULL; +static int prev_index = 0; SchedDefineTask(CreateSpan); @@ -38,7 +35,8 @@ */ static void make_vertex(TrianglePack *triPack, - VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax) + VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax, + NormalPackPtr *normal1, NormalPackPtr *normal2, NormalPackPtr *normal3) { if (triPack->ver1.y <= triPack->ver2.y) { if (triPack->ver2.y <= triPack->ver3.y) { @@ -69,6 +67,11 @@ *vMax = &triPack->ver1; } } + + *normal1 = &triPack->normal1; + *normal2 = &triPack->normal2; + *normal3 = &triPack->normal3; + } static void @@ -133,6 +136,7 @@ } + return addr_top + index; } @@ -157,6 +161,7 @@ int base, tex_base; int scale = 1; + if (scale_max==0) return 1; // broken case /** * width と height で、長い方を基準に、 * texture の scale を決める @@ -198,12 +203,12 @@ * @param[in] tex_y_len 分割する前の Triangle に貼られている Texture の * 長さの割合 (0 ... 1) */ - static void -half_triangle(SchedTask *smanager, Gptr g, SpanPackPtr *spackList, +half_triangle(SchedTask *smanager, SpanPackPtr *spackList, int charge_y_top, int charge_y_end, TriangleTexInfoPtr tex_info, VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10, + NormalPack *normal1, NormalPack *normal2, NormalPack *normal3, int length_y, float tex_y_len) { float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; @@ -278,103 +283,101 @@ * 現在の SpanPack をメインメモリに送り、 * 新しい SpanPack を取ってくる */ - if (index != g->prev_index) { - tmp_spack = g->spack; - g->spack = g->send_spack; - g->send_spack = tmp_spack; + if (index != prev_index) { + tmp_spack = spack; + spack = send_spack; + send_spack = tmp_spack; - //smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(g->send_spack, (memaddr)spackList[g->prev_index], + smanager->dma_wait(SPAN_PACK_STORE); + smanager->dma_store(send_spack, (memaddr)spackList[prev_index], sizeof(SpanPack), SPAN_PACK_STORE); - smanager->dma_load(g->spack, (memaddr)spackList[index], + smanager->dma_load(spack, (memaddr)spackList[index], sizeof(SpanPack), SPAN_PACK_LOAD); - g->prev_index = index; + prev_index = index; smanager->dma_wait(SPAN_PACK_LOAD); } - /** * 書き込む SpanPack が満杯だったら * メインメモリで allocate した領域 (next) を持ってきて * 現在の spack->next につなぎ、next を次の spack とする。 */ - if (g->spack->info.size >= MAX_SIZE_SPAN) { + if (spack->info.size >= MAX_SIZE_SPAN) { SpanPackPtr next; - __debug_spe("CreateSpan mainMem_alloc 0x%x\n", (unsigned int)sizeof(SpanPack)); smanager->mainMem_alloc(0, sizeof(SpanPack)); smanager->mainMem_wait(); next = (SpanPackPtr)smanager->mainMem_get(0); - __debug_spe("CreateSpan mainMem_allocated 0x%x\n", (unsigned int)next); - g->spack->next = next; // この部分は TaskManager でやる + spack->next = next; - tmp_spack = g->spack; - g->spack = g->send_spack; - g->send_spack = tmp_spack; + tmp_spack = spack; + spack = send_spack; + send_spack = tmp_spack; smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(g->send_spack, (memaddr)spackList[index], + smanager->dma_store(send_spack, (memaddr)spackList[index], sizeof(SpanPack), SPAN_PACK_STORE); spackList[index] = next; - smanager->dma_load(g->spack, (memaddr)spackList[index], + smanager->dma_load(spack, (memaddr)spackList[index], sizeof(SpanPack), SPAN_PACK_LOAD); smanager->dma_wait(SPAN_PACK_LOAD); - g->spack->init((index+1)*split_screen_h); + 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; - } - length = (tmp_xpos > tmp_end) ? (int)tmp_xpos - (int)tmp_end : (int)tmp_end - (int)tmp_xpos; if (length == 0) { continue; } - Span *span = &g->spack->span[g->spack->info.size++]; + 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->x = x; span->y = y; @@ -385,6 +388,13 @@ span->tex_x2 = end_tex_x; span->tex_y1 = start_tex_y; span->tex_y2 = end_tex_y; + /*ここで頂点分法線ベクトルがあったんだけど、 + * 一つだけ取り出して、spanに一つの法線ベクトルを持たしている + *by yutaka + */ + span->normal_x = normal1->x; + span->normal_y = normal1->y; + span->normal_z = normal1->z; float tex_x_len = span->tex_x2 - span->tex_x1; @@ -423,11 +433,7 @@ static int run(SchedTask *smanager, void *rbuf, void *wbuf) { - __debug_spe("CreateSpan\n"); - Gptr g = (Gptr)smanager->allocate(sizeof(G)); - g->prev_index = 0; - - PolygonPack *pp = (PolygonPack*)smanager->get_input(0); + PolygonPack *pp = (PolygonPack*)smanager->get_input(rbuf, 0); PolygonPack *next_pp = (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); PolygonPack *free_pp = next_pp; @@ -437,23 +443,20 @@ VertexPackPtr vMin, vMid, vMax; VertexPackPtr vMid10 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); - - SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); - g->spack = (SpanPackPtr)smanager->get_input(2); - g->send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - g->prev_index = (long)smanager->get_param(0); + NormalPackPtr normal1,normal2, normal3; + SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(rbuf, 1); + spack = (SpanPackPtr)smanager->get_input(rbuf, 2); + send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + prev_index = (long)smanager->get_param(0); // spack と send_spack は swap しながら DMA を繰り返すので // 自分で allocate した send_spack を覚えてないといけない - SpanPackPtr free_spack = g->send_spack; + SpanPackPtr free_spack = send_spack; int charge_y_top = (long)smanager->get_param(1); int charge_y_end = (long)smanager->get_param(2); do { - __debug_spe("CreateSpan allocated 0x%x\n",(uint32)next_pp); - - //next_pp = NULL; if (pp->next != NULL) { smanager->dma_load(next_pp, (memaddr)pp->next, sizeof(PolygonPack), POLYGON_PACK_LOAD); @@ -466,7 +469,7 @@ TriangleTexInfoPtr tri_tex_info = &triPack->tex_info; - make_vertex(triPack, &vMin, &vMid, &vMax); + make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3); make_vMid10(vMid10, vMin, vMid, vMax); /** @@ -489,11 +492,13 @@ * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という * 二つの Triangle に分けている */ - half_triangle(smanager, g, spackList, charge_y_top, charge_y_end, + half_triangle(smanager, spackList, charge_y_top, charge_y_end, tri_tex_info, vMin, vMid, vMid10, + normal1,normal2,normal3, (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); - half_triangle(smanager, g, spackList, charge_y_top, charge_y_end, + half_triangle(smanager, spackList, charge_y_top, charge_y_end, tri_tex_info, vMax, vMid, vMid10, + normal1,normal2,normal3, (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); } @@ -505,16 +510,13 @@ } while (pp); smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(g->spack, (memaddr)spackList[g->prev_index], + smanager->dma_store(spack, (memaddr)spackList[prev_index], sizeof(SpanPack), SPAN_PACK_STORE); - //smanager->dma_wait(SPAN_PACK_STORE); - __debug_spe("CreateSpan spack_stored 0x%x\n",(uint32)spackList[g->prev_index]); + smanager->dma_wait(SPAN_PACK_STORE); - // smanager で allocate したのだから free も smanager でやるべき free(free_pp); free(free_spack); free(vMid10); - free(g); return 0; }
--- a/Renderer/Engine/spe/DrawSpan.cc Sat Feb 19 03:54:12 2011 +0900 +++ b/Renderer/Engine/spe/DrawSpan.cc Mon Feb 21 03:56:57 2011 +0900 @@ -423,6 +423,7 @@ { + unsigned char rgb[4]; // 引数で受け取った color の rgb 情報の抜き出し
--- a/Renderer/Engine/task/DrawSpan.cc Sat Feb 19 03:54:12 2011 +0900 +++ b/Renderer/Engine/task/DrawSpan.cc Mon Feb 21 03:56:57 2011 +0900 @@ -394,7 +394,6 @@ { - unsigned char rgb[4]; int light_rgb; float normal_vector[4] = {normal_x,normal_y,normal_z,0};
--- a/Renderer/Engine/viewer.cc Sat Feb 19 03:54:12 2011 +0900 +++ b/Renderer/Engine/viewer.cc Mon Feb 21 03:56:57 2011 +0900 @@ -97,15 +97,12 @@ int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) int light_size = size / sizeof(float); - light_xyz_stock = (float *)manager->allocate(size); light_xyz = (float *)manager->allocate(size); - for (int i = 0; i < light_size ; i++) { light_xyz[i] = 0.0f; } - for(int i = 0; i < spe_num; i++) { HTaskPtr data_load = manager->create_task(DataAllocate); data_load->set_param(0,(memaddr)3); // num of allocate block @@ -554,7 +551,7 @@ light_sysswitch[0] = light_sysswitch_stock; - + /* HTask *data_update_wait = 0; for (int i = 0; i < spe_num; i++) { data_update_wait = manager->create_task(DataUpdate); @@ -565,6 +562,20 @@ data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); data_update_wait->spawn(); + }*/ + + HTask *data_update_wait = manager->create_task(Dummy); + for (int i = 0; i < spe_num; i++) { + + HTaskPtr data_update = manager->create_task(DataUpdate); + data_update->set_param(0,3); + data_update->set_param(1,Light); // GlobalSet ID base + data_update->set_inData(0,light_xyz,size); // Light + data_update->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1 + data_update->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 + data_update->set_cpu((CPU_TYPE)(SPE_0+i)); + data_update->wait_for(data_update_wait); + data_update->spawn(); } ppi ^= 1; @@ -620,6 +631,7 @@ task_draw_array->spawn_task_array(task_draw->next()); task_draw_array->set_cpu(SPE_ANY); + task_draw_array->wait_for(data_update_wait); //task_next->wait_for(task_draw_array); task_draw_array->spawn(); @@ -630,7 +642,7 @@ memset(&pixels[(startx-1)+this->width*(starty-1)], 0, (this->width)*sizeof(int)*rangey); - } + } #else @@ -680,7 +692,10 @@ } #endif - } + } + + data_update_wait->spawn(); + spi ^= 1; for (int i = 1; i <= r[spi].spackList_length; i++) { r[spi].spackList[i-1].reinit(i*split_screen_h);
--- a/Renderer/Test/ball_bound.cc Sat Feb 19 03:54:12 2011 +0900 +++ b/Renderer/Test/ball_bound.cc Mon Feb 21 03:56:57 2011 +0900 @@ -117,7 +117,7 @@ sgroot->createFromXMLfile("xml_file/Ball.xml"); - sgroot->OnLightSysSwitch(); + //sgroot->OnLightSysSwitch(); SceneGraphPtr light = sgroot->getLight(0); sgroot->OnLightSwitch(0);