Mercurial > hg > Game > Cerium
changeset 1405:aafad9d18a2c draft
sepalate light
author | taiki |
---|---|
date | Fri, 17 Feb 2012 15:34:15 +0900 |
parents | 0f8bee7eed3c |
children | 8587ee89ef79 |
files | Renderer/Engine/Light.cc Renderer/Engine/Light.h Renderer/Engine/viewer.cc Renderer/Engine/viewer.h |
diffstat | 4 files changed, 163 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/Light.cc Fri Feb 17 15:34:15 2012 +0900 @@ -0,0 +1,102 @@ +#include "Light.h" + +void +Light::init() +{ + int light_num = 4; + int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) + int light_size = size / sizeof(float); + + light_xyz = (float *)manager->allocate(size); + + for (int i = 0; i < light_size ; i++) { + light_xyz[i] = 0.0f; + } + + + for(int i = 0;;) { + HTaskPtr data_load = manager->create_task(DataAllocate); + data_load->set_param(0,(memaddr)3); // num of allocate block + data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size + data_load->set_param(2,(memaddr)Light); // 1st id + data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size + data_load->set_param(4,(memaddr)LightSwitch); // 2nd id + data_load->set_param(5,(memaddr)16); // 3rd size + data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id + data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + data_load->spawn(); + if (i==CPU_PPE) break; + if (i==spe_num-1) i=CPU_PPE; + i++; + } + + light_switch = (int*)manager->allocate(size); + + for (int i = 0; i < light_num; i++) { + light_switch[i] = 0; + } + + int light_sw_size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング + + light_sysswitch = (int*)manager->allocate(light_sw_size); + + for (unsigned int i = 0; i < light_sw_size / sizeof(int); i++) { + light_sysswitch[i] = 0; + } + +} + + +bool +Light::exec(HTaskPtr task_next) +{ + light_xyz_stock = sgroot->getLightVector(); + + + light_switch_stock = sgroot->getLightSwitch(); + light_sysswitch_stock = sgroot->getLightSysSwitch(); + + return true; +} + +void +Light::update(HTaskPtr task_next) +{ + + //task_next = manager->create_task(Dummy); + //task_next->set_post(post2runLoop, (void*)this); + + //Light info update + + int light_num = 4; + int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) + int light_size = size / sizeof(float); + + for (int i = 0; i < light_size; i++) { + light_xyz[i] = light_xyz_stock[i]; + } + + for (int i = 0; i < light_num; i++) { + light_switch[i] = light_switch_stock[i]; + } + + light_sysswitch[0] = light_sysswitch_stock; + + + HTask *data_update_wait = manager->create_task(Dummy); + for (int i = 0; ;) { + + 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->wait_for(data_update); + data_update->spawn(); + if (i==CPU_PPE) break; + if (i==spe_num-1) i=CPU_PPE; + i++; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/Engine/Light.h Fri Feb 17 15:34:15 2012 +0900 @@ -0,0 +1,34 @@ + +#ifndef INCLUDED_LIGHT +#define INCLUDED_LIGHT + +#include "SceneGraph.h" +#include "TaskManager.h" + +class SceneGraphRoot; + +class Light : public SceneGraph { +public: + Light(float w, float h, SceneGraphRoot *sgroot_, TaskManager *manager_) { + sgroot = sgroot_; + manager = manager_; + } + ~Light(void); + float *light_xyz; + float *light_xyz_stock; + int *light_switch; + int *light_switch_stock; + int *light_sysswitch; + int light_sysswitch_stock; + TaskManager *manager; + SceneGraphRoot *sgroot; + + void init(); + bool exec(HTaskPtr task_next); + void update(HTaskPtr task_next); + +}; + +typedef Light *LightPtr; + +#endif
--- a/Renderer/Engine/viewer.cc Wed Feb 15 17:45:24 2012 +0900 +++ b/Renderer/Engine/viewer.cc Fri Feb 17 15:34:15 2012 +0900 @@ -14,28 +14,15 @@ #include "lindaapi.h" #include "SchedTask.h" -/* measure for FPS (Frame Per Second) */ -static int start_time; -static int this_time; -int frames; -// static void post2speRunLoop(void *viewer); -//static void post2runMove(void *viewer); -//static void post2exchange_sgroot(void *viewer); -//static void post2speRunLoop(void *viewer); - -//SceneGraphRootPtr sgroot_2; - /* Data Pack sent to Other CPUs (ex. SPE) */ -RenderingData r[2]; - -int ppi, spi = 0; Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) { spe_num = _num; manager = m; - + profile = 0; + ppi = spi = 0; dev = vd; pixels = dev->video_init(manager, b, w, h); @@ -88,56 +75,8 @@ if (spe_num == 0) spe_num = 1; sgroot = new SceneGraphRoot(this->width, this->height, manager); - - int light_num = 4; - int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) - int light_size = size / sizeof(float); - - 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 - data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size - data_load->set_param(2,(memaddr)Light); // 1st id - data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size - data_load->set_param(4,(memaddr)LightSwitch); // 2nd id - data_load->set_param(5,(memaddr)16); // 3rd size - data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id - data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - data_load->spawn(); - } - - HTaskPtr data_load = manager->create_task(DataAllocate); - data_load->set_param(0,(memaddr)3); // num of allocate block - data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size - data_load->set_param(2,(memaddr)Light); // 1st id - data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size - data_load->set_param(4,(memaddr)LightSwitch); // 2nd id - data_load->set_param(5,(memaddr)16); // 3rd size - data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id - data_load->set_cpu(CPU_PPE); - data_load->spawn(); - - - light_switch = (int*)manager->allocate(size); - - for (int i = 0; i < light_num; i++) { - light_switch[i] = 0; - } - - size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング - - light_sysswitch = (int*)manager->allocate(size); - - for (unsigned int i = 0; i < size / sizeof(int); i++) { - light_sysswitch[i] = 0; - } + light = new Light(this->width, this->height, sgroot, manager); + light->init(); start_time = get_ticks(); this_time = 0; @@ -309,11 +248,7 @@ sgroot->treeApply(width, height); } - light_xyz_stock = sgroot->getLightVector(); - - - light_switch_stock = sgroot->getLightSwitch(); - light_sysswitch_stock = sgroot->getLightSysSwitch(); + light->exec(task_next); return true; } @@ -680,64 +615,7 @@ //task_next->set_post(post2runLoop, (void*)this); //Light info update - - int light_num = 4; - int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) - int light_size = size / sizeof(float); - - for (int i = 0; i < light_size; i++) { - light_xyz[i] = light_xyz_stock[i]; - } - - for (int i = 0; i < light_num; i++) { - light_switch[i] = light_switch_stock[i]; - } - - light_sysswitch[0] = light_sysswitch_stock; - -#if 0 - - HTask *data_update_wait = 0; - for (int i = 0; i < spe_num; i++) { - data_update_wait = manager->create_task(DataUpdate); - data_update_wait->set_param(0,3); - data_update_wait->set_param(1,Light); // GlobalSet ID base - data_update_wait->set_inData(0,light_xyz,size); // Light - data_update_wait->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1 - 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(); - } - -#else - - 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->wait_for(data_update); - data_update->spawn(); - } - - 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_PPE); - data_update_wait->wait_for(data_update); - data_update->spawn(); - - -#endif - + light->update(task_next); ppi ^= 1; r[ppi].ppack->clear();
--- a/Renderer/Engine/viewer.h Wed Feb 15 17:45:24 2012 +0900 +++ b/Renderer/Engine/viewer.h Fri Feb 17 15:34:15 2012 +0900 @@ -10,29 +10,34 @@ #include "Application.h" #include "SceneGraphRoot.h" #include "ViewerDevice.h" +#include "Light.h" class SceneGraphRoot; class Application; -typedef struct rendering_data { - PolygonPack *ppack; - SpanPackPtr spackList; - SpanPackPtr *spackList_ptr; - - int spackList_length; - int spackList_length_align; -} RenderingData ; - -extern RenderingData r[2]; - -extern int ppi, spi; - class Viewer : public MainLoop { public: - Viewer(){ profile = 0;}; + Light *light; +/* measure for FPS (Frame Per Second) */ + int start_time; + int this_time; + int frames; + + typedef struct rendering_data { + PolygonPack *ppack; + SpanPackPtr spackList; + SpanPackPtr *spackList_ptr; + + int spackList_length; + int spackList_length_align; + } RenderingData ; + RenderingData r[2]; + + int ppi, spi; + Viewer(){ profile = 0; ppi = spi = 0;}; Viewer(TaskManager *manager, ViewerDevice *dev, int bpp, int width, int height, int spenum); virtual ~Viewer() {} @@ -108,6 +113,8 @@ // void setSceneData(SceneGraph *g); virtual void mainLoop(); + // In Application::init, SceneGraphRoot API is called bia viewer + void createStringFont(SceneGraphPtr root, const char *string, int pixels, int screen_w, int screen_h, Uint32 color) { sgroot -> createStringFont(manager, root, string, pixels, screen_w, screen_h, color);