changeset 691:9d1bcc07734b

Test/SgRootChange not work
author hiroki@localhost.localdomain
date Tue, 08 Dec 2009 16:48:01 +0900
parents e009805443ce
children 50750b118116
files Renderer/Engine/SgChange.cc Renderer/Engine/SgChange.h Renderer/Engine/SgMain.cc Renderer/Engine/viewer.cc Renderer/Test/Makefile.cell Renderer/Test/SgRootChange.cc
diffstat 6 files changed, 269 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SgChange.cc	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Engine/SgChange.cc	Tue Dec 08 16:48:01 2009 +0900
@@ -12,8 +12,10 @@
 #include "Pad.h"
 #include "Application.h"
 #include "lindaapi.h"
+#include "global_alloc.h"
 
-static void post2runLoop(SchedTask *s,void *viewer,void *s1);
+static void post2runLoop(SchedTask *s, void *viewer, void *s1);
+static void post2runDraw(SchedTask *s, void *viewer, void *s1);
 
 /* measure for FPS (Frame Per Second) */
 int start_time;
@@ -29,10 +31,6 @@
 int spackList_length;
 int spackList_length_align;
 
-/**
- *
- */
-
 SgChange::SgChange(int b, int w, int h, int _num)
 {
     bpp = b;
@@ -84,7 +82,7 @@
 
 void
 SgChange::run_init(TaskManager *manager, Application *app)
-{
+{   
     this->manager = manager;
 
     start_time = get_ticks();
@@ -94,23 +92,78 @@
     // ココ!
     sgroot_A = new SceneGraphRoot(this->width, this->height);
     sgroot_A->tmanager = manager;
-    sgroot_B = new SceneGraphRoot(this->width, this->height);
-    sgroot_B->tmanager = manager;
+    //sgroot_B = new SceneGraphRoot(this->width, this->height);
+    //sgroot_B->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_only_sg(this, this->width, this->height);
+    
+    mainloop->mainLoop();
+}
 
-    mainloop->mainLoop();
+HTaskPtr
+SgChange::initLoop()
+{
+    HTaskPtr task_next;
+    HTaskPtr task_tex;
+    
+    sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack));
+    sgpack->init();
+    ppack  = (PolygonPack*)manager->allocate(sizeof(PolygonPack));
+    
+    spackList_length = (this->height + split_screen_h - 1) / split_screen_h;
+    spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length);
+    
+    spackList_length_align = (spackList_length + 3)&(~3);
+    
+    spackList_ptr =
+        (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align);
+    
+    for (int i = 0; i < spackList_length; i++) {
+        spackList_ptr[i] = &spackList[i];
+    }
+    
+    for (int i = 1; i <= spackList_length; i++) {
+        spackList[i-1].init(i*split_screen_h);
+    }
+    
+    task_next = manager->create_task(Dummy);
+    
+    for (int i = 0; i < spe_num; i++) {
+        task_tex = manager->create_task(LoadTexture);
+        task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i));
+        task_next->wait_for(task_tex);
+        task_tex->spawn();
+    }
+    
+    return task_next;
 }
 
 void
 SgChange::mainLoop()
 {
-    HTaskPtr task_next = manager->create_task(Dummy);
+    HTaskPtr task_next = initLoop();
 
     task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL)
     task_next->spawn();
 }
 
+
+
 static void
 post2runLoop(SchedTask *s, void *viewer_, void *arg)
 {
@@ -141,15 +194,180 @@
         return;
     }
 
+    clean_pixels();
+
+    for (int i = 1; i <= spackList_length; i++) {
+        spackList[i-1].reinit(i*split_screen_h);
+    }
+
+    //exchange_sgroot();
+    sgroot_A->updateControllerState();
     sgroot_A->allExecute(width, height);
-    exchange_sgroot();
+    light_xyz_stock = sgroot_A->getLightVector();
 
     //printf("Sgroot = %x\n", sgroot_A);
+    /*
+    task_next->set_post(&post2runLoop, (void *)this, 0);
+    task_next->spawn();
+    */
+    rendering(task_next);
+}
 
-    task_next->set_post(&post2runLoop, (void *)this, 0);
+void 
+SgChange::rendering(HTaskPtr task_next)
+{
+    common_rendering(task_next);
+    
+    task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL)
     task_next->spawn();
 }
 
