test commit to fix debug draw

pass all draws through duDebugDraw instead of calling our class directly.
This commit is contained in:
marauder2k7 2025-07-20 16:10:27 +01:00
parent 81504fb089
commit 26ebdd093b
6 changed files with 172 additions and 293 deletions

View file

@ -178,39 +178,59 @@ public:
U32 mSize = 0;
}_getBufferData;
void lock(const U32 size, U32 offsetAlign, U32 &outOffset, void* &outPtr)
void lock(const U32 size, U32 offsetAlign, U32& outOffset, void*& outPtr)
{
if( !size )
if (!size)
{
AssertFatal(0, "");
AssertFatal(0, "GLCircularVolatileBuffer::lock - size must be > 0");
outOffset = 0;
outPtr = NULL;
outPtr = nullptr;
return;
}
mLockManager.waitFirstRange( mBufferFreePos, (mBufferFreePos + size)-1 );
// Align free pos first (before wraparound check)
if (offsetAlign)
{
mBufferFreePos = ((mBufferFreePos + offsetAlign - 1) / offsetAlign) * offsetAlign;
}
if( mBufferFreePos + size > mBufferSize )
{
mUsedRanges.push_back( UsedRange( mBufferFreePos, mBufferSize-1 ) );
// If the size won't fit from current pos to end, wrap around
if (mBufferFreePos + size > mBufferSize)
{
// Protect the remaining space
if (mBufferFreePos < mBufferSize)
mUsedRanges.push_back(UsedRange(mBufferFreePos, mBufferSize - 1));
// Reset free pos
mBufferFreePos = 0;
}
// force offset buffer align
if( offsetAlign )
mBufferFreePos = ( (mBufferFreePos/offsetAlign) + 1 ) * offsetAlign;
// Realign after wrap
if (offsetAlign)
{
mBufferFreePos = ((mBufferFreePos + offsetAlign - 1) / offsetAlign) * offsetAlign;
}
// Now check for overlaps *after* wrapping
mLockManager.waitOverlapRanges(mBufferFreePos, mBufferFreePos + size - 1);
}
else
{
// Normal range wait
mLockManager.waitOverlapRanges(mBufferFreePos, mBufferFreePos + size - 1);
}
outOffset = mBufferFreePos;
if( GFXGL->mCapabilities.bufferStorage )
{
outPtr = (U8*)(mBufferPtr) + mBufferFreePos;
}
else if( GFXGL->glUseMap() )
if (GFXGL->mCapabilities.bufferStorage)
{
PRESERVE_BUFFER( mBinding );
outPtr = static_cast<U8*>(mBufferPtr) + mBufferFreePos;
}
else if (GFXGL->glUseMap())
{
PRESERVE_BUFFER(mBinding);
glBindBuffer(mBinding, mBufferName);
const GLbitfield access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT;
const GLbitfield access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT;
outPtr = glMapBufferRange(mBinding, outOffset, size, access);
}
else
@ -218,14 +238,13 @@ public:
_getBufferData.mOffset = outOffset;
_getBufferData.mSize = size;
outPtr = mFrameAllocator.lock( size );
}
outPtr = mFrameAllocator.lock(size);
}
//set new buffer pos
mBufferFreePos = mBufferFreePos + size;
mBufferFreePos += size;
//align 4bytes
mBufferFreePos = ( (mBufferFreePos/4) + 1 ) * 4;
mBufferFreePos = ((mBufferFreePos + 4 - 1) / 4) * 4;
}
void unlock()

View file

