Mercurial > hg > Game > Cerium
changeset 1406:8587ee89ef79 draft
fix Light.
author | taiki |
---|---|
date | Fri, 17 Feb 2012 17:32:50 +0900 |
parents | aafad9d18a2c |
children | 976f7b77f0bf |
files | Renderer/Engine/Collada.cc Renderer/Engine/Light.cc Renderer/Engine/Light.h Renderer/Engine/RenderingGlobal.h Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Renderer/Engine/task/DrawSpan.cc Renderer/Engine/viewer.cc |
diffstat | 7 files changed, 49 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/Collada.cc Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/Collada.cc Fri Feb 17 17:32:50 2012 +0900 @@ -195,9 +195,9 @@ return src; } -void get_texture_image(char *filename, SceneGraphPtr sg, xmlNodePtr cur, TaskManager *manager) +void get_texture_image(const char *filename, SceneGraphPtr sg, xmlNodePtr cur, TaskManager *manager) { - char image_name[20] = "/tmp/image_XXXXXX"; + const char image_name[20] = "/tmp/image_XXXXXX"; if (filename == NULL || filename[0] == 0) { return; } @@ -483,7 +483,7 @@ pp[i].info.size = tri_size; /* default texture peste */ if (s->images_flag==0) { - char *default_image = "../Test/xml_file/blend/images/ball.jpg"; + const char *default_image = "../Test/xml_file/blend/images/ball.jpg"; get_texture_image(default_image, sg, (xmlNodePtr)NULL, manager); } for (int j = 0; j < tri_size; j++,k+=9) {
--- a/Renderer/Engine/Light.cc Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/Light.cc Fri Feb 17 17:32:50 2012 +0900 @@ -1,4 +1,5 @@ #include "Light.h" +#include "Func.h" void Light::init() @@ -18,7 +19,7 @@ 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(2,(memaddr)LightData); // 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 @@ -59,7 +60,7 @@ return true; } -void +HTaskPtr Light::update(HTaskPtr task_next) { @@ -88,7 +89,7 @@ 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_param(1,LightData); // 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 @@ -99,4 +100,5 @@ if (i==spe_num-1) i=CPU_PPE; i++; } + return data_update_wait; }
--- a/Renderer/Engine/Light.h Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/Light.h Fri Feb 17 17:32:50 2012 +0900 @@ -2,14 +2,15 @@ #ifndef INCLUDED_LIGHT #define INCLUDED_LIGHT -#include "SceneGraph.h" +#include "SceneGraphRoot.h" #include "TaskManager.h" class SceneGraphRoot; -class Light : public SceneGraph { +class Light { public: - Light(float w, float h, SceneGraphRoot *sgroot_, TaskManager *manager_) { + Light(float w, float h,int spe_num_, SceneGraphRoot *sgroot_, TaskManager *manager_) { + spe_num_ = spe_num; sgroot = sgroot_; manager = manager_; } @@ -20,12 +21,13 @@ int *light_switch_stock; int *light_sysswitch; int light_sysswitch_stock; + int spe_num; TaskManager *manager; SceneGraphRoot *sgroot; void init(); bool exec(HTaskPtr task_next); - void update(HTaskPtr task_next); + HTaskPtr update(HTaskPtr task_next); };
--- a/Renderer/Engine/RenderingGlobal.h Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/RenderingGlobal.h Fri Feb 17 17:32:50 2012 +0900 @@ -1,7 +1,7 @@ /*Light 用の global_alloc ID*/ - Light, + LightData, LightSwitch, LightSysSwitch,
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Fri Feb 17 17:32:50 2012 +0900 @@ -132,7 +132,7 @@ printf("in_pp->info.size = 0\n"); } - float *light_xyz = (float*)smanager->global_get(Light); + float *light_xyz = (float*)smanager->global_get(LightData); int *light_switch = (int*)smanager->global_get(LightSwitch); int light_num = 4; // test
--- a/Renderer/Engine/task/DrawSpan.cc Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/task/DrawSpan.cc Fri Feb 17 17:32:50 2012 +0900 @@ -59,9 +59,11 @@ static memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top); static int getTexBlock(int tx, int ty, int twidth); -static void updateBuffer(Gptr g, float zpos, int rangex, int loaclx, int localy, - int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, - TilePtr tile, int world_x, int world_y, float world_z,SchedTask *smanager); +static void +updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y, + float normal_x, float normal_y, float normal_z, TilePtr tile, + int world_x, int world_y, float world_z, SchedTask *smanager, + float diffuse_l, float diffuse_r, int j); // static void reboot(SpanPackPtr spack, int cur_span_x); @@ -76,6 +78,9 @@ float diffuse_l, float diffuse_r, int rangex, int j); #ifdef __SPU__ +typedef vector float vector_float; +typedef vector unsigned int vector_uint; + static inline void normalize(vector float& v0, vector float& v1) { @@ -89,16 +94,19 @@ ret = spu_rsqrte(ret); v0 = spu_mul(v1,ret); } +#else +typedef float vector_float[4]; +typedef unsigned int vector_uint[4]; #endif /* __SPU__ */ static inline float -innerProduct1(vector float& v0, vector float& v1) +innerProduct1(vector_float& v0, vector_float& v1) { #ifndef __SPU__ return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); #else /* __SPU__ */ - vector float ret __attribute__((aligned(16))) = {0,0,0,0}; + vector_float ret __attribute__((aligned(16))) = {0,0,0,0}; float inner; ret = spu_mul(v0,v1); @@ -353,7 +361,6 @@ static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) { -#ifndef __SPU__ #ifdef PIPE_TILE @@ -446,7 +453,7 @@ //for (int j = js; j <= je; j++) { for (int j = je; j >= js; j--) { - float tex_x, tex_y, tex_z; + float tex_z; world_z -= z_inclination; #ifndef __SPU__ @@ -524,7 +531,8 @@ int light_rgb; float normal_vector[4] = {normal_x,normal_y,normal_z,0}; float light_vector[4]; - float *light_xyz = (float*)smanager->global_get(Light); +#else + float *light_xyz = (float*)smanager->global_get(LightData); #endif /* ! __SPU__ */ #ifndef __SPU__ @@ -553,17 +561,17 @@ #ifndef __SPU__ int *light_switch = (int*)smanager->global_get(LightSwitch); #else /* __SPU__ */ - vector float *light_xyz = (vector float*)smanager->global_get(Light); + vector_float *light_xyz = (vector_float*)smanager->global_get(Light); #endif /* __SPU__ */ #ifndef __SPU__ for (int i = 0; i < light_num; i++) { #else /* __SPU__ */ - vector float v_rgb __attribute__((aligned(16))) = {(float)rgb[0],(float)rgb[1],(float)rgb[2],0}; - vector float normal_vector __attribute__((aligned(16))) = {normal_x,normal_y,normal_z,0}; - vector float light_vector __attribute__((aligned(16))) = {0,0,0,0}; - vector float v_inner __attribute__((aligned(16))); - vector float v_world[4] __attribute__((aligned(16))) = {{world_x, world_y, -world_z, 0}, + vector_float v_rgb __attribute__((aligned(16))) = {(float)rgb[0],(float)rgb[1],(float)rgb[2],0}; + vector_float normal_vector __attribute__((aligned(16))) = {normal_x,normal_y,normal_z,0}; + vector_float light_vector __attribute__((aligned(16))) = {0,0,0,0}; + vector_float v_inner __attribute__((aligned(16))); + vector_float v_world[4] __attribute__((aligned(16))) = {{world_x, world_y, -world_z, 0}, {world_x, world_y, -world_z, 0}, {world_x, world_y, -world_z, 0}, {world_x, world_y, -world_z, 0}}; @@ -589,7 +597,7 @@ #else /* __SPU__ */ normalize(normal_vector, normal_vector); - vector float vtmp_rgb __attribute__((aligned(16))) = {0,0,0,0}; + vector_float vtmp_rgb __attribute__((aligned(16))) = {0,0,0,0}; int light_num = 4; int *light_switch = (int*)smanager->global_get(LightSwitch); @@ -636,11 +644,11 @@ //tmp_rgb[1] = (unsigned char)(rgb[1]*diffuse); //tmp_rgb[2] = (unsigned char)(rgb[2]*diffuse); #else /* __SPU__ */ - vector unsigned int v_flag __attribute__((aligned(16))); - vector float max_rgb __attribute__((aligned(16))) = (vector float)spu_splats((float)255.0f); + vector_uint v_flag __attribute__((aligned(16))); + vector_float max_rgb __attribute__((aligned(16))) = (vector_float)spu_splats((float)255.0f); #endif /* __SPU__ */ - vector unsigned int last_rgb __attribute__((aligned(16))); + vector_uint last_rgb __attribute__((aligned(16))); #ifndef __SPU__ int rgb_flag[3]; for (int i = 0; i < 3; i++) {
--- a/Renderer/Engine/viewer.cc Fri Feb 17 15:34:15 2012 +0900 +++ b/Renderer/Engine/viewer.cc Fri Feb 17 17:32:50 2012 +0900 @@ -75,7 +75,7 @@ if (spe_num == 0) spe_num = 1; sgroot = new SceneGraphRoot(this->width, this->height, manager); - light = new Light(this->width, this->height, sgroot, manager); + light = new Light(this->width, this->height, spe_num, sgroot, manager); light->init(); start_time = get_ticks(); @@ -84,7 +84,7 @@ pp_sum_num = 0; this->app = app; - MainLoop *mainloop = app->init(this, this->width, this->height); + MainLoop *mainloop = app->init(this, this->width, this->height); // usually viewer is returned mainloop->mainLoop(); } @@ -92,20 +92,7 @@ HTaskPtr Viewer::initLoop() { - HTaskPtr task_next; - HTaskPtr task_tex; - - /* - - こうかな - - manager->createMemList(sizeof(SpanPack), POOL_SPANPACK); - - - */ - - - + // initialize polygonpack and spanpack double buffer for pipeline. for(int i=0;i<2;i++) { r[i].ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); r[i].ppack->next = 0; @@ -123,7 +110,7 @@ * 実際に送るデータは64バイトになるのでOK * 14,15,16 の部分は何も入らない。 */ - r[i].spackList_length_align = (r[i].spackList_length + 3)&(~3); + r[i].spackList_length_align = ROUND_UP_ALIGN(r[i].spackList_length,DEFAULT_ALIGNMENT); /* 各 SPU が持つ、SpanPack の address list */ r[i].spackList_ptr = @@ -138,12 +125,12 @@ } } - task_next = manager->create_task(RUN_LOOP_TASK,0,0,0,0); + HTaskPtr task_next = manager->create_task(RUN_LOOP_TASK,0,0,0,0); task_next->set_param(0, (void*)this); // ここは、Iterator を用意するべきだよね for (int j = 0; j < spe_num; j++) { - task_tex = manager->create_task(AllocateSegment,0,0,0,0); + HTaskPtr task_tex = manager->create_task(AllocateSegment,0,0,0,0); task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + j)); task_next->wait_for(task_tex); task_tex->spawn(); @@ -615,7 +602,7 @@ //task_next->set_post(post2runLoop, (void*)this); //Light info update - light->update(task_next); + HTaskPtr data_update_wait = light->update(task_next); ppi ^= 1; r[ppi].ppack->clear();