changeset 141:56db76a03294 draft

TileList を作ろうとしたがに動かない。 今はTileList 無しver
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Sat, 29 Nov 2008 01:18:32 +0900
parents 67a5469dfef2
children dc68420f705f
files TaskManager/Cell/spe/CellScheduler.cc TaskManager/Test/test_render/Makefile TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/Span.h TaskManager/Test/test_render/SpanPack.h TaskManager/Test/test_render/TextureHash.cpp TaskManager/Test/test_render/TextureHash.h TaskManager/Test/test_render/hash_texture.h TaskManager/Test/test_render/polygon.cpp TaskManager/Test/test_render/polygon.h TaskManager/Test/test_render/spe/CreatePolygon.cpp TaskManager/Test/test_render/spe/CreateSpan.cpp TaskManager/Test/test_render/spe/CreateSpan.h TaskManager/Test/test_render/task/CreateSpan.cpp TaskManager/Test/test_render/task/CreateSpan.h TaskManager/Test/test_render/texture.h
diffstat 16 files changed, 468 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Cell/spe/CellScheduler.cc	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Cell/spe/CellScheduler.cc	Sat Nov 29 01:18:32 2008 +0900
@@ -37,7 +37,6 @@
     mainMemList[id] = NULL;
 
     mainMemNum++;
-    
     mail_write(MY_SPE_COMMAND_MALLOC);
     mail_write(id);
     mail_write(size);
@@ -49,11 +48,11 @@
     uint32 id;
     uint32 addr;
 
-    while (mainMemNum != 0) {
+    while (mainMemNum > 0) {
 	id = mail_read();
 	addr = mail_read();
 
 	mainMemList[id] = (void*)addr;
 	mainMemNum--;
-    }
+    }    
 }
--- a/TaskManager/Test/test_render/Makefile.def	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Sat Nov 29 01:18:32 2008 +0900
@@ -11,7 +11,7 @@
 #CERIUM = ../../..
 
 CC      = g++
-CFLAGS  = -O0 -g -Wall# -DDEBUG
+CFLAGS  = -O9 -g -Wall# -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I.
 LIBS = -L$(CERIUM)/TaskManager
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -6,6 +6,8 @@
 #include "SceneGraph.h"
 #include "xml.h"
 #include "sys.h"
+#include "TextureHash.h"
+#include "texture.h"
 
 using namespace std;
 
@@ -21,13 +23,17 @@
 SceneGraphPtr scene_graph = NULL;
 SceneGraphPtr scene_graph_viewer = NULL;
 
+static TextureHash texture_hash;
+struct texture_list list[TABLE_SIZE];
+
+// TextureHash.cpp
+extern int id_count;
 
 SceneGraph::SceneGraph(void)
 {
     init();
 }
 
-
 void
 SceneGraph::init(void)
 {
@@ -46,6 +52,7 @@
     stack_angle[1] = 0.0f;
     stack_angle[2] = 0.0f;
 
+    texture_id = -1;
     move = no_move;
     collision = no_collision;
 }
@@ -278,6 +285,7 @@
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
         {
 	    char image_name[20] = "/tmp/image_XXXXXX";
+	    char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
 	    int fd = mkstemp(image_name);
 	    FILE *outfile = fdopen(fd, "wb");
 	    if(NULL == outfile)
@@ -289,29 +297,58 @@
 	    decode(cont, outfile);
 	    fclose(outfile);
 
-	    texture_image = IMG_Load(image_name);
-
 	    /**
-	     * image を 32bit(RGBA) に変換する
+	     * image_name を既に Load していれば何もしない
 	     */
-	    SDL_Surface *tmpImage
-		= SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
-				       texture_image->h, 32,
-				       redMask, greenMask, blueMask, alphaMask);
-	    SDL_Surface *converted;
-	    converted = SDL_ConvertSurface(texture_image,
-					   tmpImage->format, SDL_HWSURFACE);
-	    if( converted != NULL){
-		SDL_FreeSurface(texture_image);
-		texture_image = converted;
+	    int tex_id = texture_hash.hash_regist(filename);
+	    if (tex_id < 0) {
+
+		texture_image = IMG_Load(image_name);
+		
+		/**
+		 * image を 32bit(RGBA) に変換する
+		 */
+		SDL_Surface *tmpImage
+		    = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
+					   texture_image->h, 32, redMask,
+					   greenMask, blueMask, alphaMask);
+		SDL_Surface *converted;
+		converted = SDL_ConvertSurface(texture_image, tmpImage->format,
+					       SDL_HWSURFACE);
+		if (converted != NULL) {
+		    SDL_FreeSurface(texture_image);
+		    texture_image = converted;
+		}
+
+		list[id_count-1].t_w = texture_image->w;
+		list[id_count-1].t_h = texture_image->h;
+		list[id_count-1].pixels = (Uint32*)texture_image->pixels;
+
+		texture_id = id_count-1;
+		texture_info.t_w = texture_image->w;
+		texture_info.t_h = texture_image->h;
+		texture_info.pixels_orig = (Uint32*)texture_image->pixels;
+		texture_info.pixels = NULL;
+
+		//load_texture(image_name);
+		if(unlink(image_name))
+		{
+		    cout << "unlink error\n";
+		}
+	    } else {
+		/**
+		 * 以前に Load されている Texture を共用
+		 */
+		texture_id = tex_id;
+
+		// こんなことすると list[] のいみあるのかなーと
+		// 微妙に思う、自分で書き換えた感想 by gongo
+		texture_info.t_w = list[tex_id].t_w;
+		texture_info.t_h = list[tex_id].t_h;;
+		texture_info.pixels_orig = list[tex_id].pixels_orig;
+		texture_info.pixels = list[tex_id].pixels;
 	    }
