texture sampling optimization

This commit is contained in:
Bigfoot71 2025-03-13 22:54:05 +01:00
parent 9be90fd5e6
commit d3fe48fa7d

32
src/external/rlsw.h vendored
View File

@ -922,27 +922,26 @@ static inline void sw_texture_sample(float* color, const sw_texture_t* tex, floa
// at the wrong moment during rasterization. It would be worth reviewing // at the wrong moment during rasterization. It would be worth reviewing
// this, although the scanline method complicates things. // this, although the scanline method complicates things.
// Calculate the derivatives for each axis // Previous method: There is no need to compute the square root
float du = sqrtf(xDu * xDu + yDu * yDu); // because using the squared value, the comparison remains `L2 > 1.0f * 1.0f`
float dv = sqrtf(xDv * xDv + yDv * yDv); //float du = sqrtf(xDu * xDu + yDu * yDu);
float L = (du > dv) ? du : dv; //float dv = sqrtf(xDv * xDv + yDv * yDv);
//float L = (du > dv) ? du : dv;
// Select the filter based on the size of the footprint // Calculate the derivatives for each axis
if (L > 1.0f) { float du2 = xDu * xDu + yDu * yDu;
// Minification float dv2 = xDv * xDv + yDv * yDv;
if (tex->minFilter == SW_NEAREST) { float L2 = (du2 > dv2) ? du2 : dv2;
bool useMinFilter = (L2 > 1.0f);
int filter = useMinFilter ? tex->minFilter : tex->magFilter;
if (filter == SW_NEAREST) {
sw_texture_sample_nearest(color, tex, u, v); sw_texture_sample_nearest(color, tex, u, v);
} else if (tex->minFilter == SW_LINEAR) {
sw_texture_sample_linear(color, tex, u, v);
} }
} else { else /* SW_LINEAR */ {
// Magnification
if (tex->magFilter == SW_NEAREST) {
sw_texture_sample_nearest(color, tex, u, v);
} else if (tex->magFilter == SW_LINEAR) {
sw_texture_sample_linear(color, tex, u, v); sw_texture_sample_linear(color, tex, u, v);
} }
}
} }
@ -1949,6 +1948,7 @@ void swInit(int w, int h)
RLSW.currentMatrixMode = SW_MODELVIEW; RLSW.currentMatrixMode = SW_MODELVIEW;
RLSW.currentMatrix = &RLSW.matView; RLSW.currentMatrix = &RLSW.matView;
RLSW.needToUpdateMVP = true;
sw_matrix_id(RLSW.matProjection); sw_matrix_id(RLSW.matProjection);
sw_matrix_id(RLSW.matTexture); sw_matrix_id(RLSW.matTexture);