changeset 0:df32980116bd

Initial revision
author gongo
date Sat, 02 Feb 2008 19:15:39 +0900
parents
children 07d09b93cd3d
files Renderer/Cell/Engine.cpp Renderer/Cell/Engine.h Renderer/Cell/SceneGraph2PolygonTask.h Renderer/DataPack/DataPackEngine.cpp Renderer/DataPack/DataPackEngine.h Renderer/Simple/SimpleEngine.cpp Renderer/Simple/SimpleEngine.h example/cube/CubeSceneGraph.cpp example/cube/CubeSceneGraph.h example/cube/CubeTask.cpp example/cube/CubeTask.h example/cube/RenderingEngine.cpp example/cube/RenderingEngine.h example/cube/main.cpp
diffstat 14 files changed, 393 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Cell/Engine.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,66 @@
+CellEngine::CellEngine()
+{
+    TaskManager manager = new TaskManager();
+}
+
+void
+CellEngine::init(int width, int height, int bpp)
+{
+    if(SDL_Init( SDL_INIT_VIDEO ) < 0)
+    {
+	cout << "Couldn't initialize SDL:" << SDL_GetError() << endl;
+	exit(1);
+    }
+
+    // etc...
+}
+
+TaskDepend
+CellEngine::update_all(SceneGraph* next, SceneGraph* now, TaskDepend wait)
+{
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    SceneGraphPack *nt_pack = nt->data_pack();
+    SceneGraphPack *t_pack;
+    Task* t_task = now->get_task();
+    TaskDepend task;
+
+    task = manager->create_task(function_id, now->task_size(),
+			 (unsigned int *)now->get_task(),
+			 (unsigned int *)next->get_task());
+
+    manager->set_task_depend(task, wait);
+
+    task->run();
+
+    return task;
+}
+
+TaskDepend
+CellEngin::draw_all(SceneGraph* now, TaskDepend wait)
+{
+    /**
+     * SceneGraph => Polygon
+     * Polygon => Span, Texture
+     * Texture, Span => Rendering
+     */
+
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    SceneGraphPack *nt_pack = nt->data_pack();
+    SceneGraphPack *t_pack;
+    Task* t_task = now->get_task();
+    TaskDepend task;
+
+    task = manager->create_task(function_id, now->task_size(),
+				(unsigned int *)now->get_task(),
+				(unsigned int *)next->get_task());
+
+    manager->set_task_depend(task, wait);
+
+    task->run();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Cell/Engine.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,4 @@
+class CellEngine : RenderingEngine {
+public:
+    CellEngine(int width, int height, int bpp);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Cell/SceneGraph2PolygonTask.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,2 @@
+class SceneGraph2PolygonTask : Task {
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/DataPack/DataPackEngine.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,45 @@
+void
+DataPackEngine::init(int width, int height, int bpp)
+{
+    if(SDL_Init( SDL_INIT_VIDEO ) < 0)
+    {
+	cout << "Couldn't initialize SDL:" << SDL_GetError() << endl;
+	exit(1);
+    }
+
+    // etc...
+}
+
+TaskDepend
+DataPackEngine::update_all(SceneGraph* next, SceneGraph* now, TaskDepend wait)
+{
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    SceneGraphPack *nt_pack = nt->data_pack();
+    SceneGraphPack *t_pack;
+    Task* t_task = now->get_task();
+
+    for (t_pack = now->data_pack(); t_pack < not->data_pack;) {
+	t_task->update(t_pack, nt_pack);
+	t_pack = t_pack->next();
+	nt_pack = nt_pack->next();
+    }
+}
+
+TaskDepend
+DataPackEngin::draw_all(SceneGraph* now, TaskDepend wait)
+{
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    SceneGraphPack *t_pack;
+    Task* t_task = now->get_task();
+
+    for (t_pack = now->data_pack(); t_pack < now->data_pack;) {
+	t_task->draw(t_pack, nt_pack);
+	t_pack = t_pack->next();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/DataPack/DataPackEngine.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,4 @@
+class DataPackEngine : RenderingEngine {
+public:
+    DataPackEngine(int width, int height, int bpp);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Simple/SimpleEngine.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,108 @@
+void
+SimpleEngine::init(int width, int height, int bpp)
+{
+    if(SDL_Init( SDL_INIT_VIDEO ) < 0)
+    {
+	cout << "Couldn't initialize SDL:" << SDL_GetError() << endl;
+	exit(1);
+    }
+
+    // etc...
+}
+
+TaskDepend
+SimpleEngine::update_all(SceneGraph* next, SceneGraph* now, TaskDepend wait)
+{
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    //glPushMatrix();
+    int s=0;
+    while(t)
+    {
+	//t->draw(stack);
+	t->update(t->data_pack, nt->data_pack);
+	if(t->child != NULL)
+	{
+	    stack[s++] = t->matrix; //push
+	    t = t->child;
+	}
+	else if(t->brother != NULL)
+	{
+	    stack[--s] = NULL; //pop
+	    stack[s++] = t->matrix; //push
+	    t = t->brother;
+	}
+	else
+	{
+	    while(t)
+	    {
+		if(t->brother != NULL)
+		{
+		    stack[--s] = NULL; //pop
+		    stack[s++] = t->matrix; //push
+		    t = t->brother;
+		    break;
+		}
+		else
+		{
+		    t = t->parent;
+		    if(t)
+		    {
+			stack[--s] = NULL; //pop
+		    }
+		}
+	    }
+	}
+    }
+    //glPopMatrix();
+}
+
+TaskDepend
+SimpleEngin::draw_all(SceneGraph* now, TaskDepend wait)
+{
+    Polygon *t;
+
+    t = this;
+
+    //glPushMatrix();
+    int s=0;
+    while(t)
+    {
+	t->draw(stack);
+	if(t->child != NULL)
+	{
+	    stack[s++] = t->matrix; //push
+	    t = t->child;
+	}
+	else if(t->brother != NULL)
+	{
+	    stack[--s] = NULL; //pop
+	    stack[s++] = t->matrix; //push
+	    t = t->brother;
+	}
+	else
+	{
+	    while(t)
+	    {
+		if(t->brother != NULL)
+		{
+		    stack[--s] = NULL; //pop
+		    stack[s++] = t->matrix; //push
+		    t = t->brother;
+		    break;
+		}
+		else
+		{
+		    t = t->parent;
+		    if(t)
+		    {
+			stack[--s] = NULL; //pop
+		    }
+		}
+	    }
+	}
+    }
+    //glPopMatrix();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Simple/SimpleEngine.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,4 @@
+class SimpleEngine : RenderingEngine {
+public:
+    SimpleEngine(int width, int height, int bpp);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/CubeSceneGraph.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,13 @@
+#include "CubeSceneGraph.h"
+
+CubeSceneGraph::CubeSceneGraph(char *xml)
+{
+    SceneGraph::SceneGraph(xml);
+    task = new CubeTask();
+}
+
+void
+CubeSceneGraph::update(CubeSceneGraph *old)
+{
+    task->update(old->data_pack, data_pack);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/CubeSceneGraph.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,8 @@
+#include "SceneGraph.h"
+#include "CubeTask.h"
+
+class CubeSceneGraph : SceneGraph {
+public:
+    CubeTask* task;
+    CubeSceneGraph(char *xml);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/CubeTask.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,5 @@
+void
+CubeTask::update(CubeDataPack *input, CubeDataPack *output)
+{
+    output->angle[0] = input->angle[0] + 1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/CubeTask.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,4 @@
+class CubeTask : Task {
+    void update(CubeDataPack *input, CubeDataPack *output);
+    
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/RenderingEngine.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,101 @@
+void
+RenderingEngine::init(int width, int height, int bpp)
+{
+}
+
+TaskDepend
+RenderingEngine::update_all(SceneGraph* next, SceneGraph* now, TaskDepend wait)
+{
+    SceneGraph *t, *nt;
+    t = now;
+    nt = next;
+
+    //glPushMatrix();
+    int s=0;
+    while(t)
+    {
+	//t->draw(stack);
+	t->update(t->data_pack, nt->data_pack);
+	if(t->child != NULL)
+	{
+	    stack[s++] = t->matrix; //push
+	    t = t->child;
+	}
+	else if(t->brother != NULL)
+	{
+	    stack[--s] = NULL; //pop
+	    stack[s++] = t->matrix; //push
+	    t = t->brother;
+	}
+	else
+	{
+	    while(t)
+	    {
+		if(t->brother != NULL)
+		{
+		    stack[--s] = NULL; //pop
+		    stack[s++] = t->matrix; //push
+		    t = t->brother;
+		    break;
+		}
+		else
+		{
+		    t = t->parent;
+		    if(t)
+		    {
+			stack[--s] = NULL; //pop
+		    }
+		}
+	    }
+	}
+    }
+    //glPopMatrix();
+}
+
+TaskDepend
+RenderingEngin::draw_all(SceneGraph* now, TaskDepend wait)
+{
+    Polygon *t;
+
+    t = this;
+
+    //glPushMatrix();
+    int s=0;
+    while(t)
+    {
+	t->draw(stack);
+	if(t->child != NULL)
+	{
+	    stack[s++] = t->matrix; //push
+	    t = t->child;
+	}
+	else if(t->brother != NULL)
+	{
+	    stack[--s] = NULL; //pop
+	    stack[s++] = t->matrix; //push
+	    t = t->brother;
+	}
+	else
+	{
+	    while(t)
+	    {
+		if(t->brother != NULL)
+		{
+		    stack[--s] = NULL; //pop
+		    stack[s++] = t->matrix; //push
+		    t = t->brother;
+		    break;
+		}
+		else
+		{
+		    t = t->parent;
+		    if(t)
+		    {
+			stack[--s] = NULL; //pop
+		    }
+		}
+	    }
+	}
+    }
+    //glPopMatrix();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/RenderingEngine.h	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,6 @@
+class RenderingEngine {
+public:
+    RenderingEngine();
+
+    void init(int width, int height, int bpp);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/cube/main.cpp	Sat Feb 02 19:15:39 2008 +0900
@@ -0,0 +1,23 @@
+int
+main()
+{
+    CubeSceneGraph scg[2];
+    TaskID wait = 0;
+    TaskID wait2 = 0;
+    int phase = 0;
+
+    scg[0] = new CubeSceneGraph("cube.xml");
+    scg[1] = scg[0]->copy();
+
+    // OPENGL, SHARED, DATAPACK, CELL
+    RenderingEngine *engine = RenderingEngineFactory(OPENGL);
+    engine->init(width, height, bpp);
+
+    while (1) {
+	wait = engine->update_all(scg[1-phase], scg[phase], wait);
+	//scg[1-phase]->update_all(scg[phase]);
+	wait2 = engine->draw_all(scg[phase], wait2);
+	//scg[phase]->draw_all(engine);
+	phase ^= 1;
+    }
+}