-
-	    //load_texture(image_name);
-	    if(unlink(image_name))
-	    {
-		cout << "unlink error\n";
-	    }
-        }
+	}
     }
 }
 
--- a/TaskManager/Test/test_render/Span.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/Span.h	Sat Nov 29 01:18:32 2008 +0900
@@ -5,6 +5,26 @@
 #  include "Tapestry.h"
 #endif
 
+#define MAX_TILE_LIST 30
+
+typedef struct tile {
+    void *tile;
+    int tix, tiy;
+    int padding; // 16バイト倍数にする用
+} TileInfo, *TileInfoPtr;
+
+typedef struct tile_list {
+    int size;
+    struct tile_list *next;
+    int pad[2];
+    TileInfo tileinfo[MAX_TILE_LIST];
+
+    void init(void) {
+	size = 0;
+	next = 0;
+    }
+} TileInfoList, *TileInfoListPtr; // 4*4+63*sizeof(Tile) = 1008+16
+
 class Span {
 public:
     long *tex_addr;
@@ -20,8 +40,10 @@
     float tex_y1;
     float tex_y2;
 
-    //int tile_list_size;
-    //TileList[1]; // 
+    TileInfoListPtr tilelist;
+    int pad[3];
 };
 
+typedef Span* SpanPtr;
+
 #endif
