Mercurial > hg > Members > kono > Cerium
view TaskManager/Test/test_render/spe/DrawSpan.cpp @ 266:5c9dbd54cd51
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Jun 2009 00:00:09 +0900 |
parents | 54787f182881 d949e590da26 |
children | 7f2b30acf311 |
line wrap: on
line source
#include <stdlib.h> #include <string.h> #include "DrawSpan.h" #include "polygon_pack.h" #include "SpanPack.h" #include "texture.h" #include "viewer_types.h" #include "TileHash.h" #define SPAN_PACK_LOAD 0 #define TEX_LOAD 1 SchedDefineTask(DrawSpan); <<<<<<< local static TileHashPtr hash; ======= <<<<<<< local static const int hashsize = 263; static TilePtr hash_table[hashsize] = {NULL}; unsigned short PRIME[8] = { 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd, }; >>>>>>> other static TileListPtr tileList; /** * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する * * +---+---+---+---+---+---+ * | 0 | 1 | 2 | 3 | 4 | 5 | * +---+---+---+---+---+---+ * | | | | | |11 | * +---+---+---+---+---+---+ * | | | | | |17 | * +---+---+---+---+---+---+ * | | | | | |23 | * +---+---+---+---+---+---+ * | | | | | |29 | * +---+---+---+---+---+---+ * | | | | | |35 | * +---+---+---+---+---+---+ * * 一辺を TEXTURE_SPLIT とする * 各ブロックの数字がブロックIDとなる。 */ /** * テクスチャの座標から、 * テクスチャのどのブロックかを求める * * @param[in] tx X coordinates of texture * @param[in] tx Y coordinates of texture * @param[in] twidth Width of texture * @return block ID */ static inline int get_tex_block(int tx, int ty, int twidth) { int blockX, blockY; blockX = tx / TEXTURE_SPLIT_PIXEL; blockY = ty / TEXTURE_SPLIT_PIXEL; return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; } /** * block ID と、テクスチャの TOP address から * (tx,ty) で使われるテクスチャの Tile addres を求める * * @param[in] tx X coordinates of texture * @param[in] tx Y coordinates of texture * @param[in] tw Width of texture * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address * @return block ID */ static inline uint32* getTile(int tx, int ty, int tw, uint32 *tex_addr_top) { int block = get_tex_block(tx, ty, tw); return tex_addr_top + block*TEXTURE_BLOCK_SIZE; } ======= static unsigned char *tex; >>>>>>> other void DrawSpan::linebuf_init(int *buf, int x, int rgb) { for (int i = 0; i < x; i++) { buf[i] = rgb; } } Uint32 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) { TilePtr tile; tile = hash->get(addr); if (tile == NULL) { tile = tileList->nextTile(); /** * FIFO なので、もし前のが残っていれば削除 */ hash->remove(tile->texture_addr); tile->texture_addr = addr; smanager->dma_load(tile->pixel, (uint32)addr, sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD); int index = hash->put(tile->texture_addr, tile); /** * TODO: * 入らなかったやつは * 今までのやつを描画してから続きをするとか */ if (index < 0) { printf("[%p] Can't entry\n", tile); return 0xff0000; } smanager->dma_wait(TEX_LOAD); } return tile->pixel[(TEXTURE_SPLIT_PIXEL)*ty+tx]; } int DrawSpan::run(void *rbuf, void *wbuf) { SpanPack *spack = (SpanPack*)smanager->get_input(0); SpanPack *next_spack = (SpanPack*)smanager->allocate(sizeof(SpanPack)); SpanPack *free_spack = next_spack; // next_spack の free() 用 Span *span; 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->get_input(1); int **linebuf = (int**)smanager->allocate(sizeof(int*)*rangey); for (int i = 0; i < rangey; i++) { linebuf[i] = (int*)smanager->get_output(i); <<<<<<< local linebuf_init(linebuf[i], rangex, 0xffffffff); ======= <<<<<<< local linebuf_init(linebuf[i], rangex, 0xffffff); ======= //linebuf_init(linebuf[i], rangex, 0x00ff00ff); linebuf_init(linebuf[i], rangex, 0); >>>>>>> other >>>>>>> other } 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; 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; 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; 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); SpanPack *tmp_spack = spack; spack = next_spack; next_spack = tmp_spack; } while (spack); free(free_spack); free(linebuf); <<<<<<< local ======= free(zRow); <<<<<<< local ======= <<<<<<< local free(tileList); free(tilist); free(next_tilist); >>>>>>> other >>>>>>> other ======= free(tex); >>>>>>> other return 0; }