+void
+SgChange::common_rendering(HTaskPtr task_next)
+{
+    HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph);
+
+    //task_create_pp->set_param(0, (memaddr)sgroot_B->getDrawSceneGraph());
+    task_create_pp->set_param(0, (memaddr)sgroot_A->getDrawSceneGraph());
+    task_create_pp->set_param(1, (memaddr)ppack);
+
+    task_next->wait_for(task_create_pp);
+    
+    int range_base = spe_num;
+    int range = (spackList_length + range_base - 1) / range_base;
+
+    for (int i = 0; i < range_base; i++) {
+        int index_start = range*i;
+        int index_end = (index_start + range >= spackList_length)
+            ? spackList_length : index_start + range;
+
+	HTaskPtr task_create_sp = manager->create_task(CreateSpan);
+
+        task_create_sp->set_param(0,index_start);
+
+        task_create_sp->set_param(1,index_start*split_screen_h + 1);
+        task_create_sp->set_param(2,index_end*split_screen_h);
+
+        task_create_sp->add_inData(ppack, sizeof(PolygonPack));
+        task_create_sp->add_inData(spackList_ptr,
+                                   sizeof(SpanPack*)*spackList_length_align);
+        task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack));
+
+        task_next->wait_for(task_create_sp);
+        task_create_sp->wait_for(task_create_pp);
+
+        task_create_sp->set_cpu(SPE_ANY);
+        task_create_sp->spawn();
+    }
+
+    task_create_pp->spawn();
+}
+
+static void 
+post2runDraw(SchedTask *s, void *viewer_, void *arg)
+{
+    SgChange *viewer = (SgChange *)viewer_;
+    HTaskPtr task_next = viewer->manager->create_task(Dummy);
+    viewer->run_draw(task_next);
+}
+
+void
+SgChange::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする
+{
+    common_draw(task_next);
+
+    task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL)
+    task_next->spawn();
+
+    frames++;
+}
+
+void
+SgChange::common_draw(HTaskPtr task_next)
+{
+    HTaskPtr task_draw;
+
+    //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];
+        int startx = 1;
+        int endx = split_screen_w;
+	
+        int starty = spack->info.y_top - split_screen_h + 1;
+        //int endy = spack->info.y_top;
+        int rangey = (starty + split_screen_h - 1 > this->height)
+            ? this->height - starty + 1 : split_screen_h;
+	
+        while (startx < this->width) {
+            if (spack->info.size > 0) {
+                // Draw SpanPack
+                task_draw = manager->create_task(DrawSpan);
+		
+                task_draw->set_param(0,
+				     (memaddr)&pixels[(startx-1) + this->width*(starty-1)]);
+                task_draw->set_param(1,this->width);
+		task_draw->set_param(2,startx);
+		task_draw->set_param(3,endx);
+		task_draw->set_param(4,rangey);
+		
+                task_draw->add_inData(spack, sizeof(SpanPack));
+		
+		for (int i = 0; i < rangey; i++) {
+		    task_draw->add_outData(
+			&pixels[(startx-1) + this->width*(starty-1 + i) ],
+			(endx-startx+1)*sizeof(int));
+		}
+            } else {
+		// 7.7.3 SL1 Data Cache Range Set to Zero コマンド
+		//  を使って、DMAでclearするべき... ということは、
+		// それもSPEでやる方が良い?
+                memset(&pixels[(startx-1)+this->width*(starty-1)],
+                       0, (this->width)*sizeof(int)*rangey);
+		break;
+            }
+	    
+            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;
+            endx += split_screen_w;
+	    
+            if (endx > this->width) {
+                endx = this->width;
+            }
+        }
+    }   
+}
 
 void
 SgChange::run_finish(void)
@@ -159,7 +377,7 @@
     }
 
     delete sgroot_A;
-    delete sgroot_B;
+    //delete sgroot_B;
     quit();
 }
 
--- a/Renderer/Engine/SgChange.h	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Engine/SgChange.h	Tue Dec 08 16:48:01 2009 +0900
@@ -38,10 +38,14 @@
 
     int spe_num;
 
+    float light_xyz[4];
+    float *light_xyz_stock;
+
     int rgb_size[3];
     Uint32 video_flags;
     Uint32 *pixels;
 
+    virtual void video_init(TaskManager *manager) = 0;
     void init();
 
     int get_ticks();
@@ -54,7 +58,11 @@
     virtual void run_init(TaskManager *manager, Application *app);
     virtual void run_loop(HTaskPtr task_next);
     virtual void run_finish();
