OpenGL: Respect max supported texture size (#518)

This commit is contained in:
Anders Jenbo 2025-07-04 14:47:24 +02:00 committed by GitHub
parent 5e62e7e39f
commit 4983da422c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 3 deletions

View File

@ -42,6 +42,13 @@ void GL11_DestroyTexture(GLuint texId)
glDeleteTextures(1, &texId);
}
int GL11_GetMaxTextureSize()
{
GLint maxTextureSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
return maxTextureSize;
}
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUi)
{
GLuint texId;

View File

@ -64,6 +64,7 @@ struct GLMeshCacheEntry {
void GL11_InitState();
void GL11_LoadExtensions();
void GL11_DestroyTexture(GLuint texId);
int GL11_GetMaxTextureSize();
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUI);
void GL11_UploadMesh(GLMeshCacheEntry& cache, bool hasTexture);
void GL11_DestroyMesh(GLMeshCacheEntry& cache);

View File

@ -132,10 +132,21 @@ static Uint32 UploadTextureData(SDL_Surface* src, bool useNPOT, bool isUi)
SDL_Surface* finalSurface = working;
int newW = NextPowerOfTwo(working->w);
int newH = NextPowerOfTwo(working->h);
int newW = working->w;
int newH = working->h;
if (!useNPOT) {
newW = NextPowerOfTwo(newW);
newH = NextPowerOfTwo(newH);
}
int max = GL11_GetMaxTextureSize();
if (newW > max) {
newW = max;
}
if (newH > max) {
newH = max;
}
if (!useNPOT && (newW != working->w || newH != working->h)) {
if (newW != working->w || newH != working->h) {
SDL_Surface* resized = SDL_CreateSurface(newW, newH, working->format);
if (!resized) {
SDL_Log("SDL_CreateSurface (resize) failed: %s", SDL_GetError());