--- a/TaskManager/Test/test_render/SpanPack.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/SpanPack.h	Sat Nov 29 01:18:32 2008 +0900
@@ -28,6 +28,9 @@
     }
 
     void reinit(int ytop) {
+	/**
+	 * かっこわるすぐる
+	 */ 
 	SpanPack* top = this;
 	SpanPack* p;
 	SpanPack* p1;
@@ -35,9 +38,33 @@
 	p = top->next;
 	while (p != NULL) {
 	    p1 = p->next;
+	    for (int i = 0; i < p->info.size; i++) {
+		Span* span = &p->span[i];
+		TileInfoListPtr tlist = span->tilelist;
+		TileInfoListPtr t;
+
+		while (tlist) {
+		    t = tlist->next;
+		    free(tlist);
+		    tlist = t;
+		}
+	    }
+
 	    free(p);
 	    p = p1;
 	}
+
+	for (int i = 0; i < this->info.size; i++) {
+	    Span* span = &this->span[i];
+	    TileInfoListPtr tlist = span->tilelist;
+	    TileInfoListPtr t;
+	    
+	    while (tlist) {
+		t = tlist->next;
+		free(tlist);
+		tlist = t;
+	    }
+	}
 	
 	this->info.size = 0;
 	this->info.y_top = ytop;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/TextureHash.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -0,0 +1,51 @@
+#include <string.h>
+#include <stdlib.h>
+#include "TextureHash.h"
+
+int id_count;
+
+TextureHash::TextureHash(void)
+{
+    table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE);
+
+    for (int i = 0; i < TABLE_SIZE; i++) {
+	table[i].tx_id = -1;
+	table[i].key = NULL;
+    }
+}
+
+TextureHash::~TextureHash(void)
+{
+    free(table);
+}
+
+int
+TextureHash::hash_function(const char *key)
+{
+    //float value = 0.0;
+    int value = 0;
+
+    for (int i = 0; key[i]; i++) {
+	value += key[i]*(i+1)*17+1;
+    }
+
+    return value%TABLE_SIZE;
+}
+
+int
+TextureHash::hash_regist(const char* key)
+{
+    int hash = hash_function(key);
+    
+    for (int i = 0; ; i++) {
+	if (table[hash].tx_id == -1) {
+	    table[hash].key   = (char*)key;
+	    table[hash].tx_id = id_count++;
+	    return -1;
+	} else if (strcmp(key, table[hash].key) == 0
+		   && table[hash].tx_id != -1){
+	    return table[hash].tx_id;
+	}
+	hash = ((37*hash)^(11*i)) % TABLE_SIZE;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/TextureHash.h	Sat Nov 29 01:18:32 2008 +0900
@@ -0,0 +1,21 @@
+#ifndef INCLUDED_TEXTURE_HASH
+#define INCLUDED_TEXTURE_HASH
+
+const int TABLE_SIZE = 8192;
+
+struct hashtable{
+    int tx_id;
+    char* key;
+};
+
+class TextureHash {
+public:
+    hashtable *table;
+
+    TextureHash(void);
+    ~TextureHash(void);
+    int hash_function(const char*);
+    int hash_regist(const char*);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/hash_texture.h	Sat Nov 29 01:18:32 2008 +0900
@@ -0,0 +1,15 @@
+const int N = 8192;
+
+struct
+hashtable{
+    int tx_id;
+    char* key;
+};
+
+class TextureHash {
+    hashtable table[N];
+public:
+    hash(void);
+    int hash_function(const char*);
+    int hash_regist(const char*);
+};
--- a/TaskManager/Test/test_render/polygon.cpp	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/polygon.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -4,7 +4,6 @@
 #include <SDL_image.h>
 #include "polygon.h"
 #include "xml.h"
-#include "texture.h"
 #include "sys.h"
 #include "triangle.h"
 #include "vertex.h"
--- a/TaskManager/Test/test_render/polygon.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/polygon.h	Sat Nov 29 01:18:32 2008 +0900
@@ -15,6 +15,10 @@
 #  include "SpanPack.h"
 #endif
 
+#ifndef INCLUDED_TEXTURE
+#  include "texture.h"
+#endif
+
 class Polygon {
 public:
     long long size;
@@ -28,8 +32,10 @@
     float matrix[16];
     float *anim;
     int frame;         // anime frame num
-    //int *texture;         // pointer of this surface's texture
-    static SDL_Surface* texture_image;      // pointer of this surface's texture
+    int texture_id; //texture id number
+    struct texture_list texture_info;
+    
+    static SDL_Surface* texture_image; // pointer of this surface's texture
 
     Polygon(void);
 
--- a/TaskManager/Test/test_render/spe/CreatePolygon.cpp	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/spe/CreatePolygon.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -146,9 +146,15 @@
 		    triangle->ver3.tex_x = node->texture[nt+4];
 		    triangle->ver3.tex_y = node->texture[nt+4+1];
 		
+#if 0
 		    triangle->tex_addr = node->tex_addr;
 		    triangle->tex_width = node->tex_width;
 		    triangle->tex_height = node->tex_height;
+#else
+		    triangle->tex_addr = node->texture_info.pixels;
+		    triangle->tex_width = node->texture_info.t_w;
+		    triangle->tex_height = node->texture_info.t_h;
+#endif
 		}
 
 		smanager->dma_wait(SG_NODE_LOAD);
--- a/TaskManager/Test/test_render/spe/CreateSpan.cpp	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/spe/CreateSpan.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -4,6 +4,9 @@
 static const int SPAN_PACK_LOAD    = 5;
 static const int SPAN_PACK_STORE   = 6;
 static const int POLYGON_PACK_LOAD = 7;
+static const int TILE_ALLOCATE  = 8;
+static const int TILE_LOAD  = 9;
+static const int TILE_STORE = 10;
 
 static SpanPackPtr spack = NULL;
 static SpanPackPtr send_spack = NULL;
@@ -79,6 +82,102 @@
 
 
 /**
+ * Span の1ドットずつ、必要なテクスチャのブロック(Tile)を求めていく
+ * 
+ */
+void
+CreateSpan::setTile(SpanPtr span)
+{
+    TileInfoListPtr tilelist =
+	(TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
+    TileInfoListPtr send_tilelist =
+	(TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
+    TileInfoListPtr tilelist_addr;
+    TileInfoListPtr send_tilelist_addr;
+    TileInfoPtr tile;
+
+    int cur_x = 0;
+    int len = 0;
+
+    smanager->mainMem_wait();
+    tilelist_addr = (TileInfoListPtr)smanager->mainMem_get(TILE_ALLOCATE);
+    span->tilelist = tilelist_addr;
+
+    float tex1 = span->tex_x1;
+    float tex2 = span->tex_x2;
+    float tey1 = span->tex_y1;
+    float tey2 = span->tex_y2;
+    int tex_xpos;
+    int tex_ypos;
+    int end = span->length_x;
+
+    if (span->length_x == 1) {
+	tilelist->init();
+	tile = &tilelist->tileinfo[tilelist->size++];
+
+	tex_xpos = (int)((span->tex_width-1) * tex1);
+	tex_ypos = (int)((span->tex_height-1) * tey1);
+
+	tile->tix = tex_xpos;
+	tile->tiy = tex_ypos;
+    } else {    
+	while (cur_x < span->length_x) {
+	    len = (cur_x + MAX_TILE_LIST < span->length_x) ?
+		MAX_TILE_LIST : span->length_x - cur_x;
+
+	    float tex_x, tex_y;
+
+	    tilelist->init();
+
+	    for (int i = cur_x; i < end; i++) {
+		tile = &tilelist->tileinfo[tilelist->size++];
+
+		tex_x = tex1*(end-1-i)/(end-1) + tex2*i/(end-1);
+		tex_y = tey1*(end-1-i)/(end-1) + tey2*i/(end-1);
+		if (tex_x > 1) tex_x = 1;
+		if (tex_y > 1) tex_y = 1;
+		tex_xpos = (int)((span->tex_height-1) * tex_x);
+		tex_ypos = (int)((span->tex_width-1) * tex_y);
+
+		tile->tix = tex_xpos;
+		tile->tiy = tex_ypos;
+	    }
+	
+	    if (cur_x + MAX_TILE_LIST < span->length_x) {
+		TileInfoListPtr tmp = tilelist;
+		tilelist = send_tilelist;
+		send_tilelist = tmp;
+		send_tilelist_addr = tilelist_addr;
+
+		smanager->mainMem_alloc(TILE_ALLOCATE, sizeof(TileInfoList));
+		smanager->mainMem_wait();
+		tilelist_addr =
+		    (TileInfoListPtr)smanager->mainMem_get(TILE_ALLOCATE);
+		
+		send_tilelist->next = tilelist_addr;
+		
+		smanager->dma_wait(TILE_STORE);
+		smanager->dma_store(send_tilelist, (uint32)send_tilelist_addr,
+				    sizeof(TileInfoList), TILE_STORE);
+	    }
+	    
+	    cur_x += MAX_TILE_LIST;
+	}
+    }
+
+    smanager->dma_wait(TILE_STORE);
+    tilelist->next = 0; // ?
+    smanager->dma_store(tilelist, (uint32)tilelist_addr,
+			sizeof(TileInfoList), TILE_STORE);
+
+    free(send_tilelist);
+
+    smanager->dma_wait(TILE_STORE);
+
+    free(tilelist);
+}
+
+/**
  * x軸に水平な辺を持つ三角形ポリゴンから、
  * Span を抜き出す
  */
@@ -109,7 +208,6 @@
 
     SpanPackPtr tmp_spack;
 
-
     /**
      * 三角形ポリゴンをx軸に水平に二つに分けようとして
      * ある一辺がすでに水平だった場合、つまり
@@ -185,9 +283,9 @@
 	    if (spack->info.size >= MAX_SIZE_SPAN) {
 		SpanPackPtr next;
 		
-		mainMem_alloc(0, sizeof(SpanPack));
-		mainMem_wait();
-		next = (SpanPackPtr)mainMem_get(0);
+		smanager->mainMem_alloc(0, sizeof(SpanPack));
+		smanager->mainMem_wait();
+		next = (SpanPackPtr)smanager->mainMem_get(0);
 		
 		spack->next = next;
 
@@ -200,7 +298,7 @@
 				    sizeof(SpanPack), SPAN_PACK_STORE);
 
 		spackList[index] = next;
-
+		
 		smanager->dma_load(spack, (uint32)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
 		smanager->dma_wait(SPAN_PACK_LOAD);
@@ -213,6 +311,13 @@
 	    continue;
 	}
 
+	/**
+	 * メインメモリに、Tile 用の領域確保をここで指定しておく
+	 */
+	// ちと仕様変更によりここでは使わない
+	// 予めやっておいて、その間に処理、だとちょっと動作が怪しいらしい
+	//smanager->mainMem_alloc(TILE_ALLOCATE, sizeof(TileInfoList));
+	
 	tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x);
 	tmp_end  = calc(vMid->x  - vMin->x ,div_y, i, vMin->x);
 	tmp_z    = calc(vMid10->z - vMin->z ,div_y, i, vMin->z);
@@ -273,6 +378,8 @@
 	// TilePtr の計算
 	// tix, tiy (Tile 内での x, y)
 	//
+	//smanager->mainMem_wait();
+	//setTile(span);
     }
 }
 
--- a/TaskManager/Test/test_render/spe/CreateSpan.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/spe/CreateSpan.h	Sat Nov 29 01:18:32 2008 +0900
@@ -22,6 +22,7 @@
 		       int charge_y_top, int charge_y_end,
 		       long *tex_addr, long tex_width, long tex_height,
 		       VertexPack *vMin,VertexPack *vMid,VertexPack *vMid1);
+    void setTile(SpanPtr span);
 };
 
 #endif
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/task/CreateSpan.cpp	Sat Nov 29 01:18:32 2008 +0900
@@ -4,6 +4,9 @@
 static const int SPAN_PACK_LOAD    = 5;
 static const int SPAN_PACK_STORE   = 6;
 static const int POLYGON_PACK_LOAD = 7;
