Fix color space of SDL3_gpu texture (#188)

This commit is contained in:
Anonymous Maarten 2025-05-28 05:40:46 +02:00 committed by GitHub
parent 19f1bedd16
commit 8f8bf3142e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -147,7 +147,7 @@ SDL_GPUGraphicsPipeline* InitializeGraphicsPipeline(SDL_GPUDevice* device)
vertexInputState.num_vertex_attributes = SDL_arraysize(vertexAttrs);
SDL_GPUColorTargetDescription colorTargets = {};
colorTargets.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB;
colorTargets.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
SDL_GPUGraphicsPipelineCreateInfo pipelineCreateInfo = {};
pipelineCreateInfo.vertex_shader = vertexShader;
@ -295,7 +295,7 @@ HRESULT Direct3DRM_SDL3GPUImpl::CreateViewport(
SDL_GPUTextureCreateInfo textureInfo = {};
textureInfo.type = SDL_GPU_TEXTURETYPE_2D;
textureInfo.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB;
textureInfo.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
textureInfo.width = width;
textureInfo.height = height;
textureInfo.layer_count_or_depth = 1;
@ -303,6 +303,8 @@ HRESULT Direct3DRM_SDL3GPUImpl::CreateViewport(
textureInfo.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
SDL_GPUTexture* transferTexture = SDL_CreateGPUTexture(device->m_device, &textureInfo);
if (!transferTexture) {
SDL_ReleaseGPUGraphicsPipeline(device->m_device, pipeline);
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_CreateGPUTexture for backbuffer failed (%s)", SDL_GetError());
return DDERR_GENERIC;
}
@ -313,9 +315,12 @@ HRESULT Direct3DRM_SDL3GPUImpl::CreateViewport(
depthTextureInfo.height = height;
depthTextureInfo.layer_count_or_depth = 1;
depthTextureInfo.num_levels = 1;
depthTextureInfo.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
depthTextureInfo.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
SDL_GPUTexture* depthTexture = SDL_CreateGPUTexture(device->m_device, &depthTextureInfo);
if (!depthTexture) {
SDL_ReleaseGPUGraphicsPipeline(device->m_device, pipeline);
SDL_ReleaseGPUTexture(device->m_device, transferTexture);
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_CreateGPUTexture for depth buffer (%s)", SDL_GetError());
return DDERR_GENERIC;
}
@ -326,6 +331,10 @@ HRESULT Direct3DRM_SDL3GPUImpl::CreateViewport(
SDL_GPUTransferBuffer* downloadTransferBuffer =
SDL_CreateGPUTransferBuffer(device->m_device, &downloadTransferInfo);
if (!downloadTransferBuffer) {
SDL_ReleaseGPUGraphicsPipeline(device->m_device, pipeline);
SDL_ReleaseGPUTexture(device->m_device, depthTexture);
SDL_ReleaseGPUTexture(device->m_device, transferTexture);
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_CreateGPUTransferBuffer failed (%s)", SDL_GetError());
return DDERR_GENERIC;
}

View File

@ -215,10 +215,10 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::CollectSceneData()
vtx.nx = viewNorm.x;
vtx.ny = viewNorm.y;
vtx.nz = viewNorm.z;
vtx.a = (color >> 24) & 0xFF;
vtx.r = (color >> 16) & 0xFF;
vtx.g = (color >> 8) & 0xFF;
vtx.b = (color >> 0) & 0xFF;
vtx.a = (color >> 24) & 0xFF;
verts.push_back(vtx);
}
}