diff --git a/src/Game.c b/src/Game.c index f20d460f4..5fc41b629 100644 --- a/src/Game.c +++ b/src/Game.c @@ -481,7 +481,7 @@ static void Game_Load(void) { if (Gfx.Limitations & GFX_LIMIT_VERTEX_ONLY_FOG) EnvRenderer_SetMode(EnvRenderer_Minimal | ENV_LEGACY); - if (Gfx.Limitations & GFX_LIMIT_NO_FOG) + if (Gfx.Limitations & GFX_LIMIT_MINIMAL) EnvRenderer_SetMode(ENV_MINIMAL); Server.BeginConnect(); diff --git a/src/Graphics.h b/src/Graphics.h index 3f1966a3d..7dab6932a 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -93,8 +93,8 @@ CC_VAR extern struct _GfxData { #define GFX_LIMIT_VERTEX_ONLY_FOG 0x02 /* Whether the graphics backend only supports a small maximum quad size */ #define GFX_LIMIT_MAX_VERTEX_SIZE 0x04 -/* Whether the graphics backend doesn't support fog at all */ -#define GFX_LIMIT_NO_FOG 0x08 +/* Whether the graphics backend is minimal (no fog, clouds, sky) */ +#define GFX_LIMIT_MINIMAL 0x08 extern const cc_string Gfx_LowPerfMessage; diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index b681361f7..fdf583579 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -130,8 +130,7 @@ void Gfx_Create(void) { Gfx.MaxTexHeight = 256; //Gfx.MaxTexSize = 256 * 256; Gfx.Created = true; - //Gfx.Limitations = GFX_LIMIT_VERTEX_ONLY_FOG; - Gfx.Limitations = GFX_LIMIT_NO_FOG; + Gfx.Limitations = GFX_LIMIT_VERTEX_ONLY_FOG; ResetGPU(); Gfx_ClearColor(PackedCol_Make(0, 120, 80, 255)); diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index 51580ffc7..ca990f725 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -117,7 +117,7 @@ void Gfx_Create(void) { Gfx.MaxTexWidth = 128; Gfx.MaxTexHeight = 16; // 128 Gfx.Created = true; - Gfx.Limitations = GFX_LIMIT_NO_UV_SUPPORT | GFX_LIMIT_MAX_VERTEX_SIZE | GFX_LIMIT_NO_FOG; + Gfx.Limitations = GFX_LIMIT_NO_UV_SUPPORT | GFX_LIMIT_MAX_VERTEX_SIZE; SetupHeaderCommands(); } diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index ab6d73d81..8748cbdca 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -49,7 +49,7 @@ void Gfx_Create(void) { Gfx.Created = true; Gfx.BackendType = CC_GFX_BACKEND_SOFTGPU; - Gfx.Limitations = GFX_LIMIT_NO_FOG; + Gfx.Limitations = GFX_LIMIT_MINIMAL; Gfx_RestoreState(); } @@ -88,7 +88,11 @@ void Gfx_BindTexture(GfxResourceID texId) { texWidthMask = (1 << Math_ilog2(tex->width)) - 1; texHeightMask = (1 << Math_ilog2(tex->height)) - 1; - texSinglePixel = curTexWidth == 1 && curTexHeight == 1; + + /* Technically the optimisation should only apply if width and height is 1 */ + /* But it's worth sacrificing this, so that rendering the world when */ + /* no texture pack can use the more optimised rendering path */ + texSinglePixel = curTexWidth == 1; } void Gfx_DeleteTexture(GfxResourceID* texId) { @@ -469,7 +473,6 @@ static void DrawTriangle2D(Vertex* V0, Vertex* V1, Vertex* V2) { int maxX = max(x0, max(x1, x2)); int maxY = max(y0, max(y1, y2)); - int area = edgeFunction(x0,y0, x1,y1, x2,y2); // Reject triangles completely outside if (maxX < 0 || minX > fb_maxX) return; if (maxY < 0 || minY > fb_maxY) return; @@ -477,11 +480,13 @@ static void DrawTriangle2D(Vertex* V0, Vertex* V1, Vertex* V2) { // Perform scissoring minX = max(minX, 0); maxX = min(maxX, fb_maxX); minY = max(minY, 0); maxY = min(maxY, fb_maxY); - float factor = 1.0f / area; 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; PackedCol color = V0->c; + + int area = edgeFunction(x0,y0, x1,y1, x2,y2); + float factor = 1.0f / area; // 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) @@ -628,7 +633,12 @@ static void DrawTriangle3D(Vertex* V0, Vertex* V1, Vertex* V2) { A = PackedCol_A(color); } else if (texSinglePixel) { /* Don't need to calculate complicated texturing in this case */ - MultiplyColors(color, curTexPixels[0]); + float rawY0 = v0 / w0; + float rawY1 = v1 / w1; + + float rawY = min(rawY0, rawY1); + int texY = (int)(rawY + 0.01f) & texHeightMask; + MultiplyColors(color, curTexPixels[texY * curTexWidth]); texturing = false; } diff --git a/src/ps1/Graphics_PS1.c b/src/ps1/Graphics_PS1.c index 9a7550c5d..ac73191e4 100644 --- a/src/ps1/Graphics_PS1.c +++ b/src/ps1/Graphics_PS1.c @@ -173,7 +173,7 @@ void Gfx_Create(void) { Gfx.MaxTexWidth = 256; Gfx.MaxTexHeight = 256; Gfx.Created = true; - Gfx.Limitations = GFX_LIMIT_MAX_VERTEX_SIZE | GFX_LIMIT_NO_FOG; + Gfx.Limitations = GFX_LIMIT_MAX_VERTEX_SIZE; Gfx_RestoreState(); SetupContexts(Window_Main.Width, Window_Main.Height);