Make texture scale mode a part of the 2D renderer draw state

Also added texture addressing mode support to the PSP and Vita renderers (untested)

Fixes https://github.com/libsdl-org/SDL/issues/12461
This commit is contained in:
Sam Lantinga
2025-03-05 18:56:59 -08:00
parent 6e2d3c9b5d
commit cb099ebd4f
19 changed files with 477 additions and 302 deletions

View File

@@ -124,7 +124,6 @@ typedef struct
DXGI_FORMAT mainTextureFormat;
ID3D12Resource *stagingBuffer;
D3D12_RESOURCE_STATES stagingResourceState;
D3D12_FILTER scaleMode;
D3D12_Shader shader;
const float *YCbCr_matrix;
#ifdef SDL_HAVE_YUV
@@ -1574,7 +1573,6 @@ static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
if (!textureData) {
return false;
}
textureData->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3D12_FILTER_MIN_MAG_MIP_POINT : D3D12_FILTER_MIN_MAG_MIP_LINEAR;
texture->internal = textureData;
textureData->mainTextureFormat = textureFormat;
@@ -2244,17 +2242,6 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
D3D_SAFE_RELEASE(textureData->stagingBuffer);
}
static void D3D12_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
{
D3D12_TextureData *textureData = (D3D12_TextureData *)texture->internal;
if (!textureData) {
return;
}
textureData->scaleMode = (scaleMode == SDL_SCALEMODE_NEAREST) ? D3D12_FILTER_MIN_MAG_MIP_POINT : D3D12_FILTER_MIN_MAG_MIP_LINEAR;
}
static bool D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal;
@@ -2745,8 +2732,8 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
D3D12_SetupShaderConstants(renderer, cmd, texture, &constants);
switch (textureData->scaleMode) {
case D3D12_FILTER_MIN_MAG_MIP_POINT:
switch (cmd->data.draw.texture_scale_mode) {
case SDL_SCALEMODE_NEAREST:
switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = &rendererData->samplers[D3D12_SAMPLER_NEAREST_CLAMP];
@@ -2758,7 +2745,7 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
return SDL_SetError("Unknown texture address mode: %d", cmd->data.draw.texture_address_mode);
}
break;
case D3D12_FILTER_MIN_MAG_MIP_LINEAR:
case SDL_SCALEMODE_LINEAR:
switch (cmd->data.draw.texture_address_mode) {
case SDL_TEXTURE_ADDRESS_CLAMP:
textureSampler = &rendererData->samplers[D3D12_SAMPLER_LINEAR_CLAMP];
@@ -2771,7 +2758,7 @@ static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *
}
break;
default:
return SDL_SetError("Unknown scale mode: %d", textureData->scaleMode);
return SDL_SetError("Unknown scale mode: %d", cmd->data.draw.texture_scale_mode);
}
#ifdef SDL_HAVE_YUV
if (textureData->yuv) {
@@ -3248,7 +3235,6 @@ bool D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Proper
#endif
renderer->LockTexture = D3D12_LockTexture;
renderer->UnlockTexture = D3D12_UnlockTexture;
renderer->SetTextureScaleMode = D3D12_SetTextureScaleMode;
renderer->SetRenderTarget = D3D12_SetRenderTarget;
renderer->QueueSetViewport = D3D12_QueueNoOp;
renderer->QueueSetDrawColor = D3D12_QueueNoOp;