changeset 1047:6a80ca9a65d9

broken texure ( h/w != 2^n ) protection
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 08 Dec 2010 05:38:45 +0900
parents 8c75060eb153
children 40cde8c1a6cd
files Renderer/Engine/Camera.cc Renderer/Engine/Makefile.def Renderer/Engine/SceneGraph.cc Renderer/Engine/TextureHash.h Renderer/Engine/polygon.cc Renderer/Engine/sys.cc Renderer/Engine/task/CreateSpan.cc Renderer/Engine/task/DrawSpan.cc Renderer/Test/Makefile.def
diffstat 9 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Camera.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/Camera.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -157,6 +157,7 @@
       }
     }
 
+    update(w,h); // to make matrix[]
 }
 
 Camera::~Camera(void)
--- a/Renderer/Engine/Makefile.def	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/Makefile.def	Wed Dec 08 05:38:45 2010 +0900
@@ -5,7 +5,7 @@
 ABIBIT = 32 
 ABI = -m$(ABIBIT)
 CC      = g++
-OPT	= -g -O9 #-DSPE_CREATE_POLYGON_CHECK -DSPE_CREATE_POLYGON=1
+OPT	= -g # -O9 #-DSPE_CREATE_POLYGON_CHECK -DSPE_CREATE_POLYGON=1
 CFLAGS  = -Wall $(ABI) $(OPT)  #  -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I.
--- a/Renderer/Engine/SceneGraph.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -483,6 +483,8 @@
                 int tex_w = texture_image->w;
                 int tex_h = texture_image->h;
                 int all_pixel_num = 0;
+		int nw = tex_w;
+		int nh = tex_h;
 
                 /**
                  * テクスチャの w or h が 8 pixel で分割できる間、
@@ -495,6 +497,9 @@
                  *  (128, 64) => 64,32 : 32,16: 16,8
                  *     scale = 8
                  */
+		//if (tex_w!=power_of_two(tex_w)) nw = tex_w = power_of_two(tex_w)/2;
+		//if (tex_h!=power_of_two(tex_h)) nh = tex_h = power_of_two(tex_h)/2;
+
                 while (tex_w % TEXTURE_SPLIT_PIXEL == 0 &&
                        tex_h % TEXTURE_SPLIT_PIXEL == 0) {
                     all_pixel_num += tex_w*tex_h;
@@ -504,13 +509,14 @@
                 }
 
                 scale >>= 1;
+		// scale==0 means broken texture
 
                 tapestry = makeTapestry(manager, texture_image->w, texture_image->h,
                                         (uint32*)texture_image->pixels,
                                         all_pixel_num, scale);
 
-                list[id].t_w = texture_image->w;
-                list[id].t_h = texture_image->h;
+                list[id].t_w = nw;
+                list[id].t_h = nh;
                 list[id].pixels_orig = (Uint32*)texture_image->pixels;
                 list[id].pixels = tapestry;
                 list[id].scale_max = scale;
--- a/Renderer/Engine/TextureHash.h	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/TextureHash.h	Wed Dec 08 05:38:45 2010 +0900
@@ -16,6 +16,7 @@
     ~TextureHash(void);
     int hash_function(const char* image_name);
     int hash_regist(const char* image_name, int &tx_id);
+    void remove(int id) {  table[id].tx_id = -1; }
 };
 
 #endif
--- a/Renderer/Engine/polygon.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/polygon.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -14,9 +14,6 @@
 #include "viewer_types.h"
 using namespace std;
 
-//extern int decode(char *cont, char *file_name);
-extern int decode(char *cont, FILE *outfile);
-
 
 Polygon::Polygon(void)
 {
--- a/Renderer/Engine/sys.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/sys.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -146,7 +146,12 @@
     }
 }
 
-void get_matrix( float *matrix, float *rxyz, float *txyz, float *stack)
+/**
+       stack 上の変換行列に、相対的に、rxyz の回転、txyz の平行移動を
+       行ったものを matrix に代入する
+ */
+void
+get_matrix( float *matrix, float *rxyz, float *txyz, float *stack)
 {
   float radx,rady,radz;
   radx = rxyz[0]*3.14/180;
--- a/Renderer/Engine/task/CreateSpan.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/task/CreateSpan.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -153,6 +153,7 @@
     int base, tex_base;
     int scale = 1;
 
+    if (scale_max==0) return 1; // broken case
     /**
      * width と height で、長い方を基準に、
      * texture の scale を決める
--- a/Renderer/Engine/task/DrawSpan.cc	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Wed Dec 08 05:38:45 2010 +0900
@@ -267,6 +267,7 @@
     tex_ypos = (int)((span->tex_height-1) * tey);
 
     if (zpos < g->zRow[localx + (rangex*localy)]) {
+	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);
         tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
@@ -374,6 +375,7 @@
             int tex_localx;
             int tex_localy;
 
+	    if (!span->tex_addr) continue; // broken case, I'd like to write some thing...
             tex_addr = getTile(tex_xpos, tex_ypos,
                                span->tex_width, (memaddr)span->tex_addr);
             tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
--- a/Renderer/Test/Makefile.def	Wed Dec 08 02:41:36 2010 +0900
+++ b/Renderer/Test/Makefile.def	Wed Dec 08 05:38:45 2010 +0900
@@ -4,7 +4,7 @@
 ABIBIT = 32
 ABI =  -m$(ABIBIT)
 CC      = g++
-CFLAGS  = -g -Wall $(ABI) -O9   # -O -DDEBUG
+CFLAGS  = -g -Wall $(ABI) # -O9   # -O -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I$(CERIUM)/Renderer/Engine -I. -I$(CERIUM)/include/Cerium
 LIBS = -L$(CERIUM)/TaskManager -L$(CERIUM)/Renderer/Engine $(ABI)