Mercurial > hg > Members > kono > Cerium
changeset 678:e201be3f6897
add Load light info for some spe
author | yutaka@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Sun, 06 Dec 2009 07:40:26 +0900 |
parents | a06eef665c45 |
children | 14d179ff1e9f 72d8bd31fc8c |
files | Renderer/Engine/RenderingTasks.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Engine/global_alloc.h Renderer/Engine/spe/spe-main.cc Renderer/Engine/sys.cc Renderer/Engine/sys.h Renderer/Engine/task/DataLoad.cc Renderer/Engine/task/DataLoad.h Renderer/Engine/task/DataUpdate.cc Renderer/Engine/task/DataUpdate.h Renderer/Engine/task/task_init.cc Renderer/Engine/viewer.cc Renderer/Engine/viewer.h |
diffstat | 14 files changed, 206 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/RenderingTasks.h Sun Dec 06 07:40:26 2009 +0900 @@ -2,6 +2,9 @@ SDL_INIT, FINISH, + DataLoad, + DataUpdate, + Create_SGP, Update_SGP, CreatePolygon,
--- a/Renderer/Engine/SceneGraphRoot.cc Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Dec 06 07:40:26 2009 +0900 @@ -25,7 +25,7 @@ sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); camera = new Camera(w, h, this); - light = new Light(w, h); + light = new SceneGraph; iterator = new SceneGraphIterator; controller = create_controller(); @@ -36,6 +36,14 @@ sgroot = this; + //int size = 4; + //light_vector = (float*)malloc(sizeof(float)*size); + + light->xyz[0] = 0; + light->xyz[1] = 0; + light->xyz[2] = 0; + + // TODO // 今はとりあえず camera を Root にしています // 今はそれすらもしてません @@ -405,6 +413,18 @@ list = list->next; } + get_matrix(light->matrix, light->angle, light->xyz, camera->matrix); + + light_vector[0] = 0.0f; + light_vector[1] = 0.0f; + light_vector[2] = 0.0f; + light_vector[3] = 1.0f; + + ApplyMatrix(light_vector, light->matrix); + + light_vector[0] /= light_vector[2]; + light_vector[1] /= light_vector[2]; + if(sg_exec_tree != NULL) { return; } @@ -538,10 +558,18 @@ return camera; } -LightPtr + +SceneGraphPtr SceneGraphRoot::getLight() { return light; } + + +float* +SceneGraphRoot::getLightVector() +{ + return light_vector; +}
--- a/Renderer/Engine/SceneGraphRoot.h Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/SceneGraphRoot.h Sun Dec 06 07:40:26 2009 +0900 @@ -4,7 +4,6 @@ #include "SceneGraph.h" #include "SceneGraphArray.h" #include "Camera.h" -#include "Light.h" #include "SceneGraphIterator.h" #include <sys/types.h> @@ -53,13 +52,15 @@ Camera *camera; // 光源のオブジェクト - Light *light; + SceneGraphPtr light; + // 光源の疑似 xml file + float light_vector[4]; // SceneGraphIterator SceneGraphIteratorPtr iterator; - // fd of Linda taple space - int tid; + // fd of Linda taple space + int tid; /** * Functions @@ -77,7 +78,8 @@ SceneGraphIteratorPtr getIterator(); SceneGraphIteratorPtr getIterator(SceneGraphPtr list); CameraPtr getCamera(); - LightPtr getLight(); + SceneGraphPtr getLight(); + float* getLightVector(); /* Other System API */ void allExecute(int screen_w, int screen_h);
--- a/Renderer/Engine/global_alloc.h Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/global_alloc.h Sun Dec 06 07:40:26 2009 +0900 @@ -12,6 +12,8 @@ GLOBAL_TEXTURE_HASH, GLOBAL_TILE_LIST, KEY_STATUS, + LOAD_ID, + }; #endif
--- a/Renderer/Engine/spe/spe-main.cc Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/spe/spe-main.cc Sun Dec 06 07:40:26 2009 +0900 @@ -1,6 +1,9 @@ #include "../Func.h" #include "SchedTask.h" +SchedExternTask(DataLoad); +SchedExternTask(DataUpdate); + SchedExternTask(LoadTexture); SchedExternTask(SetTexture); SchedExternTask(DrawSpan); @@ -22,6 +25,10 @@ void task_init(Scheduler *s) { + + SchedRegister( DataLoad); + SchedRegister( DataUpdate); + SchedRegister( LoadTexture); SchedRegister( SetTexture); SchedRegister( DrawSpan);
--- a/Renderer/Engine/sys.cc Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/sys.cc Sun Dec 06 07:40:26 2009 +0900 @@ -241,3 +241,24 @@ xyz[1] += y; xyz[2] += z; } + +/** + * ベクトルに行列を乗算する + * @param[out] v vector (float[4]) + * @param[in] m matrix (float[16]) + */ +void +ApplyMatrix(float *v, float *m) +{ + float t[4]; + + t[0] = v[0]; + t[1] = v[1]; + t[2] = v[2]; + t[3] = v[3]; + + for (int i = 0; i < 4; i++) { + v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; + } +} +
--- a/Renderer/Engine/sys.h Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/sys.h Sun Dec 06 07:40:26 2009 +0900 @@ -20,5 +20,6 @@ void transposeMatrix(float *m0, float *m1); void unitMatrix(float *m); void transMatrix(float *m0, float *m1, float *v); +void ApplyMatrix(float *v1, float *v2); #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataLoad.cc Sun Dec 06 07:40:26 2009 +0900 @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <string.h> +#include "DataLoad.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(DataLoad); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + + int length = (int)s->get_param(0); + int load_id = (int)s->get_param(1); + + //printf("size %d",sizeof(float)*length); + + s->global_alloc(load_id, sizeof(float)*length); + + //MemList *ml = s->createMemList(length,length); + //s->global_set(load_id, (void *)ml); + + return 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataLoad.h Sun Dec 06 07:40:26 2009 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_LOAD +#define INCLUDED_TASK_LOAD + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataUpdate.cc Sun Dec 06 07:40:26 2009 +0900 @@ -0,0 +1,28 @@ +#include <stdio.h> +#include "DataUpdate.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(DataUpdate); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + + float *idata = (float*)s->get_input(rbuf, 0); + int load_id = (int)s->get_param(0); + float *global_data = (float*)s->global_get(load_id); + + global_data[0] = idata[0]; + global_data[1] = idata[1]; + global_data[2] = idata[2]; + global_data[3] = idata[3]; + +#if 0 + s->printf("spe %f ",idata[0]); + s->printf("spe %f ",idata[1]); + s->printf("spe %f\n",idata[2]); +#endif + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/task/DataUpdate.h Sun Dec 06 07:40:26 2009 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_DATAUPDATE +#define INCLUDED_TASK_DATAUPDATE + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- a/Renderer/Engine/task/task_init.cc Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/task/task_init.cc Sun Dec 06 07:40:26 2009 +0900 @@ -1,6 +1,9 @@ #include "../Func.h" #include "Scheduler.h" +SchedExternTask(DataLoad); +SchedExternTask(DataUpdate); + SchedExternTask(Create_SGP); SchedExternTask(Update_SGP); SchedExternTask(CreatePolygonFromSceneGraph); @@ -34,6 +37,9 @@ void task_initialize() { + SchedRegister( DataLoad); + SchedRegister( DataUpdate); + SchedRegister( Create_SGP); SchedRegister( Update_SGP); SchedRegister(CreatePolygonFromSceneGraph); @@ -53,7 +59,7 @@ SchedRegister( UpdateKey); SchedRegister( InitKey); - SchedRegister( ShowTime); + //SchedRegister( ShowTime); SchedRegister( Switch); // usr
--- a/Renderer/Engine/viewer.cc Sun Dec 06 01:48:18 2009 +0900 +++ b/Renderer/Engine/viewer.cc Sun Dec 06 07:40:26 2009 +0900 @@ -12,6 +12,7 @@ #include "Pad.h" #include "Application.h" #include "lindaapi.h" +#include "global_alloc.h" static void post2runLoop(SchedTask *s,void *viewer,void *s1); static void post2runDraw(SchedTask *s,void *viewer,void *s1); @@ -49,6 +50,7 @@ width = w; height = h; spe_num = _num; + } int @@ -104,6 +106,22 @@ sgroot = new SceneGraphRoot(this->width, this->height); sgroot->tmanager = manager; + int size = 4; + + light_xyz[0] = 0.0f; + light_xyz[1] = 0.0f; + light_xyz[2] = 0.0f; + light_xyz[3] = 0.0f; + + HTaskPtr data_load; + for(int i = 0; i < spe_num; i++) { + data_load = manager->create_task(DataLoad); + data_load->set_param(0,(memaddr)size); + data_load->set_param(1,(memaddr)LOAD_ID); + data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + data_load->spawn(); + } + MainLoop *mainloop = app->init(this, this->width, this->height); mainloop->mainLoop(); @@ -361,10 +379,11 @@ for (int i = 1; i <= spackList_length; i++) { spackList[i-1].reinit(i*split_screen_h); } - + //run_move(task_next); sgroot->updateControllerState(); sgroot->allExecute(width, height); + light_xyz_stock = sgroot->getLightVector(); //sgroot->checkRemove(); // ここから下は Rendering という関数にする @@ -450,6 +469,8 @@ // SceneGraph(木構造) -> PolygonPack + + task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); task_create_pp->set_param(1,(memaddr)ppack); @@ -503,6 +524,36 @@ //task_next = manager->create_task(Dummy); //task_next->set_post(post2runLoop, (void*)this); + //Light info update + + HTaskPtr data_update; + HTaskPtr data_update_wait; + int size = 4; + + light_xyz[0] = light_xyz_stock[0]; + light_xyz[1] = light_xyz_stock[1]; + light_xyz[2] = light_xyz_stock[2]; + light_xyz[3] = light_xyz_stock[3]; + + data_update_wait = manager->create_task(DataUpdate); + data_update_wait->add_inData(light_xyz,sizeof(float)*size); + data_update_wait->set_param(0,size); + data_update_wait->set_param(1,LOAD_ID); + data_update_wait->set_cpu((CPU_TYPE)((int)SPE_0)); + + + for (int i = 1; i < spe_num; i++) { + data_update = manager->create_task(DataUpdate); + data_update->add_inData(light_xyz,sizeof(float)*size); + data_update->set_param(0,size); + data_update->set_param(1,LOAD_ID); + data_update->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + data_update_wait->wait_for(data_update); + data_update->spawn(); + } + + data_update_wait->spawn(); + ppack->clear(); for (int i = 0; i < spackList_length; i++) { SpanPack *spack = &spackList[i]; @@ -544,6 +595,7 @@ task_draw->set_cpu(SPE_ANY); task_next->wait_for(task_draw); + task_draw->wait_for(data_update_wait); task_draw->spawn(); startx += split_screen_w; @@ -554,6 +606,7 @@ } } } + } /* end */