Skip to content

Commit

Permalink
DX9 Compatibility changes for Nav rendering
Browse files Browse the repository at this point in the history
- Currently disables rendering for DX11 until implementation is complete
  • Loading branch information
brainiac committed Oct 14, 2023
1 parent 569870b commit 0a37028
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
4 changes: 2 additions & 2 deletions plugin/MQ2Nav.vcxproj
Expand Up @@ -132,8 +132,8 @@
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<OptimizeReferences Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</OptimizeReferences>
<OptimizeReferences Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</OptimizeReferences>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">d3d9.lib;d3dx9d.lib;libprotobufd.lib;zlibd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">d3d9.lib;d3dx9.lib;libprotobuf.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">libprotobufd.lib;zlibd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">libprotobuf.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion plugin/ModelLoader.cpp
Expand Up @@ -38,7 +38,7 @@ bool s_drawBoundingBoxes = false;
class ModelData : public Renderable
{
public:
ModelData(int doorId, const std::shared_ptr<ModelInfo>& modelInfo, IDirect3DDevice9* device)
ModelData(int doorId, const std::shared_ptr<ModelInfo>& modelInfo, eqlib::Direct3DDevice9* device)
: m_switchID(doorId)
, m_modelInfo(modelInfo)
{
Expand Down Expand Up @@ -196,12 +196,14 @@ class ModelData : public Renderable
}
#endif

#if HAS_DIRECTX_9
if (m_targetted || m_highlight || s_drawBoundingBoxes)
{
gpD3D9Device->SetRenderState(D3DRS_ZENABLE, !zDisabled && !s_visibleOverride);
m_grpBB->SetTransform(&scale);
m_grpBB->Render();
}
#endif
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion plugin/NavMeshRenderer.cpp
Expand Up @@ -133,7 +133,8 @@ void NavMeshRenderer::Render()
if (!m_loaded || m_loading || !m_primGroup || !gpD3D9Device)
return;

IDirect3DDevice9* pDevice = gpD3D9Device;
#if HAS_DIRECTX_9
eqlib::Direct3DDevice9* pDevice = gpD3D9Device;
if (!pDevice) return;

pDevice->SetPixelShader(nullptr);
Expand Down Expand Up @@ -176,6 +177,7 @@ void NavMeshRenderer::Render()
}

m_primGroup->Render();
#endif
}

//----------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions plugin/NavigationPath.cpp
Expand Up @@ -558,6 +558,7 @@ bool NavigationLine::CreateDeviceObjects()
if (m_loaded)
return true;

#if HAS_DIRECTX_9
auto shaderFile = LoadResource(IDR_VOLUMELINES_FX);
if (shaderFile.empty())
return false;
Expand Down Expand Up @@ -607,13 +608,15 @@ bool NavigationLine::CreateDeviceObjects()
InvalidateDeviceObjects();
return false;
}
#endif

m_loaded = true;
return true;
}

void NavigationLine::InvalidateDeviceObjects()
{
#if HAS_DIRECTX_9
if (m_effect)
{
m_effect->Release();
Expand All @@ -627,21 +630,25 @@ void NavigationLine::InvalidateDeviceObjects()
m_vDeclaration->Release();
m_vDeclaration = nullptr;
}
#endif

m_loaded = false;
}

void NavigationLine::ReleasePath()
{
#if HAS_DIRECTX_9
if (m_vertexBuffer)
{
m_vertexBuffer->Release();
m_vertexBuffer = nullptr;
}
#endif
}

void NavigationLine::Render()
{
#if HAS_DIRECTX_9
if (!m_loaded)
return;
if (m_needsUpdate && m_path)
Expand Down Expand Up @@ -741,10 +748,12 @@ void NavigationLine::Render()

gpD3D9Device->SetRenderState(D3DRS_ZENABLE, depthTest);
gpD3D9Device->SetRenderState(D3DRS_ZFUNC, depthFunc);
#endif
}

void NavigationLine::GenerateBuffers()
{
#if HAS_DIRECTX_9
const std::vector<int>& renderPath = m_path->GetRenderPath();
int size = (int)renderPath.size();

Expand Down Expand Up @@ -867,6 +876,7 @@ void NavigationLine::GenerateBuffers()
}

m_vertexBuffer->Unlock();
#endif
m_needsUpdate = false;
}

Expand Down
15 changes: 15 additions & 0 deletions plugin/RenderHandler.cpp
Expand Up @@ -14,6 +14,15 @@

