summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/d_scan.c
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-08-09 20:31:24 -0400
committerFranklin Wei <franklin@rockbox.org>2019-08-09 21:27:55 -0400
commitf5bb7fddecc0066a6cfb580538f297cec1def5d8 (patch)
tree97d943bcf7089b274f30ad25fab591516b16637b /apps/plugins/sdl/progs/quake/d_scan.c
parentee70dad305a94709c877e776d723aee64d023cb5 (diff)
downloadrockbox-f5bb7fddecc0066a6cfb580538f297cec1def5d8.tar.gz
rockbox-f5bb7fddecc0066a6cfb580538f297cec1def5d8.zip
quake: merge the remaining Pocket Quake PQ_OPT changes
I didn't do _OPT3 because it's disabled in the PQ source. This gives as +0.2FPS boost over the last commit. Change-Id: I9c3c8fb7bd23262beb810da6e9469d6b6c4b2a81
Diffstat (limited to 'apps/plugins/sdl/progs/quake/d_scan.c')
-rw-r--r--apps/plugins/sdl/progs/quake/d_scan.c190
1 files changed, 190 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/d_scan.c b/apps/plugins/sdl/progs/quake/d_scan.c
index 008c783be6..a2e58649e3 100644
--- a/apps/plugins/sdl/progs/quake/d_scan.c
+++ b/apps/plugins/sdl/progs/quake/d_scan.c
@@ -254,6 +254,7 @@ void Turbulent8 (espan_t *pspan)
254D_DrawSpans8 254D_DrawSpans8
255============= 255=============
256*/ 256*/
257#ifndef USE_PQ_OPT5
257void D_DrawSpans8 (espan_t *pspan) 258void D_DrawSpans8 (espan_t *pspan)
258{ 259{
259 int count, spancount; 260 int count, spancount;
@@ -381,8 +382,197 @@ void D_DrawSpans8 (espan_t *pspan)
381 382
382 } while ((pspan = pspan->pnext) != NULL); 383 } while ((pspan = pspan->pnext) != NULL);
383} 384}
385#else
384 386
387static int sdivzorig, sdivzstepv, sdivzstepu, sdivz8stepu;
388static int tdivzorig, tdivzstepv, tdivzstepu, tdivz8stepu;
389static int zi8stepu;
390static float last = 0;
391
392/*==============================================
393// UpdateFixedPointVars
394//============================================*/
395void UpdateFixedPointVars( int all )
396{
397 // JB: Store texture transformation matrix in fixed point vars
398 if (all)
399 {
400/*
401 sdivzorig = (int)(524288.0f * d_sdivzorigin); // 13.19 fixed point
402 tdivzorig = (int)(524288.0f * d_tdivzorigin);
403 sdivzstepv = (int)(524288.0f * d_sdivzstepv);
404 tdivzstepv = (int)(524288.0f * d_tdivzstepv);
405 sdivzstepu = (int)(524288.0f * d_sdivzstepu);
406 sdivz8stepu = sdivzstepu*8;
407 tdivzstepu = (int)(524288.0f * d_tdivzstepu);
408 tdivz8stepu = tdivzstepu*8;
409*/
410
411 sdivzorig = (int)(4194304.0f * d_sdivzorigin); // 10.22 fixed point
412 tdivzorig = (int)(4194304.0f * d_tdivzorigin);
413 sdivzstepv = (int)(4194304.0f * d_sdivzstepv);
414 tdivzstepv = (int)(4194304.0f * d_tdivzstepv);
415 sdivzstepu = (int)(4194304.0f * d_sdivzstepu);
416 sdivz8stepu = sdivzstepu*8;
417 tdivzstepu = (int)(4194304.0f * d_tdivzstepu);
418 tdivz8stepu = tdivzstepu*8;
419
420 }
421/*
422 ziorig = (int)(524288.0f * d_ziorigin); // 13.19 fixed point
423 zistepv = (int)(524288.0f * d_zistepv );
424 zistepu = (int)(524288.0f * d_zistepu );
425*/
426#ifndef USE_PQ_OPT3
427 d_ziorigin_fxp = (int)(4194304.0f * d_ziorigin); // 10.22 fixed point
428 d_zistepv_fxp = (int)(4194304.0f * d_zistepv );
429 d_zistepu_fxp = (int)(4194304.0f * d_zistepu );
430#endif
431
432 zi8stepu = d_zistepu_fxp * 8;
433 last = d_zistepv;
434}
435
436void D_DrawSpans8 (espan_t *pspan)
437{
438 int count, spancount, spancountminus1;
439 unsigned char *pbase, *pdest;
440 fixed16_t s1, t1;
441 int zi, sdivz, tdivz, sstep, tstep;
442 int snext, tnext;
443 pbase = (unsigned char *)cacheblock;
444 //Jacco Biker's fixed point conversion
445
446 // Recalc fixed point values
447 UpdateFixedPointVars( 1 );
448 do
449 {
450 pdest = (unsigned char *)((byte *)d_viewbuffer + (screenwidth * pspan->v) + pspan->u);
451 count = pspan->count;
452 // calculate the initial s/z, t/z, 1/z, s, and t and clamp
453 sdivz = sdivzorig + pspan->v * sdivzstepv + pspan->u * sdivzstepu;
454 tdivz = tdivzorig + pspan->v * tdivzstepv + pspan->u * tdivzstepu;
455 zi = d_ziorigin_fxp + pspan->v * d_zistepv_fxp + pspan->u * d_zistepu_fxp;
456 if (zi == 0) zi = 1;
457 s1 = (((sdivz << 8) / zi) << 8) + sadjust; // 5.27 / 13.19 = 24.8 >> 8 = 16.16
458 if (s1 > bbextents) s1 = bbextents; else if (s1 < 0) s1 = 0;
459 t1 = (((tdivz << 8) / zi) << 8) + tadjust;
460 if (t1 > bbextentt) t1 = bbextentt; else if (t1 < 0) t1 = 0;
461 // calculate final s/z, t/z, 1/z, s, and t and clamp
462 //sdivz += sdivzstepu * (count - 1);
463 //tdivz += tdivzstepu * (count - 1);
464 //zi += d_zistepu_fxp * (count - 1);
465 //if (zi == 0) zi = 1;
466#if 0
467 s2 = (((sdivz << 8) / zi) << 8) + sadjust;
468 if (s2 > bbextents) s2 = bbextents; else if (s2 < 8) s2 = 8;
469 t2 = (((tdivz << 8) / zi) << 8) + tadjust;
470 if (t2 > bbextentt) t2 = bbextentt; else if (t2 < 8) t2 = 8;
471 if (count > 1)
472 {
473 sstep = (s2 - s1) / (count - 1);
474 tstep = (t2 - t1) / (count - 1);
475 }
476#else
477 //End Jacco Biker mod
478 //Dan East: Fixed point conversion for perspective correction
479 do
480 {
481 // calculate s and t at the far end of the span
482 if (count >= 8)
483 spancount = 8;
484 else
485 spancount = count;
486
487 count -= spancount;
488
489 if (count)
490 {
491 // calculate s/z, t/z, zi->fixed s and t at far end of span,
492 // calculate s and t steps across span by shifting
493 sdivz += sdivz8stepu;
494 tdivz += tdivz8stepu;
495 zi += zi8stepu;
496 if (!zi) zi = 1;
497 //z = zi;
498 //z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
499 snext = (((sdivz<<8)/zi)<<8)+sadjust;
500 //snext = (int)(sdivz * z) + sadjust;
501 if (snext > bbextents)
502 snext = bbextents;
503 else if (snext < 8)
504 snext = 8; // prevent round-off error on <0 steps from
505 // from causing overstepping & running off the
506 // edge of the texture
507
508 tnext = (((tdivz<<8)/zi)<<8) + tadjust;
509 if (tnext > bbextentt)
510 tnext = bbextentt;
511 else if (tnext < 8)
512 tnext = 8; // guard against round-off error on <0 steps
513
514 sstep = (snext - s1) >> 3;
515 tstep = (tnext - t1) >> 3;
516 }
517 else
518 {
519 // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
520 // can't step off polygon), clamp, calculate s and t steps across
521 // span by division, biasing steps low so we don't run off the
522 // texture
523 spancountminus1 = spancount - 1;
524 sdivz += sdivzstepu * spancountminus1;
525 tdivz += tdivzstepu * spancountminus1;
526 zi += d_zistepu_fxp * spancountminus1;
527 if (!zi) zi = 1;
528 //z = zi;//(float)0x10000 / zi; // prescale to 16.16 fixed-point
529 snext = (((sdivz<<8) / zi)<<8) + sadjust;
530 if (snext > bbextents)
531 snext = bbextents;
532 else if (snext < 8)
533 snext = 8; // prevent round-off error on <0 steps from
534 // from causing overstepping & running off the
535 // edge of the texture
536
537 tnext = (((tdivz<<8) / zi)<<8) + tadjust;
538 if (tnext > bbextentt)
539 tnext = bbextentt;
540 else if (tnext < 8)
541 tnext = 8; // guard against round-off error on <0 steps
542
543 if (spancount > 1)
544 {
545 sstep = ((snext - s1)) / ((spancount - 1));
546 tstep = ((tnext - t1)) / ((spancount - 1));
547 }
548 }
549 do
550 {
551 *pdest++ = *(pbase + (s1 >> 16) + (t1 >> 16) * cachewidth);
552 s1 += sstep;
553 t1 += tstep;
554 } while (--spancount > 0);
555
556 s1 = snext;
557 t1 = tnext;
558
559 } while (count > 0);
385#endif 560#endif
561#if 0
562 // Draw span
563 for ( i = 0; i < count; i++ )
564 {
565 *pdest++ = *(pbase + (s1 >> 16) + (t1 >> 16) * cachewidth);
566 s1 += sstep;
567 t1 += tstep;
568 }
569#endif
570 } while ((pspan = pspan->pnext) != NULL);
571}
572
573#endif //USE_PQ_OPT5
574
575#endif // !id386
386 576
387 577
388#if !id386 578#if !id386