SoftGPU: Optimise tex coord calculation

On test machine with -O1 and 28,000 FPS goes from ~48 to ~52
This commit is contained in:
UnknownShadow200 2025-02-24 20:12:22 +11:00
parent 7f13b8b1e1
commit be5a215a6c
2 changed files with 10 additions and 5 deletions

View File

@ -600,10 +600,11 @@ static void DrawTriangle3D(Vertex* V0, Vertex* V1, Vertex* V2) {
}
float z0 = V0->z, z1 = V1->z, z2 = V2->z;
float u0 = V0->u, u1 = V1->u, u2 = V2->u;
float v0 = V0->v, v1 = V1->v, v2 = V2->v;
PackedCol color = V0->c;
float u0 = V0->u * curTexWidth, u1 = V1->u * curTexWidth, u2 = V2->u * curTexWidth;
float v0 = V0->v * curTexHeight, v1 = V1->v * curTexHeight, v2 = V2->v * curTexHeight;
// https://fgiesen.wordpress.com/2013/02/10/optimizing-the-basic-rasterizer/
// Essentially these are the deltas of edge functions between X/Y and X/Y + 1 (i.e. one X/Y step)
int dx01 = y0 - y1, dy01 = x1 - x0;
@ -660,8 +661,8 @@ static void DrawTriangle3D(Vertex* V0, Vertex* V1, Vertex* V2) {
if (texturing) {
float u = (ic0 * u0 + ic1 * u1 + ic2 * u2) * w;
float v = (ic0 * v0 + ic1 * v1 + ic2 * v2) * w;
int texX = ((int)(Math_AbsF(u - FastFloor(u)) * curTexWidth )) & texWidthMask;
int texY = ((int)(Math_AbsF(v - FastFloor(v)) * curTexHeight)) & texHeightMask;
int texX = ((int)u) & texWidthMask;
int texY = ((int)v) & texHeightMask;
int texIndex = texY * curTexWidth + texX;
BitmapCol tColor = curTexPixels[texIndex];

View File

@ -371,8 +371,12 @@ static void DoCreateWindow(int width, int height, int _2d) {
y = Display_CentreY(height);
RegisterAtoms();
#if CC_GFX_BACKEND_IS_GL()
win_visual = _2d ? Select2DVisual() : GLContext_SelectVisual();
visualID = win_visual.visual ? win_visual.visual->visualid : 0;
#else
win_visual = Select2DVisual();
#endif
visualID = win_visual.visual ? win_visual.visual->visualid : 0;
Platform_Log2("Creating window (depth: %i, visual: %h)", &win_visual.depth, &visualID);
attributes.colormap = XCreateColormap(win_display, win_rootWin, win_visual.visual, AllocNone);