comparison TaskManager/Test/test_render/task/DrawSpan.cpp @ 166:e297ecaf2b4d

fix
author gongo@localhost.localdomain
date Tue, 09 Dec 2008 11:53:51 +0900
parents 38cbb7aecc70
children c8b868871dce
comparison
equal deleted inserted replaced
165:246881f0634b 166:e297ecaf2b4d
6 #include "texture.h" 6 #include "texture.h"
7 #include "viewer_types.h" 7 #include "viewer_types.h"
8 8
9 #define SPAN_PACK_LOAD 0 9 #define SPAN_PACK_LOAD 0
10 #define TEX_LOAD 1 10 #define TEX_LOAD 1
11 #define TILE_INFO_LOAD 2
12 11
13 SchedDefineTask(DrawSpan); 12 SchedDefineTask(DrawSpan);
14 13
15 static const int hashsize = 263; 14 static const int hashsize = 263;
16 15
155 return zRow; 154 return zRow;
156 } 155 }
157 156
158 157
159 char* 158 char*
160 DrawSpan::get_pixel(int tx, int ty, void *texture_image) 159 DrawSpan::get_pixel(int tx, int ty, uint32 *texture_image)
161 { 160 {
162 return (char*)texture_image+(4*((TEXTURE_SPLIT_PIXEL)*ty+tx)); 161 return (char*)(texture_image+((TEXTURE_SPLIT_PIXEL)*ty+tx));
163 } 162 }
164 163
165 Uint32 164 Uint32
166 DrawSpan::get_rgb(int tx, int ty, void *addr) 165 DrawSpan::get_rgb(int tx, int ty, uint32 *addr)
167 { 166 {
168 Uint8 red, green, blue, alpha; 167 Uint8 red, green, blue, alpha;
169 TilePtr tile; 168 TilePtr tile;
170 169
171 /** 170 /**
263 float tex1 = span->tex_x1; 262 float tex1 = span->tex_x1;
264 float tex2 = span->tex_x2; 263 float tex2 = span->tex_x2;
265 float tey1 = span->tex_y1; 264 float tey1 = span->tex_y1;
266 float tey2 = span->tex_y2; 265 float tey2 = span->tex_y2;
267 266
267 /**
268 * Span が持つ 1 pixel 毎の
269 * テクスチャの座標
270 */
268 int tex_xpos; 271 int tex_xpos;
269 int tex_ypos; 272 int tex_ypos;
270 int tex_zpos; 273
271 274 /**
275 * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と
276 * そのブロックのアドレス(MainMemory)
277 */
272 int tex_localx; 278 int tex_localx;
273 int tex_localy; 279 int tex_localy;
274 uint32 *tex_addr; 280 uint32 *tex_addr;
275 281
276 int x = span->x; 282 int x = span->x;
288 continue; 294 continue;
289 } 295 }
290 296
291 tex_xpos = (int)((span->tex_width-1) * tex1); 297 tex_xpos = (int)((span->tex_width-1) * tex1);
292 tex_ypos = (int)((span->tex_height-1) * tey1); 298 tex_ypos = (int)((span->tex_height-1) * tey1);
293 tex_zpos = (int)z;
294 299
295 if (zpos < zRow[localx + (rangex * localy)]) { 300 if (zpos < zRow[localx + (rangex * localy)]) {
301 tex_addr = getTile(tex_xpos, tex_ypos,
302 span->tex_width, span->tex_addr);
296 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; 303 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
297 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; 304 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
298 tex_addr = getTile(tex_xpos, tex_ypos, 305
299 span->tex_width, span->tex_addr);
300
301 rgb = get_rgb(tex_localx, tex_localy, tex_addr); 306 rgb = get_rgb(tex_localx, tex_localy, tex_addr);
302 307
303 zRow[localx + (rangex * localy)] = zpos; 308 zRow[localx + (rangex * localy)] = zpos;
304 linebuf[localy][localx] = rgb; 309 linebuf[localy][localx] = rgb;
305 } 310 }
313 318
314 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); 319 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1);
315 320
316 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); 321 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1);
317 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); 322 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1);
323 /**
324 * ・・・なんかかっこいい書き方ないかな
325 */
318 if (tex_x > 1) tex_x = 1; 326 if (tex_x > 1) tex_x = 1;
327 if (tex_x < 0) tex_x = 0;
319 if (tex_y > 1) tex_y = 1; 328 if (tex_y > 1) tex_y = 1;
329 if (tex_y < 0) tex_y = 0;
320 tex_xpos = (int)((span->tex_width-1) * tex_x); 330 tex_xpos = (int)((span->tex_width-1) * tex_x);
321 tex_ypos = (int)((span->tex_height-1) * tex_y); 331 tex_ypos = (int)((span->tex_height-1) * tex_y);
322 332
323 if (tex_z < zRow[localx + (rangex*localy)]) { 333 if (tex_z < zRow[localx + (rangex*localy)]) {
334 tex_addr = getTile(tex_xpos, tex_ypos,
335 span->tex_width, span->tex_addr);
324 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; 336 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL;
325 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; 337 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
326 tex_addr = getTile(tex_xpos, tex_ypos,
327 span->tex_width, span->tex_addr);
328 338
329 rgb = get_rgb(tex_localx, tex_localy, tex_addr); 339 rgb = get_rgb(tex_localx, tex_localy, tex_addr);
330 340
331 zRow[localx + (rangex*localy)] = tex_z; 341 zRow[localx + (rangex*localy)] = tex_z;
332 linebuf[localy][localx] = rgb; 342 linebuf[localy][localx] = rgb;