@ -38,19 +38,15 @@
duDebugDrawTorque::duDebugDrawTorque()
{
VECTOR_SET_ASSOCIATION(mVertList);
mPrimType = 0;
mQuadsMode = false;
mVertCount = 0;
mGroup = 0;
mCurrColor = 0;
mOverrideColor = 0;
mOverride = false;
dMemset(&mStore, 0, sizeof(mStore));
}
duDebugDrawTorque::~duDebugDrawTorque()
{
clear();
}
void duDebugDrawTorque::depthMask(bool state)
@ -60,6 +56,22 @@ void duDebugDrawTorque::depthMask(bool state)
void duDebugDrawTorque::texture(bool state)
{
// need a checker texture?...... if(state is true) then set first slot to that texture.
}
unsigned int duDebugDrawTorque::areaToCol(unsigned int area)
{
switch (area)
{
// Ground (0) : light blue
case GroundArea: return duRGBA(0, 192, 255, 255);
// Water : blue
case WaterArea: return duRGBA(0, 0, 255, 255);
// Road : brown
case OffMeshArea: return duRGBA(50, 20, 12, 255);
// Unexpected : red
default: return duRGBA(255, 0, 0, 255);
}
}
/// Begin drawing primitives.
@ -67,29 +79,25 @@ void duDebugDrawTorque::texture(bool state)
/// @param size [in] size of a primitive, applies to point size and line width only.
void duDebugDrawTorque::begin(duDebugDrawPrimitives prim, float size)
{
mCurrColor = -1;
if (!mVertList.empty())
mVertList.clear();
mQuadsMode = false;
mVertCount = 0;
mPrimType = 0;
switch(prim)
switch (prim)
{
case DU_DRAW_POINTS: mPrimType = GFXPointList; break;
case DU_DRAW_LINES: mPrimType = GFXLineList; break;
case DU_DRAW_POINTS: mPrimType = GFXPointList; break;
case DU_DRAW_LINES: mPrimType = GFXLineList; break;
case DU_DRAW_TRIS: mPrimType = GFXTriangleList; break;
case DU_DRAW_QUADS: mPrimType = GFXTriangleList;
mQuadsMode = true; break;
case DU_DRAW_QUADS: mPrimType = GFXTriangleList; mQuadsMode = true; break;
}
mBuffers.push_back(Buffer(mPrimType));
mBuffers.last().group = mGroup;
mDesc.setCullMode(GFXCullNone);
mDesc.setBlend(true);
}
void duDebugDrawTorque::beginGroup(U32 group)
{
mGroup = group;
}
/// Submit a vertex
/// @param pos [in] position of the verts.
/// @param color [in] color of the verts.
@ -103,30 +111,7 @@ void duDebugDrawTorque::vertex(const float* pos, unsigned int color)
/// @param color [in] color of the verts.
void duDebugDrawTorque::vertex(const float x, const float y, const float z, unsigned int color)
{
if(mQuadsMode)
{
if(mVertCount == 3)
{
_vertex(x, -z, y, color);
_vertex(mStore[0][0], mStore[0][1], mStore[0][2], color);
_vertex(mStore[1][0], mStore[1][1], mStore[1][2], color);
_vertex(mStore[1][0], mStore[1][1], mStore[1][2], color);
_vertex(mStore[2][0], mStore[2][1], mStore[2][2], color);
_vertex(x, -z, y, color);
mVertCount = 0;
}
else
{
mStore[mVertCount][0] = x;
mStore[mVertCount][1] = -z;
mStore[mVertCount][2] = y;
mVertCount++;
}
}
else
{
_vertex(x, -z, y, color);
}
_vertex(x, -z, y, color);
}
/// Submit a vertex
@ -148,105 +133,60 @@ void duDebugDrawTorque::vertex(const float x, const float y, const float z, unsi
/// Push a vertex onto the buffer.
void duDebugDrawTorque::_vertex(const float x, const float y, const float z, unsigned int color)
{
// Use override color if we must.
//if(mOverride)
//color = mOverrideColor;
if(mCurrColor != color || !mBuffers.last().buffer.size())
{
U8 r, g, b, a;
// Convert color integer to components.
rcCol(color, r, g, b, a);
mBuffers.last().buffer.push_back(Instruction(r, g, b, a));
mCurrColor = color;
}
// Construct vertex data.
mBuffers.last().buffer.push_back(Instruction(x, y, z));
GFXVertexPCT vert;
vert.point.set(x, y, z);
U8 r, g, b, a;
// Convert color integer to components.
rcCol(color, r, g, b, a);
vert.color.set(r, g, b, a);
mVertList.push_back(vert);
}
/// End drawing primitives.
void duDebugDrawTorque::end()
{
}
if (mVertList.empty())
return;
void duDebugDrawTorque::overrideColor(unsigned int col)
{
mOverride = true;
mOverrideColor = col;
}
const U32 maxVertsPerDraw = GFX_MAX_DYNAMIC_VERTS;
void duDebugDrawTorque::cancelOverride()
{
mOverride = false;
}
U32 totalVerts = mVertList.size();
U32 stride = 1;
U32 stripStart = 0;
void duDebugDrawTorque::renderBuffer(Buffer &b)
{
PrimBuild::begin(b.primType, b.buffer.size());
Vector<Instruction> &buf = b.buffer;
for(U32 i = 0; i < buf.size(); i++)
switch (mPrimType)
{
switch(buf[i].type)
{
case Instruction::POINT:
PrimBuild::vertex3f(buf[i].data.point.x,
buf[i].data.point.y,
buf[i].data.point.z);
break;
case Instruction::COLOR:
if(mOverride)
break;
PrimBuild::color4i(buf[i].data.color.r,
buf[i].data.color.g,
buf[i].data.color.b,
buf[i].data.color.a);
break;
default:
break;
}
case GFXLineList: stride = 2; break;
case GFXTriangleList: stride = 3; break;
case GFXLineStrip: stripStart = 1; stride = 1; break;
case GFXTriangleStrip:stripStart = 2; stride = 1; break;
default: stride = 1; break;
}
PrimBuild::end();
GFX->setPrimitiveBuffer(NULL);
GFX->setStateBlockByDesc(mDesc);
GFX->setupGenericShaders(GFXDevice::GSColor);
for (U32 i = 0; i < totalVerts; i += maxVertsPerDraw)
{
U32 batchSize = getMin(maxVertsPerDraw, totalVerts - i);
mVertexBuffer.set(GFX, batchSize, GFXBufferTypeDynamic);
GFXVertexPCT* verts = mVertexBuffer.lock();
if (verts)
dMemcpy(verts, &mVertList[i], sizeof(GFXVertexPCT) * batchSize);
mVertexBuffer.unlock();
GFX->setVertexBuffer(mVertexBuffer);
U32 numPrims = (batchSize / stride) - stripStart;
GFX->drawPrimitive((GFXPrimitiveType)mPrimType, 0, numPrims);
}
mVertList.clear();
}
void duDebugDrawTorque::render()
{
GFXStateBlockRef sb = GFX->createStateBlock(mDesc);
GFX->setStateBlock(sb);
// Use override color for all rendering.
if(mOverride)
{
U8 r, g, b, a;
rcCol(mOverrideColor, r, g, b, a);
PrimBuild::color4i(r, g, b, a);
}
for(U32 b = 0; b < mBuffers.size(); b++)
{
renderBuffer(mBuffers[b]);
}
}
void duDebugDrawTorque::renderGroup(U32 group)
{
GFXStateBlockRef sb = GFX->createStateBlock(mDesc);
GFX->setStateBlock(sb);
// Use override color for all rendering.
if(mOverride)
{
U8 r, g, b, a;
rcCol(mOverrideColor, r, g, b, a);
PrimBuild::color4i(r, g, b, a);
}
for(U32 b = 0; b < mBuffers.size(); b++)
{
if(mBuffers[b].group == group)
renderBuffer(mBuffers[b]);
}
}
void duDebugDrawTorque::clear()
{
for(U32 b = 0; b < mBuffers.size(); b++)
mBuffers[b].buffer.clear();
mBuffers.clear();
}

View file

@ -23,12 +23,33 @@
#ifndef _DU_DEBUG_DRAW_TORQUE_H_
#define _DU_DEBUG_DRAW_TORQUE_H_
#ifndef _TVECTOR_H_
#include "core/util/tVector.h"
#endif
#include <DebugDraw.h>
#include "gfx/gfxStateBlock.h"
/// @brief Implements the duDebugDraw interface in Torque.
class duDebugDrawTorque: public duDebugDraw {
#ifndef _GFXSTATEBLOCK_H_
#include "gfx/gfxStateBlock.h"
#endif
#ifndef _GFXVERTEXTYPES_H_
#include "gfx/gfxVertexTypes.h"
#endif
#ifndef _GFXVERTEXBUFFER_H_
#include "gfx/gfxVertexBuffer.h"
#endif
/**
* @class duDebugDrawTorque
* @brief Implements the duDebugDraw interface in Torque.
*
* Every debug draw from recast goes through a process of begin, add vertex and then end
* just like our primbuilder class, but we need to catch these vertices
* and add them to a GFXVertexBuffer as recast supports GL_QUADS which is now
* deprecated.
*/
class duDebugDrawTorque : public duDebugDraw {
public:
duDebugDrawTorque();
~duDebugDrawTorque();
@ -36,23 +57,11 @@ public:
/// Enable/disable Z read.
void depthMask(bool state) override;
/// Enable/disable texturing. Not used.
void texture(bool state) override;
/// Special colour overwrite for when I get picky about the colours Mikko chose.
void overrideColor(unsigned int col);
/// Stop the colour override.
void cancelOverride();
/// Begin drawing primitives.
/// @param prim [in] primitive type to draw, one of rcDebugDrawPrimitives.
/// @param size [in] size of a primitive, applies to point size and line width only.
void begin(duDebugDrawPrimitives prim, float size = 1.0f) override;
/// All new buffers go into this group.
void beginGroup(U32 group);
/// Submit a vertex
/// @param pos [in] position of the verts.
/// @param color [in] color of the verts.
@ -66,27 +75,35 @@ public:
/// Submit a vertex
/// @param pos [in] position of the verts.
/// @param color [in] color of the verts.
/// @param uv [in] the uv coordinates.
void vertex(const float* pos, unsigned int color, const float* uv) override;
/// Submit a vertex
/// @param x,y,z [in] position of the verts.
/// @param color [in] color of the verts.
/// @param u [in] the u coordinate.
/// @param v [in] the v coordinate.
void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) override;
/// Set a texture
/// @param state, use a texture in this draw, usually a checker texture.
void texture(bool state) override;
/// <summary>
/// Assigns a colour to an area type.
/// </summary>
/// <param name="area">The area type.</param>
/// <returns>The colour in recast format for the area.</returns>
unsigned int areaToCol(unsigned int area) override;
/// End drawing primitives.
void end() override;
/// Render buffered primitive.
void render();
/// Render buffered primitives in a group.
void renderGroup(U32 group);
/// Delete buffered primitive.
void clear();
private:
GFXStateBlockDesc mDesc;
Vector<GFXVertexPCT> mVertList; // Our vertex list for setting up vertexBuffer in the End function.
GFXVertexBufferHandle<GFXVertexPCT> mVertexBuffer; // our vertex buffer for drawing.
U32 mPrimType;
bool mQuadsMode;
@ -94,64 +111,7 @@ private:
U32 mVertCount;
F32 mStore[3][3];
U32 mGroup;
struct Instruction {
// Contain either a point or a color command.
union {
struct {
U8 r, g, b, a;
} color;
struct {
float x, y, z;
} point;
U32 primType;
} data;
// Which type of data do we store?
enum {
COLOR,
POINT,
PRIMTYPE,
} type;
// Construct as color instruction.
Instruction(U8 r, U8 g, U8 b, U8 a) {
type = COLOR;
data.color.r = r;
data.color.g = g;
data.color.b = b;
data.color.a = a;
}
// Construct as point.
Instruction(float x, float y, float z) {
type = POINT;
data.point.x = x;
data.point.y = y;
data.point.z = z;
}
Instruction(U32 t = 0) {
type = PRIMTYPE;
data.primType = t;
}
};
struct Buffer {
U32 group;
Vector<Instruction> buffer;
GFXPrimitiveType primType;
Buffer(U32 type = 0) {
primType = (GFXPrimitiveType)type;
group = 0;
}
};
Vector<Buffer> mBuffers;
U32 mCurrColor;
U32 mOverrideColor;
bool mOverride;
void _vertex(const float x, const float y, const float z, unsigned int color);
void renderBuffer(Buffer &b);
};
#endif

View file

@ -383,7 +383,6 @@ void GuiNavEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event)
if(gServerContainer.castRay(startPnt, endPnt, StaticShapeObjectType, &ri))
{
mTile = mMesh->getTile(ri.point);
dd.clear();
mMesh->renderTileData(dd, mTile);
}
}
@ -610,13 +609,13 @@ void GuiNavEditorCtrl::renderScene(const RectI & updateRect)
{
renderBoxOutline(mMesh->getTileBox(mCurTile), ColorI::BLUE);
renderBoxOutline(mMesh->getTileBox(mTile), ColorI::GREEN);
if(Con::getBoolVariable("$Nav::Editor::renderVoxels", false)) dd.renderGroup(0);
if(Con::getBoolVariable("$Nav::Editor::renderInput", false))
/*if (Con::getBoolVariable("$Nav::Editor::renderVoxels", false)) dd.renderGroup(0);
if (Con::getBoolVariable("$Nav::Editor::renderInput", false))
{
dd.depthMask(false);
dd.renderGroup(1);
dd.depthMask(true);
}
}*/
}
if(mMode == mTestMode)
@ -630,7 +629,6 @@ void GuiNavEditorCtrl::renderScene(const RectI & updateRect)
duDebugDrawTorque d;
if(!mMesh.isNull())
mMesh->renderLinks(d);
d.render();
// Now draw all the 2d stuff!
GFX->setClipRect(updateRect);

