diff TaskManager/Test/test_render/SceneGraph.cpp @ 173:56be4a6e5513

add scale
author gongo@localhost.localdomain
date Thu, 11 Dec 2008 20:17:01 +0900
parents dc68bc5c9e41
children 559b48b69b76
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Thu Dec 11 16:33:39 2008 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Thu Dec 11 20:17:01 2008 +0900
@@ -323,86 +323,76 @@
 		    texture_image = converted;
 		}
 
-		int image_tmp = texture_image->w*texture_image->h*4;
-		int tile_size = image_tmp + image_tmp/2 + image_tmp/4 + image_tmp/8 + image_tmp/16;
-		//uint32 *tex_dest = (uint32*)manager->malloc(texture_image->w*texture_image->h*4);
-		uint32 *tex_dest = (uint32*)manager->malloc(tile_size);
-
+		uint32 *tex_dest;
 
 		{
 		    int t = 0;
-		    int tex_width = texture_image->w;
-		    int tex_height = texture_image->h;
+		    int tex_w = texture_image->w;
+		    int tex_h = texture_image->h;
 		    Uint32 *tex_src = (Uint32*)texture_image->pixels;
-		    
-		    for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL) {
-			for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL) {
-			    for (int j = 0; j < TEXTURE_SPLIT_PIXEL; j++) {
-				for (int i = 0; i < TEXTURE_SPLIT_PIXEL; i++) {
-				    tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
+		    int scale = 1;
+		    int scale_cnt;
+		    int cur_w = tex_w;
+		    int cur_h = tex_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 (cur_w % TEXTURE_SPLIT_PIXEL == 0 && 
+			   cur_h % TEXTURE_SPLIT_PIXEL == 0) {
+			printf("(%3d, %3d) = %4d\n", cur_w, cur_h, cur_w*cur_h);
+			all_pixel_num += cur_w*cur_h;
+			cur_w >>= 1;
+			cur_h >>= 1;
+			scale <<= 1;
+		    }
+
+		    scale >>= 1;
+		    scale_cnt = scale;
+		    tex_dest
+			= (uint32*)manager->malloc(sizeof(int)*all_pixel_num);
+
+		    printf("scale = %d, all = %d\n", scale, all_pixel_num);
+
+		    int diff = TEXTURE_SPLIT_PIXEL;
+		    int p_diff = 1;
+		    while (scale_cnt) {
+			for (int y = 0; y < tex_h; y += diff) {
+			    for (int x = 0; x < tex_w; x += diff) {
+				for (int j = 0; j < diff; j += p_diff) {
+				    for (int i = 0; i < diff; i += p_diff) {
+					tex_dest[t++]
+					    = tex_src[(x+i) + tex_w*(y+j)];
+				    }
 				}
 			    }
 			}
+
+			diff <<= 1;
+			p_diff <<= 1;
+			scale_cnt >>= 1;
 		    }
-		    
-		    // 1 / 2
-		    for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*2) {
-		      for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*2) {
-			for (int j = 0; j < TEXTURE_SPLIT_PIXEL*2; j+=2) {
-			  for (int i = 0; i < TEXTURE_SPLIT_PIXEL*2; i+=2) {
-			    tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
-			  }
-			}
-		      }
-                    }
-		    
-		    // 1 / 4
-		    for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*4) {
-		      for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*4) {
-			for (int j = 0; j < TEXTURE_SPLIT_PIXEL*4; j+=4) {
-			  for (int i = 0; i < TEXTURE_SPLIT_PIXEL*4; i+=4) {
-			    tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
-			  }
-			}
-		      }
-                    }
-		    
-		    // 1 / 8
-                    for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*8) {
-                      for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*8) {
-                        for (int j = 0; j < TEXTURE_SPLIT_PIXEL*8; j+=8) {
-                          for (int i = 0; i < TEXTURE_SPLIT_PIXEL*8; i+=8) {
-                            tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
-                          }
-                        }
-                      }
-                    }
-
-                    // 1 / 16
-                    for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL*16) {
-                      for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL*16) {
-                        for (int j = 0; j < TEXTURE_SPLIT_PIXEL*16; j+=16) {
-                          for (int i = 0; i < TEXTURE_SPLIT_PIXEL*16; i+=16) {
-                            tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)];
-                          }
-                        }
-                      }
-                    }
-		    
 		}
 
-		list[id_count-1].t_w = texture_image->w/2;
-		list[id_count-1].t_h = texture_image->h/2;
+		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 = tex_dest + image_tmp/4;
+		list[id_count-1].pixels = tex_dest;
 
 		texture_id = id_count-1;
-		texture_info.t_w = texture_image->w/2;
-		texture_info.t_h = texture_image->h/2;
+		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 = tex_dest + image_tmp/4;
-
-		printf("[%s] %p\n", filename, tex_dest);
+		texture_info.pixels = tex_dest;
 
 		if(unlink(image_name))
 		{