mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-31 22:42:52 +08:00
Fix GetSampler() bug for INDEX8 pixel format (#15099)
This commit is contained in:
@@ -2395,6 +2395,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)
|
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);
|
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||||
if (!data->samplers[key]) {
|
if (!data->samplers[key]) {
|
||||||
@@ -2412,12 +2417,7 @@ static ID3D11SamplerState *D3D11_GetSamplerState(D3D11_RenderData *data, SDL_Pix
|
|||||||
break;
|
break;
|
||||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||||
case SDL_SCALEMODE_LINEAR:
|
case SDL_SCALEMODE_LINEAR:
|
||||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||||
|
|||||||
@@ -2838,6 +2838,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)
|
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);
|
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||||
if (!data->samplers_created[key]) {
|
if (!data->samplers_created[key]) {
|
||||||
@@ -2863,12 +2868,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE *D3D12_GetSamplerState(D3D12_RenderData *data
|
|||||||
break;
|
break;
|
||||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||||
case SDL_SCALEMODE_LINEAR:
|
case SDL_SCALEMODE_LINEAR:
|
||||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||||
|
|||||||
@@ -790,6 +790,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)
|
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);
|
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||||
if (!data->samplers[key]) {
|
if (!data->samplers[key]) {
|
||||||
@@ -803,16 +808,9 @@ static SDL_GPUSampler *GetSampler(GPU_RenderData *data, SDL_PixelFormat format,
|
|||||||
break;
|
break;
|
||||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||||
case SDL_SCALEMODE_LINEAR:
|
case SDL_SCALEMODE_LINEAR:
|
||||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
sci.min_filter = SDL_GPU_FILTER_LINEAR;
|
||||||
// We'll do linear sampling in the shader
|
sci.mag_filter = SDL_GPU_FILTER_LINEAR;
|
||||||
sci.min_filter = SDL_GPU_FILTER_NEAREST;
|
sci.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||||
|
|||||||
@@ -1584,6 +1584,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)
|
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)];
|
NSNumber *key = [NSNumber numberWithInteger:RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v)];
|
||||||
id<MTLSamplerState> mtlsampler = data.mtlsamplers[key];
|
id<MTLSamplerState> mtlsampler = data.mtlsamplers[key];
|
||||||
if (mtlsampler == nil) {
|
if (mtlsampler == nil) {
|
||||||
@@ -1596,14 +1601,8 @@ static id<MTLSamplerState> GetSampler(SDL3METAL_RenderData *data, SDL_PixelForma
|
|||||||
break;
|
break;
|
||||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||||
case SDL_SCALEMODE_LINEAR:
|
case SDL_SCALEMODE_LINEAR:
|
||||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
|
||||||
// We'll do linear sampling in the shader
|
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
|
||||||
samplerdesc.minFilter = MTLSamplerMinMagFilterNearest;
|
|
||||||
samplerdesc.magFilter = MTLSamplerMinMagFilterNearest;
|
|
||||||
} else {
|
|
||||||
samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
|
|
||||||
samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||||
|
|||||||
@@ -3870,6 +3870,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)
|
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);
|
Uint32 key = RENDER_SAMPLER_HASHKEY(scale_mode, address_u, address_v);
|
||||||
SDL_assert(key < SDL_arraysize(data->samplers));
|
SDL_assert(key < SDL_arraysize(data->samplers));
|
||||||
if (!data->samplers[key]) {
|
if (!data->samplers[key]) {
|
||||||
@@ -3889,14 +3894,8 @@ static VkSampler VULKAN_GetSampler(VULKAN_RenderData *data, SDL_PixelFormat form
|
|||||||
break;
|
break;
|
||||||
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
|
||||||
case SDL_SCALEMODE_LINEAR:
|
case SDL_SCALEMODE_LINEAR:
|
||||||
if (format == SDL_PIXELFORMAT_INDEX8) {
|
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
|
||||||
// We'll do linear sampling in the shader
|
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
|
||||||
samplerCreateInfo.magFilter = VK_FILTER_NEAREST;
|
|
||||||
samplerCreateInfo.minFilter = VK_FILTER_NEAREST;
|
|
||||||
} else {
|
|
||||||
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
|
|
||||||
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
SDL_SetError("Unknown scale mode: %d", scale_mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user