From e86caaa4e11db6d1212797a116a6be8dc15ccab1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 1 Jan 2025 11:03:54 +1100 Subject: [PATCH] SoftGPU: Don't render clouds or sky --- src/Drawer2D.c | 5 +++-- src/Game.c | 8 +++++++- src/Graphics.h | 12 +++++++++--- src/Graphics_GL1.c | 4 ++++ src/Graphics_Saturn.c | 2 +- src/Platform_Posix.c | 5 +++-- src/Window_X11.c | 10 ++++++++-- 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 61f2a8607..af7859c6a 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -316,11 +316,12 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) { void Context2D_MakeTexture(struct Texture* tex, struct Context2D* ctx) { int flags = TEXTURE_FLAG_NONPOW2 | TEXTURE_FLAG_LOWRES; + int nouv = Gfx.Limitations & GFX_LIMIT_NO_UV_SUPPORT; Gfx_RecreateTexture(&tex->ID, &ctx->bmp, flags, false); /* TODO need to find a better solution in NoUVSupport case */ - tex->width = Gfx.NoUVSupport ? ctx->bmp.width : ctx->width; - tex->height = Gfx.NoUVSupport ? ctx->bmp.height : ctx->height; + tex->width = nouv ? ctx->bmp.width : ctx->width; + tex->height = nouv ? ctx->bmp.height : ctx->height; tex->uv.u1 = 0.0f; tex->uv.v1 = 0.0f; tex->uv.u2 = (float)ctx->width / (float)ctx->bmp.width; diff --git a/src/Game.c b/src/Game.c index 81ed15534..44b58f77d 100644 --- a/src/Game.c +++ b/src/Game.c @@ -475,7 +475,13 @@ static void Game_Load(void) { } entTaskI = ScheduledTask_Add(GAME_DEF_TICKS, Entities_Tick); - if (Gfx_WarnIfNecessary()) EnvRenderer_SetMode(EnvRenderer_Minimal | ENV_LEGACY); + Gfx_WarnIfNecessary(); + + if (Gfx.Limitations & GFX_LIMIT_VERTEX_ONLY_FOG) + EnvRenderer_SetMode(EnvRenderer_Minimal | ENV_LEGACY); + if (Gfx.BackendType == CC_GFX_BACKEND_SOFTGPU) + EnvRenderer_SetMode(ENV_MINIMAL); + Server.BeginConnect(); } diff --git a/src/Graphics.h b/src/Graphics.h index db24953ff..ff5051523 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -68,9 +68,8 @@ CC_VAR extern struct _GfxData { struct Matrix View, Projection; /* Whether the graphics backend supports non power of two textures */ cc_bool SupportsNonPowTwoTextures; - /* Whether the graphics backend supports U/V that don't occupy whole texture */ - /* e.g. Saturn, 3D0 systems don't support it */ - cc_bool NoUVSupport; + /* Limitations of the graphics backend, see GFX_LIMIT values */ + cc_bool Limitations; /* Type of the backend (e.g. OpenGL, Direct3D 9, etc)*/ cc_uint8 BackendType; cc_bool __pad; @@ -86,6 +85,13 @@ CC_VAR extern struct _GfxData { GfxResourceID DefaultIb; } Gfx; +/* Whether the graphics backend supports U/V that don't occupy whole texture */ +/* e.g. Saturn, 3D0 systems don't support it */ +#define GFX_LIMIT_NO_UV_SUPPORT 0x01 +/* Whether the graphics backend requires very large quads to be broken +/* up into smaller quads, to reduce fog interpolation artifacts */ +#define GFX_LIMIT_VERTEX_ONLY_FOG 0x02 + extern const cc_string Gfx_LowPerfMessage; #define ICOUNT(verticesCount) (((verticesCount) >> 2) * 6) diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index 6d2433798..dd7826537 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -500,6 +500,8 @@ cc_bool Gfx_WarnIfNecessary(void) { Chat_AddRaw("&cSoftware rendering is being used, performance will greatly suffer."); Chat_AddRaw("&cVSync may not work, and you may see disappearing clouds and map edges."); Chat_AddRaw("&cYou may need to install video card drivers."); + + Gfx.Limitations |= GFX_LIMIT_VERTEX_ONLY_FOG; return true; } if (String_ContainsConst(&renderer, "Intel")) { @@ -508,6 +510,8 @@ cc_bool Gfx_WarnIfNecessary(void) { #ifdef CC_BUILD_WIN Chat_AddRaw("&cTry downloading the Direct3D 9 build instead."); #endif + + Gfx.Limitations |= GFX_LIMIT_VERTEX_ONLY_FOG; return true; } return false; diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index fac6b5b0a..6735a27f0 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -101,7 +101,7 @@ void Gfx_Create(void) { Gfx.MaxTexWidth = 128; Gfx.MaxTexHeight = 16; // 128 Gfx.Created = true; - Gfx.NoUVSupport = true; + Gfx.Limitations = GFX_LIMIT_NO_UV_SUPPORT; } void Gfx_Free(void) { diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 3ee1f3b6e..414011f13 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -1609,13 +1609,14 @@ cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { } cc_result Platform_GetEntropy(void* data, int len) { + int ret; int fd = open("/dev/urandom", O_RDONLY); if (fd < 0) return ERR_NOT_SUPPORTED; // TODO: check return code? and partial reads? - read(fd, data, len); + ret = read(fd, data, len); close(fd); - return 0; + return ret == -1 ? errno : 0; } diff --git a/src/Window_X11.c b/src/Window_X11.c index 75901e0a2..6aab72025 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -439,8 +439,14 @@ static void DoCreateWindow(int width, int height) { XGetInputFocus(win_display, &focus, &focusRevert); if (focus == win) Window_Main.Focused = true; } -void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } -void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } + +void Window_Create2D(int width, int height) { + DoCreateWindow(width, height); +} + +void Window_Create3D(int width, int height) { + DoCreateWindow(width, height); +} void Window_Destroy(void) { Window win = Window_Main.Handle.val;