mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-11 11:35:37 +00:00
Fix GetSampler() bug for INDEX8 pixel format (#15099)
(cherry picked from commit 4a4ae4a79d)
This commit is contained in:
committed by
Sam Lantinga
parent
27439467ce
commit
01d8bb5b7c
@@ -2423,6 +2423,11 @@ static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
|
||||
|
||||
static ID3D11SamplerState *D3D11_GetSamplerState(D3D11_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
|
||||
{
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader if needed
|
||||
scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
}
|
||||
|
||||
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||
if (!data->samplers[key]) {
|
||||
@@ -2440,12 +2445,7 @@ static ID3D11SamplerState *D3D11_GetSamplerState(D3D11_RenderData *data, SDL_Pix
|
||||
break;
|
||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
} else {
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
}
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||
|
||||
@@ -2863,6 +2863,11 @@ static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *
|
||||
|
||||
static D3D12_CPU_DESCRIPTOR_HANDLE *D3D12_GetSamplerState(D3D12_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
|
||||
{
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader if needed
|
||||
scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
}
|
||||
|
||||
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||
if (!data->samplers_created[key]) {
|
||||
@@ -2888,12 +2893,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE *D3D12_GetSamplerState(D3D12_RenderData *data
|
||||
break;
|
||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader
|
||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
||||
} else {
|
||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
}
|
||||
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||
|
||||
@@ -774,6 +774,11 @@ static void SetViewportAndScissor(GPU_RenderData *data)
|
||||
|
||||
static SDL_GPUSampler *GetSampler(GPU_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
|
||||
{
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader if needed
|
||||
scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
}
|
||||
|
||||
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||
if (!data->samplers[key]) {
|
||||
@@ -787,16 +792,9 @@ static SDL_GPUSampler *GetSampler(GPU_RenderData *data, SDL_PixelFormat format,
|
||||
break;
|
||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader
|
||||
sci.min_filter = SDL_GPU_FILTER_NEAREST;
|
||||
sci.mag_filter = SDL_GPU_FILTER_NEAREST;
|
||||
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
|
||||
} else {
|
||||
sci.min_filter = SDL_GPU_FILTER_LINEAR;
|
||||
sci.mag_filter = SDL_GPU_FILTER_LINEAR;
|
||||
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||
}
|
||||
sci.min_filter = SDL_GPU_FILTER_LINEAR;
|
||||
sci.mag_filter = SDL_GPU_FILTER_LINEAR;
|
||||
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||
|
||||
@@ -1560,6 +1560,11 @@ static bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, c
|
||||
|
||||
static id<MTLSamplerState> GetSampler(SDL3METAL_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
|
||||
{
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader if needed
|
||||
scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
}
|
||||
|
||||
NSNumber *key = [NSNumber numberWithInteger:RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v)];
|
||||
id<MTLSamplerState> mtlsampler = data.mtlsamplers[key];
|
||||
if (mtlsampler == nil) {
|
||||
@@ -1572,14 +1577,8 @@ static id<MTLSamplerState> GetSampler(SDL3METAL_RenderData *data, SDL_PixelForma
|
||||
break;
|
||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader
|
||||
samplerdesc.minFilter = MTLSamplerMinMagFilterNearest;
|
||||
samplerdesc.magFilter = MTLSamplerMinMagFilterNearest;
|
||||
} else {
|
||||
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
|
||||
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
|
||||
}
|
||||
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
|
||||
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||
|
||||
@@ -3874,6 +3874,11 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand
|
||||
|
||||
static VkSampler VULKAN_GetSampler(VULKAN_RenderData *data, SDL_PixelFormat format, SDL_ScaleMode scale_mode, SDL_TextureAddressMode address_u, SDL_TextureAddressMode address_v)
|
||||
{
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader if needed
|
||||
scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
}
|
||||
|
||||
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||
if (!data->samplers[key]) {
|
||||
@@ -3893,14 +3898,8 @@ static VkSampler VULKAN_GetSampler(VULKAN_RenderData *data, SDL_PixelFormat form
|
||||
break;
|
||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
||||
// We'll do linear sampling in the shader
|
||||
samplerCreateInfo.magFilter = VK_FILTER_NEAREST;
|
||||
samplerCreateInfo.minFilter = VK_FILTER_NEAREST;
|
||||
} else {
|
||||
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
|
||||
}
|
||||
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||
|
||||
Reference in New Issue
Block a user