Fixed bug 4134 - Render targets lose scale quality after minimizing a fullscreen window Olli-Samuli Lehmus If one creates a window with the SDL_WINDOW_FULLSCREEN_DESKTOP flag, and creates a render target with SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"), and afterwards sets SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"), after minimizing the window, the scale quality hint is lost on the render target. Textures however do keep their interpolation modes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 8cd3a7b..18d0a11 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -493,6 +493,21 @@ GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format)
return renderer->info.texture_formats[0];
}
+SDL_ScaleMode SDL_GetScaleMode(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || SDL_strcasecmp(hint, "nearest") == 0) {
+ return SDL_ScaleModeNearest;
+ } else if (SDL_strcasecmp(hint, "linear") == 0) {
+ return SDL_ScaleModeLinear;
+ } else if (SDL_strcasecmp(hint, "best") == 0) {
+ return SDL_ScaleModeBest;
+ } else {
+ return (SDL_ScaleMode)SDL_atoi(hint);
+ }
+}
+
SDL_Texture *
SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)
{
@@ -534,6 +549,7 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
texture->g = 255;
texture->b = 255;
texture->a = 255;
+ texture->scaleMode = SDL_GetScaleMode();
texture->renderer = renderer;
texture->next = renderer->textures;
if (renderer->textures) {
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index f0f54c8..037124d 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -31,6 +31,13 @@
typedef struct SDL_RenderDriver SDL_RenderDriver;
+typedef enum
+{
+ SDL_ScaleModeNearest,
+ SDL_ScaleModeLinear,
+ SDL_ScaleModeBest
+} SDL_ScaleMode;
+
typedef struct
{
float x;
@@ -55,6 +62,7 @@ struct SDL_Texture
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
+ SDL_ScaleMode scaleMode; /**< The texture scale mode */
Uint8 r, g, b, a; /**< Texture modulation values */
SDL_Renderer *renderer;
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index d3be571..69a9dff 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -664,18 +664,6 @@ D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
return SDL_TRUE;
}
-static D3DTEXTUREFILTERTYPE
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return D3DTEXF_POINT;
- } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
- return D3DTEXF_LINEAR;
- }
-}
-
static int
D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h)
{
@@ -829,7 +817,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (!texturedata) {
return SDL_OutOfMemory();
}
- texturedata->scaleMode = GetScaleQuality();
+ texturedata->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR;
texture->driverdata = texturedata;
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index e0ccfc4..153cee7 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -1161,17 +1161,6 @@ D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
return SDL_TRUE;
}
-static D3D11_FILTER
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return D3D11_FILTER_MIN_MAG_MIP_POINT;
- } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
- return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
- }
-}
-
static int
D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
@@ -1192,7 +1181,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_OutOfMemory();
return -1;
}
- textureData->scaleMode = GetScaleQuality();
+ textureData->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
texture->driverdata = textureData;
diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index f7af72d..7fbc839 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -853,8 +853,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
METAL_TextureData *texturedata = [[METAL_TextureData alloc] init];
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ if (texture->scaleMode == SDL_ScaleModeNearest) {
texturedata.mtlsampler = data.mtlsamplernearest;
} else {
texturedata.mtlsampler = data.mtlsamplerlinear;
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 1c379eb..f3e8326 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -703,18 +703,6 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
return SDL_TRUE;
}
-static GLenum
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return GL_NEAREST;
- } else {
- return GL_LINEAR;
- }
-}
-
static int
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
@@ -803,7 +791,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
data->format = format;
data->formattype = type;
- scaleMode = GetScaleQuality();
+ scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c
index d6bfca5..4007dff 100644
--- a/src/render/opengles/SDL_render_gles.c
+++ b/src/render/opengles/SDL_render_gles.c
@@ -524,18 +524,6 @@ power_of_2(int input)
return value;
}
-static GLenum
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return GL_NEAREST;
- } else {
- return GL_LINEAR;
- }
-}
-
static int
GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
@@ -603,7 +591,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
data->format = format;
data->formattype = type;
- scaleMode = GetScaleQuality();
+ scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
renderdata->glBindTexture(data->type, data->texture);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 0cd388c..14671f7 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -553,18 +553,6 @@ static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture);
static int GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
-static GLenum
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return GL_NEAREST;
- } else {
- return GL_LINEAR;
- }
-}
-
static int
GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
@@ -625,7 +613,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
data->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21));
data->texture_u = 0;
data->texture_v = 0;
- scaleMode = GetScaleQuality();
+ scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
/* Allocate a blob for image renderdata */
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c
index 38f893e..babc252 100644
--- a/src/render/psp/SDL_render_psp.c
+++ b/src/render/psp/SDL_render_psp.c
@@ -187,18 +187,6 @@ TextureNextPow2(unsigned int w)
static int
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return GU_NEAREST; /* GU_NEAREST good for tile-map */
- } else {
- return GU_LINEAR; /* GU_LINEAR good for scaling */
- }
-}
-
-static int
PixelFormatToPSPFMT(Uint32 format)
{
switch (format) {
@@ -514,7 +502,7 @@ void
TextureActivate(SDL_Texture * texture)
{
PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
- int scaleMode = GetScaleQuality();
+ int scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GU_NEAREST : GU_LINEAR;
/* Swizzling is useless with small textures. */
if (texture->w >= 16 || texture->h >= 16)
diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c
index 89e54b8..0c14cac 100644
--- a/src/render/software/SDL_render_sw.c
+++ b/src/render/software/SDL_render_sw.c
@@ -588,18 +588,6 @@ SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
}
static int
-GetScaleQuality(void)
-{
- const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
-
- if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
- return 0;
- } else {
- return 1;
- }
-}
-
-static int
SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
@@ -717,7 +705,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
if (!retval) {
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle);
- src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
+ src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, (texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
if (src_rotated == NULL) {
retval = -1;
}