Skip to content

Commit

Permalink
Merge pull request #2053 from LukeUsher/improve-texturestate-mappings
Browse files Browse the repository at this point in the history
rework texturestate mapping to be more sane + fix unmapped get
  • Loading branch information
PatrickvL committed Nov 28, 2020
2 parents 8c986c2 + a99d3f9 commit 8415397
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/core/hle/D3D8/Direct3D9/TextureStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void XboxTextureStateConverter::BuildTextureStateMappingTable()
// Values range 0-9 (D3DTSS_COLOROP to D3DTSS_TEXTURETRANSFORMFLAGS) become 12-21
// Values 10-21 (D3DTSS_ADDRESSU to D3DTSS_ALPHAKILL) become 0-11
bool bOldOrder = g_LibVersion_D3D8 <= 3948; // Verfied old order in 3944, new order in 4039

if (bOldOrder) {
if (State <= 9) {
index += 12;
Expand All @@ -115,7 +116,7 @@ void XboxTextureStateConverter::BuildTextureStateMappingTable()
}

EmuLog(LOG_LEVEL::INFO, "%s = %d", CxbxTextureStateInfo[State].S, index);
XboxTextureStateOffsets[State] = index;
XboxTextureStateOffsets[index] = State;
}
}

Expand Down Expand Up @@ -173,14 +174,9 @@ void XboxTextureStateConverter::Apply()
// If point sprites are enabled, we need to overwrite our existing state 0 with State 3 also
DWORD HostStage = (pointSpriteOverride && XboxStage == 3) ? 0 : XboxStage;

for (int StateIndex = xbox::X_D3DTSS_FIRST; StateIndex <= xbox::X_D3DTSS_LAST; StateIndex++) {
for (int State = xbox::X_D3DTSS_FIRST; State <= xbox::X_D3DTSS_LAST; State++) {
// Read the value of the current stage/state from the Xbox data structure
DWORD Value = D3D__TextureState[(XboxStage * xbox::X_D3DTS_STAGESIZE) + StateIndex];

// Convert the index of the current state to an index that we can use
// This handles the case when XDKs have different state values
DWORD State = XboxTextureStateOffsets[StateIndex];

DWORD Value = Get(XboxStage, State); // OR D3D__TextureState[(XboxStage * xbox::X_D3DTS_STAGESIZE) + XboxTextureStateOffsets[State]];
switch (State) {
// These types map 1:1 but have some unsupported values
case xbox::X_D3DTSS_ADDRESSU: case xbox::X_D3DTSS_ADDRESSV: case xbox::X_D3DTSS_ADDRESSW:
Expand Down Expand Up @@ -328,5 +324,5 @@ uint32_t XboxTextureStateConverter::Get(int textureStage, DWORD xboxState) {
if (xboxState < xbox::X_D3DTSS_FIRST || xboxState > xbox::X_D3DTSS_LAST)
CxbxKrnlCleanup("Requested texture state was out of range: %d", xboxState);

return D3D__TextureState[(textureStage * xbox::X_D3DTS_STAGESIZE) + xboxState];
return D3D__TextureState[(textureStage * xbox::X_D3DTS_STAGESIZE) + XboxTextureStateOffsets[xboxState]];
}

0 comments on commit 8415397

Please sign in to comment.