rodecomp/Source/Render/DX9/GroundQueuesDX9.cpp
ragnarok-clanker ffbeee0f2a Maintenance: Forced maintainer submission (resubmission of 14678 after td sync to 8deac7a3; replaces 14460 and 14473). Native-run fix
Batch #14681 by ragnarok-clanker: forced by an admin (6 lower score(s), 70 changed function(s)); checked with 555 compiled unit(s), including every includer of Source/Client/Mode/CLoginMode.h, Source/Client/Session.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/GrannyGameActor.h, Source/Contents/Actors/Pc.h, Source/Contents/Actors/RenderObject.h, Source/Contents/EffectResourceSwitcher.h, Source/Contents/Effects/CartCannon.h, Source/Contents/Effects/EZ2STREffectEx.h, Source/Contents/Effects/EffectActor.h, Source/Contents/Effects/MonsterSkillEffects.h, Source/Contents/Effects/RagEffect.h, Source/Contents/Effects/RectUpEffect.h, Source/Contents/Ground/GroundGeometry.h, Source/Network/Connection/Connection.h, Source/Resource/Audio/WaveResource.h, Source/Resource/Bitmap/BitmapResource.h, Source/Resource/EZeffectResource.h, Source/Resource/EmblemResource.h, Source/Resource/GifResource.h, Source/Resource/ImfResource.h, Source/Resource/Models/AnimatedModelResource.h, Source/Resource/Models/GrannyModelResource.h, Source/Resource/Models/ModelResource.h, Source/Resource/PaletteResource.h, Source/Resource/RmaResource.h, Source/Resource/Sprites/ActionResource.h, Source/Resource/Sprites/SpriteResource.h, Source/Resource/World/GroundResource.h, Source/Resource/World/TerrainResource.h, Source/Resource/World/WorldResource.h, Source/UI/Buttons/UIBmpRadioBtn.h, Source/UI/Buttons/UITextButton.h, Source/UI/Item/UIItemPurchaseWnd.h, Source/UI/Item/UIItemSellWnd.h, Source/UI/Item/UIItemSellWnd2.h, Source/UI/Item/UIItemStoreWnd.h, Source/UI/Item/UIItemWnd.h, Source/UI/Item/UIParaItemShopWnd.h, Source/UI/Items/UIItemRepairWnd.h, Source/UI/Items/UIMakeTargetListWnd.h, Source/UI/Items/UIMakeTargetProcessWnd.h, Source/UI/Items/UIWeaponRefineWnd.h, Source/UI/Rodex/UIRodexInboxWnd.h, Source/UI/Shop/UIMerchantItemShopWnd.h, Source/UI/Shop/UIMerchantMirrorItemWnd.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/StylingShop/UIStylingShopWnd.h, Source/UI/UIChangeMaterialWnd.h, Source/UI/UIIngredientInfoWnd.h, Source/UI/UIItemReformWnd.h, Source/UI/UILapineScrollBar.h, Source/UI/Window/UIHotKeyWnd.h, Source/UI/Window/UINewSelectCharWnd.h.
2026-11-07 14:05:21 +00:00

86 lines
3.5 KiB
C++

#include "Render/DX9/DeviceOwnerDX9.h"
#include "Contents/Configuration/ServiceOptions.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/TextureDX9.h"
#include "Render/TextureQuad.h"
#include <algorithm>
#include <bit>
#include <cstdint>
namespace {
// INLINED
bool TextureBefore(const RenderCommand* left, const RenderCommand* right) {
return reinterpret_cast<std::uintptr_t>(left->texture) < reinterpret_cast<std::uintptr_t>(right->texture);
}
}
// OFFSET: 0x00566D60
// FUNCTION: fn_02227
void CRendererDX9::DrawBaseQueue() {
ScopedDeviceStateDX9 restore(this->device->state);
std::sort(this->queues.queue_0168.begin(), this->queues.queue_0168.end(), TextureBefore);
for (RenderCommand* command : this->queues.queue_0168) {
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}
// OFFSET: 0x005668B0
// FUNCTION: fn_02226
void CRendererDX9::DrawGroundQueues(RenderQueues& queues) {
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_AMBIENT, 0xFFFFFFFFu);
this->device->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
if (g_serviceOptions.Get(119) != 0) {
if (g_multitexture == 1) {
ScopedDeviceStateDX9 restoreDual(this->device->state);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
auto& queue = queues.lightmapped.first;
std::sort(queue.begin(), queue.end(), [](const LightmappedPrimitive* left, const LightmappedPrimitive* right) {
const auto first = reinterpret_cast<std::uintptr_t>(left->texture);
const auto second = reinterpret_cast<std::uintptr_t>(right->texture);
if (first != second) {
return first < second;
}
return reinterpret_cast<std::uintptr_t>(left->lightmap) < reinterpret_cast<std::uintptr_t>(right->lightmap);
});
for (LightmappedPrimitive* command : queue) {
if (command->vertexCount > 0) {
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(1, command->lightmap ? static_cast<CTextureDX9*>(command->lightmap)->NativeTexture() : nullptr);
this->DrawLightmappedPrimitive(command);
}
}
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
} else {
this->DrawBaseQueue();
ScopedDeviceStateDX9 restoreLightmap(this->device->state);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCALPHA);
std::sort(queues.queue_0174.begin(), queues.queue_0174.end(), TextureBefore);
for (RenderCommand* command : queues.queue_0174) {
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}
} else {
this->DrawBaseQueue();
}
this->device->state.SetRenderState(D3DRS_AMBIENT, 0);
this->device->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
}