Skip to content

Commit 134b477

Browse files
committed
Added support for linear and pixel art scaling for palettized textures
1 parent e1fde46 commit 134b477

Some content is hidden

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

43 files changed

+11262
-7512
lines changed

include/SDL3/SDL_render.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,6 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, S
12341234
* The default texture scale mode is SDL_SCALEMODE_LINEAR.
12351235
*
12361236
* If the scale mode is not supported, the closest supported mode is chosen.
1237-
* Palettized textures will always use SDL_SCALEMODE_NEAREST.
12381237
*
12391238
* \param texture the texture to update.
12401239
* \param scaleMode the SDL_ScaleMode to use for texture scaling.

src/render/SDL_render.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,11 +1525,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
15251525
texture->color.b = 1.0f;
15261526
texture->color.a = 1.0f;
15271527
texture->blendMode = SDL_ISPIXELFORMAT_ALPHA(format) ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE;
1528-
if (SDL_ISPIXELFORMAT_INDEXED(format)) {
1529-
texture->scaleMode = SDL_SCALEMODE_NEAREST;
1530-
} else {
1531-
texture->scaleMode = renderer->scale_mode;
1532-
}
1528+
texture->scaleMode = renderer->scale_mode;
15331529
texture->view.pixel_w = w;
15341530
texture->view.pixel_h = h;
15351531
texture->view.viewport.w = -1;
@@ -2162,12 +2158,8 @@ bool SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
21622158

