Maintenance: [forced, user-approved] R9: remove the invented TextureDX9Context, SurfaceDX9Context and RendererDX9Operations, plus the

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
This commit is contained in:
ragnarok-clanker 2026-11-03 13:19:27 +00:00
commit 15ee30e2aa
27 changed files with 462 additions and 586 deletions

View file

@ -1,6 +1,7 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/TextureDX9.h"
#include <algorithm>
@ -28,49 +29,49 @@ namespace {
// OFFSET: 0x00565DA0
// FUNCTION: fn_02224
void RendererDX9Operations::DrawAlphaQueues(RenderQueues& queues, unsigned char twoPass) {
ScopedDeviceStateDX9 restore(this->state);
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->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
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->state.SetRenderState(D3DRS_ALPHAREF, WritesDepth(command) ? 1 : 240);
this->device->state.SetRenderState(D3DRS_ALPHAREF, WritesDepth(command) ? 1 : 240);
} else {
this->state.SetRenderState(D3DRS_ZWRITEENABLE, WritesDepth(command));
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, WritesDepth(command));
}
this->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->DrawPrimitive(&command);
}
};
const auto drawPair = [&](bool alphaTest) {
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
draw(queues.queue_018C, alphaTest);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
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->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
drawPair(true);
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS);
drawPair(true);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
this->DrawDepthQueue(queues.queue_01A4, true);
} else {
drawPair(false);

View file

@ -276,15 +276,3 @@ HRESULT DeviceOwnerDX9::Present(int) {
return this->lastPresent;
}
// INLINED
SurfaceDX9Context DeviceOwnerDX9::SurfaceContext() const {
return {this->device, this->backBufferDescription, this->backBuffer};
}
// INLINED
TextureDX9Context DeviceOwnerDX9::TextureContext(
RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd
) const {
return {this->direct3D, this->device, this->adapter, this->presentation.BackBufferFormat, this->caps, this->dynamicTextures, nullptr, &primitives, &queues,
depthAlpha, depthStart, depthEnd};
}

View file

@ -26,9 +26,6 @@ public:
bool CaptureBackBuffer();
bool RestoreBackBuffer();
ScopedDeviceStateDX9 SaveState();
SurfaceDX9Context SurfaceContext() const;
TextureDX9Context
TextureContext(class RenderPrimitivePool& primitives, RenderQueues& queues, bool depthAlpha, float depthStart, float depthEnd) const;
/* 0000 */ HWND window;
/* 0004 */ IDirect3D9Ex* direct3D;

View file

@ -1,7 +1,8 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Contents/Configuration/ServiceOptions.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/TextureDX9.h"
#include "Render/TextureQuad.h"
@ -14,31 +15,31 @@ namespace {
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 DrawBaseQueue(RendererDX9Operations& renderer, std::vector<RenderCommand*>& queue) {
ScopedDeviceStateDX9 restore(renderer.state);
std::sort(queue.begin(), queue.end(), TextureBefore);
// 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 : queue) {
renderer.state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
renderer.DrawPrimitive(command);
}
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 RendererDX9Operations::DrawGroundQueues(RenderQueues& queues) {
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_COLORWRITEENABLE, 0xFFFFFFFFu);
this->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
void CRendererDX9::DrawGroundQueues(RenderQueues& queues) {
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_COLORWRITEENABLE, 0xFFFFFFFFu);
this->device->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
if (g_serviceOptions.Get(119) != 0) {
if (g_multitexture == 1) {
ScopedDeviceStateDX9 restoreDual(this->state);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
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);
@ -53,33 +54,33 @@ void RendererDX9Operations::DrawGroundQueues(RenderQueues& queues) {
for (LightmappedPrimitive* command : queue) {
if (command->vertexCount > 0) {
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->state.SetTexture(1, command->lightmap ? static_cast<CTextureDX9*>(command->lightmap)->NativeTexture() : nullptr);
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->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
} else {
DrawBaseQueue(*this, queues.queue_0168);
ScopedDeviceStateDX9 restoreLightmap(this->state);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCALPHA);
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->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}
} else {
DrawBaseQueue(*this, queues.queue_0168);
this->DrawBaseQueue();
}
this->state.SetRenderState(D3DRS_COLORWRITEENABLE, 0);
this->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
this->device->state.SetRenderState(D3DRS_COLORWRITEENABLE, 0);
this->device->state.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
}

View file

@ -1,6 +1,7 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/TextureDX9.h"
#include <algorithm>
@ -8,10 +9,10 @@
// OFFSET: 0x005666E0
// FUNCTION: fn_02225
void RendererDX9Operations::DrawOpaqueQueues(RenderQueues& queues) {
ScopedDeviceStateDX9 restore(this->state);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
void CRendererDX9::DrawOpaqueQueues(RenderQueues& queues) {
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
const auto before = [](const RenderCommand* left, const RenderCommand* right) {
return reinterpret_cast<std::uintptr_t>(left->texture) < reinterpret_cast<std::uintptr_t>(right->texture);
};
@ -19,18 +20,18 @@ void RendererDX9Operations::DrawOpaqueQueues(RenderQueues& queues) {
for (RenderCommand* command : queues.queue_015C) {
if (command) {
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
std::sort(queues.queue_01B0.begin(), queues.queue_01B0.end(), before);
for (RenderCommand* command : queues.queue_01B0) {
if (command) {
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}

View file

@ -1,6 +1,7 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/RendererFogDX9.h"
#include "Render/DX9/TextureDX9.h"
@ -10,14 +11,14 @@
// OFFSET: 0x00567180
// FUNCTION: fn_02228
void RendererDX9Operations::DrawAuxiliaryQueue(RenderQueues& queues) {
void CRendererDX9::DrawAuxiliaryQueue(RenderQueues& queues) {
auto& queue = queues.queue_0240;
if (queue.empty()) {
return;
}
ScopedDeviceStateDX9 restore(this->state);
ScopedDeviceStateDX9 restore(this->device->state);
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);
@ -28,25 +29,25 @@ void RendererDX9Operations::DrawAuxiliaryQueue(RenderQueues& queues) {
return reinterpret_cast<std::uintptr_t>(left->lightmap) < reinterpret_cast<std::uintptr_t>(right->lightmap);
});
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
this->state.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->state.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
this->device->state.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
this->device->state.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
for (LightmappedPrimitive* command : queue) {
if (command->vertexCount > 0) {
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->state.SetTexture(1, command->lightmap ? static_cast<CTextureDX9*>(command->lightmap)->NativeTexture() : nullptr);
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);
}
}
@ -54,35 +55,35 @@ void RendererDX9Operations::DrawAuxiliaryQueue(RenderQueues& queues) {
// OFFSET: 0x00567610
// FUNCTION: fn_02229
void RendererDX9Operations::DrawQueues(
RenderQueues& queues, unsigned char twoPass, RendererFogDX9& fog, const float& aspect
void CRendererDX9::DrawQueues(
RenderQueues& queues, unsigned char twoPass
) {
fog.Apply(this->context, this->state, aspect);
this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHAREF, 207);
this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 0);
this->state.SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->ApplyFog();
this->device->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 207);
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 0);
this->device->state.SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->DrawOpaqueQueues(queues);
this->DrawGroundQueues(queues);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->DrawAuxiliaryQueue(queues);
const auto drawCommand = [&](RenderCommand& command) {
this->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->SetTextureMode(command.unknown_0020);
this->state.SetRenderState(D3DRS_SRCBLEND, command.unknown_0018);
this->state.SetRenderState(D3DRS_DESTBLEND, command.unknown_001C);
this->device->state.SetRenderState(D3DRS_SRCBLEND, command.unknown_0018);
this->device->state.SetRenderState(D3DRS_DESTBLEND, command.unknown_001C);
this->DrawPrimitive(&command);
};
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
for (RenderCommand* command : queues.queue_0210) {
if (command) {
@ -92,13 +93,13 @@ void RendererDX9Operations::DrawQueues(
}
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->DrawDepthQueue(queues.queue_021C, true);
}
{
ScopedDeviceStateDX9 restore(this->state);
ScopedDeviceStateDX9 restore(this->device->state);
std::sort(queues.queue_0180.begin(), queues.queue_0180.end(), [](const DepthPrimitive& left, const DepthPrimitive& right) {
if (left.depth < right.depth) {
return true;
@ -110,81 +111,81 @@ void RendererDX9Operations::DrawQueues(
return left.depth == right.depth && reinterpret_cast<std::uintptr_t>(left.primitive) < reinterpret_cast<std::uintptr_t>(right.primitive);
});
this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHAREF, 159);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
this->device->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 159);
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
this->DrawDepthQueue(queues.queue_0180, false);
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->state.SetRenderState(D3DRS_ALPHAREF, 159);
this->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 159);
this->device->state.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS);
this->DrawDepthQueue(queues.queue_0180, false);
}
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
this->DrawDepthQueue(queues.queue_01C8, true);
}
this->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->device->state.SetRenderState(D3DRS_ZWRITEENABLE, 0);
this->DrawAlphaQueues(queues, twoPass);
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_ALPHAREF, 207);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 207);
this->DrawDepthQueue(queues.queue_0228, true);
}
this->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->device->state.SetRenderState(D3DRS_FOGENABLE, 0);
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
this->DrawDepthQueue(queues.queue_01D4, true);
}
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
this->device->state.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
for (RenderCommand* command : queues.queue_01EC) {
drawCommand(*command);
}
}
this->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->device->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
this->DrawDepthQueue(queues.queue_01E0, true);
}
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
this->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
this->device->state.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
this->DrawDepthQueue(queues.queue_0198, false);
}
{
ScopedDeviceStateDX9 restore(this->state);
ScopedDeviceStateDX9 restore(this->device->state);
for (const DepthPrimitive& entry : queues.queue_0234) {
RenderCommand& command = *entry.primitive;
this->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command.texture ? static_cast<CTextureDX9*>(command.texture)->NativeTexture() : nullptr);
this->SetTextureMode(command.unknown_0020);
const bool selected = !(entry.depth >= 0.99f);
this->state.SetRenderState(D3DRS_SRCBLEND, selected ? command.unknown_0018 : D3DBLEND_SRCALPHA);
this->state.SetRenderState(D3DRS_DESTBLEND, selected ? command.unknown_001C : D3DBLEND_INVSRCALPHA);
this->device->state.SetRenderState(D3DRS_SRCBLEND, selected ? command.unknown_0018 : D3DBLEND_SRCALPHA);
this->device->state.SetRenderState(D3DRS_DESTBLEND, selected ? command.unknown_001C : D3DBLEND_INVSRCALPHA);
this->DrawPrimitive(&command);
}
}