+static const int TILE_ALLOCATE  = 8;
+static const int TILE_LOAD  = 9;
+static const int TILE_STORE = 10;
 
 static SpanPackPtr spack = NULL;
 static SpanPackPtr send_spack = NULL;
@@ -79,6 +82,101 @@
 
 
 /**
+ * Span の1ドットずつ、必要なテクスチャのブロック(Tile)を求めていく
+ * 
+ */
+void
+CreateSpan::setTile(SpanPtr span)
+{
+    TileInfoListPtr tilelist = (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));
+    TileInfoListPtr send_tilelist = (TileInfoListPtr)smanager->allocate(sizeof(TileInfoList));;
+    TileInfoListPtr tilelist_addr;
+    TileInfoListPtr tmp = NULL;
+
+    TileInfoPtr tile;
+    int remain = span->length_x; // 残りのドット(Tile)数
+    int len = 0;
+
+    //smanager->mainMem_wait();
+    tilelist_addr = (TileInfoListPtr)smanager->mainMem_get(TILE_ALLOCATE);
+    span->tilelist = tilelist_addr;
+    smanager->dma_load(tilelist, (uint32)tilelist_addr,
+		       sizeof(TileInfoList), TILE_LOAD);
+
+    uint32 hoge = (uint32)tilelist_addr;
+    
+    while (remain > 0) {
+	if (remain > MAX_TILE_LIST) {
+	    smanager->mainMem_alloc(TILE_ALLOCATE, sizeof(TileInfoList));
+	    len = MAX_TILE_LIST;
+	} else {
+	    len = remain;
+	}
+
+	float tex1 = span->tex_x1;
+	float tex2 = span->tex_x2;
+	float tey1 = span->tex_y1;
+	float tey2 = span->tex_y2;
+	int tex_xpos;
+	int tex_ypos;
+
+	smanager->dma_wait(TILE_LOAD);
+
+	if (len == 1) {
+	    tile = &tilelist->tileinfo[tilelist->size++];
+	    tex_xpos = (int)((span->tex_width-1) * tex1);
+	    tex_ypos = (int)((span->tex_height-1) * tey1);
+	} else {
+	    float tex_x, tex_y;
+
+	    for (int i = 0; i < len; i++) {
+		tile = &tilelist->tileinfo[tilelist->size++];
+
+		tex_x = tex1*(len-1-i)/(len-1) + tex2*i/(len-1);
+		tex_y = tey1*(len-1-i)/(len-1) + tey2*i/(len-1);
+		if (tex_x > 1) tex_x = 1;
+		if (tex_y > 1) tex_y = 1;
+		tex_xpos = (int)((span->tex_height-1) * tex_x);
+		tex_ypos = (int)((span->tex_width-1) * tex_y);
+
+		tile->tix = tex_xpos;
+		tile->tiy = tex_ypos;
+	    }
+	}
+
+	if (remain > MAX_TILE_LIST) {
+	    TileInfoListPtr send = tilelist_addr;
+
+	    tmp = tilelist;
+	    tilelist = send_tilelist;
+	    send_tilelist = tmp;
+
+	    smanager->mainMem_wait();
+	    tilelist_addr =
+		(TileInfoListPtr)smanager->mainMem_get(TILE_ALLOCATE);
+
+	    send_tilelist->next = tilelist_addr;
+
+	    smanager->dma_wait(TILE_STORE);
+	    smanager->dma_store(send_tilelist, (uint32)send,
+				sizeof(TileInfoList),TILE_STORE);
+	    
+	    smanager->dma_load(tilelist, (uint32)tilelist_addr,
+			       sizeof(TileInfoList), TILE_LOAD);    
+	}
+	remain -= MAX_TILE_LIST;
+    }
+
+    smanager->dma_wait(TILE_STORE);
+    smanager->dma_store(tilelist, (uint32)tilelist_addr,
+			sizeof(TileInfoList), TILE_STORE);
+    smanager->dma_wait(TILE_STORE);
+
+    free(tilelist);
+    free(send_tilelist);
+}
+
+/**
  * x軸に水平な辺を持つ三角形ポリゴンから、
  * Span を抜き出す
  */