View file

@ -1329,23 +1329,6 @@ bool NavMesh::testEdgeCover(const Point3F &pos, const VectorF &dir, CoverPointDa
void NavMesh::renderToDrawer()
{
mDbgDraw.clear();
// Recast debug draw
NetObject *no = getServerObject();
if(no)
{
NavMesh *n = static_cast<NavMesh*>(no);
if(n->nm)
{
mDbgDraw.beginGroup(0);
duDebugDrawNavMesh (&mDbgDraw, *n->nm, 0);
mDbgDraw.beginGroup(1);
duDebugDrawNavMeshPortals(&mDbgDraw, *n->nm);
mDbgDraw.beginGroup(2);
duDebugDrawNavMeshBVTree (&mDbgDraw, *n->nm);
}
}
}
void NavMesh::prepRenderImage(SceneRenderState *state)
@ -1374,37 +1357,17 @@ void NavMesh::render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInsta
{
NavMesh *n = static_cast<NavMesh*>(no);
if(n->isSelected())
if ((!gEditingMission && n->mAlwaysRender) || (gEditingMission && Con::getBoolVariable("$Nav::Editor::renderMesh", 1)))
{
GFXDrawUtil *drawer = GFX->getDrawUtil();
GFXStateBlockDesc desc;
desc.setZReadWrite(true, false);
desc.setBlend(true);
desc.setCullMode(GFXCullNone);
drawer->drawCube(desc, getWorldBox(), n->mBuilding
? ColorI(255, 0, 0, 80)
: ColorI(136, 228, 255, 45));
desc.setFillModeWireframe();
drawer->drawCube(desc, getWorldBox(), ColorI::BLACK);
if (n->nm)
{
duDebugDrawNavMesh(&mDbgDraw, *n->nm, 0);
if (Con::getBoolVariable("$Nav::Editor::renderPortals"))
duDebugDrawNavMeshPortals(&mDbgDraw, *n->nm);
if (Con::getBoolVariable("$Nav::Editor::renderBVTree"))
duDebugDrawNavMeshBVTree(&mDbgDraw, *n->nm);
}
}
if(n->mBuilding)
{
int alpha = 80;
if(!n->isSelected() || !Con::getBoolVariable("$Nav::EditorOpen"))
alpha = 20;
mDbgDraw.overrideColor(duRGBA(255, 0, 0, alpha));
}
else
{
mDbgDraw.cancelOverride();
}
if((!gEditingMission && n->mAlwaysRender) || (gEditingMission && Con::getBoolVariable("$Nav::Editor::renderMesh", 1))) mDbgDraw.renderGroup(0);
if(Con::getBoolVariable("$Nav::Editor::renderPortals")) mDbgDraw.renderGroup(1);
if(Con::getBoolVariable("$Nav::Editor::renderBVTree")) mDbgDraw.renderGroup(2);
}
}
@ -1445,10 +1408,11 @@ void NavMesh::renderTileData(duDebugDrawTorque &dd, U32 tile)
return;
if(nm)
{
dd.beginGroup(0);
if(mTileData[tile].chf) duDebugDrawCompactHeightfieldSolid(&dd, *mTileData[tile].chf);
duDebugDrawNavMesh(&dd, *nm, 0);
if(mTileData[tile].chf)
duDebugDrawCompactHeightfieldSolid(&dd, *mTileData[tile].chf);
dd.beginGroup(1);
duDebugDrawNavMeshPortals(&dd, *nm);
int col = duRGBA(255, 0, 255, 255);
RecastPolyList &in = mTileData[tile].geom;
dd.begin(DU_DRAW_LINES);

View file

@ -640,9 +640,7 @@ void NavPath::renderSimple(ObjectRenderInst *ri, SceneRenderState *state, BaseMa
if(np->mQuery && !dtStatusSucceed(np->mStatus))
{
duDebugDrawTorque dd;
dd.overrideColor(duRGBA(250, 20, 20, 255));
duDebugDrawNavMeshNodes(&dd, *np->mQuery);
dd.render();
}
}
}