View file

@ -7,8 +7,7 @@
// OFFSET: 0x0056CF60
// FUNCTION: fn_02353
CRenderSystemDX9::CRenderSystemDX9() : m_device(new DeviceOwnerDX9), m_defaultTexture(nullptr), m_textureContext{}, m_surfaceContext{} {
this->RefreshContexts();
CRenderSystemDX9::CRenderSystemDX9() : m_device(new DeviceOwnerDX9), m_defaultTexture(nullptr) {
}
// OFFSET: 0x0056D180
@ -21,20 +20,6 @@ CRenderSystemDX9::~CRenderSystemDX9() {
delete this->m_defaultTexture;
}
// INLINED
void CRenderSystemDX9::RefreshContexts() {
this->m_surfaceContext = this->m_device->SurfaceContext();
auto& context = this->m_textureContext;
context.direct3D = this->m_device->direct3D;
context.device = this->m_device->device;
context.adapter = this->m_device->adapter;
context.displayFormat = this->m_device->presentation.BackBufferFormat;
context.caps = this->m_device->caps;
context.dynamicTextures = this->m_device->dynamicTextures;
context.depthStart = g_depthStart;
context.depthEnd = g_depthEnd;
}
// OFFSET: 0x0056E250
// FUNCTION: fn_02373
std::int32_t CRenderSystemDX9::Backend() {
@ -45,7 +30,6 @@ std::int32_t CRenderSystemDX9::Backend() {
HRESULT CRenderSystemDX9::Initialize(HWND window) {
const HRESULT result =
InitializeConfiguredDeviceDX9(*this->m_device, window);
this->RefreshContexts();
return result;
}
@ -85,8 +69,6 @@ CRenderer* CRenderSystemDX9::CreateRenderer() {
renderer->viewport.SetSize(
std::bit_cast<std::int32_t>(this->Width()), std::bit_cast<std::int32_t>(this->Height())
);
this->m_textureContext.primitives = &renderer->primitives;
this->m_textureContext.queues = &renderer->queues;
return renderer;
}
@ -100,16 +82,14 @@ void CRenderSystemDX9::DestroySurface(CSurface* surface) {
// OFFSET: 0x0056D480
// FUNCTION: fn_02360
CSurface* CRenderSystemDX9::CreateSurface(std::uint32_t width, std::uint32_t height) {
this->RefreshContexts();
return new (std::nothrow) CSurfaceDX9(this->m_surfaceContext, std::bit_cast<std::int32_t>(width), std::bit_cast<std::int32_t>(height));
return new (std::nothrow) CSurfaceDX9(*this->m_device, std::bit_cast<std::int32_t>(width), std::bit_cast<std::int32_t>(height));
}
// OFFSET: 0x0056D510
// FUNCTION: fn_02361
CTexture* CRenderSystemDX9::CreateTexture(std::uint32_t width, std::uint32_t height, std::int32_t format, bool dynamic, bool renderTarget) {
this->RefreshContexts();
return new (std::nothrow)
CTextureDX9(this->m_textureContext, std::bit_cast<std::int32_t>(width), std::bit_cast<std::int32_t>(height), format, dynamic, renderTarget);
CTextureDX9(*this->m_device, std::bit_cast<std::int32_t>(width), std::bit_cast<std::int32_t>(height), format, dynamic, renderTarget);
}
// OFFSET: 0x0056D5B0
@ -126,8 +106,7 @@ CSurface* CRenderSystemDX9::CreateSurfaceOrTexture(std::uint32_t width, std::uin
// FUNCTION: fn_02369
CTexture* CRenderSystemDX9::BackBufferTexture() {
if (!this->m_defaultTexture) {
this->RefreshContexts();
this->m_defaultTexture = new CTextureDX9(this->m_textureContext);
this->m_defaultTexture = new CTextureDX9(*this->m_device);
}
return this->m_defaultTexture;
@ -137,8 +116,7 @@ CTexture* CRenderSystemDX9::BackBufferTexture() {
// FUNCTION: fn_02371
std::shared_ptr<CSurface> CRenderSystemDX9::BackBufferSurface() {
if (!this->m_backBuffer) {
this->RefreshContexts();
this->m_backBuffer = std::make_shared<CSurfaceDX9>(this->m_surfaceContext, this->m_device->backBuffer);
this->m_backBuffer = std::make_shared<CSurfaceDX9>(*this->m_device, this->m_device->backBuffer);
}
return this->m_backBuffer;

View file

@ -39,9 +39,6 @@ private:
/* 0008 */ CTexture* m_defaultTexture;
/* 000C */ std::shared_ptr<CSurface> m_backBuffer;
TextureDX9Context m_textureContext;
SurfaceDX9Context m_surfaceContext;
void RefreshContexts();
};
#endif

View file

@ -1,6 +1,7 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/TextureQuad.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/Primitives/LightmappedPrimitive.h"
#include "Client/Mode/CGameMode.h"
#include "Client/Mode/ModeMgr.h"
#include "Contents/World/World.h"
@ -14,8 +15,7 @@
// OFFSET: 0x00564EB0
// FUNCTION: fn_02209
CRendererDX9::CRendererDX9(DeviceOwnerDX9& owner)
: CRenderer(*GetRenderSystemHolder()->system), device(&owner), nativeDevice(owner.device), clearColor(0), lastTick(0), frames(0), fps(0.0f), unknown_context(nullptr),
m_textureContext(owner.TextureContext(this->primitives, this->queues, false, g_depthStart, g_depthEnd)) {
: device(&owner), nativeDevice(owner.device), clearColor(0), lastTick(0), frames(0), fps(0.0f) {
}
// OFFSET: 0x00564FE0
@ -23,30 +23,6 @@ CRendererDX9::CRendererDX9(DeviceOwnerDX9& owner)
// FUNCTION: fn_02210
CRendererDX9::~CRendererDX9() = default;
TextureDX9Context& CRendererDX9::TextureContext() {
this->m_textureContext.dynamicTextures = this->device->dynamicTextures;
this->m_textureContext.depthAlpha = this->fog.supported != 0;
this->m_textureContext.depthStart = g_depthStart;
this->m_textureContext.depthEnd = g_depthEnd;
return this->m_textureContext;
}
RendererDX9Operations CRendererDX9::Operations(TextureDX9Context& context) {
context.device = this->nativeDevice;
return {context, this->device->state};
}
void CRendererDX9::SetCamera(const float* eye, const float* target, const float* up) {
auto& context = this->TextureContext();
this->Operations(context).SetCamera(eye, target, up);
}
void CRendererDX9::SetLighting(const float* direction, const float* diffuse, const float* ambient) {
auto& context = this->TextureContext();
this->Operations(context).SetLighting(direction, diffuse, ambient);
}
// OFFSET: 0x00568360
// FUNCTION: fn_02238
void CRendererDX9::SetClearColor(unsigned color) {
@ -57,16 +33,6 @@ void CRendererDX9::SetFog(int enabled) {
this->fog.Set(enabled, this->device->caps);
}
void CRendererDX9::ClearDepth(int clearColor) {
auto& context = this->TextureContext();
this->Operations(context).ClearDepth(clearColor);
}
void CRendererDX9::ClearWorld() {
auto& context = this->TextureContext();
this->Operations(context).ClearWorld(this->clearColor, this->fog.enabled, static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene->unknown_00FC, g_worldOverlayColor);
}
HRESULT CRendererDX9::Present(int option) {
RendererPresentation presentation{this->frame, this->lastTick, this->frames, this->fps};
return presentation.Present(*this->device, option);
@ -89,23 +55,21 @@ bool CRendererDX9::RestoreBackBuffer() {
// OFFSET: 0x00565860
// FUNCTION: fn_02220
void CRendererDX9::DrawAuxiliaryPrimitive(LightmappedPrimitive* primitive) {
auto& context = this->TextureContext();
this->Operations(context).DrawLightmappedPrimitive(primitive);
}
if (primitive->vertexCount <= 0) {
return;
}
void CRendererDX9::DrawLightmappedPrimitive(LightmappedPrimitive* primitive) {
auto& context = this->TextureContext();
this->Operations(context).DrawLightmappedPrimitive(primitive);
}
this->device->state.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2);
const auto type = static_cast<D3DPRIMITIVETYPE>(primitive->primitiveType);
const unsigned divisor = type == D3DPT_TRIANGLELIST ? 3 : 2;
void CRendererDX9::DrawPrimitive(RenderCommand* primitive) {
auto& context = this->TextureContext();
this->Operations(context).DrawPrimitive(primitive);
}
bool CRendererDX9::RenderToTexture(int width, int height, const std::list<RenderPrimitive*>& primitives, CTexture*& texture) {
auto& context = this->TextureContext();
return this->Operations(context).RenderToTexture(width, height, primitives, texture);
if (primitive->indexCount) {
this->nativeDevice->DrawIndexedPrimitiveUP(
type, 0, primitive->vertexCount, primitive->indexCount / divisor, primitive->indices, D3DFMT_INDEX16, primitive->vertices, sizeof(LightmappedVertex)
);
} else {
this->nativeDevice->DrawPrimitiveUP(type, primitive->vertexCount / divisor, primitive->vertices, sizeof(LightmappedVertex));
}
}
bool CRendererDX9::SaveBitmapResource(const char* filename, int format, CBitmapRes* bitmap) {
@ -116,8 +80,7 @@ bool CRendererDX9::SaveBitmapResource(const char* filename, int format, CBitmapR
overlay.reset(g_texMgr.Upload(image.width, image.height, image.pixels, image.alpha != 0, 0, false, false, false));
}
auto& context = this->TextureContext();
return this->Operations(context).SaveScreenshot(*this->device, GetRenderSystemHolder()->system, filename, format, overlay.get(), nullptr);
return this->SaveScreenshot(filename, format, overlay.get(), nullptr);
}
// OFFSET: 0x00567FC0
@ -142,9 +105,8 @@ void CRendererDX9::CleanupTextures() {
bool CRendererDX9::SaveLogo(std::string filename) {
const char* name = Resolve("scr_logo.bmp");
CTexture* overlay = g_texMgr.Load(name, 0, false, true, false);
auto& context = this->TextureContext();
return this->Operations(context).SaveScreenshot(*this->device, GetRenderSystemHolder()->system, filename.c_str(), 1, overlay, nullptr);
return this->SaveScreenshot(filename.c_str(), 1, overlay, nullptr);
}
void CRendererDX9::Submit(RenderCommand* command, std::uint16_t flags) {

View file

@ -2,7 +2,8 @@
#define RAGNAROK_SOURCE_RENDER_DX9_RENDERERDX9_H
#include "Render/Renderer.h"
#include "Render/DX9/RendererDX9Operations.h"
#include <list>
#include <vector>
#include "Render/DX9/RendererPresentation.h"
#include "Render/DX9/TextureDX9.h"
@ -34,7 +35,16 @@ public:
bool LockBackBuffer() override;
HRESULT UnlockBackBuffer() override;
TextureDX9Context& TextureContext();
void SetTextureMode(int mode);
void DrawDepthQueue(std::vector<DepthPrimitive>& queue, bool sort);
void DrawOpaqueQueues(RenderQueues& queues);
void DrawGroundQueues(RenderQueues& queues);
void DrawAlphaQueues(RenderQueues& queues, unsigned char twoPass);
void DrawAuxiliaryQueue(RenderQueues& queues);
void DrawBaseQueue();
void DrawQueues(RenderQueues& queues, unsigned char twoPass);
void ApplyFog();
bool SaveScreenshot(const char* filename, int format, CTexture* overlay, const tagRECT* rectangle);
void Submit(RenderCommand* command, std::uint16_t flags);
void Submit(LightmappedPrimitive* command, int queue);
@ -46,14 +56,11 @@ public:
/* 0270 */ float fps;
private:
void* unknown_context;
TextureDX9Context m_textureContext;
RendererDX9Operations Operations(TextureDX9Context& textureContext);
bool SaveBitmapResource(const char* filename, int format, CBitmapRes* overlay);
};
#if defined(_WIN32) && !defined(_WIN64)
static_assert(sizeof(CRendererDX9) == 0x3D4);
static_assert(sizeof(CRendererDX9) == 0x274);
#endif
#endif

View file

@ -1,9 +1,14 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/BlendColor.h"
#include "Client/Mode/CGameMode.h"
#include "Client/Mode/ModeMgr.h"
#include "Contents/World/World.h"
#include "Render/TextureQuad.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/Primitives/LightmappedPrimitive.h"
#include "Render/Primitives/RenderPrimitive.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/TextureDX9.h"
#include <algorithm>
@ -13,12 +18,12 @@
// OFFSET: 0x00568460
// FUNCTION: fn_02240
void RendererDX9Operations::SetCamera(const float*, const float*, const float*) {
void CRendererDX9::SetCamera(const float*, const float*, const float*) {
}
// OFFSET: 0x00568370
// FUNCTION: fn_02239
void RendererDX9Operations::SetLighting(const float* direction, const float* diffuse, const float* ambient) {
void CRendererDX9::SetLighting(const float* direction, const float* diffuse, const float* ambient) {
D3DLIGHT9 light{};
light.Type = D3DLIGHT_DIRECTIONAL;
light.Direction.x = -direction[0];
@ -33,69 +38,70 @@ void RendererDX9Operations::SetLighting(const float* direction, const float* dif
light.Ambient.b = ambient[2];
light.Ambient.a = 255.0f;
this->context.device->SetLight(0, &light);
this->context.device->LightEnable(0, TRUE);
this->nativeDevice->SetLight(0, &light);
this->nativeDevice->LightEnable(0, TRUE);
}
// OFFSET: 0x00565150
// FUNCTION: fn_02214
void RendererDX9Operations::ClearDepth(int clearColor) {
this->context.device->Clear(0, nullptr, clearColor ? D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER : D3DCLEAR_ZBUFFER, 0xFF000000u, 1.0f, 0);
void CRendererDX9::ClearDepth(int clearColor) {
this->nativeDevice->Clear(0, nullptr, clearColor ? D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER : D3DCLEAR_ZBUFFER, 0xFF000000u, 1.0f, 0);
}
// OFFSET: 0x005651A0
// FUNCTION: fn_02215
void RendererDX9Operations::ClearWorld(unsigned color, int mode, unsigned char worldFlag, unsigned overlay) {
if (mode == 1 && worldFlag == 1) {
color = BlendColor(color, overlay);
void CRendererDX9::ClearWorld() {
unsigned color = this->clearColor;
if (this->fog.enabled == 1 && static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene->unknown_00FC == 1) {
color = BlendColor(this->clearColor, g_worldOverlayColor);
}
this->context.device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, color, 1.0f, 0);
this->nativeDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, color, 1.0f, 0);
}
// OFFSET: 0x00565740
// FUNCTION: fn_02218
void RendererDX9Operations::DrawPrimitive(RenderCommand* primitive) {
void CRendererDX9::DrawPrimitive(RenderCommand* primitive) {
if (primitive->vertexCount <= 0) {
return;
}
this->state.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1);
this->device->state.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1);
const auto type = static_cast<D3DPRIMITIVETYPE>(primitive->primitiveType);
const unsigned divisor = type == D3DPT_TRIANGLELIST ? 3 : 2;
if (primitive->indexCount) {
this->context.device->DrawIndexedPrimitiveUP(
this->nativeDevice->DrawIndexedPrimitiveUP(
type, 0, primitive->vertexCount, primitive->indexCount / divisor, primitive->indices, D3DFMT_INDEX16, primitive->vertices, sizeof(RenderVertex)
);
} else {
this->context.device->DrawPrimitiveUP(type, primitive->vertexCount / divisor, primitive->vertices, sizeof(RenderVertex));
this->nativeDevice->DrawPrimitiveUP(type, primitive->vertexCount / divisor, primitive->vertices, sizeof(RenderVertex));
}
}
// OFFSET: 0x005657D0
// FUNCTION: fn_02219
void RendererDX9Operations::DrawLightmappedPrimitive(LightmappedPrimitive* primitive) {
void CRendererDX9::DrawLightmappedPrimitive(LightmappedPrimitive* primitive) {
if (primitive->vertexCount <= 0) {
return;
}
this->state.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2);
this->device->state.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2);
const auto type = static_cast<D3DPRIMITIVETYPE>(primitive->primitiveType);
const unsigned divisor = type == D3DPT_TRIANGLELIST ? 3 : 2;
if (primitive->indexCount) {
this->context.device->DrawIndexedPrimitiveUP(
this->nativeDevice->DrawIndexedPrimitiveUP(
type, 0, primitive->vertexCount, primitive->indexCount / divisor, primitive->indices, D3DFMT_INDEX16, primitive->vertices, sizeof(LightmappedVertex)
);
} else {
this->context.device->DrawPrimitiveUP(type, primitive->vertexCount / divisor, primitive->vertices, sizeof(LightmappedVertex));
this->nativeDevice->DrawPrimitiveUP(type, primitive->vertexCount / divisor, primitive->vertices, sizeof(LightmappedVertex));
}
}
// OFFSET: 0x005658F0
// FUNCTION: fn_02221
void RendererDX9Operations::DrawDepthQueue(std::vector<DepthPrimitive>& queue, bool sort) {
void CRendererDX9::DrawDepthQueue(std::vector<DepthPrimitive>& queue, bool sort) {
if (sort) {
std::sort(queue.begin(), queue.end(), [](const DepthPrimitive& left, const DepthPrimitive& right) {
if (left.depth < right.depth) {
@ -112,23 +118,23 @@ void RendererDX9Operations::DrawDepthQueue(std::vector<DepthPrimitive>& queue, b
for (const DepthPrimitive& entry : queue) {
RenderCommand* command = entry.primitive;
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}
}
// OFFSET: 0x00565210
// FUNCTION: fn_02216
bool RendererDX9Operations::RenderToTexture(int width, int height, const std::list<RenderPrimitive*>& primitives, CTexture*& texture) {
bool CRendererDX9::RenderToTexture(int width, int height, const std::list<RenderPrimitive*>& primitives, CTexture*& texture) {
IDirect3DTexture9* nativeTexture = nullptr;
if (texture) {
nativeTexture = static_cast<CTextureDX9*>(texture)->NativeTexture();
} else {
if (FAILED(this->context.device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &nativeTexture, nullptr))) {
if (FAILED(this->nativeDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &nativeTexture, nullptr))) {
return false;
}
CTextureDX9* created = new (std::nothrow) CTextureDX9(this->context, nativeTexture);
CTextureDX9* created = new (std::nothrow) CTextureDX9(*this->device, nativeTexture);
if (!created) {
return false;
@ -145,27 +151,27 @@ bool RendererDX9Operations::RenderToTexture(int width, int height, const std::li
IDirect3DSurface9* target = nullptr;
bool result = false;
if (SUCCEEDED(nativeTexture->GetSurfaceLevel(0, &target)) && SUCCEEDED(this->context.device->GetRenderTarget(0, &previous)) &&
SUCCEEDED(this->context.device->SetRenderTarget(0, target))) {
if (SUCCEEDED(nativeTexture->GetSurfaceLevel(0, &target)) && SUCCEEDED(this->nativeDevice->GetRenderTarget(0, &previous)) &&
SUCCEEDED(this->nativeDevice->SetRenderTarget(0, target))) {
{
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->context.device->Clear(0, nullptr, D3DCLEAR_TARGET, 0, 1.0f, 0);
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->device->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->device->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
this->nativeDevice->Clear(0, nullptr, D3DCLEAR_TARGET, 0, 1.0f, 0);
if (SUCCEEDED(this->context.device->BeginScene())) {
if (SUCCEEDED(this->nativeDevice->BeginScene())) {
for (RenderPrimitive* primitive : primitives) {
this->state.SetTexture(0, primitive->texture ? static_cast<CTextureDX9*>(primitive->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, primitive->texture ? static_cast<CTextureDX9*>(primitive->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(primitive);
}
this->context.device->EndScene();
this->nativeDevice->EndScene();
}
}
this->context.device->SetRenderTarget(0, previous);
this->nativeDevice->SetRenderTarget(0, previous);
result = true;
}

View file

@ -1,44 +0,0 @@
#ifndef RAGNAROK_SOURCE_RENDER_DX9_RENDERERDX9OPERATIONS_H
#define RAGNAROK_SOURCE_RENDER_DX9_RENDERERDX9OPERATIONS_H
#include <list>
#include <vector>
class CTexture;
struct RenderPrimitive;
struct RenderCommand;
struct DeviceStateDX9;
struct TextureDX9Context;
struct DepthPrimitive;
struct RenderQueues;
struct LightmappedPrimitive;
struct ServiceOptions;
struct RendererFogDX9;
class DeviceOwnerDX9;
class CRenderSystemBase;
struct tagRECT;
struct RendererDX9Operations {
TextureDX9Context& context;
DeviceStateDX9& state;
void SetCamera(const float* eye, const float* target, const float* up);
void SetLighting(const float* direction, const float* diffuse, const float* ambient);
void ClearDepth(int clearColor);
void ClearWorld(unsigned color, int mode, unsigned char worldFlag, unsigned overlay);
void SetTextureMode(int mode);
void DrawPrimitive(RenderCommand* primitive);
void DrawLightmappedPrimitive(LightmappedPrimitive* primitive);
void DrawDepthQueue(std::vector<DepthPrimitive>& queue, bool sort);
void DrawOpaqueQueues(RenderQueues& queues);
void DrawGroundQueues(RenderQueues& queues);
void DrawAlphaQueues(RenderQueues& queues, unsigned char twoPass);
void DrawAuxiliaryQueue(RenderQueues& queues);
void DrawQueues(
RenderQueues& queues, unsigned char twoPass, RendererFogDX9& fog, const float& aspect
);
bool RenderToTexture(int width, int height, const std::list<RenderPrimitive*>& primitives, CTexture*& texture);
bool SaveScreenshot(DeviceOwnerDX9& owner, CRenderSystemBase* renderSystem, const char* filename, int format, CTexture* overlay, const tagRECT* rectangle);
};
#endif

View file

@ -1,6 +1,8 @@
#include "Render/DX9/D3DX9Runtime.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/DX9/RendererFogDX9.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/TextureDX9.h"
#include "Render/TextureQuad.h"
@ -19,21 +21,20 @@ void RendererFogDX9::Set(int value, const D3DCAPS9& caps) {
// OFFSET: 0x005654D0
// FUNCTION: fn_02217
void RendererFogDX9::Apply(
const TextureDX9Context& context, DeviceStateDX9& state, const float& aspect
) {
if (this->dirty == 1) {
const float inverseAspect = 1.0f / aspect;
const bool supported = (context.caps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0;
void CRendererDX9::ApplyFog() {
DeviceStateDX9& state = this->device->state;
if (this->fog.dirty == 1) {
const float inverseAspect = 1.0f / this->viewport.aspect;
const bool supported = (this->device->caps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0;
D3DMATRIX identity{};
identity._11 = identity._22 = identity._33 = identity._44 = 1.0f;
const float start = g_depthStart * 1490.0f + 10.0f;
const float end = g_depthEnd * 1490.0f + 10.0f;
D3DMATRIX projection;
D3DXMatrixPerspectiveFovLH(&projection, 0.2617994f, inverseAspect, 10.0f, 1500.0f);
context.device->SetTransform(D3DTS_WORLD, &identity);
context.device->SetTransform(D3DTS_PROJECTION, &projection);
context.device->SetTransform(D3DTS_VIEW, &identity);
this->nativeDevice->SetTransform(D3DTS_WORLD, &identity);
this->nativeDevice->SetTransform(D3DTS_PROJECTION, &projection);
this->nativeDevice->SetTransform(D3DTS_VIEW, &identity);
state.SetRenderState(D3DRS_FOGCOLOR, g_worldOverlayColor);
state.SetRenderState(D3DRS_RANGEFOGENABLE, g_fogRange);
@ -45,11 +46,11 @@ void RendererFogDX9::Apply(
state.SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
state.SetRenderState(D3DRS_FOGVERTEXMODE, g_fogVertexMode);
} else {
this->enabled = 0;
this->fog.enabled = 0;
}
this->dirty = 0;
this->fog.dirty = 0;
}
state.SetRenderState(D3DRS_FOGENABLE, this->enabled);
state.SetRenderState(D3DRS_FOGENABLE, this->fog.enabled);
}

View file

@ -4,7 +4,6 @@
#include <cstddef>
#include <d3d9.h>
struct TextureDX9Context;
struct DeviceStateDX9;
struct RendererFogDX9 {
@ -13,7 +12,6 @@ struct RendererFogDX9 {
/* 0158 */ int supported;
void Set(int enabled, const D3DCAPS9& caps);
void Apply(const TextureDX9Context& context, DeviceStateDX9& state, const float& aspect);
};
static_assert(sizeof(RendererFogDX9) == 12);

View file

@ -6,7 +6,6 @@
#include "Render/Primitives/RenderPrimitivePool.h"
#include "Render/Primitives/RenderQueues.h"
#include "Render/Primitives/RenderVertexPool.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DeviceContext/DCSurface.h"
// OFFSET: 0x0055A360
@ -24,10 +23,7 @@ void CRenderer::ClearFrame() {
// FUNCTION: fn_02222
bool CRendererDX9::Draw() {
this->device->Begin(GetRenderSystemHolder()->system);
auto& context = this->TextureContext();
this->Operations(context).DrawQueues(
this->queues, this->twoPass, this->fog, this->viewport.aspect
);
this->DrawQueues(this->queues, this->twoPass);
this->ClearFrame();
this->device->End();

View file

@ -1,6 +1,7 @@
#include "Render/DX9/D3DX9Runtime.h"
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
#include "Render/DeviceContext/DCSurface.h"
#include "Render/Primitives/UIRPData.h"
#include <bit>
@ -18,27 +19,26 @@ namespace {
// OFFSET: 0x005680A0
// FUNCTION: fn_02236
bool RendererDX9Operations::SaveScreenshot(
DeviceOwnerDX9& owner, CRenderSystemBase* renderSystem, const char* filename, int format, CTexture* overlay, const tagRECT* rectangle
) {
bool CRendererDX9::SaveScreenshot(const char* filename, int format, CTexture* overlay, const tagRECT* rectangle) {
DeviceOwnerDX9& owner = *this->device;
if (overlay) {
unsigned x = rectangle ? static_cast<unsigned>(rectangle->right) : owner.backBufferDescription.Width;
unsigned y = rectangle ? static_cast<unsigned>(rectangle->bottom) : owner.backBufferDescription.Height;
x -= overlay->Width();
y -= overlay->Height();
ScreenshotOverlay drawing;
drawing.Draw(*this->context.primitives, std::bit_cast<std::int32_t>(x), std::bit_cast<std::int32_t>(y), overlay, 0xFFFFFFFFu, 0, 0, false);
drawing.Draw(this->primitives, std::bit_cast<std::int32_t>(x), std::bit_cast<std::int32_t>(y), overlay, 0xFFFFFFFFu, 0, 0, false);
if (owner.Begin(renderSystem)) {
ScopedDeviceStateDX9 restore(this->state);
this->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
if (owner.Begin(GetRenderSystemHolder()->system)) {
ScopedDeviceStateDX9 restore(this->device->state);
this->device->state.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
this->device->state.SetRenderState(D3DRS_FOGENABLE, 0);
this->device->state.SetRenderState(D3DRS_ALPHAREF, 1);
this->device->state.SetRenderState(D3DRS_ALPHATESTENABLE, 1);
this->device->state.SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
for (RenderPrimitive* command : drawing.Primitives()) {
this->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->device->state.SetTexture(0, command->texture ? static_cast<CTextureDX9*>(command->texture)->NativeTexture() : nullptr);
this->DrawPrimitive(command);
}

View file

@ -1,4 +1,5 @@
#include "Render/DX9/SurfaceDX9.h"
#include "Render/DX9/DeviceOwnerDX9.h"
#include <algorithm>
#include <cstring>
@ -45,14 +46,14 @@ namespace {
// OFFSET: 0x00570720
// FUNCTION: fn_02427
CSurfaceDX9::CSurfaceDX9(SurfaceDX9Context& context, int width, int height)
: m_context(&context), m_width(AlignDimension(width)), m_height(AlignDimension(height)), m_surface(nullptr) {
context.device->CreateOffscreenPlainSurface(this->m_width, this->m_height, context.backBufferDescription.Format, D3DPOOL_DEFAULT, &this->m_surface, nullptr);
CSurfaceDX9::CSurfaceDX9(DeviceOwnerDX9& owner, int width, int height)
: m_owner(&owner), m_width(AlignDimension(width)), m_height(AlignDimension(height)), m_surface(nullptr) {
owner.device->CreateOffscreenPlainSurface(this->m_width, this->m_height, owner.backBufferDescription.Format, D3DPOOL_DEFAULT, &this->m_surface, nullptr);
}
// OFFSET: 0x005707D0
// FUNCTION: fn_02428
CSurfaceDX9::CSurfaceDX9(SurfaceDX9Context& context, IDirect3DSurface9* surface) : m_context(&context) {
CSurfaceDX9::CSurfaceDX9(DeviceOwnerDX9& owner, IDirect3DSurface9* surface) : m_owner(&owner) {
D3DSURFACE_DESC description;
if (FAILED(surface->GetDesc(&description))) {
this->m_width = 0;
@ -95,8 +96,8 @@ bool CSurfaceDX9::Resize(int width, int height) {
this->m_width = AlignDimension(width);
this->m_height = AlignDimension(height);
return SUCCEEDED(this->m_context->device->CreateOffscreenPlainSurface(
this->m_width, this->m_height, this->m_context->backBufferDescription.Format, D3DPOOL_DEFAULT, &this->m_surface, nullptr
return SUCCEEDED(this->m_owner->device->CreateOffscreenPlainSurface(
this->m_width, this->m_height, this->m_owner->backBufferDescription.Format, D3DPOOL_DEFAULT, &this->m_surface, nullptr
)) &&
this->m_surface;
}
@ -207,7 +208,7 @@ void CSurfaceDX9::Upload(int x, int y, int width, int height, const std::uint32_
// FUNCTION: fn_02431
void CSurfaceDX9::Fill(const RECT* rectangle, std::uint32_t color) {
if (this->m_surface) {
this->m_context->device->ColorFill(this->m_surface, rectangle, color);
this->m_owner->device->ColorFill(this->m_surface, rectangle, color);
}
}
@ -224,10 +225,10 @@ void CSurfaceDX9::Draw(int x, int y, int width, int height, std::uint32_t) {
}
const RECT target{x, y, x + width, y + height};
const RECT destination = Clip(target, this->m_context->backBufferDescription);
const RECT destination = Clip(target, this->m_owner->backBufferDescription);
const RECT original{0, 0, destination.right - destination.left, destination.bottom - destination.top};
const RECT source = Clip(original, description);
this->m_context->device->StretchRect(this->m_surface, &source, this->m_context->backBuffer, &destination, D3DTEXF_NONE);
this->m_owner->device->StretchRect(this->m_surface, &source, this->m_owner->backBuffer, &destination, D3DTEXF_NONE);
}
// OFFSET: 0x00570BA0
@ -238,6 +239,6 @@ void CSurfaceDX9::Stretch(int x, int y, int width, int height) {
}
const RECT target{x, y, x + width, y + height};
const RECT destination = Clip(target, this->m_context->backBufferDescription);
this->m_context->device->StretchRect(this->m_surface, nullptr, this->m_context->backBuffer, &destination, D3DTEXF_LINEAR);
const RECT destination = Clip(target, this->m_owner->backBufferDescription);
this->m_owner->device->StretchRect(this->m_surface, nullptr, this->m_owner->backBuffer, &destination, D3DTEXF_LINEAR);
}

View file

@ -5,16 +5,12 @@
#include <d3d9.h>
struct SurfaceDX9Context {
IDirect3DDevice9* device;
D3DSURFACE_DESC backBufferDescription;
IDirect3DSurface9* backBuffer;
};
class DeviceOwnerDX9;
class CSurfaceDX9 : public CSurface {
public:
CSurfaceDX9(SurfaceDX9Context& context, int width, int height);
CSurfaceDX9(SurfaceDX9Context& context, IDirect3DSurface9* surface);
CSurfaceDX9(DeviceOwnerDX9& owner, int width, int height);
CSurfaceDX9(DeviceOwnerDX9& owner, IDirect3DSurface9* surface);
~CSurfaceDX9() override;
std::uint32_t Width() override;
std::uint32_t Height() override;
@ -29,7 +25,7 @@ public:
void Stretch(int x, int y, int width, int height) override;
protected:
/* 0004 */ SurfaceDX9Context* m_context;
/* 0004 */ DeviceOwnerDX9* m_owner;
/* 0008 */ std::uint32_t m_width;
/* 000C */ std::uint32_t m_height;
/* 0010 */ IDirect3DSurface9* m_surface;

View file

@ -1,3 +1,6 @@
#include "Render/Renderer.h"
#include "Render/TextureQuad.h"
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/D3DX9Runtime.h"
#include "Render/Primitives/RenderPrimitivePool.h"
#include "Render/Primitives/RenderQueues.h"
@ -50,8 +53,8 @@ namespace {
// OFFSET: 0x00572500
// FUNCTION: fn_02474
CTextureDX9::CTextureDX9(TextureDX9Context& context)
: m_context(&context), m_renderTargetUsage(false), m_dynamic(false), m_allowDynamic(false), m_renderTarget(false), m_texture(nullptr), m_surface(nullptr),
CTextureDX9::CTextureDX9(DeviceOwnerDX9& owner)
: m_owner(&owner), m_renderTargetUsage(false), m_dynamic(false), m_allowDynamic(false), m_renderTarget(false), m_texture(nullptr), m_surface(nullptr),
m_description{} {
this->m_textureWidth = this->m_textureHeight = this->m_width = this->m_height = 1;
this->m_format = TextureFormat::A1R5G5B5;
@ -59,7 +62,7 @@ CTextureDX9::CTextureDX9(TextureDX9Context& context)
// OFFSET: 0x005725C0
// FUNCTION: fn_02475
CTextureDX9::CTextureDX9(TextureDX9Context& context, int width, int height, int format, bool dynamic, bool renderTarget) : CTextureDX9(context) {
CTextureDX9::CTextureDX9(DeviceOwnerDX9& owner, int width, int height, int format, bool dynamic, bool renderTarget) : CTextureDX9(owner) {
this->m_allowDynamic = dynamic;
this->m_renderTarget = renderTarget;
this->Create(width, height, format);
@ -68,7 +71,7 @@ CTextureDX9::CTextureDX9(TextureDX9Context& context, int width, int height, int
// OFFSET: 0x00572650
// FUNCTION: fn_02476
CTextureDX9::CTextureDX9(TextureDX9Context& context, IDirect3DTexture9* texture) : CTextureDX9(context) {
CTextureDX9::CTextureDX9(DeviceOwnerDX9& owner, IDirect3DTexture9* texture) : CTextureDX9(owner) {
this->m_texture = texture;
if (SUCCEEDED(texture->GetSurfaceLevel(0, &this->m_surface)) && SUCCEEDED(this->m_surface->GetDesc(&this->m_description))) {
this->m_renderTargetUsage = (this->m_description.Usage & D3DUSAGE_RENDERTARGET) != 0;
@ -147,9 +150,9 @@ bool CTextureDX9::Create(int width, int height, int format) {
break;
}
UINT w = std::min<UINT>(RoundUpPowerOfTwo(width), this->m_context->caps.MaxTextureWidth);
UINT h = std::min<UINT>(RoundUpPowerOfTwo(height), this->m_context->caps.MaxTextureHeight);
UINT ratio = this->m_context->caps.MaxTextureAspectRatio;
UINT w = std::min<UINT>(RoundUpPowerOfTwo(width), this->m_owner->caps.MaxTextureWidth);
UINT h = std::min<UINT>(RoundUpPowerOfTwo(height), this->m_owner->caps.MaxTextureHeight);
UINT ratio = this->m_owner->caps.MaxTextureAspectRatio;
if (ratio) {
if (w / h > ratio) {
@ -168,10 +171,10 @@ bool CTextureDX9::Create(int width, int height, int format) {
D3DPOOL pool = D3DPOOL_MANAGED;
this->m_dynamic = false;
if (this->m_allowDynamic && this->m_context->dynamicTextures) {
this->m_dynamic = this->m_context->direct3D && (this->m_context->caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) &&
this->m_context->direct3D->CheckDeviceFormat(
this->m_context->adapter, D3DDEVTYPE_HAL, this->m_context->displayFormat, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, nativeFormat
if (this->m_allowDynamic && this->m_owner->dynamicTextures) {
this->m_dynamic = this->m_owner->direct3D && (this->m_owner->caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) &&
this->m_owner->direct3D->CheckDeviceFormat(
this->m_owner->adapter, D3DDEVTYPE_HAL, this->m_owner->presentation.BackBufferFormat, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, nativeFormat
) == D3D_OK;
pool = D3DPOOL_DEFAULT;
if (this->m_dynamic) {
@ -179,7 +182,7 @@ bool CTextureDX9::Create(int width, int height, int format) {
}
}
if (FAILED(this->m_context->device->CreateTexture(w, h, 1, usage, nativeFormat, pool, &this->m_texture, nullptr)) ||
if (FAILED(this->m_owner->device->CreateTexture(w, h, 1, usage, nativeFormat, pool, &this->m_texture, nullptr)) ||
FAILED(this->m_texture->GetSurfaceLevel(0, &this->m_surface)) || FAILED(this->m_surface->GetDesc(&this->m_description))) {
return false;
}
@ -379,8 +382,8 @@ void CTextureDX9::Upload(int x, int y, int width, int height, const std::uint32_
if (surface) {
surface->AddRef();
}
} else if (SUCCEEDED(this->m_context->device->CreateTexture(
this->m_textureWidth, this->m_textureHeight, !this->m_context->dynamicTextures, 0, this->m_description.Format, D3DPOOL_SYSTEMMEM, &temporary,
} else if (SUCCEEDED(this->m_owner->device->CreateTexture(
this->m_textureWidth, this->m_textureHeight, !this->m_owner->dynamicTextures, 0, this->m_description.Format, D3DPOOL_SYSTEMMEM, &temporary,
nullptr
)) &&
SUCCEEDED(temporary->GetSurfaceLevel(0, &surface))) {
@ -394,7 +397,7 @@ void CTextureDX9::Upload(int x, int y, int width, int height, const std::uint32_
D3DXFilterTexture(temporary, nullptr, UINT(-1), DWORD(-1));
}
this->m_context->device->UpdateTexture(temporary, this->m_texture);
this->m_owner->device->UpdateTexture(temporary, this->m_texture);
} else {
this->Filter();
}
@ -479,21 +482,19 @@ bool CTextureDX9::CopyTexture(CTexture* source, int sourceX, int sourceY, int so
// OFFSET: 0x00544410
void CTextureDX9::Draw(int x, int y, int width, int height, std::uint32_t color) {
this->DrawTo(
*this->m_context->primitives, *this->m_context->queues, x, y, width, height, color, this->m_context->depthAlpha, this->m_context->depthStart,
this->m_context->depthEnd
g_renderer->primitives, g_renderer->queues, x, y, width, height, color, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd
);
}
// OFFSET: 0x00544610
void CTextureDX9::Stretch(int x, int y, int width, int height) {
this->StretchTo(
*this->m_context->primitives, *this->m_context->queues, x, y, width, height, this->m_context->depthAlpha, this->m_context->depthStart,
this->m_context->depthEnd
g_renderer->primitives, g_renderer->queues, x, y, width, height, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd
);
}
// OFFSET: 0x0056CEE0
// FUNCTION: fn_02352
std::unique_ptr<CTextureDX9> CreateTextureDX9(TextureDX9Context** context) {
return std::make_unique<CTextureDX9>(**context);
std::unique_ptr<CTextureDX9> CreateTextureDX9(DeviceOwnerDX9** owner) {
return std::make_unique<CTextureDX9>(**owner);
}

View file

@ -7,28 +7,14 @@
struct RenderQueues;
class RenderPrimitivePool;
struct TextureDX9Context {
IDirect3D9* direct3D;
IDirect3DDevice9* device;
UINT adapter;
D3DFORMAT displayFormat;
D3DCAPS9 caps;
bool dynamicTextures;
void* unknown_d3dx;
RenderPrimitivePool* primitives;
RenderQueues* queues;
bool depthAlpha;
float depthStart;
float depthEnd;
};
class DeviceOwnerDX9;
class CTextureDX9 : public CTexture {
public:
explicit CTextureDX9(TextureDX9Context& context);
CTextureDX9(TextureDX9Context& context, int width, int height, int format, bool dynamic, bool renderTarget);
explicit CTextureDX9(DeviceOwnerDX9& owner);
CTextureDX9(DeviceOwnerDX9& owner, int width, int height, int format, bool dynamic, bool renderTarget);
CTextureDX9(TextureDX9Context& context, IDirect3DTexture9* texture);
CTextureDX9(DeviceOwnerDX9& owner, IDirect3DTexture9* texture);
~CTextureDX9() override;
bool Resize(int width, int height) override;
SurfaceLock Lock() override;
@ -49,7 +35,7 @@ public:
}
protected:
/* 0124 */ TextureDX9Context* m_context;
/* 0124 */ DeviceOwnerDX9* m_owner;
/* 0128 */ bool m_renderTargetUsage;
/* 0129 */ bool m_dynamic;
/* 012A */ bool m_allowDynamic;

View file

@ -1,204 +1,205 @@
#include "Render/DX9/DeviceOwnerDX9.h"
#include "Render/DX9/DeviceStateDX9.h"
#include "Render/DX9/RendererDX9Operations.h"
#include "Render/DX9/RendererDX9.h"
// OFFSET: 0x00568470
// FUNCTION: fn_02241
void RendererDX9Operations::SetTextureMode(int mode) {
void CRendererDX9::SetTextureMode(int mode) {
switch (mode) {
case 0:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
break;
case 1:
case 2:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
break;
case 3:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
break;
case 4:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
break;
case 5:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 6:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 7:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 8:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 9:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDTEXTUREALPHA);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 10:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 11:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 12:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 13:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 14:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
case 15:
this->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);
this->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
this->device->state.SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
this->device->state.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
this->device->state.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
this->device->state.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);
this->device->state.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
this->device->state.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
break;
}
}

View file

@ -196,8 +196,8 @@ timer:
// OFFSET: 0x00560A40
// FUNCTION: fn_02161
CRenderer::CRenderer(CRenderSystemBase& system) : frame(0), unknown_003C(0), unknown_0040(0), unknown_0044(0), twoPass(0), unknown_004C(0) {
this->atlas.Initialize(system, 50);
CRenderer::CRenderer() : frame(0), unknown_003C(0), unknown_0040(0), unknown_0044(0), twoPass(0), unknown_004C(0) {
this->atlas.Initialize(50);
this->fog.enabled = 0;
this->fog.dirty = 1;
this->fog.supported = 0;

View file

@ -18,7 +18,7 @@ class CBitmapRes;
class CRenderer {
public:
explicit CRenderer(CRenderSystemBase& system);
CRenderer();
virtual ~CRenderer();
virtual void SetCamera(const float* eye, const float* target, const float* up) = 0;
virtual void SetLighting(const float* direction, const float* diffuse, const float* ambient) = 0;

View file

@ -4,7 +4,7 @@
// OFFSET: 0x00559420
// FUNCTION: fn_02065
CRendererDX7::CRendererDX7(CRenderSystemBase& system) : CRenderer(system) {
CRendererDX7::CRendererDX7() {
this->frame = 0;
this->unknown_025C = 0;
this->time = timeGetTime();

View file

@ -5,7 +5,7 @@
class CRendererDX7 : public CRenderer {
public:
explicit CRendererDX7(CRenderSystemBase& system);
CRendererDX7();
/* 025C */ unsigned unknown_025C;
/* 0260 */ unsigned time;

View file

@ -1,6 +1,7 @@
#include "Render/RenderSystemBase.h"
#include "Render/Textures/SpriteAtlas.h"
#include "Render/Textures/Texture.h"
#include "Render/Textures/TextureCache.h"
#include <bit>
#include <windows.h>
@ -62,7 +63,7 @@ std::size_t SpriteAtlas::Hash::operator()(const Key& key) const {
// OFFSET: 0x0056FB00
// FUNCTION: fn_02407
void SpriteAtlas::Initialize(CRenderSystemBase& system, unsigned spareCount) {
void SpriteAtlas::Initialize(unsigned spareCount) {
this->Clear();
this->ClearSpare();
if (this->m_spare.capacity() < spareCount) {
@ -70,7 +71,7 @@ void SpriteAtlas::Initialize(CRenderSystemBase& system, unsigned spareCount) {
}
for (unsigned i = 0; i < spareCount; ++i) {
CTexture* texture = system.CreateTexture(256, 256, TextureFormat::A1R5G5B5, false, false);
CTexture* texture = CreateTexture(256, 256, TextureFormat::A1R5G5B5, false, false);
if (!texture) {
break;
}

View file

@ -37,7 +37,7 @@ class SpriteAtlas {
public:
SpriteAtlas();
~SpriteAtlas();
void Initialize(CRenderSystemBase& system, unsigned spareCount);
void Initialize(unsigned spareCount);
void Clear();
CTexture* Find(const SpriteRleImage* image, const std::uint32_t* palette, SpriteAtlasRecord& output);
CTexture* Insert(