From b70c0a9dc511b6a3dd4e507863e35ae5b00f44c2 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 5 Nov 2026 04:11:40 +0000 Subject: [PATCH] Decompile fn_02224 (CRendererDX9::DrawAlphaQueues) Batch #11661 by cremane: 0 byte-identical, 1 confirmed by peer review. - fn_02224 CRendererDX9::DrawAlphaQueues: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Render/DX9/AlphaQueuesDX9.cpp | 68 ++++++++++++++++------------ 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/Source/Render/DX9/AlphaQueuesDX9.cpp b/Source/Render/DX9/AlphaQueuesDX9.cpp index 7c3989ab..2697069f 100644 --- a/Source/Render/DX9/AlphaQueuesDX9.cpp +++ b/Source/Render/DX9/AlphaQueuesDX9.cpp @@ -31,8 +31,12 @@ namespace { // FUNCTION: fn_02224 void CRendererDX9::DrawAlphaQueues(RenderQueues& queues, unsigned char twoPass) { ScopedDeviceStateDX9 restore(this->device->state); - std::sort(queues.queue_018C.begin(), queues.queue_018C.end(), Before); - std::sort(queues.queue_01BC.begin(), queues.queue_01BC.end(), Before); + const auto before = [](const DepthPrimitive& left, const DepthPrimitive& right) { + return Before(left, right); + }; + + std::sort(queues.queue_018C.begin(), queues.queue_018C.end(), before); + std::sort(queues.queue_01BC.begin(), queues.queue_01BC.end(), before); this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1); this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); @@ -40,40 +44,48 @@ void CRendererDX9::DrawAlphaQueues(RenderQueues& queues, unsigned char twoPass) this->device->state.SetRenderState(D3DRS_ALPHAREF, 1); this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); - const auto draw = [&](const std::vector& queue, bool alphaTest) { - for (const DepthPrimitive& entry : queue) { - RenderCommand& command = *entry.primitive; - - if (alphaTest) { - this->device->state.SetRenderState(D3DRS_ALPHAREF, WritesDepth(command) ? 1 : 240); - } else { - this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, WritesDepth(command)); - } - - this->device->state.SetTexture(0, command.texture ? static_cast(command.texture)->NativeTexture() : nullptr); - this->DrawPrimitive(&command); - } - }; - const auto drawPair = [&](bool alphaTest) { - this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); - this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); - draw(queues.queue_018C, alphaTest); - this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); - this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); - draw(queues.queue_01BC, alphaTest); - }; - if (twoPass == 1) { + const auto drawAlphaTested = [this](const DepthPrimitive& entry) { + RenderCommand* command = entry.primitive; + this->device->state.SetRenderState(D3DRS_ALPHAREF, WritesDepth(*command) ? 1 : 240); + this->device->state.SetTexture(0, command->texture ? static_cast(command->texture)->NativeTexture() : nullptr); + this->DrawPrimitive(command); + }; + this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 1); this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); - drawPair(true); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + std::for_each(queues.queue_018C.begin(), queues.queue_018C.end(), drawAlphaTested); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + std::for_each(queues.queue_01BC.begin(), queues.queue_01BC.end(), drawAlphaTested); + this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0); this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS); - drawPair(true); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + std::for_each(queues.queue_018C.begin(), queues.queue_018C.end(), drawAlphaTested); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + std::for_each(queues.queue_01BC.begin(), queues.queue_01BC.end(), drawAlphaTested); + this->device->state.SetRenderState(D3DRS_ALPHAREF, 1); this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); this->DrawDepthQueue(queues.queue_01A4, true); } else { - drawPair(false); + const auto drawDepthWriting = [this](const DepthPrimitive& entry) { + RenderCommand* command = entry.primitive; + this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, WritesDepth(*command)); + this->device->state.SetTexture(0, command->texture ? static_cast(command->texture)->NativeTexture() : nullptr); + this->DrawPrimitive(command); + }; + + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + std::for_each(queues.queue_018C.begin(), queues.queue_018C.end(), drawDepthWriting); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + std::for_each(queues.queue_01BC.begin(), queues.queue_01BC.end(), drawDepthWriting); } }