-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
render: Initial attempt at adding SDL_GenerateTextureMipmap(). #10254
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,9 @@ typedef struct | |
PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT; | ||
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT; | ||
|
||
/* glGenerateMipmap support */ | ||
PFNGLGENERATEMIPMAPPROC glGenerateMipmap; | ||
|
||
/* Shader support */ | ||
GL_ShaderContext *shaders; | ||
|
||
|
@@ -843,6 +846,24 @@ static void GL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) | |
GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch); | ||
} | ||
|
||
static int GL_GenMipmaps(SDL_Renderer *renderer, SDL_Texture *texture) | ||
{ | ||
GL_RenderData *renderdata = (GL_RenderData *)renderer->driverdata; | ||
SDL_assert(renderdata->glGenerateMipmap != NULL); // should have been set up at CreateRenderer time and we shouldn't be here if it isn't! | ||
|
||
if (texture != renderdata->drawstate.texture) { | ||
if (renderdata->GL_ARB_multitexture_supported) { | ||
renderdata->glActiveTextureARB(GL_TEXTURE0_ARB); | ||
} | ||
const GL_TextureData *texturedata = (GL_TextureData *)texture->driverdata; | ||
renderdata->glBindTexture(renderdata->textype, texturedata->texture); | ||
renderdata->drawstate.texture = texture; | ||
} | ||
|
||
renderdata->glGenerateMipmap(renderdata->textype); | ||
return 0; // GL does not report failure here. | ||
Comment on lines
+863
to
+864
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, glGenerateMipmap does report errors (in particular, for NPOT textures): https://registry.khronos.org/OpenGL-Refpages/es2.0/xhtml/glGenerateMipmap.xml |
||
} | ||
|
||
static void GL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode) | ||
{ | ||
GL_RenderData *renderdata = (GL_RenderData *)renderer->driverdata; | ||
|
@@ -1719,23 +1740,21 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro | |
data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); | ||
} | ||
|
||
int glmajorver = 1; | ||
const char *glverstr = (const char *)data->glGetString(GL_VERSION); | ||
if (glverstr) { | ||
char verbuf[16]; | ||
SDL_strlcpy(verbuf, glverstr, sizeof(verbuf)); | ||
char *ptr = SDL_strchr(verbuf, '.'); | ||
if (ptr) { | ||
*ptr = '\0'; | ||
glmajorver = SDL_atoi(verbuf); | ||
} | ||
} | ||
|
||
hint = SDL_getenv("GL_ARB_texture_non_power_of_two"); | ||
if (!hint || *hint != '0') { | ||
SDL_bool isGL2 = SDL_FALSE; | ||
const char *verstr = (const char *)data->glGetString(GL_VERSION); | ||
if (verstr) { | ||
char verbuf[16]; | ||
char *ptr; | ||
SDL_strlcpy(verbuf, verstr, sizeof(verbuf)); | ||
ptr = SDL_strchr(verbuf, '.'); | ||
if (ptr) { | ||
*ptr = '\0'; | ||
if (SDL_atoi(verbuf) >= 2) { | ||
isGL2 = SDL_TRUE; | ||
} | ||
} | ||
} | ||
if (isGL2 || SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) { | ||
if ((glmajorver >= 2) || SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) { | ||
non_power_of_two_supported = SDL_TRUE; | ||
} | ||
} | ||
|
@@ -1765,6 +1784,11 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro | |
} | ||
} | ||
|
||
if (glmajorver >= 3) { | ||
data->glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)SDL_GL_GetProcAddress("glGenerateMipmap"); | ||
renderer->GenMipmaps = (data->glGenerateMipmap != NULL) ? GL_GenMipmaps : NULL; | ||
Comment on lines
+1787
to
+1789
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For OpenGL < 3, glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) can be used as a fallback. |
||
} | ||
|
||
/* Check for shader support */ | ||
data->shaders = GL_CreateShaderContext(); | ||
SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "OpenGL shaders: %s", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mipmaps need one of
GL_*_MIPMAP_*
modes (e.gGL_LINEAR_MIPMAP_LINEAR
) forGL_TEXTURE_MIN_FILTER
to have effect. See https://www.khronos.org/opengl/wiki/Common_Mistakes#Automatic_mipmap_generation