Skip to content

Commit

Permalink
[FEATURE] : partly debug staff on dx11
Browse files Browse the repository at this point in the history
  • Loading branch information
mortany committed Oct 25, 2022
1 parent 3b061f4 commit 1e95501
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/Layers/xrRender/R_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void CBackend::OnDeviceCreate ()
// streams
Vertex.Create ();
Index.Create ();

// Debug Draw
InitializeDebugDraw();
// invalidate caching
Invalidate ();
}
Expand All @@ -150,6 +151,8 @@ void CBackend::OnDeviceDestroy()
#if defined(USE_DX10) || defined(USE_DX11)
//DestroyConstantBuffers();
#endif // USE_DX10
// Debug Draw
DestroyDebugDraw();
}

#if defined(USE_DX10) || defined(USE_DX11)
Expand Down
10 changes: 10 additions & 0 deletions src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@ class ECORE_API CBackend

CBackend() { Invalidate(); };

private:
// Debug Draw
void InitializeDebugDraw();
void DestroyDebugDraw();

// DX9 doesn't need this
#if defined(USE_DX10) || defined(USE_DX11)
ref_geom vs_L;
ref_geom vs_TL;
#endif
#if defined(USE_DX10) || defined(USE_DX11)
private:
// DirectX 10 internal functionality
Expand Down
68 changes: 59 additions & 9 deletions src/Layers/xrRender/R_Backend_DBG.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#include "stdafx.h"
#pragma hdrstop

#if defined(USE_DX10) || defined(USE_DX11)
extern IC u32 GetIndexCount(D3DPRIMITIVETYPE T, u32 iPrimitiveCount);
#endif

void CBackend::InitializeDebugDraw()
{
#if defined(USE_DX10) || defined(USE_DX11)
vs_L.create(FVF::F_L, RCache.Vertex.Buffer(), RCache.Index.Buffer());
vs_TL.create(FVF::F_TL, RCache.Vertex.Buffer(), RCache.Index.Buffer());
#endif
}

void CBackend::DestroyDebugDraw()
{
#if defined(USE_DX10) || defined(USE_DX11)
vs_L.destroy();
vs_TL.destroy();
#endif
}

void CBackend::dbg_DP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 vBase, u32 pc)
{
RCache.set_Geometry (geom);
Expand All @@ -17,8 +37,29 @@ void CBackend::dbg_DIP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV
void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pIdx, int pcnt)
{
#if defined(USE_DX10) || defined(USE_DX11)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
u32 vBase;
{
FVF::L* pv = (FVF::L*)Vertex.Lock(vcnt, vs_L->vb_stride, vBase);
for (size_t i = 0; i < vcnt; i++)
{
pv[i] = pVerts[i];
}
Vertex.Unlock(vcnt, vs_L->vb_stride);
}

u32 iBase;
{
const size_t count = GetIndexCount(T, pcnt);
u16* indices = Index.Lock(count, iBase);
for (size_t i = 0; i < count; i++)
indices[i] = pIdx[i];
Index.Unlock(count);
}
set_Geometry(vs_L);
set_RT(HW.pBaseRT);
RImplementation.rmNormal();
set_Stencil(FALSE);
Render(T, vBase, 0, vcnt, iBase, pcnt);
#else // USE_DX10
OnFrameEnd ();
CHK_DX(HW.pDevice->SetFVF (FVF::F_L));
Expand All @@ -31,8 +72,21 @@ void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pI
void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int pcnt)
{
#if defined(USE_DX10) || defined(USE_DX11)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
u32 vBase;
{
const size_t count = GetIndexCount(T, pcnt);
FVF::L* pv = (FVF::L*)Vertex.Lock(count, vs_L->vb_stride, vBase);
for (size_t i = 0; i < count; i++)
{
pv[i] = pVerts[i];
}
Vertex.Unlock(count, vs_L->vb_stride);
}
set_Geometry(vs_L);
set_RT(HW.pBaseRT);
RImplementation.rmFar();
set_Stencil(FALSE);
Render(T, vBase, pcnt);
#else // USE_DX10
OnFrameEnd ();
CHK_DX(HW.pDevice->SetFVF (FVF::F_L));
Expand Down Expand Up @@ -126,7 +180,6 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
0.3536f,-0.1464f,-0.9239f, 0.3827f,0.0000f,-0.9239f, 0.3536f,0.1464f,-0.9239f,
0.2706f,0.2706f,-0.9239f, 0.1464f,0.3536f,-0.9239f, 0.0000f,0.0000f,-1.0000f
};
#if !defined(USE_DX10) && !defined(USE_DX11)
u16 gFaces[224*3] =
{
0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,7, 0,7,8, 0,8,9, 0,9,10,
Expand Down Expand Up @@ -155,7 +208,6 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
96,97,81, 113,98,97, 113,99,98, 113,100,99, 113,101,100, 113,102,101, 113,103,102, 113,104,103, 113,105,104,
113,106,105, 113,107,106, 113,108,107, 113,109,108, 113,110,109, 113,111,110, 113,112,111, 113,97,112
};
#endif // #if defined(USE_DX10) || defined(USE_DX11)

const int vcnt = sizeof(gVertices)/(sizeof(float)*3);
FVF::L verts[vcnt];
Expand All @@ -167,9 +219,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
set_xform_world (T);

#if defined(USE_DX10) || defined(USE_DX11)
// TODO: DX10: implement
//VERIFY(!"CBackend::dbg_Draw not implemented.");
//dbg_Draw(D3DPT_TRIANGLELIST,verts,vcnt,gFaces,224);

#else // USE_DX10
HW.pDevice->SetRenderState (D3DRS_FILLMODE, D3DFILL_WIREFRAME);
dbg_Draw(D3DPT_TRIANGLELIST,verts,vcnt,gFaces,224);
Expand Down
10 changes: 9 additions & 1 deletion src/Layers/xrRender/dxDebugRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "dxDebugRender.h"
#include "dxUIShader.h"

#include "dxRenderDeviceRender.h"
dxDebugRender DebugRenderImpl;
dxDebugRender DebugRenderImpl_1;
dxDebugRender::dxDebugRender()
Expand All @@ -17,6 +17,14 @@ void dxDebugRender::Render()
return;

RCache.set_xform_world (Fidentity);

#if defined(USE_DX10) || defined(USE_DX11)
RCache.set_Shader(dxRenderDeviceRender::Instance().m_WireShader);
const u32 color = m_line_vertices[0].color;
RCache.set_c("tfactor", float(color_get_R(color)) / 255.f, float(color_get_G(color)) / 255.f, \
float(color_get_B(color)) / 255.f, float(color_get_A(color)) / 255.f);
#endif // USE_DX10

RCache.dbg_Draw (D3DPT_LINELIST,&*m_line_vertices.begin(),m_line_vertices.size(),&*m_line_indices.begin(),m_line_indices.size()/2);
m_line_vertices.resize (0);
m_line_indices.resize (0);
Expand Down

0 comments on commit 1e95501

Please sign in to comment.