From cfbe9ca51427cacedc9fb683a9dd4b44fff45a7d Mon Sep 17 00:00:00 2001 From: Tapir Tapirsson Date: Tue, 13 Aug 2024 20:16:39 +0200 Subject: [PATCH] Add function to query max texture size --- Framework/Graphics/Graphics.cs | 4 +--- Framework/Platform.cs | 2 ++ Platform/include/foster_platform.h | 2 ++ Platform/src/foster_platform.c | 6 ++++++ Platform/src/foster_renderer.h | 2 ++ Platform/src/foster_renderer_opengl.c | 6 ++++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Framework/Graphics/Graphics.cs b/Framework/Graphics/Graphics.cs index c499e63..539e043 100644 --- a/Framework/Graphics/Graphics.cs +++ b/Framework/Graphics/Graphics.cs @@ -37,9 +37,7 @@ public static class Graphics internal static void Initialize() { Renderer = Platform.FosterGetRenderer(); - - // TODO: actually query the graphics device for this - MaxTextureSize = 8192; + MaxTextureSize = Platform.FosterGetMaxTextureSize(); } /// diff --git a/Framework/Platform.cs b/Framework/Platform.cs index 4ed2dde..bacfdab 100644 --- a/Framework/Platform.cs +++ b/Framework/Platform.cs @@ -229,6 +229,8 @@ static unsafe Platform() [LibraryImport(DLL)] public static partial void FosterGetDisplaySize(out int width, out int height); [LibraryImport(DLL)] + public static partial int FosterGetMaxTextureSize(); + [LibraryImport(DLL)] public static partial void FosterSetFlags(FosterFlags flags); [LibraryImport(DLL)] public static partial void FosterSetCentered(); diff --git a/Platform/include/foster_platform.h b/Platform/include/foster_platform.h index 78aaf48..dcd10cd 100644 --- a/Platform/include/foster_platform.h +++ b/Platform/include/foster_platform.h @@ -618,6 +618,8 @@ FOSTER_API void FosterGetSizeInPixels(int* width, int* height); FOSTER_API void FosterGetDisplaySize(int* width, int* height); +FOSTER_API int FosterGetMaxTextureSize(); + FOSTER_API void FosterSetFlags(FosterFlags flags); FOSTER_API void FosterSetCentered(); diff --git a/Platform/src/foster_platform.c b/Platform/src/foster_platform.c index 3b6b1e2..f574924 100644 --- a/Platform/src/foster_platform.c +++ b/Platform/src/foster_platform.c @@ -416,6 +416,12 @@ void FosterGetDisplaySize(int* width, int* height) *height = mode.h; } +int FosterGetMaxTextureSize() +{ + FOSTER_ASSERT_RUNNING_RET(FosterGetMaxTextureSize, -1); + return fstate.device.getMaxTextureSize(); +} + void FosterSetFlags(FosterFlags flags) { FOSTER_ASSERT_RUNNING(FosterSetFlags); diff --git a/Platform/src/foster_renderer.h b/Platform/src/foster_renderer.h index da3a238..04e0731 100644 --- a/Platform/src/foster_renderer.h +++ b/Platform/src/foster_renderer.h @@ -13,6 +13,8 @@ typedef struct FosterRenderDevice void (*shutdown)(); void (*frameBegin)(); void (*frameEnd)(); + + int (*getMaxTextureSize)(); FosterTexture* (*textureCreate)(int width, int height, FosterTextureFormat format); void (*textureSetData)(FosterTexture* texture, void* data, int length); diff --git a/Platform/src/foster_renderer_opengl.c b/Platform/src/foster_renderer_opengl.c index 2f3dff4..6d9cfd8 100644 --- a/Platform/src/foster_renderer_opengl.c +++ b/Platform/src/foster_renderer_opengl.c @@ -1098,6 +1098,11 @@ void FosterFrameEnd_OpenGL() SDL_GL_SwapWindow(state->window); } +int FosterGetMaxTextureSize_OpenGL() +{ + return fgl.max_texture_size; +} + FosterTexture* FosterTextureCreate_OpenGL(int width, int height, FosterTextureFormat format) { FosterTexture_OpenGL result; @@ -1820,6 +1825,7 @@ bool FosterGetDevice_OpenGL(FosterRenderDevice* device) device->shutdown = FosterShutdown_OpenGL; device->frameBegin = FosterFrameBegin_OpenGL; device->frameEnd = FosterFrameEnd_OpenGL; + device->getMaxTextureSize = FosterGetMaxTextureSize_OpenGL; device->textureCreate = FosterTextureCreate_OpenGL; device->textureSetData = FosterTextureSetData_OpenGL; device->textureGetData = FosterTextureGetData_OpenGL;