Skip to content

Commit

Permalink
Merge pull request #100 from tapir2342/query-max-texture-size
Browse files Browse the repository at this point in the history
Add function to query max texture size
  • Loading branch information
NoelFB authored Aug 28, 2024
2 parents 41938fe + cfbe9ca commit b29205e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Framework/Graphics/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Framework/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions Platform/include/foster_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions Platform/src/foster_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Platform/src/foster_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Platform/src/foster_renderer_opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b29205e

Please sign in to comment.