Mercurial > hg > Game > Cerium
changeset 1158:bfc2c6628fef draft
not yet
author | Yutaka_Kinjyo |
---|---|
date | Tue, 26 Apr 2011 11:46:55 +0900 |
parents | ea68d54411a7 |
children | 42f5958ab74e |
files | Renderer/Engine/Makefile.def Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/task/DrawSpan.cc Renderer/Engine/task/DrawSpan.h |
diffstat | 4 files changed, 71 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/Makefile.def Mon Apr 25 21:55:41 2011 +0900 +++ b/Renderer/Engine/Makefile.def Tue Apr 26 11:46:55 2011 +0900 @@ -5,7 +5,7 @@ ABIBIT = 64 ABI = -m$(ABIBIT) CC = g++ -OPT = -O9 -DUSE_TASKARRAY -DUSE_PIPELINE # -g # +OPT = -DUSE_TASKARRAY -DUSE_PIPELINE -g #-O9 # CFLAGS = -Wall $(ABI) $(OPT) # -DDEBUG
--- a/Renderer/Engine/spe/DrawSpan.cc Mon Apr 25 21:55:41 2011 +0900 +++ b/Renderer/Engine/spe/DrawSpan.cc Tue Apr 26 11:46:55 2011 +0900 @@ -349,9 +349,6 @@ int js = (x < startx) ? startx - x : 0; int je = (x + x_len > endx) ? endx - x : x_len; - /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ - int tex_xpos, tex_ypos; - // span の始点に対応する座標 (tex1, tey1) float tex1 = span->tex_x1; float tey1 = span->tex_y1; @@ -373,25 +370,30 @@ int ret = je+1; - - //for (int j = js; j <= je; j++) { for (int j = je; j >= js; j--) { + float tex_z; + world_z -= z_inclination; localx = getLocalX(x-1+j); tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); if (tex_z < g->zRow[localx + (rangex*localy)]) { - float tex_x, tex_y, tex_z; + float tex_x, tex_y; 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; + + /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ + int tex_xpos, tex_ypos; + tex_xpos = (int)((span->tex_width-1) * tex_x); tex_ypos = (int)((span->tex_height-1) * tex_y);
--- a/Renderer/Engine/task/DrawSpan.cc Mon Apr 25 21:55:41 2011 +0900 +++ b/Renderer/Engine/task/DrawSpan.cc Tue Apr 26 11:46:55 2011 +0900 @@ -30,6 +30,20 @@ int doneWrite; } G, *Gptr; +/*double buffering するために、保持すべき状態*/ +typedef struct DrawParam { + + float tex_z; + int localx; + int tex_localx; + int tex_localy; + TilePtr tile; + float world_z; + int display; //他のオブジェクトの裏にいて表示するかしないかのflag + +} DrawParam, *DrawParamPtr; + + static int** linebuf_init(SchedTask *smanager, int width, int height, int rgb); static float* zRow_init(SchedTask *smanager, int width, int height); // static TilePtr set_rgb(memaddr addr, int wait_tag); @@ -50,7 +64,8 @@ static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); // static void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); -static memaddr getTexAddr(SchedTask *smanager, SpanPtr span, float &world_z, int startx, int endx, int je, Gptr g); +static int getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, + int endx, int index, int j, DrawParamPtr param); static int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z, SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z); @@ -312,102 +327,58 @@ drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) { - TilePtr tile[2] = {NULL}; int cur = 0; - - int x = span->x; - int rangex = endx - startx + 1; - int x_len = span->length_x; - - float normal_x = span->normal_x; - float normal_y = span->normal_y; - float normal_z = span->normal_z; - - int js = (x < startx) ? startx - x : 0; - int je = (x + x_len > endx) ? endx - x : x_len; - - /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ - int tex_xpos, tex_ypos; + DrawParamPtr param = (DrawParamPtr)smanager->allocate(sizeof(DrawParam)*2); - // span の始点に対応する座標 (tex1, tey1) - float tex1 = span->tex_x1; - float tey1 = span->tex_y1; - - // span の終点に対応する座標 (tex2, tey2) - float tex2 = span->tex_x2; - float tey2 = span->tex_y2; + int rangex = endx - startx + 1; - // span の始点、終点に対応する z 座標 - float zpos1 = span->start_z; - float zpos2 = span->end_z; + int js = (span->x < startx) ? startx - span->x : 0; + int je = (span->x + span->length_x > endx) ? endx - span->x : span->length_x; - //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 - float z_inclination = (zpos1 - zpos2) / x_len; - float world_z = zpos2; - - // Tile 内での座標 int localy = getLocalY(span->y-1); int ret = je+1; - if (!span->tex_addr) - return -1; // broken case, I'd like to write some thing... + int index = 0; - //ここに関数かな - memaddr tex_addr = getTexAddr(smanager, span, world_z, startx, endx, je, g); - tile[cur] = smanager->get_segment(tex_addr,g->tileList); + getDrawParam(smanager, g, span, localy, startx, endx, index, je, ¶m[cur]); + //for (int j = je; j >= js; j--) { <-もとはこうで、一度先にtextureをloadしておくから、je-1にしてる for (int j = je-1; j >= js; j--) { - world_z += z_inclination; - float tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - int localx = getLocalX(x-1+j); - - if (tex_z < g->zRow[localx + (rangex*localy)]) { - - float tex_x, tex_y; + index += 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); + getDrawParam(smanager, g, span, localy, startx, endx, index, j, ¶m[cur^1]); //次のループで使用するtexture - // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と - // そのブロックのアドレス(MainMemory) - memaddr tex_addr; - int tex_localx; - int tex_localy; - - tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, (memaddr)span->tex_addr); + if (param[cur].display) { + smanager->wait_segment(param[cur].tile); // 前でload命令を出しておいたtextureを待つ。 - //tex_addr = getTextAddr(); - tile[cur^1] = smanager->get_segment(tex_addr,g->tileList); - - tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; - tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - //TilePtr tile = smanager->get_segment(tex_addr,g->tileList); - //smanager->wait_segment(tile); - smanager->wait_segment(tile[cur]); - - updateBuffer(g, tex_z, rangex, localx, localy, - tex_localx, tex_localy, - normal_x, normal_y, normal_z, tile[cur], - span->x+j, span->y, world_z, smanager); + updateBuffer(g, param[cur].tex_z, rangex, param[cur].localx, localy, + param[cur].tex_localx, param[cur].tex_localy, + span->normal_x, span->normal_y, span->normal_z, param[cur].tile, + span->x+j+1, span->y, param[cur].world_z, smanager); } cur ^= 1; } + if (param[cur].display) { + smanager->wait_segment(param[cur].tile); + + updateBuffer(g, param[cur].tex_z, rangex, param[cur].localx, localy, + param[cur].tex_localx, param[cur].tex_localy, + span->normal_x, span->normal_y, span->normal_z, param[cur].tile, + span->x+js, span->y, param[cur].world_z, smanager); + + } + + free(param); + return ret; } -static memaddr -getTexAddr(SchedTask *smanager, SpanPtr span, float &world_z, int startx, int endx, int j, Gptr g) { +static int +getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param) { int x = span->x; int rangex = endx - startx + 1; @@ -430,15 +401,12 @@ //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 float z_inclination = (zpos1 - zpos2) / x_len; - - // Tile 内での座標 - int localy = getLocalY(span->y-1); + param->world_z = (z_inclination*index); - world_z += z_inclination; - float tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - int localx = getLocalX(x-1+j); + param->tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + param->localx = getLocalX(x-1+j); - if (tex_z < g->zRow[localx + (rangex*localy)]) { + if (param->tex_z < g->zRow[param->localx + (rangex*localy)]) { float tex_x, tex_y; @@ -455,14 +423,23 @@ // そのブロックのアドレス(MainMemory) memaddr tex_addr; + if (!span->tex_addr) return -1; // broken case, I'd like to write some thing... tex_addr = getTile(tex_xpos, tex_ypos, span->tex_width, (memaddr)span->tex_addr); - - return tex_addr; + param->tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + param->tex_localy = tex_xpos % TEXTURE_SPLIT_PIXEL; + + param->display = 1; // z軸の一番まえだから表示されるよ + + param->tile = smanager->get_segment(tex_addr, g->tileList); + + return 1; // } - return NULL; + param->display = 0; //z軸の前に他のオブジェクトがあるので、計算しなくていい。 + + return 1; }