Skip to content

Commit 3e9e22f

Browse files
committed
Added SDL_SCALEMODE_PIXELART
This is based on the algorithm presented by t3ssel8r: https://www.youtube.com/watch?v=d6tp43wZqps
1 parent 853375d commit 3e9e22f

File tree

63 files changed

+15602
-12759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+15602
-12759
lines changed

include/SDL3/SDL_surface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ typedef Uint32 SDL_SurfaceFlags;
8383
typedef enum SDL_ScaleMode
8484
{
8585
SDL_SCALEMODE_INVALID = -1,
86-
SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
87-
SDL_SCALEMODE_LINEAR /**< linear filtering */
86+
SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
87+
SDL_SCALEMODE_LINEAR, /**< linear filtering */
88+
SDL_SCALEMODE_PIXELART /**< nearest pixel sampling with improved scaling for pixel art */
8889
} SDL_ScaleMode;
8990

9091
/**

src/render/SDL_render.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,8 +1964,12 @@ bool SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
19641964
{
19651965
CHECK_TEXTURE_MAGIC(texture, false);
19661966

1967-
if (scaleMode != SDL_SCALEMODE_NEAREST &&
1968-
scaleMode != SDL_SCALEMODE_LINEAR) {
1967+
switch (scaleMode) {
1968+
case SDL_SCALEMODE_NEAREST:
1969+
case SDL_SCALEMODE_LINEAR:
1970+
case SDL_SCALEMODE_PIXELART:
1971+
break;
1972+
default:
19691973
return SDL_InvalidParamError("scaleMode");
19701974
}
19711975

@@ -5707,7 +5711,7 @@ static bool CreateDebugTextAtlas(SDL_Renderer *renderer)
57075711
// Convert temp surface into texture
57085712
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, atlas);
57095713
if (texture) {
5710-
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
5714+
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_PIXELART);
57115715
renderer->debug_char_texture_atlas = texture;
57125716
}
57135717
SDL_DestroySurface(atlas);

src/render/direct3d/SDL_render_d3d.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ static void UpdateTextureScaleMode(D3D_RenderData *data, SDL_ScaleMode scaleMode
921921
{
922922
if (scaleMode != data->scaleMode[index]) {
923923
switch (scaleMode) {
924+
case SDL_SCALEMODE_PIXELART:
924925
case SDL_SCALEMODE_NEAREST:
925926
IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MINFILTER, D3DTEXF_POINT);
926927
IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT);

0 commit comments

Comments
 (0)