Batch #10258 by ragnarok-clanker: forced by an admin (9 lower score(s), 44 changed function(s)); checked with 318 compiled unit(s), including every includer of Source/Render/DX9/DeviceOwnerDX9.h, Source/Render/DX9/RenderSystemDX9.h, Source/Render/DX9/RendererDX9.h, Source/Render/DX9/RendererFogDX9.h, Source/Render/DX9/SurfaceDX9.h, Source/Render/DX9/TextureDX9.h, Source/Render/Renderer.h, Source/Render/RendererDX7.h, Source/Render/Textures/SpriteAtlas.h, Source/Render/DX9/RendererDX9Operations.h. Deletes: Source/Render/DX9/RendererDX9Operations.h
79 lines
3 KiB
C++
79 lines
3 KiB
C++
#include "Render/DX9/DeviceOwnerDX9.h"
|
|
#include "Render/DX9/DeviceStateDX9.h"
|
|
#include "Render/Primitives/RenderQueues.h"
|
|
#include "Render/DX9/RendererDX9.h"
|
|
#include "Render/DX9/TextureDX9.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
|
|
namespace {
|
|
// INLINED
|
|
bool Before(const DepthPrimitive& left, const DepthPrimitive& right) {
|
|
if (left.depth < right.depth) {
|
|
return true;
|
|
}
|
|
|
|
if (right.depth < left.depth) {
|
|
return false;
|
|
}
|
|
|
|
return left.depth == right.depth && reinterpret_cast<std::uintptr_t>(left.primitive) < reinterpret_cast<std::uintptr_t>(right.primitive);
|
|
}
|
|
|
|
// INLINED
|
|
bool WritesDepth(const RenderCommand& command) {
|
|
return (command.unknown_0014 & 0xFFu) != 0 && (command.unknown_0014 & 0xFF00u) != 0;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00565DA0
|
|
// 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);
|
|
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
|
|
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
this->device->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
|
|
|
|
const auto draw = [&](const std::vector<DepthPrimitive>& 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<CTextureDX9*>(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) {
|
|
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
|
|
drawPair(true);
|
|
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS);
|
|
drawPair(true);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
|
|
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
|
|
this->DrawDepthQueue(queues.queue_01A4, true);
|
|
} else {
|
|
drawPair(false);
|
|
}
|
|
}
|