Mercurial > hg > Game > Cerium
comparison TaskManager/Test/test_render/spe/DrawSpan.cpp @ 131:215c22c07a4c draft
fix
author | gongo@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Tue, 25 Nov 2008 17:24:18 +0900 |
parents | 95e2046eb46f |
children | 8f1419174cdf |
comparison
equal
deleted
inserted
replaced
130:40978d4b608a | 131:215c22c07a4c |
---|---|
60 int hashval = hash((uint32)key); | 60 int hashval = hash((uint32)key); |
61 | 61 |
62 for (int i = 0; i < hashsize/2; i++) { | 62 for (int i = 0; i < hashsize/2; i++) { |
63 int index = (hashval + i*i)%hashsize; | 63 int index = (hashval + i*i)%hashsize; |
64 | 64 |
65 if (hash_table[index]->texture_addr == key) { | 65 if (hash_table[index] != NULL && |
66 hash_table[index]->texture_addr == key) { | |
66 return hash_table[index]; | 67 return hash_table[index]; |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 return NULL; | 71 return NULL; |
104 return (char*)texture_image+(4*((8)*ty+tx)); | 105 return (char*)texture_image+(4*((8)*ty+tx)); |
105 #endif | 106 #endif |
106 } | 107 } |
107 | 108 |
108 Uint32 | 109 Uint32 |
109 DrawSpan::get_rgb(int tx, int ty, void *texture) | 110 DrawSpan::get_rgb(int tx, int ty, int tw, int th, void *texture) |
110 { | 111 { |
111 Uint8 red, green, blue, alpha; | 112 Uint8 red, green, blue, alpha; |
112 | 113 |
113 if (tx<0) tx = 0; | 114 if (tx<0) tx = 0; |
114 if (tex_width-1< tx) tx = tex_width-1 ; | 115 if (tw-1< tx) tx = tw-1 ; |
115 if (ty<0) ty = 0; | 116 if (ty<0) ty = 0; |
116 if (tex_height-1< ty) ty = tex_height-1 ; | 117 if (th-1< ty) ty = th-1 ; |
117 | 118 |
118 void *texture_addr; | 119 void *texture_addr; |
119 | 120 |
120 int blockX = tx / 8; | 121 int blockX = tx / 8; |
121 int blockY = ty / 8; | 122 int blockY = ty / 8; |
122 void** addrList = (void**)global_get(TEXTURE2_ID); | 123 void** addrList = (void**)global_get(TEXTURE2_ID); |
123 TilePtr tile; | 124 TilePtr tile; |
124 | 125 |
125 texture_addr = addrList[blockX + (tex_width/8)*blockY]; | 126 texture_addr = addrList[blockX + (tw/8)*blockY]; |
126 | 127 |
128 /** | |
129 * get,put はオブジェクト(Hashとか?)を作ってアクセスするかな | |
130 */ | |
127 tile = get(texture_addr); | 131 tile = get(texture_addr); |
128 if (tile == NULL) { | 132 if (tile == NULL) { |
129 if (tileList->size >= MAX_TILE) { | 133 if (tileList->size >= MAX_TILE) { |
130 tileList->init(); | 134 tileList->init(); |
131 bzero(hash_table, sizeof(TilePtr)*hashsize); | 135 bzero(hash_table, sizeof(TilePtr)*hashsize); |
136 | 140 |
137 smanager->dma_load(tile->pixel, (uint32)texture_addr, | 141 smanager->dma_load(tile->pixel, (uint32)texture_addr, |
138 sizeof(uint32)*64, TEX_LOAD); | 142 sizeof(uint32)*64, TEX_LOAD); |
139 | 143 |
140 int index = put(tile->texture_addr, tile); | 144 int index = put(tile->texture_addr, tile); |
145 | |
146 /** | |
147 * TODO: | |
148 * 入らなかったやつは | |
149 * 今までのやつを描画してから続きをするとか | |
150 */ | |
141 if (index < 0) { | 151 if (index < 0) { |
142 printf("[%p] Can't entry\n", tile); | 152 printf("[%p] Can't entry\n", tile); |
143 return 0xff0000; | 153 return 0xff0000; |
144 } | 154 } |
145 | 155 |
146 tileList->size++; | 156 tileList->size++; |
147 | 157 |
148 smanager->dma_wait(TEX_LOAD); | 158 smanager->dma_wait(TEX_LOAD); |
149 } | 159 } |
150 | 160 |
151 char *p = get_pixel(tx%8, ty%8, tile); | 161 char *p = get_pixel(tx%8, ty%8, tile->pixel); |
152 | 162 |
153 alpha = 255; | 163 alpha = 255; |
154 red = (Uint8) p[0]; | 164 red = (Uint8) p[0]; |
155 green = (Uint8) p[1]; | 165 green = (Uint8) p[1]; |
156 blue = (Uint8) p[2]; | 166 blue = (Uint8) p[2]; |
222 float zpos = span->end_z; | 232 float zpos = span->end_z; |
223 | 233 |
224 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 | 234 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 |
225 int localx = getLocalX(x-1); | 235 int localx = getLocalX(x-1); |
226 int localy = getLocalY(y-1); | 236 int localy = getLocalY(y-1); |
227 | 237 |
228 if (end == 1) { | 238 if (end == 1) { |
229 if (x < rangex_start || rangex_end < x) { | 239 if (x < rangex_start || rangex_end < x) { |
230 continue; | 240 continue; |
231 } | 241 } |
232 | |
233 tex_xpos = (int)((span->tex_height-1) * tex1); | 242 tex_xpos = (int)((span->tex_height-1) * tex1); |
234 tex_ypos = (int)((span->tex_width-1) * tey1); | 243 tex_ypos = (int)((span->tex_width-1) * tey1); |
235 tex_zpos = (int)z; | 244 tex_zpos = (int)z; |
236 | 245 |
237 if (zpos < zRow[localx + (rangex * localy)]) { | 246 if (zpos < zRow[localx + (rangex * localy)]) { |
238 rgb = get_rgb(tex_xpos, tex_ypos, texture_image); | 247 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width, |
248 span->tex_height, texture_image); | |
239 zRow[localx + (rangex * localy)] = zpos; | 249 zRow[localx + (rangex * localy)] = zpos; |
240 linebuf[localy][localx] = rgb; | 250 linebuf[localy][localx] = rgb; |
241 } | 251 } |
242 } else { | 252 } else { |
243 float tex_x, tex_y, tex_z; | 253 float tex_x, tex_y, tex_z; |
254 if (tex_y > 1) tex_y = 1; | 264 if (tex_y > 1) tex_y = 1; |
255 tex_xpos = (int)((span->tex_height-1) * tex_x); | 265 tex_xpos = (int)((span->tex_height-1) * tex_x); |
256 tex_ypos = (int)((span->tex_width-1) * tex_y); | 266 tex_ypos = (int)((span->tex_width-1) * tex_y); |
257 | 267 |
258 if (tex_z < zRow[localx + (rangex*localy)]) { | 268 if (tex_z < zRow[localx + (rangex*localy)]) { |
259 rgb = get_rgb(tex_xpos, tex_ypos, texture_image); | 269 rgb = get_rgb(tex_xpos, tex_ypos, span->tex_width, |
270 span->tex_height, texture_image); | |
260 zRow[localx + (rangex*localy)] = tex_z; | 271 zRow[localx + (rangex*localy)] = tex_z; |
261 linebuf[localy][localx] = rgb; | 272 linebuf[localy][localx] = rgb; |
262 } | 273 } |
263 } | 274 } |
264 } | 275 } |