| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Routines to draw the texture mapped scanlines. |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#include <math.h> |
| 27 |
#include <limits.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <stdint.h> |
| 31 |
#include <string.h> |
| 32 |
#include "maths.h" |
| 33 |
#include "gr.h" |
| 34 |
#include "grdef.h" |
| 35 |
#include "texmap.h" |
| 36 |
#include "texmapl.h" |
| 37 |
#include "scanline.h" |
| 38 |
#include "strutil.h" |
| 39 |
#include "dxxerror.h" |
| 40 |
|
| 41 |
namespace dcx { |
| 42 |
|
| 43 |
tmap_scanline_function_table tmap_scanline_functions; |
| 44 |
|
| 45 |
void c_tmap_scanline_flat() |
| 46 |
{ |
| 47 |
uint8_t *dest; |
| 48 |
int x, index = fx_xleft + (bytes_per_row * fx_y ); |
| 49 |
|
| 50 |
dest = (write_buffer + fx_xleft + (bytes_per_row * fx_y )); |
| 51 |
|
| 52 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 53 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 54 |
*dest++ = tmap_flat_color; |
| 55 |
} |
| 56 |
// memset(dest,tmap_flat_color,fx_xright-fx_xleft+1); |
| 57 |
} |
| 58 |
|
| 59 |
void c_tmap_scanline_shaded(const gr_fade_level fade) |
| 60 |
{ |
| 61 |
uint8_t tmp; |
| 62 |
int x, index = fx_xleft + (bytes_per_row * fx_y ); |
| 63 |
|
| 64 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 65 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 66 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 67 |
tmp = *dest; |
| 68 |
*dest++ = gr_fade_table[fade][tmp]; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
void c_tmap_scanline_lin_nolight() |
| 73 |
{ |
| 74 |
uint c; |
| 75 |
int x, index = fx_xleft + (bytes_per_row * fx_y ); |
| 76 |
fix u,v,dudx, dvdx; |
| 77 |
|
| 78 |
u = fx_u; |
| 79 |
v = fx_v*64; |
| 80 |
dudx = fx_du_dx; |
| 81 |
dvdx = fx_dv_dx*64; |
| 82 |
|
| 83 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 84 |
|
| 85 |
if (!Transparency_on) { |
| 86 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 87 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 88 |
*dest++ = static_cast<uint32_t>(pixptr[ (f2i(v)&(64*63)) + (f2i(u)&63) ]); |
| 89 |
u += dudx; |
| 90 |
v += dvdx; |
| 91 |
} |
| 92 |
} else { |
| 93 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 94 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 95 |
c = static_cast<uint32_t>(pixptr[ (f2i(v)&(64*63)) + (f2i(u)&63) ]); |
| 96 |
if ( c!=255) |
| 97 |
*dest = c; |
| 98 |
dest++; |
| 99 |
u += dudx; |
| 100 |
v += dvdx; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
void c_tmap_scanline_lin() |
| 106 |
{ |
| 107 |
uint c; |
| 108 |
int x, j, index = fx_xleft + (bytes_per_row * fx_y); |
| 109 |
fix u,v,l,dudx, dvdx, dldx; |
| 110 |
|
| 111 |
u = fx_u; |
| 112 |
v = fx_v*64; |
| 113 |
dudx = fx_du_dx; |
| 114 |
dvdx = fx_dv_dx*64; |
| 115 |
|
| 116 |
l = fx_l>>8; |
| 117 |
dldx = fx_dl_dx/256; |
| 118 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 119 |
|
| 120 |
if (!Transparency_on) { |
| 121 |
const auto read_fade_table_entry = [&fadeTableLocalCopy = gr_fade_table, pixPtrLocalCopy = pixptr](const fix l, const fix v, const fix u) { |
| 122 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 123 |
return fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[(f2i(v) & (64 * 63)) + (f2i(u) & 63)]]; |
| 124 |
//end edit -MM |
| 125 |
}; |
| 126 |
x = fx_xright-fx_xleft+1; |
| 127 |
|
| 128 |
if ((j = reinterpret_cast<uintptr_t>(dest) & 3) != 0) |
| 129 |
{ |
| 130 |
j = 4 - j; |
| 131 |
|
| 132 |
if (j > x) |
| 133 |
j = x; |
| 134 |
|
| 135 |
while (j > 0) |
| 136 |
{ |
| 137 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 138 |
*dest++ = read_fade_table_entry(l, v, u); |
| 139 |
l += dldx; |
| 140 |
u += dudx; |
| 141 |
v += dvdx; |
| 142 |
x--; |
| 143 |
j--; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
j &= ~3; |
| 148 |
while (j > 0) |
| 149 |
{ |
| 150 |
uint32_t destlong; |
| 151 |
destlong = read_fade_table_entry(l, v, u) << 24; |
| 152 |
l += dldx; |
| 153 |
u += dudx; |
| 154 |
v += dvdx; |
| 155 |
destlong |= read_fade_table_entry(l, v, u) << 16; |
| 156 |
l += dldx; |
| 157 |
u += dudx; |
| 158 |
v += dvdx; |
| 159 |
destlong |= read_fade_table_entry(l, v, u) << 8; |
| 160 |
l += dldx; |
| 161 |
u += dudx; |
| 162 |
v += dvdx; |
| 163 |
destlong |= read_fade_table_entry(l, v, u); |
| 164 |
l += dldx; |
| 165 |
u += dudx; |
| 166 |
v += dvdx; |
| 167 |
*reinterpret_cast<uint32_t *>(dest) = destlong; |
| 168 |
dest += 4; |
| 169 |
x -= 4; |
| 170 |
j -= 4; |
| 171 |
index += 4; |
| 172 |
if (index+4 >= SWIDTH*SHEIGHT) return; |
| 173 |
} |
| 174 |
|
| 175 |
while (x-- > 0) |
| 176 |
{ |
| 177 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 178 |
*dest++ = read_fade_table_entry(l, v, u); |
| 179 |
l += dldx; |
| 180 |
u += dudx; |
| 181 |
v += dvdx; |
| 182 |
} |
| 183 |
|
| 184 |
} else { |
| 185 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 186 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 187 |
c = static_cast<uint32_t>(pixptr[ (f2i(v)&(64*63)) + (f2i(u)&63) ]); |
| 188 |
if ( c!=TRANSPARENCY_COLOR) |
| 189 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 190 |
*dest = gr_fade_table.base_type::operator[]((l >> 8) & 0x7f)[c]; |
| 191 |
//end edit -MM |
| 192 |
dest++; |
| 193 |
l += dldx; |
| 194 |
u += dudx; |
| 195 |
v += dvdx; |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
// This texture mapper uses floating point extensively and writes 8 pixels at once, so it likely works |
| 201 |
// best on 64 bit RISC processors. |
| 202 |
// WARNING: it is not endian clean. For big endian, reverse the shift counts in the unrolled loops. I |
| 203 |
// have no means to test that, so I didn't try it. Please tell me if you get this to work on a big |
| 204 |
// endian machine. |
| 205 |
// If you're using an Alpha, use the Compaq compiler for this file for quite some fps more. |
| 206 |
// Unfortunately, it won't compile the whole source, so simply compile everything, change the |
| 207 |
// compiler to ccc, remove scanline.o and compile again. |
| 208 |
// Please send comments/suggestions to [email protected]. |
| 209 |
static void c_fp_tmap_scanline_per() |
| 210 |
{ |
| 211 |
const auto read_pixptr_entry = [pixPtrLocalCopy = pixptr](const double rec_z, const fix v, const fix u) { |
| 212 |
return pixPtrLocalCopy[((static_cast<int>(v * rec_z)) & (64 * 63)) + ((static_cast<int>(u * rec_z)) & 63)]; |
| 213 |
}; |
| 214 |
const auto read_fade_table_entry = [&fadeTableLocalCopy = gr_fade_table, &read_pixptr_entry](const double rec_z, const fix v, const fix u, const double l) { |
| 215 |
return fadeTableLocalCopy.base_type::operator[](static_cast<int>(fabs(l)))[read_pixptr_entry(rec_z, v, u)]; |
| 216 |
}; |
| 217 |
const auto read_opaque_fade_table_entry = [&fadeTableLocalCopy = gr_fade_table](const double l, const unsigned c) { |
| 218 |
return fadeTableLocalCopy.base_type::operator[](static_cast<int>(fabs(l)))[c]; |
| 219 |
}; |
| 220 |
uint c; |
| 221 |
int x, j, index = fx_xleft + (bytes_per_row * fx_y); |
| 222 |
double u, v, z, l, dudx, dvdx, dzdx, dldx, rec_z; |
| 223 |
|
| 224 |
u = f2db(fx_u); |
| 225 |
v = f2db(fx_v) * 64.0; |
| 226 |
z = f2db(fx_z); |
| 227 |
l = f2db(fx_l); |
| 228 |
dudx = f2db(fx_du_dx); |
| 229 |
dvdx = f2db(fx_dv_dx) * 64.0; |
| 230 |
dzdx = f2db(fx_dz_dx); |
| 231 |
dldx = f2db(fx_dl_dx); |
| 232 |
|
| 233 |
rec_z = 1.0 / z; // gcc 2.95.2 is won't do this optimization itself |
| 234 |
|
| 235 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 236 |
x = fx_xright - fx_xleft + 1; |
| 237 |
|
| 238 |
if (!Transparency_on) { |
| 239 |
if (x >= 8) { |
| 240 |
if ((j = reinterpret_cast<uintptr_t>(dest) & 7) != 0) { |
| 241 |
j = 8 - j; |
| 242 |
|
| 243 |
while (j > 0) { |
| 244 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 245 |
*dest++ = |
| 246 |
read_fade_table_entry(rec_z, v, u, l); |
| 247 |
l += dldx; |
| 248 |
u += dudx; |
| 249 |
v += dvdx; |
| 250 |
z += dzdx; |
| 251 |
rec_z = 1.0 / z; |
| 252 |
x--; |
| 253 |
j--; |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
j = x; |
| 258 |
while (j >= 8) { |
| 259 |
uint64_t destlong = |
| 260 |
read_fade_table_entry(rec_z, v, u, l); |
| 261 |
l += dldx; |
| 262 |
u += dudx; |
| 263 |
v += dvdx; |
| 264 |
z += dzdx; |
| 265 |
rec_z = 1.0 / z; |
| 266 |
destlong |= |
| 267 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 8; |
| 268 |
l += dldx; |
| 269 |
u += dudx; |
| 270 |
v += dvdx; |
| 271 |
z += dzdx; |
| 272 |
rec_z = 1.0 / z; |
| 273 |
destlong |= |
| 274 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 16; |
| 275 |
l += dldx; |
| 276 |
u += dudx; |
| 277 |
v += dvdx; |
| 278 |
z += dzdx; |
| 279 |
rec_z = 1.0 / z; |
| 280 |
destlong |= |
| 281 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 24; |
| 282 |
l += dldx; |
| 283 |
u += dudx; |
| 284 |
v += dvdx; |
| 285 |
z += dzdx; |
| 286 |
rec_z = 1.0 / z; |
| 287 |
destlong |= |
| 288 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 32; |
| 289 |
l += dldx; |
| 290 |
u += dudx; |
| 291 |
v += dvdx; |
| 292 |
z += dzdx; |
| 293 |
rec_z = 1.0 / z; |
| 294 |
destlong |= |
| 295 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 40; |
| 296 |
l += dldx; |
| 297 |
u += dudx; |
| 298 |
v += dvdx; |
| 299 |
z += dzdx; |
| 300 |
rec_z = 1.0 / z; |
| 301 |
destlong |= |
| 302 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 48; |
| 303 |
l += dldx; |
| 304 |
u += dudx; |
| 305 |
v += dvdx; |
| 306 |
z += dzdx; |
| 307 |
rec_z = 1.0 / z; |
| 308 |
destlong |= |
| 309 |
static_cast<uint64_t>(read_fade_table_entry(rec_z, v, u, l)) << 56; |
| 310 |
l += dldx; |
| 311 |
u += dudx; |
| 312 |
v += dvdx; |
| 313 |
z += dzdx; |
| 314 |
rec_z = 1.0 / z; |
| 315 |
|
| 316 |
*(reinterpret_cast<uint64_t *>(dest)) = destlong; |
| 317 |
dest += 8; |
| 318 |
x -= 8; |
| 319 |
j -= 8; |
| 320 |
index += 8; |
| 321 |
if (index+8 >= SWIDTH*SHEIGHT) return; |
| 322 |
} |
| 323 |
} |
| 324 |
while (x-- > 0) { |
| 325 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 326 |
*dest++ = |
| 327 |
read_fade_table_entry(rec_z, v, u, l); |
| 328 |
l += dldx; |
| 329 |
u += dudx; |
| 330 |
v += dvdx; |
| 331 |
z += dzdx; |
| 332 |
rec_z = 1.0 / z; |
| 333 |
} |
| 334 |
} else { |
| 335 |
if (x >= 8) { |
| 336 |
if ((j = reinterpret_cast<uintptr_t>(dest) & 7) != 0) { |
| 337 |
j = 8 - j; |
| 338 |
|
| 339 |
while (j > 0) { |
| 340 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 341 |
const auto c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 342 |
if (c != 255) |
| 343 |
*dest = read_opaque_fade_table_entry(l, c); |
| 344 |
dest++; |
| 345 |
l += dldx; |
| 346 |
u += dudx; |
| 347 |
v += dvdx; |
| 348 |
z += dzdx; |
| 349 |
rec_z = 1.0 / z; |
| 350 |
x--; |
| 351 |
j--; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
j = x; |
| 356 |
while (j >= 8) { |
| 357 |
uint64_t destlong; |
| 358 |
destlong = *(reinterpret_cast<uint64_t *>(dest)); |
| 359 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 360 |
if (c != 255) { |
| 361 |
destlong &= ~static_cast<uint64_t>(0xFF); |
| 362 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)); |
| 363 |
} |
| 364 |
l += dldx; |
| 365 |
u += dudx; |
| 366 |
v += dvdx; |
| 367 |
z += dzdx; |
| 368 |
rec_z = 1.0 / z; |
| 369 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 370 |
if (c != 255) { |
| 371 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 8); |
| 372 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 8; |
| 373 |
} |
| 374 |
l += dldx; |
| 375 |
u += dudx; |
| 376 |
v += dvdx; |
| 377 |
z += dzdx; |
| 378 |
rec_z = 1.0 / z; |
| 379 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 380 |
if (c != 255) { |
| 381 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 16); |
| 382 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 16; |
| 383 |
} |
| 384 |
l += dldx; |
| 385 |
u += dudx; |
| 386 |
v += dvdx; |
| 387 |
z += dzdx; |
| 388 |
rec_z = 1.0 / z; |
| 389 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 390 |
if (c != 255) { |
| 391 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 24); |
| 392 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 24; |
| 393 |
} |
| 394 |
l += dldx; |
| 395 |
u += dudx; |
| 396 |
v += dvdx; |
| 397 |
z += dzdx; |
| 398 |
rec_z = 1.0 / z; |
| 399 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 400 |
if (c != 255) { |
| 401 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 32); |
| 402 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 32; |
| 403 |
} |
| 404 |
l += dldx; |
| 405 |
u += dudx; |
| 406 |
v += dvdx; |
| 407 |
z += dzdx; |
| 408 |
rec_z = 1.0 / z; |
| 409 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 410 |
if (c != 255) { |
| 411 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 40); |
| 412 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 40; |
| 413 |
} |
| 414 |
l += dldx; |
| 415 |
u += dudx; |
| 416 |
v += dvdx; |
| 417 |
z += dzdx; |
| 418 |
rec_z = 1.0 / z; |
| 419 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 420 |
if (c != 255) { |
| 421 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 48); |
| 422 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 48; |
| 423 |
} |
| 424 |
l += dldx; |
| 425 |
u += dudx; |
| 426 |
v += dvdx; |
| 427 |
z += dzdx; |
| 428 |
rec_z = 1.0 / z; |
| 429 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 430 |
if (c != 255) { |
| 431 |
destlong &= ~(static_cast<uint64_t>(0xFF) << 56); |
| 432 |
destlong |= static_cast<uint64_t>(read_opaque_fade_table_entry(l, c)) << 56; |
| 433 |
} |
| 434 |
l += dldx; |
| 435 |
u += dudx; |
| 436 |
v += dvdx; |
| 437 |
z += dzdx; |
| 438 |
rec_z = 1.0 / z; |
| 439 |
|
| 440 |
*(reinterpret_cast<uint64_t *>(dest)) = destlong; |
| 441 |
dest += 8; |
| 442 |
x -= 8; |
| 443 |
j -= 8; |
| 444 |
index += 8; |
| 445 |
if (index+8 >= SWIDTH*SHEIGHT) return; |
| 446 |
} |
| 447 |
} |
| 448 |
while (x-- > 0) { |
| 449 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 450 |
c = static_cast<uint32_t>(read_pixptr_entry(rec_z, v, u)); |
| 451 |
if (c != 255) |
| 452 |
*dest = read_opaque_fade_table_entry(l, c); |
| 453 |
dest++; |
| 454 |
l += dldx; |
| 455 |
u += dudx; |
| 456 |
v += dvdx; |
| 457 |
z += dzdx; |
| 458 |
rec_z = 1.0 / z; |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
// note the unrolling loop is broken. It is never called, and uses big endian. -- FH |
| 464 |
static void c_tmap_scanline_per() |
| 465 |
{ |
| 466 |
uint c; |
| 467 |
int x, j, index = fx_xleft + (bytes_per_row * fx_y); |
| 468 |
fix l,u,v,z; |
| 469 |
fix dudx, dvdx, dzdx, dldx; |
| 470 |
|
| 471 |
u = fx_u; |
| 472 |
v = fx_v*64; |
| 473 |
z = fx_z; |
| 474 |
dudx = fx_du_dx; |
| 475 |
dvdx = fx_dv_dx*64; |
| 476 |
dzdx = fx_dz_dx; |
| 477 |
|
| 478 |
l = fx_l>>8; |
| 479 |
dldx = fx_dl_dx/256; |
| 480 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 481 |
|
| 482 |
if (!Transparency_on) { |
| 483 |
const auto pixPtrLocalCopy{pixptr}; |
| 484 |
auto &fadeTableLocalCopy = gr_fade_table; |
| 485 |
|
| 486 |
x = fx_xright-fx_xleft+1; // x = number of pixels in scanline |
| 487 |
|
| 488 |
if ((j = reinterpret_cast<uintptr_t>(dest) & 3) != 0) |
| 489 |
{ |
| 490 |
j = 4 - j; |
| 491 |
|
| 492 |
if (j > x) |
| 493 |
j = x; |
| 494 |
|
| 495 |
while (j > 0) |
| 496 |
{ |
| 497 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 498 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 499 |
*dest++ = fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[static_cast<uint32_t>(pixPtrLocalCopy[((v / z) & (64 * 63)) + ((u / z) & 63)])]; |
| 500 |
//end edit -MM |
| 501 |
l += dldx; |
| 502 |
u += dudx; |
| 503 |
v += dvdx; |
| 504 |
z += dzdx; |
| 505 |
x--; |
| 506 |
j--; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
j &= ~3; |
| 511 |
while (j > 0) |
| 512 |
{ |
| 513 |
uint32_t destlong; |
| 514 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 515 |
destlong = fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ] << 24; |
| 516 |
//end edit -MM |
| 517 |
l += dldx; |
| 518 |
u += dudx; |
| 519 |
v += dvdx; |
| 520 |
z += dzdx; |
| 521 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 522 |
destlong |= fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ] << 16; |
| 523 |
//end edit -MM |
| 524 |
l += dldx; |
| 525 |
u += dudx; |
| 526 |
v += dvdx; |
| 527 |
z += dzdx; |
| 528 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 529 |
destlong |= fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ] << 8; |
| 530 |
//end edit -MM |
| 531 |
l += dldx; |
| 532 |
u += dudx; |
| 533 |
v += dvdx; |
| 534 |
z += dzdx; |
| 535 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 536 |
destlong |= fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ]; |
| 537 |
//end edit -MM |
| 538 |
l += dldx; |
| 539 |
u += dudx; |
| 540 |
v += dvdx; |
| 541 |
z += dzdx; |
| 542 |
*reinterpret_cast<uint32_t *>(dest) = destlong; |
| 543 |
dest += 4; |
| 544 |
x -= 4; |
| 545 |
j -= 4; |
| 546 |
index += 4; |
| 547 |
if (index+4 >= SWIDTH*SHEIGHT) return; |
| 548 |
} |
| 549 |
|
| 550 |
while (x-- > 0) |
| 551 |
{ |
| 552 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 553 |
//edited 05/18/99 Matt Mueller - changed from 0xff00 to 0x7f00 to fix glitches |
| 554 |
*dest++ = fadeTableLocalCopy.base_type::operator[]((l >> 8) & 0x7f)[pixPtrLocalCopy[ ( (v/z)&(64*63) ) + ((u/z)&63) ] ]; |
| 555 |
//end edit -MM |
| 556 |
l += dldx; |
| 557 |
u += dudx; |
| 558 |
v += dvdx; |
| 559 |
z += dzdx; |
| 560 |
} |
| 561 |
|
| 562 |
} else { |
| 563 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 564 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 565 |
c = static_cast<uint32_t>(pixptr[ ( (v/z)&(64*63) ) + ((u/z)&63) ]); |
| 566 |
if ( c!=TRANSPARENCY_COLOR) |
| 567 |
*dest = gr_fade_table.base_type::operator[]((l >> 8) & 0x7f)[c]; |
| 568 |
dest++; |
| 569 |
l += dldx; |
| 570 |
u += dudx; |
| 571 |
v += dvdx; |
| 572 |
z += dzdx; |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
static void c_tmap_scanline_quad() |
| 578 |
{ |
| 579 |
uint c; |
| 580 |
int x, index = fx_xleft + (bytes_per_row * fx_y); |
| 581 |
fix u,v,l,dudx, dvdx, dldx; |
| 582 |
|
| 583 |
// Quadratic setup stuff: |
| 584 |
fix a1, a2, b1, b2, dudx1, dvdx1; |
| 585 |
fix u0 = fx_u; |
| 586 |
fix u2 = fx_u + fx_du_dx*(fx_xright-fx_xleft+1); // This just needs to be uright from outer loop |
| 587 |
fix v0 = fx_v; |
| 588 |
fix v2 = fx_v + fx_dv_dx*(fx_xright-fx_xleft+1); // This just needs to be vright from outer loop |
| 589 |
fix w0 = fx_z; |
| 590 |
fix w2 = fx_z + fx_dz_dx*(fx_xright-fx_xleft+1); // This just needs to be zright from outer loop |
| 591 |
fix u1 = fixdiv((u0+u2),(w0+w2)); |
| 592 |
fix v1 = fixdiv((v0+v2),(w0+w2)); |
| 593 |
int dx = fx_xright-fx_xleft+1; |
| 594 |
u0 = fixdiv( u0, w0 ); // Divide Z out. This should be in outer loop |
| 595 |
v0 = fixdiv( v0, w0 ); // Divide Z out. This should be in outer loop |
| 596 |
u2 = fixdiv( u2, w2 ); // Divide Z out. This should be in outer loop |
| 597 |
v2 = fixdiv( v2, w2 ); // Divide Z out. This should be in outer loop |
| 598 |
a1 = (-3*u0+4*u1-u2)/dx; |
| 599 |
b1 = (-3*v0+4*v1-v2)/dx; |
| 600 |
a2 = (2*(u0-2*u1+u2))/(dx*dx); |
| 601 |
b2 = (2*(v0-2*v1+v2))/(dx*dx); |
| 602 |
dudx = a1 + a2; |
| 603 |
dvdx = b1 + b2; |
| 604 |
dudx1 = 2*a2; |
| 605 |
dvdx1 = 2*b2; |
| 606 |
u = u0; |
| 607 |
v = v0; |
| 608 |
|
| 609 |
// Normal lighting setup |
| 610 |
l = fx_l>>8; |
| 611 |
dldx = fx_dl_dx>>8; |
| 612 |
|
| 613 |
// Normal destination pointer setup |
| 614 |
auto dest = &write_buffer[fx_xleft + (bytes_per_row * fx_y)]; |
| 615 |
|
| 616 |
if (!Transparency_on) { |
| 617 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 618 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 619 |
*dest++ = gr_fade_table.base_type::operator[]((l >> 8) & 0x7f)[pixptr[ (f2i(v)&63)*64 + (f2i(u)&63) ] ]; |
| 620 |
l += dldx; |
| 621 |
u += dudx; |
| 622 |
v += dvdx; |
| 623 |
dudx += dudx1; // Extra add for quadratic! |
| 624 |
dvdx += dvdx1; // Extra add for quadratic! |
| 625 |
} |
| 626 |
} else { |
| 627 |
for (x= fx_xright-fx_xleft+1 ; x > 0; --x ) { |
| 628 |
if (++index >= SWIDTH*SHEIGHT) return; |
| 629 |
c = static_cast<uint32_t>(pixptr[ (f2i(v)&63)*64 + (f2i(u)&63) ]); |
| 630 |
if ( c!=255) |
| 631 |
*dest = gr_fade_table.base_type::operator[]((l >> 8) & 0x7f)[c]; |
| 632 |
dest++; |
| 633 |
l += dldx; |
| 634 |
u += dudx; |
| 635 |
v += dvdx; |
| 636 |
dudx += dudx1; // Extra add for quadratic! |
| 637 |
dvdx += dvdx1; // Extra add for quadratic! |
| 638 |
} |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
//runtime selection of optimized tmappers. 12/07/99 Matthew Mueller |
| 643 |
//the reason I did it this way rather than having a *tmap_funcs that then points to a c_tmap or fp_tmap struct thats already filled in, is to avoid a second pointer dereference. |
| 644 |
void select_tmap(const std::string &type) |
| 645 |
{ |
| 646 |
if (type == "fp") |
| 647 |
{ |
| 648 |
cur_tmap_scanline_per=c_fp_tmap_scanline_per; |
| 649 |
} |
| 650 |
else if (type == "quad") |
| 651 |
{ |
| 652 |
cur_tmap_scanline_per=c_tmap_scanline_quad; |
| 653 |
} |
| 654 |
else { |
| 655 |
cur_tmap_scanline_per=c_tmap_scanline_per; |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
} |