From be5a215a6cf7ea53b70777fff849b368288e7e82 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 24 Feb 2025 20:12:22 +1100 Subject: [PATCH] SoftGPU: Optimise tex coord calculation On test machine with -O1 and 28,000 FPS goes from ~48 to ~52 --- src/Graphics_SoftGPU.c | 9 +++++---- src/Window_X11.c | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index 94b062b37..156834a82 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -600,9 +600,10 @@ 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) @@ -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]; diff --git a/src/Window_X11.c b/src/Window_X11.c index 48e23cf00..9dcc4b03a 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -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);