#include <glm/glm.hpp>

#if HAS_DIRECTX_9
#pragma comment(lib, "d3d9")
#ifdef _DEBUG
#pragma comment(lib, "d3dx9d")
#else
#pragma comment(lib, "d3dx9")
#endif
#endif

//============================================================================

RenderHandler::RenderHandler()
Expand Down Expand Up @@ -87,18 +96,23 @@ void RenderHandler::PerformRender()
{
ResetDeviceState();

#if HAS_DIRECTX_9
D3DPERF_BeginEvent(D3DCOLOR_XRGB(255, 0, 0), L"RenderHandler::PerformRender");
#endif

for (auto& r : m_renderables)
{
r->Render();
}

#if HAS_DIRECTX_9
D3DPERF_EndEvent();
#endif
}

void ResetDeviceState()
{
#if HAS_DIRECTX_9
gpD3D9Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
gpD3D9Device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, false);
gpD3D9Device->SetRenderState(D3DRS_ALPHATESTENABLE, false);
Expand Down Expand Up @@ -174,4 +188,5 @@ void ResetDeviceState()
glm::mat4 matrix = glm::identity<glm::mat4>();

gpD3D9Device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&matrix);
#endif
}
8 changes: 7 additions & 1 deletion plugin/RenderList.cpp
Expand Up @@ -28,7 +28,7 @@ static inline int PrimVertexCount(RenderList::PrimitiveType type)
return 0;
}

RenderList::RenderList(IDirect3DDevice9* pDevice, PrimitiveType type)
RenderList::RenderList(eqlib::Direct3DDevice9* pDevice, PrimitiveType type)
: m_pDevice(pDevice)
, m_type(type)
, m_tempMax(PrimVertexCount(type))
Expand Down Expand Up @@ -161,6 +161,7 @@ void RenderList::End()

void RenderList::Render()
{
#if HAS_DIRECTX_9
GenerateBuffers();

if (!m_pVB || !m_pIB)
Expand Down Expand Up @@ -220,10 +221,12 @@ void RenderList::Render()
break;
}
}
#endif
}

void RenderList::GenerateBuffers()
{
#if HAS_DIRECTX_9
bool rebuildBuffers = false;
int vertexSize = 0, indexSize = 0;

Expand Down Expand Up @@ -289,10 +292,12 @@ void RenderList::GenerateBuffers()
m_pVB->Unlock();
m_pIB->Unlock();
}
#endif
}

void RenderList::InvalidateDeviceObjects()
{
#if HAS_DIRECTX_9
if (m_pVB)
{
m_pVB->Release();
Expand All @@ -304,6 +309,7 @@ void RenderList::InvalidateDeviceObjects()
m_pIB->Release();
m_pIB = nullptr;
}
#endif
}

bool RenderList::CreateDeviceObjects()
Expand Down
13 changes: 6 additions & 7 deletions plugin/RenderList.h
Expand Up @@ -6,8 +6,7 @@
#pragma once

#include "plugin/Renderable.h"

#include <d3d9.h>
#include "eqlib/EQDX9.h"
#include <glm/glm.hpp>

#include <map>
Expand All @@ -29,7 +28,7 @@ class RenderList : public Renderable
Prim_Count
};

RenderList(IDirect3DDevice9* d3dDevice, PrimitiveType type);
RenderList(eqlib::Direct3DDevice9* d3dDevice, PrimitiveType type);
~RenderList();

void Reset();
Expand Down Expand Up @@ -112,9 +111,9 @@ class RenderList : public Renderable
bool m_eqCoords = false;

private:
IDirect3DDevice9* m_pDevice = nullptr;
IDirect3DVertexBuffer9* m_pVB = nullptr;
IDirect3DIndexBuffer9* m_pIB = nullptr;
eqlib::Direct3DDevice9* m_pDevice = nullptr;
eqlib::Direct3DVertexBuffer9* m_pVB = nullptr;
eqlib::Direct3DIndexBuffer9* m_pIB = nullptr;

std::vector<Vertex> m_vertices;

Expand All @@ -128,7 +127,7 @@ class RenderList : public Renderable
class RenderGroup : public Renderable
{
public:
RenderGroup(IDirect3DDevice9* device)
RenderGroup(eqlib::Direct3DDevice9* device)
{
for (int i = 0; i < RenderList::Prim_Count; ++i)
{
Expand Down

0 comments on commit 0a37028

Please sign in to comment.