Skip to content

Commit 5a36bdb

Browse files
authored
fix(smudge): Fix minor errors in W3DSmudge (#2483)
1 parent d62c8f0 commit 5a36bdb

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DSmudge.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ void W3DSmudgeManager::ReleaseResources()
7070
REF_PTR_RELEASE(m_indexBuffer);
7171
}
7272

73-
//Make sure (SMUDGE_DRAW_SIZE * 12) < 65535 because that's the max index buffer size.
73+
7474
#define SMUDGE_DRAW_SIZE 500 //draw at most 50 smudges per call. Tweak value to improve CPU/GPU parallelism.
7575

76+
static_assert(SMUDGE_DRAW_SIZE * 5 < 0x10000, "Vertex index exceeds 16-bit limit");
77+
78+
7679
void W3DSmudgeManager::ReAcquireResources()
7780
{
7881
ReleaseResources();
@@ -237,16 +240,20 @@ Bool W3DSmudgeManager::testHardwareSupport()
237240

238241
//bottom right
239242
v[0].p = Vector4( BLOCK_SIZE-0.5f, BLOCK_SIZE-0.5f, 0.0f, 1.0f );
240-
v[0].u = BLOCK_SIZE/(Real)TheDisplay->getWidth(); v[0].v = BLOCK_SIZE/(Real)TheDisplay->getHeight();
243+
v[0].u = BLOCK_SIZE/(Real)TheDisplay->getWidth();
244+
v[0].v = BLOCK_SIZE/(Real)TheDisplay->getHeight();
241245
//top right
242246
v[1].p = Vector4( BLOCK_SIZE-0.5f, 0-0.5f, 0.0f, 1.0f );
243-
v[1].u = BLOCK_SIZE/(Real)TheDisplay->getWidth(); v[1].v = 0;
247+
v[1].u = BLOCK_SIZE/(Real)TheDisplay->getWidth();
248+
v[1].v = 0;
244249
//bottom left
245250
v[2].p = Vector4( 0-0.5f, BLOCK_SIZE-0.5f, 0.0f, 1.0f );
246-
v[2].u = 0; v[2].v = BLOCK_SIZE/(Real)TheDisplay->getHeight();
251+
v[2].u = 0;
252+
v[2].v = BLOCK_SIZE/(Real)TheDisplay->getHeight();
247253
//top left
248254
v[3].p = Vector4( 0-0.5f, 0-0.5f, 0.0f, 1.0f );
249-
v[3].u = 0; v[3].v = 0;
255+
v[3].u = 0;
256+
v[3].v = 0;
250257

251258
v[0].color = UNIQUE_COLOR;
252259
v[1].color = UNIQUE_COLOR;
@@ -390,27 +397,20 @@ void W3DSmudgeManager::render(RenderInfoClass &rinfo)
390397

391398
Vector2 &thisUV=verts[i].uv;
392399

393-
//Clamp coordinates so we're not referencing texels outside the view.
394-
if (thisUV.X > texClampX)
395-
smudge->m_offset.X = 0;
396-
else
397-
if (thisUV.X < 0)
400+
// Zero coordinates that fall outside valid texel bounds
401+
if (thisUV.X < 0 || thisUV.X > texClampX)
398402
smudge->m_offset.X = 0;
399403

400-
if (thisUV.Y > texClampY)
401-
smudge->m_offset.Y = 0;
402-
else
403-
if (thisUV.Y < 0)
404+
if (thisUV.Y < 0 || thisUV.Y > texClampY)
404405
smudge->m_offset.Y = 0;
405-
406406
}
407407

408408
//Finish center vertex
409409
//Ge uv coordinates by interpolating corner uv coordinates and applying desired offset.
410410
uvSpanX=verts[3].uv.X - verts[0].uv.X;
411411
uvSpanY=verts[1].uv.Y - verts[0].uv.Y;
412412
verts[4].uv.X=verts[0].uv.X+uvSpanX*(0.5f+smudge->m_offset.X);
413-
verts[4].uv.Y=verts[0].uv.Y+uvSpanY*(0.5f+smudge->m_offset.X);
413+
verts[4].uv.Y=verts[0].uv.Y+uvSpanY*(0.5f+smudge->m_offset.Y);
414414

415415
count++; //increment visible smudge count.
416416
smudge=smudge->Succ();
@@ -487,7 +487,8 @@ void W3DSmudgeManager::render(RenderInfoClass &rinfo)
487487

488488
//Check if we exceeded maximum number of smudges allowed per draw call.
489489
if (smudgesInRenderBatch >= count)
490-
{ remainingSmudgeStart = smudge;
490+
{
491+
remainingSmudgeStart = smudge;
491492
goto flushSmudges;
492493
}
493494

@@ -520,11 +521,12 @@ void W3DSmudgeManager::render(RenderInfoClass &rinfo)
520521
if (set) //start next batch at beginning of set.
521522
remainingSmudgeStart = set->getUsedSmudgeList().Head();
522523
}
523-
flushSmudges:
524-
DX8Wrapper::Set_Vertex_Buffer(vb_access);
525524
}
526525

527-
DX8Wrapper::Draw_Triangles( 0,smudgesInRenderBatch*4, 0, smudgesInRenderBatch*5);
526+
flushSmudges:
527+
DX8Wrapper::Set_Vertex_Buffer(vb_access);
528+
529+
DX8Wrapper::Draw_Triangles(0,smudgesInRenderBatch*4, 0, smudgesInRenderBatch*5);
528530

529531
//Debug Code which draws outline around smudge
530532
/* DX8Wrapper::_Get_D3D_Device8()->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

0 commit comments

Comments
 (0)