21632159
switch (scaleMode) {
21642160
case SDL_SCALEMODE_NEAREST:
2165-
break;
21662161
case SDL_SCALEMODE_PIXELART:
21672162
case SDL_SCALEMODE_LINEAR:
2168-
if (SDL_ISPIXELFORMAT_INDEXED(texture->format)) {
2169-
scaleMode = SDL_SCALEMODE_NEAREST;
2170-
}
21712163
break;
21722164
default:
21732165
return SDL_InvalidParamError("scaleMode");

src/render/direct3d/D3D9_PixelShader_Palette.h

Lines changed: 228 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,263 @@
66
//
77
// sampler2D image;
88
// sampler1D palette;
9+
// float4 texel_size;
10+
// float texture_type;
911
//
1012
//
1113
// Registers:
1214
//
1315
// Name Reg Size
1416
// ------------ ----- ----
17+
// texture_type c0 1
18+
// texel_size c1 1
1519
// image s0 1
1620
// palette s1 1
1721
//
1822

1923
ps_2_0
20-
def c0, 0.99609375, 0.001953125, 0, 0
21-
dcl t0.xy
24+
def c2, -1, 255, 0.5, 0.00390625
25+
def c3, -2, 0, 0, 0
26+
def c4, 1, 0, 0, 1
2227
dcl v0
28+
dcl t0.xy
2329
dcl_2d s0
2430
dcl_2d s1
25-
texld r0, t0, s0
26-
mad r0.xy, r0.x, c0.x, c0.y
27-
texld r0, r0, s1
31+
mov r0.xz, c2
32+
mad r1.x, t0.x, c1.z, r0.z
33+
mad r1.y, t0.y, c1.w, r0.z
34+
frc r0.yz, r1.zxyw
35+
add r1.xy, -r0.yzxw, r1
36+
add r1.zw, r1.wzyx, -c2.z
37+
add r1.xy, r1, c2.z
38+
mul r1.xy, r1, c1
39+
mul r2.xy, r1.wzyx, c1
40+
mov r3.x, r2.x
41+
mov r3.y, r1.y
42+
mov r4.y, r2.y
43+
mov r4.x, r1.x
44+
texld r3, r3, s0
45+
texld r2, r2, s0
46+
texld r1, r1, s0
47+
texld r4, r4, s0
48+
texld r5, t0, s0
49+
mad r0.w, r3.x, c2.y, c2.z
50+
mul r3.xy, r0.w, c2.w
51+
mad r0.w, r2.x, c2.y, c2.z
52+
mul r2.xy, r0.w, c2.w
53+
mad r0.w, r1.x, c2.y, c2.z
54+
mul r1.xy, r0.w, c2.w
55+
mad r0.w, r4.x, c2.y, c2.z
56+
mul r4.xy, r0.w, c2.w
57+
mad r0.w, r5.x, c2.y, c2.z
58+
mul r5.xy, r0.w, c2.w
59+
texld r3, r3, s1
60+
texld r2, r2, s1
61+
texld r1, r1, s1
62+
texld r4, r4, s1
63+
texld r5, r5, s1
64+
lrp r6, r0.z, r3, r2
65+
lrp r2, r0.z, r1, r4
66+
lrp r1, r0.y, r2, r6
67+
mov r2.x, c0.x
68+
add r0.y, r2.x, c3.x
69+
mul r0.y, r0.y, r0.y
70+
cmp r1, -r0.y, r1, c4
71+
add r0.x, r0.x, c0.x
72+
mul r0.x, r0.x, r0.x
73+
cmp r0, -r0.x, r5, r1
2874
mul r0, r0, v0
2975
mov oC0, r0
3076

31-
// approximately 5 instruction slots used (2 texture, 3 arithmetic)
77+
// approximately 45 instruction slots used (10 texture, 35 arithmetic)
3278
#endif
3379

3480
const BYTE g_ps20_main[] =
3581
{
3682
0, 2, 255, 255, 254, 255,
37-
42, 0, 67, 84, 65, 66,
38-
28, 0, 0, 0, 123, 0,
83+
67, 0, 67, 84, 65, 66,
84+
28, 0, 0, 0, 223, 0,
3985
0, 0, 0, 2, 255, 255,
40-
2, 0, 0, 0, 28, 0,
86+
4, 0, 0, 0, 28, 0,
4187
0, 0, 0, 1, 0, 0,
42-
116, 0, 0, 0, 68, 0,
88+
216, 0, 0, 0, 108, 0,
4389
0, 0, 3, 0, 0, 0,
44-
1, 0, 0, 0, 76, 0,
90+
1, 0, 0, 0, 116, 0,
4591
0, 0, 0, 0, 0, 0,
46-
92, 0, 0, 0, 3, 0,
92+
132, 0, 0, 0, 3, 0,
4793
1, 0, 1, 0, 0, 0,
48-
100, 0, 0, 0, 0, 0,
49-
0, 0, 105, 109, 97, 103,
50-
101, 0, 171, 171, 4, 0,
51-
12, 0, 1, 0, 1, 0,
52-
1, 0, 0, 0, 0, 0,
53-
0, 0, 112, 97, 108, 101,
54-
116, 116, 101, 0, 4, 0,
55-
11, 0, 1, 0, 1, 0,
56-
1, 0, 0, 0, 0, 0,
57-
0, 0, 112, 115, 95, 50,
58-
95, 48, 0, 77, 105, 99,
59-
114, 111, 115, 111, 102, 116,
60-
32, 40, 82, 41, 32, 72,
61-
76, 83, 76, 32, 83, 104,
62-
97, 100, 101, 114, 32, 67,
63-
111, 109, 112, 105, 108, 101,
64-
114, 32, 49, 48, 46, 49,
65-
0, 171, 81, 0, 0, 5,
66-
0, 0, 15, 160, 0, 0,
67-
127, 63, 0, 0, 0, 59,
94+
140, 0, 0, 0, 0, 0,
95+
0, 0, 156, 0, 0, 0,
96+
2, 0, 1, 0, 1, 0,
97+
0, 0, 168, 0, 0, 0,
98+
0, 0, 0, 0, 184, 0,
99+
0, 0, 2, 0, 0, 0,
100+
1, 0, 0, 0, 200, 0,
101+
0, 0, 0, 0, 0, 0,
102+
105, 109, 97, 103, 101, 0,
103+
171, 171, 4, 0, 12, 0,
104+
1, 0, 1, 0, 1, 0,
105+
0, 0, 0, 0, 0, 0,
106+
112, 97, 108, 101, 116, 116,
107+
101, 0, 4, 0, 11, 0,
108+
1, 0, 1, 0, 1, 0,
109+
0, 0, 0, 0, 0, 0,
110+
116, 101, 120, 101, 108, 95,
111+
115, 105, 122, 101, 0, 171,
112+
1, 0, 3, 0, 1, 0,
113+
4, 0, 1, 0, 0, 0,
114+
0, 0, 0, 0, 116, 101,
115+
120, 116, 117, 114, 101, 95,
116+
116, 121, 112, 101, 0, 171,
117+
171, 171, 0, 0, 3, 0,
118+
1, 0, 1, 0, 1, 0,
68119
0, 0, 0, 0, 0, 0,
69-
0, 0, 31, 0, 0, 2,
70-
0, 0, 0, 128, 0, 0,
71-
3, 176, 31, 0, 0, 2,
72-
0, 0, 0, 128, 0, 0,
73-
15, 144, 31, 0, 0, 2,
74-
0, 0, 0, 144, 0, 8,
75-
15, 160, 31, 0, 0, 2,
76-
0, 0, 0, 144, 1, 8,
77-
15, 160, 66, 0, 0, 3,
78-
0, 0, 15, 128, 0, 0,
79-
228, 176, 0, 8, 228, 160,
80-
4, 0, 0, 4, 0, 0,
81-
3, 128, 0, 0, 0, 128,
82-
0, 0, 0, 160, 0, 0,
83-
85, 160, 66, 0, 0, 3,
84-
0, 0, 15, 128, 0, 0,
120+
112, 115, 95, 50, 95, 48,
121+
0, 77, 105, 99, 114, 111,
122+
115, 111, 102, 116, 32, 40,
123+
82, 41, 32, 72, 76, 83,
124+
76, 32, 83, 104, 97, 100,
125+
101, 114, 32, 67, 111, 109,
126+
112, 105, 108, 101, 114, 32,
127+
49, 48, 46, 49, 0, 171,
128+
81, 0, 0, 5, 2, 0,
129+
15, 160, 0, 0, 128, 191,
130+
0, 0, 127, 67, 0, 0,
131+
0, 63, 0, 0, 128, 59,
132+
81, 0, 0, 5, 3, 0,
133+
15, 160, 0, 0, 0, 192,
134+
0, 0, 0, 0, 0, 0,
135+
0, 0, 0, 0, 0, 0,
136+
81, 0, 0, 5, 4, 0,
137+
15, 160, 0, 0, 128, 63,
138+
0, 0, 0, 0, 0, 0,
139+
0, 0, 0, 0, 128, 63,
140+
31, 0, 0, 2, 0, 0,
141+
0, 128, 0, 0, 15, 144,
142+
31, 0, 0, 2, 0, 0,
143+
0, 128, 0, 0, 3, 176,
144+
31, 0, 0, 2, 0, 0,
145+
0, 144, 0, 8, 15, 160,
146+
31, 0, 0, 2, 0, 0,
147+
0, 144, 1, 8, 15, 160,
148+
1, 0, 0, 2, 0, 0,
149+
5, 128, 2, 0, 228, 160,
150+
4, 0, 0, 4, 1, 0,
151+
1, 128, 0, 0, 0, 176,
152+
1, 0, 170, 160, 0, 0,
153+
170, 128, 4, 0, 0, 4,
154+
1, 0, 2, 128, 0, 0,
155+
85, 176, 1, 0, 255, 160,
156+
0, 0, 170, 128, 19, 0,
157+
0, 2, 0, 0, 6, 128,
158+
1, 0, 210, 128, 2, 0,
159+
0, 3, 1, 0, 3, 128,
160+
0, 0, 201, 129, 1, 0,
161+
228, 128, 2, 0, 0, 3,
162+
1, 0, 12, 128, 1, 0,
163+
27, 128, 2, 0, 170, 161,
164+
2, 0, 0, 3, 1, 0,
165+
3, 128, 1, 0, 228, 128,
166+
2, 0, 170, 160, 5, 0,
167+
0, 3, 1, 0, 3, 128,
168+
1, 0, 228, 128, 1, 0,
169+
228, 160, 5, 0, 0, 3,
170+
2, 0, 3, 128, 1, 0,
171+
27, 128, 1, 0, 228, 160,
172+
1, 0, 0, 2, 3, 0,
173+
1, 128, 2, 0, 0, 128,
174+
1, 0, 0, 2, 3, 0,
175+
2, 128, 1, 0, 85, 128,
176+
1, 0, 0, 2, 4, 0,
177+
2, 128, 2, 0, 85, 128,
178+
1, 0, 0, 2, 4, 0,
179+
1, 128, 1, 0, 0, 128,
180+
66, 0, 0, 3, 3, 0,
181+
15, 128, 3, 0, 228, 128,
182+
0, 8, 228, 160, 66, 0,
183+
0, 3, 2, 0, 15, 128,
184+
2, 0, 228, 128, 0, 8,
185+
228, 160, 66, 0, 0, 3,
186+
1, 0, 15, 128, 1, 0,
187+
228, 128, 0, 8, 228, 160,
188+
66, 0, 0, 3, 4, 0,
189+
15, 128, 4, 0, 228, 128,
190+
0, 8, 228, 160, 66, 0,
191+
0, 3, 5, 0, 15, 128,
192+
0, 0, 228, 176, 0, 8,
193+
228, 160, 4, 0, 0, 4,
194+
0, 0, 8, 128, 3, 0,
195+
0, 128, 2, 0, 85, 160,
196+
2, 0, 170, 160, 5, 0,
197+
0, 3, 3, 0, 3, 128,
198+
0, 0, 255, 128, 2, 0,
199+
255, 160, 4, 0, 0, 4,
200+
0, 0, 8, 128, 2, 0,
201+
0, 128, 2, 0, 85, 160,
202+
2, 0, 170, 160, 5, 0,
203+
0, 3, 2, 0, 3, 128,
204+
0, 0, 255, 128, 2, 0,
205+
255, 160, 4, 0, 0, 4,
206+
0, 0, 8, 128, 1, 0,
207+
0, 128, 2, 0, 85, 160,
208+
2, 0, 170, 160, 5, 0,
209+
0, 3, 1, 0, 3, 128,
210+
0, 0, 255, 128, 2, 0,
211+
255, 160, 4, 0, 0, 4,
212+
0, 0, 8, 128, 4, 0,
213+
0, 128, 2, 0, 85, 160,
214+
2, 0, 170, 160, 5, 0,
215+
0, 3, 4, 0, 3, 128,
216+
0, 0, 255, 128, 2, 0,
217+
255, 160, 4, 0, 0, 4,
218+
0, 0, 8, 128, 5, 0,
219+
0, 128, 2, 0, 85, 160,
220+
2, 0, 170, 160, 5, 0,
221+
0, 3, 5, 0, 3, 128,
222+
0, 0, 255, 128, 2, 0,
223+
255, 160, 66, 0, 0, 3,
224+
3, 0, 15, 128, 3, 0,
85225
228, 128, 1, 8, 228, 160,
226+
66, 0, 0, 3, 2, 0,
227+
15, 128, 2, 0, 228, 128,
228+
1, 8, 228, 160, 66, 0,
229+
0, 3, 1, 0, 15, 128,
230+
1, 0, 228, 128, 1, 8,
231+
228, 160, 66, 0, 0, 3,
232+
4, 0, 15, 128, 4, 0,
233+
228, 128, 1, 8, 228, 160,
234+
66, 0, 0, 3, 5, 0,
235+
15, 128, 5, 0, 228, 128,
236+
1, 8, 228, 160, 18, 0,
237+
0, 4, 6, 0, 15, 128,
238+
0, 0, 170, 128, 3, 0,
239+
228, 128, 2, 0, 228, 128,
240+
18, 0, 0, 4, 2, 0,
241+
15, 128, 0, 0, 170, 128,
242+
1, 0, 228, 128, 4, 0,
243+
228, 128, 18, 0, 0, 4,
244+
1, 0, 15, 128, 0, 0,
245+
85, 128, 2, 0, 228, 128,
246+
6, 0, 228, 128, 1, 0,
247+
0, 2, 2, 0, 1, 128,
248+
0, 0, 0, 160, 2, 0,
249+
0, 3, 0, 0, 2, 128,
250+
2, 0, 0, 128, 3, 0,
251+
0, 160, 5, 0, 0, 3,
252+
0, 0, 2, 128, 0, 0,
253+
85, 128, 0, 0, 85, 128,
254+
88, 0, 0, 4, 1, 0,
255+
15, 128, 0, 0, 85, 129,
256+
1, 0, 228, 128, 4, 0,
257+
228, 160, 2, 0, 0, 3,
258+
0, 0, 1, 128, 0, 0,
259+
0, 128, 0, 0, 0, 160,
260+
5, 0, 0, 3, 0, 0,
261+
1, 128, 0, 0, 0, 128,
262+
0, 0, 0, 128, 88, 0,
263+
0, 4, 0, 0, 15, 128,
264+
0, 0, 0, 129, 5, 0,
265+
228, 128, 1, 0, 228, 128,
86266
5, 0, 0, 3, 0, 0,
87267
15, 128, 0, 0, 228, 128,
88268
0, 0, 228, 144, 1, 0,

src/render/direct3d/D3D9_PixelShader_Palette.hlsl

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)