Mercurial > hg > Game > Cerium
changeset 185:063e546eca1f draft
add file
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Tue, 06 Jan 2009 15:40:15 +0900 |
parents | a19d3ed4ce5b |
children | 06cdf8baa989 |
files | TaskManager/Test/test_render/spe/DrawSpanRenew.cpp TaskManager/Test/test_render/spe/DrawSpanRenew.h TaskManager/Test/test_render/task/DrawSpanRenew.cpp TaskManager/Test/test_render/task/DrawSpanRenew.h |
diffstat | 4 files changed, 424 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/DrawSpanRenew.cpp Tue Jan 06 15:40:15 2009 +0900 @@ -0,0 +1,197 @@ +#include <stdlib.h> +#include <string.h> +#include "DrawSpanRenew.h" +#include "polygon_pack.h" +#include "SpanPack.h" +#include "texture.h" +#include "viewer_types.h" +#include "Func.h" + +#define SPAN_PACK_LOAD 0 +#define TEX_LOAD 1 + +SchedDefineTask(DrawSpanRenew); + +int +DrawSpanRenew::run(void *rbuf, void *wbuf) +{ + hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); + tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); + + int rangex_start = smanager->get_param(0); + int rangex_end = smanager->get_param(1); + + // このタスクが担当する x の範囲 + int rangex = rangex_end - rangex_start + 1; + + // y の範囲 (render_y + rangey - 1) + int rangey = smanager->get_param(2); + + float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey); + + for (int i = 0; i < rangex*rangey; i++) { + zRow[i] = 65535.0f; + } + + int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); + + for (int i = 0; i < rangey; i++) { + linebuf[i] = (int*)smanager->get_output(i); + linebuf_init(linebuf[i], rangex, 0xffffffff); + } + + SpanPackPtr spack = (SpanPackPtr)smanager->get_param(3); + SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + Span *span; + + // span->length_x の処理での再起動位置 + int js_cont = smanager->get_param(4); + + do { + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } + + for (int t = spack->info.start; t < spack->info.size; t++) { + span = &spack->span[t]; + + Uint32 rgb = 0x00ff00; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; + + /** + * Span が持つ 1 pixel 毎の + * テクスチャの座標 + */ + int tex_xpos; + int tex_ypos; + + /** + * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + uint32 *tex_addr; + + int x = span->x; + int y = span->y; + int x_len = span->length_x; + float z = span->start_z; + float zpos = span->end_z; + + // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + int localx = getLocalX(x-1); + int localy = getLocalY(y-1); + + if (x_len == 1) { + if (x < rangex_start || rangex_end < x) { + continue; + } + + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); + + if (zpos < zRow[localx + (rangex * localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + /** + * Tile が無い場合、一旦タスクはここで中断し、 + * Tile をロードするタスクを走らせた後に再起動する + */ + if (!isAvailableTile(tex_addr)) { + spack->info.start = t; + //set_rgb(tex_addr); + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, 0); + goto FINISH; + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex * localy)] = zpos; + linebuf[localy][localx] = rgb; + } + } else { + int js = (x < rangex_start) ? rangex_start - x : 0; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; + float tex_x, tex_y, tex_z; + + /** + * 一回比較すれば、以後再起動するまでは + * js_cont は使わないから 0 にしてるわけだけど、 + * 最初の一回のためだけにこれはめんどくさいのー。 + */ + js = (js < js_cont) ? js_cont : js; + js_cont = 0; + + for (int j = js; j <= je; j++) { + localx = getLocalX(x-1+j); + + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + if (!isAvailableTile(tex_addr)) { + printf("empty\n"); + spack->info.start = t; + //set_rgb(tex_addr); + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, j); + goto FINISH; + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex*localy)] = tex_z; + linebuf[localy][localx] = rgb; + } + } + } + } + + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; + } while (spack); + + +FINISH: + free(spack); + free(next_spack); + free(linebuf); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/spe/DrawSpanRenew.h Tue Jan 06 15:40:15 2009 +0900 @@ -0,0 +1,15 @@ +#ifndef INCLUDED_TASK_DRAW_SPAN2 +#define INCLUDED_TASK_DRAW_SPAN2 + +#ifndef INCLUDED_TASK_DRAW_SPAN +# include "DrawSpan.h" +#endif + +class DrawSpanRenew : public DrawSpan { +public: + SchedConstructor(DrawSpanRenew); + + int run(void *rbuf, void *wbuf); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Tue Jan 06 15:40:15 2009 +0900 @@ -0,0 +1,197 @@ +#include <stdlib.h> +#include <string.h> +#include "DrawSpanRenew.h" +#include "polygon_pack.h" +#include "SpanPack.h" +#include "texture.h" +#include "viewer_types.h" +#include "Func.h" + +#define SPAN_PACK_LOAD 0 +#define TEX_LOAD 1 + +SchedDefineTask(DrawSpanRenew); + +int +DrawSpanRenew::run(void *rbuf, void *wbuf) +{ + hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); + tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); + + int rangex_start = smanager->get_param(0); + int rangex_end = smanager->get_param(1); + + // このタスクが担当する x の範囲 + int rangex = rangex_end - rangex_start + 1; + + // y の範囲 (render_y + rangey - 1) + int rangey = smanager->get_param(2); + + float *zRow = (float*)smanager->allocate(sizeof(float)*rangex*rangey); + + for (int i = 0; i < rangex*rangey; i++) { + zRow[i] = 65535.0f; + } + + int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); + + for (int i = 0; i < rangey; i++) { + linebuf[i] = (int*)smanager->get_output(i); + linebuf_init(linebuf[i], rangex, 0xffffffff); + } + + SpanPackPtr spack = (SpanPackPtr)smanager->get_param(3); + SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + Span *span; + + // span->length_x の処理での再起動位置 + int js_cont = smanager->get_param(4); + + do { + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } + + for (int t = spack->info.start; t < spack->info.size; t++) { + span = &spack->span[t]; + + Uint32 rgb = 0x00ff00; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; + + /** + * Span が持つ 1 pixel 毎の + * テクスチャの座標 + */ + int tex_xpos; + int tex_ypos; + + /** + * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + uint32 *tex_addr; + + int x = span->x; + int y = span->y; + int x_len = span->length_x; + float z = span->start_z; + float zpos = span->end_z; + + // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + int localx = getLocalX(x-1); + int localy = getLocalY(y-1); + + if (x_len == 1) { + if (x < rangex_start || rangex_end < x) { + continue; + } + + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); + + if (zpos < zRow[localx + (rangex * localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + /** + * Tile が無い場合、一旦タスクはここで中断し、 + * Tile をロードするタスクを走らせた後に再起動する + */ + if (!isAvailableTile(tex_addr)) { + spack->info.start = t; + //set_rgb(tex_addr); + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, 0); + goto FINISH; + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex * localy)] = zpos; + linebuf[localy][localx] = rgb; + } + } else { + int js = (x < rangex_start) ? rangex_start - x : 0; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; + float tex_x, tex_y, tex_z; + + /** + * 一回比較すれば、以後再起動するまでは + * js_cont は使わないから 0 にしてるわけだけど、 + * 最初の一回のためだけにこれはめんどくさいのー。 + */ + js = (js < js_cont) ? js_cont : js; + js_cont = 0; + + for (int j = js; j <= je; j++) { + localx = getLocalX(x-1+j); + + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + if (!isAvailableTile(tex_addr)) { + printf("empty\n"); + spack->info.start = t; + //set_rgb(tex_addr); + set_rgbs(tex_addr, + getTile(span->tex_width-1, tex_ypos, + span->tex_width, span->tex_addr)); + reboot(spack, j); + goto FINISH; + } + + rgb = get_rgb(tex_localx, tex_localy, tex_addr); + + zRow[localx + (rangex*localy)] = tex_z; + linebuf[localy][localx] = rgb; + } + } + } + } + + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; + } while (spack); + + +FINISH: + free(spack); + free(next_spack); + free(linebuf); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/DrawSpanRenew.h Tue Jan 06 15:40:15 2009 +0900 @@ -0,0 +1,15 @@ +#ifndef INCLUDED_TASK_DRAW_SPAN2 +#define INCLUDED_TASK_DRAW_SPAN2 + +#ifndef INCLUDED_TASK_DRAW_SPAN +# include "DrawSpan.h" +#endif + +class DrawSpanRenew : public DrawSpan { +public: + SchedConstructor(DrawSpanRenew); + + int run(void *rbuf, void *wbuf); +}; + +#endif