+    virtual void run_draw(HTaskPtr task_next);
     virtual void exchange_sgroot();
+    virtual void rendering(HTaskPtr task_next);
+    virtual void common_draw(HTaskPtr task_next);
+    virtual void common_rendering(HTaskPtr task_next);
     void mainLoop();
 
     void createFromXMLfile(const char *file)
--- a/Renderer/Engine/SgMain.cc	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Engine/SgMain.cc	Tue Dec 08 16:48:01 2009 +0900
@@ -1,5 +1,7 @@
 #include "TaskManager.h"
 #include "SgChange.h"
+#include "sgchangeSDL.h"
+#include "sgchangeFB.h"
 #include "Application.h"
 
 /* prototype */
@@ -14,6 +16,7 @@
     int width  = 640;
     int height = 480;
     int spenum = 1;
+    video_type vtype = VTYPE_SDL;
 
     for(int i = 1; argv[i]; ++i)
     {
@@ -29,10 +32,32 @@
 	if (strcmp(argv[i], "-cpu") == 0) {
 	    spenum = atoi(argv[++i]);
 	}
+	if (strcmp(argv[i], "-video") == 0) {
+	    if (strcmp(argv[i+1], "sdl") == 0) { 
+		vtype = VTYPE_SDL;
+	    } else if (strcmp(argv[i+1], "fb") == 0) {
+		vtype = VTYPE_FB;
+	    }
+	    i++;
+	}
     }
 
+    /*
     SgChange *screen = new SgChange(bpp, width, height, spenum);
     screen->run_init(manager, application());
+    */
+
+    SgChange *screen;
+    if (vtype == VTYPE_SDL) {
+	screen = new SgChangeSDL(manager, bpp, width, height, spenum);
+    } else if (vtype == VTYPE_FB) {
+	screen = new SgChangeFB(manager, bpp, width, height, spenum);
+    }else{
+	screen = new SgChangeSDL(manager, bpp, width, height, spenum);
+    }    
+
+    screen->video_init(manager);
+    screen->run_init(manager, application());
 
     return 0;
 }
--- a/Renderer/Engine/viewer.cc	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Engine/viewer.cc	Tue Dec 08 16:48:01 2009 +0900
@@ -105,7 +105,7 @@
 
     sgroot = new SceneGraphRoot(this->width, this->height);
     sgroot->tmanager = manager;
-
+    
     int size = 4;
 
     light_xyz[0] = 0.0f;
--- a/Renderer/Test/Makefile.cell	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Test/Makefile.cell	Tue Dec 08 16:48:01 2009 +0900
@@ -20,7 +20,7 @@
 run: $(TARGET)
 	sudo ./$(TARGET) -width 576 -height 384 -bpp 32
 run-hd: $(TARGET)
-	sudo /usr/bin/ps3-video-mode -v 133
+	sudo ps3-video-mode -v 133
 	sudo ./$(TARGET) -video fb -width 1920 -height 1080 -bpp 32
 
 
--- a/Renderer/Test/SgRootChange.cc	Sun Dec 06 20:04:47 2009 +0900
+++ b/Renderer/Test/SgRootChange.cc	Tue Dec 08 16:48:01 2009 +0900
@@ -4,9 +4,6 @@
 #include "MainLoop.h"
 #include "SgRootChange.h"
 
-
-
-
 // prototype
 MainLoopPtr 
 SgRootChange::init(Viewer *sgroot, int screen_w, int screen_h)
@@ -18,18 +15,9 @@
 SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h)
 {
     SceneGraphPtr ball;
-    SceneGraphPtr cube;
-    SceneGraphRoot *sg_buff_A = sgroot->sgroot_A;
-    SceneGraphRoot *sg_buff_B = sgroot->sgroot_B;
-
-    sg_buff_A->createFromXMLfile(sgroot->manager, "xml_file/Ball.xml");
-    sg_buff_B->createFromXMLfile(sgroot->manager, "xml_file/cube.xml");
-
-    ball = sgroot->sgroot_A->createSceneGraph("Ball");
-    cube = sgroot->sgroot_B->createSceneGraph("Cube");
-
-    sgroot->sgroot_A->setSceneData(ball);
-    sgroot->sgroot_B->setSceneData(cube);
+    sgroot->createFromXMLfile("xml_file/Ball.xml");
+    ball = sgroot->createSceneGraph("Ball");
+    sgroot->setSceneData(ball);
 
     return sgroot;
 }