|
114 | 114 | #endif |
115 | 115 |
|
116 | 116 | #ifndef SW_COLOR_BUFFER_BITS |
117 | | - #define SW_COLOR_BUFFER_BITS 32 //< 32 (rgba), 16 (rgb packed) or 8 (rgb packed) |
| 117 | + #define SW_COLOR_BUFFER_BITS 32 //< 32 (rgba), 16 (rgb packed) or 8 (rgb packed) |
118 | 118 | #endif |
119 | 119 |
|
120 | 120 | #ifndef SW_DEPTH_BUFFER_BITS |
121 | | - #define SW_DEPTH_BUFFER_BITS 16 //< 24, 16 or 8 |
| 121 | + #define SW_DEPTH_BUFFER_BITS 16 //< 32, 24 or 16 |
122 | 122 | #endif |
123 | 123 |
|
124 | 124 | #ifndef SW_MAX_PROJECTION_STACK_SIZE |
@@ -748,32 +748,32 @@ SWAPI void swBindTexture(uint32_t id); |
748 | 748 | #define SW_COLOR_PACK_COMP 4 |
749 | 749 | #endif |
750 | 750 |
|
751 | | -#if (SW_DEPTH_BUFFER_BITS == 8) |
752 | | - #define SW_DEPTH_TYPE uint8_t |
753 | | - #define SW_DEPTH_IS_PACKED 1 |
754 | | - #define SW_DEPTH_PACK_COMP 1 |
755 | | - #define SW_DEPTH_MAX UINT8_MAX |
756 | | - #define SW_DEPTH_SCALE (1.0f/UINT8_MAX) |
757 | | - #define SW_PACK_DEPTH(d) ((SW_DEPTH_TYPE)((d)*SW_DEPTH_MAX)) |
758 | | - #define SW_UNPACK_DEPTH(p) (p) |
759 | | -#elif (SW_DEPTH_BUFFER_BITS == 16) |
760 | | - #define SW_DEPTH_TYPE uint16_t |
761 | | - #define SW_DEPTH_IS_PACKED 1 |
762 | | - #define SW_DEPTH_PACK_COMP 1 |
763 | | - #define SW_DEPTH_MAX UINT16_MAX |
764 | | - #define SW_DEPTH_SCALE (1.0f/UINT16_MAX) |
765 | | - #define SW_PACK_DEPTH(d) ((SW_DEPTH_TYPE)((d)*SW_DEPTH_MAX)) |
766 | | - #define SW_UNPACK_DEPTH(p) (p) |
767 | | -#else // 24 bits |
768 | | - #define SW_DEPTH_TYPE uint8_t |
769 | | - #define SW_DEPTH_IS_PACKED 0 |
770 | | - #define SW_DEPTH_PACK_COMP 3 |
771 | | - #define SW_DEPTH_MAX 0xFFFFFF |
772 | | - #define SW_DEPTH_SCALE (1.0f/0xFFFFFF) |
773 | | - #define SW_PACK_DEPTH_0(d) (((uint32_t)((d)*SW_DEPTH_MAX)>>16)&0xFF) |
774 | | - #define SW_PACK_DEPTH_1(d) (((uint32_t)((d)*SW_DEPTH_MAX)>>8)&0xFF) |
775 | | - #define SW_PACK_DEPTH_2(d) ((uint32_t)((d)*SW_DEPTH_MAX)&0xFF) |
776 | | - #define SW_UNPACK_DEPTH(p) (((p)[0]<<16)|((p)[1]<<8)|(p)[2]) |
| 751 | +#if (SW_DEPTH_BUFFER_BITS == 16) |
| 752 | + #define SW_DEPTH_TYPE uint16_t |
| 753 | + #define SW_DEPTH_IS_PACKED 1 |
| 754 | + #define SW_DEPTH_PACK_COMP 1 |
| 755 | + #define SW_DEPTH_MAX UINT16_MAX |
| 756 | + #define SW_DEPTH_SCALE (1.0f/UINT16_MAX) |
| 757 | + #define SW_PACK_DEPTH(d) ((SW_DEPTH_TYPE)((d)*SW_DEPTH_MAX)) |
| 758 | + #define SW_UNPACK_DEPTH(p) (p) |
| 759 | +#elif (SW_DEPTH_BUFFER_BITS == 24) |
| 760 | + #define SW_DEPTH_TYPE uint8_t |
| 761 | + #define SW_DEPTH_IS_PACKED 0 |
| 762 | + #define SW_DEPTH_PACK_COMP 3 |
| 763 | + #define SW_DEPTH_MAX 0xFFFFFFU |
| 764 | + #define SW_DEPTH_SCALE (1.0f/0xFFFFFFU) |
| 765 | + #define SW_PACK_DEPTH_0(d) ((uint8_t)(((uint32_t)((d)*SW_DEPTH_MAX)>>16)&0xFFU)) |
| 766 | + #define SW_PACK_DEPTH_1(d) ((uint8_t)(((uint32_t)((d)*SW_DEPTH_MAX)>>8)&0xFFU)) |
| 767 | + #define SW_PACK_DEPTH_2(d) ((uint8_t)((uint32_t)((d)*SW_DEPTH_MAX)&0xFFU)) |
| 768 | + #define SW_UNPACK_DEPTH(p) ((((uint32_t)(p)[0]<<16)|((uint32_t)(p)[1]<<8)|(uint32_t)(p)[2])) |
| 769 | +#else // 32 bits |
| 770 | + #define SW_DEPTH_TYPE float |
| 771 | + #define SW_DEPTH_IS_PACKED 1 |
| 772 | + #define SW_DEPTH_PACK_COMP 1 |
| 773 | + #define SW_DEPTH_MAX 1.0f |
| 774 | + #define SW_DEPTH_SCALE 1.0f |
| 775 | + #define SW_PACK_DEPTH(d) ((SW_DEPTH_TYPE)(d)) |
| 776 | + #define SW_UNPACK_DEPTH(p) (p) |
777 | 777 | #endif |
778 | 778 |
|
779 | 779 | #define SW_STATE_CHECK(flags) (SW_STATE_CHECK_EX(RLSW.stateFlags, (flags))) |
@@ -1346,6 +1346,8 @@ static inline void sw_framebuffer_write_color(sw_pixel_t *dst, const float src[4 |
1346 | 1346 |
|
1347 | 1347 | static inline void sw_framebuffer_write_depth(sw_pixel_t *dst, float depth) |
1348 | 1348 | { |
| 1349 | + depth = sw_saturate(depth); // REVIEW: An overflow can occur in certain circumstances with clipping, and needs to be reviewed... |
| 1350 | + |
1349 | 1351 | #if SW_DEPTH_IS_PACKED |
1350 | 1352 | dst->depth[0] = SW_PACK_DEPTH(depth); |
1351 | 1353 | #else |
|
0 commit comments