@@ -109,7 +207,6 @@
 
     SpanPackPtr tmp_spack;
 
-
     /**
      * 三角形ポリゴンをx軸に水平に二つに分けようとして
      * ある一辺がすでに水平だった場合、つまり
@@ -185,9 +282,9 @@
 	    if (spack->info.size >= MAX_SIZE_SPAN) {
 		SpanPackPtr next;
 		
-		mainMem_alloc(0, sizeof(SpanPack));
-		mainMem_wait();
-		next = (SpanPackPtr)mainMem_get(0);
+		smanager->mainMem_alloc(0, sizeof(SpanPack));
+		smanager->mainMem_wait();
+		next = (SpanPackPtr)smanager->mainMem_get(0);
 		
 		spack->next = next;
 
@@ -200,7 +297,7 @@
 				    sizeof(SpanPack), SPAN_PACK_STORE);
 
 		spackList[index] = next;
-
+		
 		smanager->dma_load(spack, (uint32)spackList[index],
 				   sizeof(SpanPack), SPAN_PACK_LOAD);
 		smanager->dma_wait(SPAN_PACK_LOAD);
@@ -213,6 +310,11 @@
 	    continue;
 	}
 
+	/**
+	 * メインメモリに、Tile 用の領域確保をここで指定しておく
+	 */ 
+	smanager->mainMem_alloc(TILE_ALLOCATE, sizeof(TileInfoList));
+	
 	tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x);
 	tmp_end  = calc(vMid->x  - vMin->x ,div_y, i, vMin->x);
 	tmp_z    = calc(vMid10->z - vMin->z ,div_y, i, vMin->z);
