Mercurial > hg > Game > Cerium
changeset 178:4efb799779d7 draft
add makeTapestry in SceneGraph.cpp
author | gongo@localhost.localdomain |
---|---|
date | Tue, 16 Dec 2008 17:45:28 +0900 |
parents | deb02b0e6291 |
children | 6e62f8cfbfe3 |
files | TaskManager/Test/test_render/ChangeLog TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/spe/CreateSpan.cpp |
diffstat | 3 files changed, 99 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ChangeLog Tue Dec 16 17:16:35 2008 +0900 +++ b/TaskManager/Test/test_render/ChangeLog Tue Dec 16 17:45:28 2008 +0900 @@ -1,5 +1,9 @@ 2008-12-16 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + * SceneGraph.cpp (makeTapestry): add + SceneGraph::get_data にあったけど、ごちゃごちゃしてたので + 関数として生成 + * viewer.cpp (Viewer::run_init, Viewer::run_draw): fix * spe/DrawSpan.cpp (DrawSpan::zRow_init): delete
--- a/TaskManager/Test/test_render/SceneGraph.cpp Tue Dec 16 17:16:35 2008 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.cpp Tue Dec 16 17:45:28 2008 +0900 @@ -30,6 +30,71 @@ // TextureHash.cpp extern int id_count; +/** + * 事前に計算したテクスチャの最大縮小率 scale まで、 + * テクスチャを 1/2 縮小していく。 + * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 + * これらを連続したメモリ領域に格納していく。 + * 以下の (1), (2), (3) を Tapestry と呼ぶ + * + * 例 scale = 4 の場合 + * + * Tapestry(1) 1/1 + * +---+---+---+---+ + * | 0 | 1 | 2 | 3 | + * +---+---+---+---+ + * | 4 | 5 | 6 | 7 | (2) 1/2 + * +---+---+---+---+ +---+---+ + * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 + * +---+---+---+---+ +---+---+ +---+ + * | 12| 13| 14| 15| | 18| 19| | 20| + * +---+---+---+---+ +---+---+ +---| + * + * (1) (2) (3) + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * + * @param[in] tex_w Width of orignal texture + * @param[in] tex_h Height of orignal texture + * @param[in] tex_src Original texture + * @param[in] all_pixel_num Tapestry の合計 pixel 数 + * @param[in] scale テクスチャの最大縮小率 (= 2^n) + * @return (1) のアドレス + */ +static uint32* +makeTapestry(int tex_w, int tex_h, uint32 *tex_src, + int all_pixel_num, int scale_cnt) +{ + uint32 *tex_dest; + + int t = 0; + int diff = TEXTURE_SPLIT_PIXEL; + int p_diff = 1; + + tex_dest = (uint32*)manager->malloc(sizeof(int)*all_pixel_num); + + 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; + } + + return tex_dest; +} + + SceneGraph::SceneGraph(void) { init(); @@ -323,74 +388,49 @@ texture_image = converted; } - uint32 *tex_dest; + uint32 *tapestry; int scale = 1; - - { - int t = 0; - int tex_w = texture_image->w; - int tex_h = texture_image->h; - Uint32 *tex_src = (Uint32*)texture_image->pixels; - int scale_cnt; - int cur_w = tex_w; - int cur_h = tex_h; - int all_pixel_num = 0; + 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 (cur_w % TEXTURE_SPLIT_PIXEL == 0 && - cur_h % TEXTURE_SPLIT_PIXEL == 0) { - all_pixel_num += cur_w*cur_h; - cur_w >>= 1; /* cur_w /= 2 */ - cur_h >>= 1; - scale <<= 1; /* scale *= 2 */ - } + /** + * テクスチャの 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; - scale_cnt = scale; - tex_dest - = (uint32*)manager->malloc(sizeof(int)*all_pixel_num); + scale >>= 1; - 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; - } - } + 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 = tex_dest; + list[id_count-1].pixels = tapestry; list[id_count-1].scale_max = scale; 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 = tex_dest; + texture_info.pixels = tapestry; texture_info.scale_max = scale; if (unlink(image_name))
--- a/TaskManager/Test/test_render/spe/CreateSpan.cpp Tue Dec 16 17:16:35 2008 +0900 +++ b/TaskManager/Test/test_render/spe/CreateSpan.cpp Tue Dec 16 17:45:28 2008 +0900 @@ -384,7 +384,7 @@ (int)(span->tex_width*tex_x_len), (int)(span->tex_height*tex_y_len), tex_scale_max); - //scale = (4 > tex_scale_max) ? tex_scale_max : 4; + //scale = (8 > tex_scale_max) ? tex_scale_max : 8; uint32 *tapestry = getTapestry(tex_width, tex_height, scale, tex_addr);