mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-01 13:34:18 +01:00
adjust texture swizzle
This commit is contained in:
parent
64610c161f
commit
b011d756ee
@ -3,6 +3,56 @@
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
|
||||
|
||||
uint32 LatteTextureMtl_AdjustTextureCompSel(Latte::E_GX2SURFFMT format, uint32 compSel)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case Latte::E_GX2SURFFMT::R8_UNORM: // R8 is replicated on all channels (while OpenGL would return 1.0 for BGA instead)
|
||||
case Latte::E_GX2SURFFMT::R8_SNORM: // probably the same as _UNORM, but needs testing
|
||||
if (compSel >= 1 && compSel <= 3)
|
||||
compSel = 0;
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::A1_B5_G5_R5_UNORM: // order of components is reversed (RGBA -> ABGR)
|
||||
if (compSel >= 0 && compSel <= 3)
|
||||
compSel = 3 - compSel;
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::BC4_UNORM:
|
||||
case Latte::E_GX2SURFFMT::BC4_SNORM:
|
||||
if (compSel >= 1 && compSel <= 3)
|
||||
compSel = 0;
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::BC5_UNORM:
|
||||
case Latte::E_GX2SURFFMT::BC5_SNORM:
|
||||
// RG maps to RG
|
||||
// B maps to ?
|
||||
// A maps to G (guessed)
|
||||
if (compSel == 3)
|
||||
compSel = 1; // read Alpha as Green
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::A2_B10_G10_R10_UNORM:
|
||||
// reverse components (Wii U: ABGR, OpenGL: RGBA)
|
||||
// used in Resident Evil Revelations
|
||||
if (compSel >= 0 && compSel <= 3)
|
||||
compSel = 3 - compSel;
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::X24_G8_UINT:
|
||||
// map everything to alpha?
|
||||
if (compSel >= 0 && compSel <= 3)
|
||||
compSel = 3;
|
||||
break;
|
||||
case Latte::E_GX2SURFFMT::R4_G4_UNORM:
|
||||
// red and green swapped
|
||||
if (compSel == 0)
|
||||
compSel = 1;
|
||||
else if (compSel == 1)
|
||||
compSel = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return compSel;
|
||||
}
|
||||
|
||||
LatteTextureViewMtl::LatteTextureViewMtl(MetalRenderer* mtlRenderer, LatteTextureMtl* texture, Latte::E_DIM dim, Latte::E_GX2SURFFMT format, sint32 firstMip, sint32 mipCount, sint32 firstSlice, sint32 sliceCount)
|
||||
: LatteTextureView(texture, firstMip, mipCount, firstSlice, sliceCount, dim, format), m_mtlr(mtlRenderer), m_baseTexture(texture)
|
||||
{
|
||||
@ -74,7 +124,10 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
|
||||
uint32 compSelG = (gpuSamplerSwizzle >> 19) & 0x7;
|
||||
uint32 compSelB = (gpuSamplerSwizzle >> 22) & 0x7;
|
||||
uint32 compSelA = (gpuSamplerSwizzle >> 25) & 0x7;
|
||||
// TODO: adjust
|
||||
compSelR = LatteTextureMtl_AdjustTextureCompSel(format, compSelR);
|
||||
compSelG = LatteTextureMtl_AdjustTextureCompSel(format, compSelG);
|
||||
compSelB = LatteTextureMtl_AdjustTextureCompSel(format, compSelB);
|
||||
compSelA = LatteTextureMtl_AdjustTextureCompSel(format, compSelA);
|
||||
|
||||
MTL::TextureType textureType;
|
||||
switch (dim)
|
||||
|
Loading…
Reference in New Issue
Block a user