changeset 1157:ea68d54411a7 draft

not yet
author Yutaka_Kinjyo
date Mon, 25 Apr 2011 21:55:41 +0900
parents cb7b88c8c8c9
children bfc2c6628fef
files Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/task/DrawSpan.cc Renderer/Engine/task/DrawSpan.h Renderer/Engine/viewer.cc
diffstat 4 files changed, 127 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/spe/DrawSpan.cc	Wed Apr 20 16:31:11 2011 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Mon Apr 25 21:55:41 2011 +0900
@@ -316,6 +316,8 @@
 }
 #endif
 
+
+
 /**
  * 長さが 1 より大きい Span の描画
  *
@@ -344,7 +346,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;
 
@@ -372,26 +373,28 @@
 
     int ret = je+1;
 
+
+
     //for (int j = js; j <= je; j++) {
     for (int j = je; j >= js; j--) {
-        float tex_x, tex_y, 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);
 
-        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 < g->zRow[localx + (rangex*localy)]) {
+
+            float tex_x, tex_y, tex_z;
 
-        if (tex_z < g->zRow[localx + (rangex*localy)]) {
+            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;
--- 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
--- a/Renderer/Engine/task/DrawSpan.h	Wed Apr 20 16:31:11 2011 +0900
+++ b/Renderer/Engine/task/DrawSpan.h	Mon Apr 25 21:55:41 2011 +0900
@@ -1,5 +1,4 @@
 #ifndef INCLUDED_TASK_DRAW_SPAN
 #define INCLUDED_TASK_DRAW_SPAN
 
-
 #endif
--- a/Renderer/Engine/viewer.cc	Wed Apr 20 16:31:11 2011 +0900
+++ b/Renderer/Engine/viewer.cc	Mon Apr 25 21:55:41 2011 +0900
@@ -599,12 +599,11 @@
 #ifdef USE_TASKARRAY
 
 	// mem_flag は spe 側で黒い部分を 0 で埋めるフラグ
-	if(spack->info.size > 0 || mem_flag == 1) {
 
-	  int array_task_num = (this->width + split_screen_w - 1) / split_screen_w;
-	  HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey);
-	  Task *task_draw = 0;
-	  
+        int array_task_num = (this->width + split_screen_w - 1) / split_screen_w;
+        HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey);
+        Task *task_draw = 0;
+        
 	  while (startx < this->width) {
 	    
 	    // Draw SpanPack
@@ -641,17 +640,6 @@
 	  task_next->wait_for(task_draw_array);
 #endif
 	  task_draw_array->spawn();
-
-	  
-	 
-        } else {
-
-	  memset(&pixels[(startx-1)+this->width*(starty-1)],
-		 0, (this->width)*sizeof(int)*rangey);
-
-	}
-	  
-
 #else
 
        HTaskPtr task_draw;