@@ -273,6 +375,8 @@
 	// TilePtr の計算
 	// tix, tiy (Tile 内での x, y)
 	//
+	smanager->mainMem_wait();
+	setTile(span);
     }
 }
 
--- a/TaskManager/Test/test_render/task/CreateSpan.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/task/CreateSpan.h	Sat Nov 29 01:18:32 2008 +0900
@@ -22,5 +22,7 @@
 		       int charge_y_top, int charge_y_end,
 		       long *tex_addr, long tex_width, long tex_height,
 		       VertexPack *vMin,VertexPack *vMid,VertexPack *vMid1);
+    void setTile(SpanPtr span);
 };
+
 #endif
--- a/TaskManager/Test/test_render/texture.h	Fri Nov 28 15:24:55 2008 +0900
+++ b/TaskManager/Test/test_render/texture.h	Sat Nov 29 01:18:32 2008 +0900
@@ -1,4 +1,34 @@
+#ifndef INCLUDED_TEXTURE
+#define INCLUDED_TEXTURE
+
+#if 0 // もういらないっぽい OpenGL 使用時の遺産
 #include <SDL.h>
 #include <SDL_opengl.h>
+GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
+#endif
 
-GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord);
+#define S_X 128
+#define SSIZE 128*128
+#define SS64 64*64
+#define SS32 32*32
+
+typedef struct {
+    Uint32 tx128[SSIZE];
+    Uint32 tx64[SS64];
+    Uint32 tx32[SS32];
+    Uint32 block[SSIZE+SS64+SS32];
+} Sptx;
+
+typedef struct
+Texture{
+    int px, py;
+    Sptx s[100];
+};
+
+struct texture_list {
+    int t_w, t_h;
+    Uint32 *pixels_orig;
+    Uint32 *pixels;
+};
+
+#endif