changeset 224:ebfb9e389716

SceneGraph.cpp xmlcreate
author tkaito@nw0534.st.ie.u-ryukyu.ac.jp
date Tue, 10 Feb 2009 20:45:51 +0900
parents c9625a3f2180
children 1a5d05b3a48d
files TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraph.cpp
diffstat 2 files changed, 121 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Makefile.def	Tue Feb 10 13:11:26 2009 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Tue Feb 10 20:45:51 2009 +0900
@@ -6,8 +6,8 @@
 #CERIUM = /Users/gongo/Source/hg/Cerium
 
 # ex: linux/ps3
-CERIUM = /home/gongo/Cerium
-#CERIUM = /Users/tkaito/hg/Game/Cerium
+#CERIUM = /home/gongo/Cerium
+CERIUM = /Users/tkaito/Cerium
 
 #CERIUM = ../../..
 
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Tue Feb 10 13:11:26 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Tue Feb 10 20:45:51 2009 +0900
@@ -225,10 +225,10 @@
     /* XMLのノードを一つずつ解析  */
     for (cur=cur->children; cur; cur=cur->next) {
 	/* 扱うのはsurfaceオンリー  */
-	if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) {
-	    continue;
-	}
-
+	//if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) {
+	//    continue;
+	//}
+      if (!xmlStrcmp(cur->name,(xmlChar*)"surface")) {
 	/* ポリゴン(SceneGraph)生成  */
 	tmp = new SceneGraph(cur);
 	if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
@@ -250,6 +250,116 @@
 
 	    scene_graph->add_next(tmp);
 	}
+      }else if (!xmlStrcmp(cur->name,(xmlChar*)"image")) {
+	
+	char *cont;
+	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)
+	  {
+	    cout << "error open file\n";
+	  }
+	cont = (char *)xmlNodeGetContent(cur);
+	decode(cont, outfile);
+	fclose(outfile);
+		
+	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;
+	    }
+	    
+	    uint32 *tapestry;
+	    int scale = 1;
+	    int tex_w = texture_image->w;
+	    int tex_h = texture_image->h;
+	    int all_pixel_num = 0;
+	    
+	    /**
+	     * テクスチャの w or h が 8 pixel で分割できる間、
+	     * 1/2 の縮小画像を作る。
+	     * ここでは、最大の scale (1/scale) を見つける
+	     *
+	     * (ex)
+	     *  (128,128) => 64,64 : 32,32: 16,16 : 8,8
+	     *     scale = 16
+	     *  (128, 64) => 64,32 : 32,16: 16,8
+	     *     scale = 8
+	     */
+	    
+	    while (tex_w % TEXTURE_SPLIT_PIXEL == 0 &&
+		   tex_h % TEXTURE_SPLIT_PIXEL == 0) {
+	      all_pixel_num += tex_w*tex_h;
+	      tex_w >>= 1; /* tex_w /= 2 */
+	      
+	      tex_h >>= 1;
+	      scale <<= 1; /* scale *= 2 */
+	      
+	    }
+	    
+	    scale >>= 1;
+	    
+	    tapestry = makeTapestry(texture_image->w, texture_image->h,
+				    (uint32*)texture_image->pixels,
+				    all_pixel_num,
+				    scale);
+	    
+	    list[id_count-1].t_w = texture_image->w;
+	    list[id_count-1].t_h = texture_image->h;
+	    list[id_count-1].pixels_orig = (Uint32*)texture_image->pixels;
+	    list[id_count-1].pixels = tapestry;
+	    list[id_count-1].scale_max = scale;
+	    
+	    tmp->texture_id = id_count-1;
+	    tmp->texture_info.t_w = texture_image->w;
+	    tmp->texture_info.t_h = texture_image->h;
+	    tmp->texture_info.pixels_orig = (Uint32*)texture_image->pixels;
+	    tmp->texture_info.pixels = tapestry;
+	    tmp->texture_info.scale_max = scale;
+	    
+	    if (unlink(image_name))
+	      {
+		cout << "unlink error\n";
+	      }
+	    
+	  } else {
+	  /**
+	   * 以前に Load されている Texture を共用
+	   */
+	  
+	  tmp->texture_id = tex_id;
+	  
+	  // こんなことすると list[] のいみあるのかなーと
+	  // 微妙に思う、自分で書き換えた感想 by gongo
+	  
+	  tmp->texture_info.t_w = list[tex_id].t_w;
+	  tmp->texture_info.t_h = list[tex_id].t_h;;
+	  tmp->texture_info.pixels_orig = list[tex_id].pixels_orig;
+	  tmp->texture_info.pixels = list[tex_id].pixels;
+	  tmp->texture_info.scale_max = list[tex_id].scale_max;
+	  
+	}
+      }else {
+	continue;
+      }
     }
   
     xmlFreeDoc(doc);
@@ -415,6 +525,11 @@
 	    cont = (char *)xmlNodeGetContent(cur);
 	    pickup_texture(cont);
 	}
+	else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag"))
+        {
+	  char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name");
+	  texture_hash.hash_regist(filename);
+	}
 	else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
         {
 	    char image_name[20] = "/tmp/image_XXXXXX";