Mercurial > hg > Game > Cerium
diff Renderer/Engine/task/DrawSpan.cc @ 1157:ea68d54411a7 draft
not yet
author | Yutaka_Kinjyo |
---|---|
date | Mon, 25 Apr 2011 21:55:41 +0900 |
parents | 4e898dca4ab9 |
children | bfc2c6628fef |
line wrap: on
line diff
--- a/Renderer/Engine/task/DrawSpan.cc Wed Apr 20 16:31:11 2011 +0900 +++ b/Renderer/Engine/task/DrawSpan.cc Mon Apr 25 21:55:41 2011 +0900 @@ -50,10 +50,14 @@ 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 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); + + static float innerProduct1(float *v0, float *v1) { @@ -261,6 +265,7 @@ tex_ypos = (int)((span->tex_height-1) * tey); if (zpos < g->zRow[localx + (rangex*localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, span->tex_width, (memaddr)span->tex_addr); tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; @@ -306,6 +311,10 @@ static int 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; @@ -314,7 +323,6 @@ 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; @@ -338,22 +346,102 @@ float world_z = zpos2; // Tile 内での座標 - int localx, localy = getLocalY(span->y-1); + 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... - //for (int j = js; j <= je; j++) { - for (int j = je; j >= js; j--) { - float tex_x, tex_y, tex_z; + //ここに関数かな + memaddr tex_addr = getTexAddr(smanager, span, world_z, startx, endx, je, g); + tile[cur] = smanager->get_segment(tex_addr,g->tileList); + + 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); - localx = getLocalX(x-1+j); + if (tex_z < g->zRow[localx + (rangex*localy)]) { + + 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; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + // (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); + + //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); + } + + cur ^= 1; - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + } + + return ret; +} + +static memaddr +getTexAddr(SchedTask *smanager, SpanPtr span, float &world_z, int startx, int endx, int j, Gptr g) { + + int x = span->x; + int rangex = endx - startx + 1; + int x_len = span->length_x; + + /* 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; + // span の終点に対応する座標 (tex2, tey2) + float tex2 = span->tex_x2; + float tey2 = span->tex_y2; + + // span の始点、終点に対応する z 座標 + float zpos1 = span->start_z; + float zpos2 = span->end_z; + + //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 + float z_inclination = (zpos1 - zpos2) / x_len; + + // Tile 内での座標 + int localy = getLocalY(span->y-1); + + 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; + 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; @@ -362,29 +450,20 @@ 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 < g->zRow[localx + (rangex*localy)]) { - // (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); - 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); - - updateBuffer(g, tex_z, rangex, localx, localy, - tex_localx, tex_localy, - normal_x, normal_y, normal_z, tile, - span->x+j, span->y, world_z, smanager); - } + + // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と + // そのブロックのアドレス(MainMemory) + memaddr tex_addr; + + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, (memaddr)span->tex_addr); + + + return tex_addr; } - return ret; + return NULL; + } static int