@@ -5799,42 +5799,33 @@ static void SW_RASTER_LINE_THIN(const sw_vertex_t *v0, const sw_vertex_t *v1)
57995799 substep = (dy >= 0.0f )? (1.0f - sw_fract (y0 )) : sw_fract (y0 );
58005800 }
58015801
5802- // Compute per pixel increments
5803- float xInc = dx /steps ;
5804- float yInc = dy /steps ;
5802+ // Line setup, independent of pipeline state
58055803 float stepRcp = sw_rcp (steps );
5804+ float xInc = dx * stepRcp ;
5805+ float yInc = dy * stepRcp ;
5806+ int numPixels = (int )(steps - substep ) + 1 ;
5807+ const int fbWidth = RLSW .colorBuffer -> width ;
5808+ uint8_t * cPixels = RLSW .colorBuffer -> pixels ;
58065809#if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5807- float zInc = (v1 -> position [2 ] - v0 -> position [2 ])* stepRcp ;
5808- #endif
5809- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5810- float rInc = (v1 -> color [0 ] - v0 -> color [0 ])* stepRcp ;
5811- float gInc = (v1 -> color [1 ] - v0 -> color [1 ])* stepRcp ;
5812- float bInc = (v1 -> color [2 ] - v0 -> color [2 ])* stepRcp ;
5813- float aInc = (v1 -> color [3 ] - v0 -> color [3 ])* stepRcp ;
5810+ uint8_t * dPixels = RLSW .depthBuffer -> pixels ;
58145811#endif
58155812
58165813 // Initializing the interpolation starting values
58175814 float x = x0 + xInc * substep ;
58185815 float y = y0 + yInc * substep ;
58195816#if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5817+ float zInc = (v1 -> position [2 ] - v0 -> position [2 ])* stepRcp ;
58205818 float z = v0 -> position [2 ] + zInc * substep ;
58215819#endif
58225820#if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5823- float r = v0 -> color [0 ] + rInc * substep ;
5824- float g = v0 -> color [1 ] + gInc * substep ;
5825- float b = v0 -> color [2 ] + bInc * substep ;
5826- float a = v0 -> color [3 ] + aInc * substep ;
5827- #endif
5828-
5829- // Start line rasterization
5830- const int fbWidth = RLSW .colorBuffer -> width ;
5831- uint8_t * cPixels = RLSW .colorBuffer -> pixels ;
5832- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5833- uint8_t * dPixels = RLSW .depthBuffer -> pixels ;
5821+ float cInc [4 ], color [4 ];
5822+ SW_VEC_OP (cInc [i ] = (v1 -> color [i ] - v0 -> color [i ])* stepRcp , i , 4 );
5823+ SW_VEC_OP (color [i ] = v0 -> color [i ] + cInc [i ]* substep , i , 4 );
5824+ #else
5825+ // Flat: constant across the whole line, computed once for the whole loop
5826+ const float * srcColor = v0 -> color ;
58345827#endif
58355828
5836- int numPixels = (int )(steps - substep ) + 1 ;
5837-
58385829 for (int i = 0 ; i < numPixels ; i ++ )
58395830 {
58405831 int px = x ;
@@ -5846,52 +5837,41 @@ static void SW_RASTER_LINE_THIN(const sw_vertex_t *v0, const sw_vertex_t *v1)
58465837 uint8_t * dPtr = dPixels + baseOffset * SW_FRAMEBUFFER_DEPTH_SIZE ;
58475838 #endif
58485839
5849- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5840+ #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5841+ // TODO: Implement different depth funcs?
5842+ float depth = SW_FRAMEBUFFER_DEPTH_GET (dPtr , 0 );
5843+ if (z <= depth )
58505844 {
5851- // TODO: Implement different depth funcs?
5852- float depth = SW_FRAMEBUFFER_DEPTH_GET (dPtr , 0 );
5853- if (z > depth ) goto discard ;
5854-
58555845 // TODO: Implement depth mask
58565846 SW_FRAMEBUFFER_DEPTH_SET (dPtr , z , 0 );
5857- }
5858- #endif
5859-
5860- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5861- float srcColor [4 ] = {r , g , b , a };
5862- #else
5863- const float * srcColor = v0 -> color ;
58645847 #endif
58655848
5849+ #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5850+ const float * srcColor = color ;
5851+ #endif
5852+
58665853 #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_BLEND
5867- {
58685854 float dstColor [4 ];
58695855 SW_FRAMEBUFFER_COLOR_GET (dstColor , cPtr , 0 );
58705856 RLSW .blendFunc (dstColor , srcColor );
58715857 SW_FRAMEBUFFER_COLOR_SET (cPtr , dstColor , 0 );
5872- }
58735858 #else
5874- {
58755859 SW_FRAMEBUFFER_COLOR_SET (cPtr , srcColor , 0 );
5876- }
58775860 #endif
58785861
58795862 #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5880- discard :
5863+ }
58815864 #endif
5865+
5866+ // Advance unconditionally: depth test only guards the write above
58825867 x += xInc ;
58835868 y += yInc ;
5884- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5885- {
5886- z += zInc ;
5887- }
5888- #endif
5889- #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5890- r += rInc ;
5891- g += gInc ;
5892- b += bInc ;
5893- a += aInc ;
5894- #endif
5869+ #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_DEPTH_TEST
5870+ z += zInc ;
5871+ #endif
5872+ #if (SW_RASTER_LINE_FLAGS ) & SW_STATE_COLOR_INTERP
5873+ SW_VEC_OP (color [i ] += cInc [i ], i , 4 );
5874+ #endif
58955875 }
58965876}
58975877
0 commit comments