Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class W3DDisplay : public Display
void addFpsSample(Real elapsedSeconds); ///< add a new sample to the history buffer.
Real calculateAverageFPS(Real timeWindowSeconds); ///< calculate average FPS over a time window.
Real calculateLow1PercentFPS(Real timeWindowSeconds); ///< calculate 1% low FPS over a time window.
void setup2DRenderState(TextureClass *tex, DrawImageMode mode, Bool grayscale);
void setup2DRenderState(TextureClass *tex, DrawImageMode mode, Bool grayscale, Int vertexCount, Int indexCount);
virtual void onBeginBatch() override;
virtual void onEndBatch() override;
virtual void onFlush() override;
Expand Down
130 changes: 118 additions & 12 deletions Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,20 @@ void W3DDisplay::onFlush()
}
}

void W3DDisplay::setup2DRenderState(TextureClass *tex, DrawImageMode mode, Bool grayscale)
static const Int QUAD_VERTEX_COUNT = 4;
static const Int QUAD_INDEX_COUNT = 6;
static const Int ROTATED_QUAD_VERTEX_COUNT = 6;
static const Int TRIANGLE_VERTEX_COUNT = 3;
static const Int TRIANGLE_INDEX_COUNT = 3;

void W3DDisplay::setup2DRenderState(TextureClass *tex, DrawImageMode mode, Bool grayscale, Int vertexCount, Int indexCount)
{
if (m_isBatching)
{
if (!m_batchNeedsInit && m_batchTexture == tex && m_batchMode == mode && m_batchGrayscale == grayscale)
// TheSuperHackers @fix arcticdolphin 12/10/2026 Flush when the upcoming draw would exceed the renderer capacity.
const Bool hasRoom = !m_2DRender || m_2DRender->Can_Add(vertexCount, indexCount);

if (!m_batchNeedsInit && hasRoom && m_batchTexture == tex && m_batchMode == mode && m_batchGrayscale == grayscale)
Comment thread
Skyaero42 marked this conversation as resolved.
{
return;
}
Expand Down Expand Up @@ -2420,7 +2429,7 @@ void W3DDisplay::drawLine( Int startX, Int startY,
Real lineWidth,
UnsignedInt lineColor )
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

m_2DRender->Add_Line( Vector2( startX, startY ), Vector2( endX, endY ),
lineWidth, lineColor );
Expand All @@ -2439,7 +2448,7 @@ void W3DDisplay::drawLine( Int startX, Int startY,
Real lineWidth,
UnsignedInt lineColor1,UnsignedInt lineColor2 )
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

m_2DRender->Add_Line( Vector2( startX, startY ), Vector2( endX, endY ),
lineWidth, lineColor1, lineColor2 );
Expand Down Expand Up @@ -2490,7 +2499,7 @@ void W3DDisplay::drawOpenRect( Int startX, Int startY, Int width, Int height,
}
else
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, 4*QUAD_VERTEX_COUNT, 4*QUAD_INDEX_COUNT);

m_2DRender->Add_Outline( RectClass( startX, startY,
startX + width, startY + height ),
Expand All @@ -2509,7 +2518,7 @@ void W3DDisplay::drawOpenRect( Int startX, Int startY, Int width, Int height,
void W3DDisplay::drawFillRect( Int startX, Int startY, Int width, Int height,
UnsignedInt color )
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

m_2DRender->Add_Rect( RectClass( startX, startY,
startX + width, startY + height ),
Expand All @@ -2527,8 +2536,6 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
if(percent < 1 || percent > 100)
return;

setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);

// The rectangles are numberd as follows
//(x,y) |---------|
// | 4 | 1 |
Expand All @@ -2539,11 +2546,24 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
// we're done, lets just draw one rectangle for it all.
if(percent == 100)
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

m_2DRender->Add_Rect(RectClass( startX, startY,
startX + width, startY + height), 0,0, color);
}
else if( percent> 75)
{
Int triangleCount;
if (percent > 87)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, 2*QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, 2*QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

//rectangle #1 & 2
m_2DRender->Add_Rect(RectClass( startX + width/2, startY,
startX + width, startY + height), 0,0, color);
Expand Down Expand Up @@ -2580,6 +2600,17 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
}
else if( percent > 50)
{
Int triangleCount;
if (percent > 62)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

//rectangle #1 & 2
m_2DRender->Add_Rect(RectClass( startX + width/2, startY,
startX + width, startY + height), 0,0, color);
Expand Down Expand Up @@ -2612,6 +2643,17 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
}
else if(percent > 25)
{
Int triangleCount;
if (percent > 37)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

// rectangle #1
m_2DRender->Add_Rect(RectClass( startX + width/2, startY,
startX + width, startY + height/2), 0,0, color);
Expand Down Expand Up @@ -2644,6 +2686,17 @@ void W3DDisplay::drawRectClock(Int startX, Int startY, Int width, Int height, In
}
else
{
Int triangleCount;
if (percent > 12)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, triangleCount*TRIANGLE_VERTEX_COUNT, triangleCount*TRIANGLE_INDEX_COUNT);

// draw the part of rectangle 1

if(percent > 12)
Expand Down Expand Up @@ -2691,8 +2744,6 @@ void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int h
if( percent < 0 || percent > 99 )
return;

setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE);

// The rectangles are numbered as follows
//(x,y) |---------|
// | 4 | 1 |
Expand All @@ -2710,12 +2761,25 @@ void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int h

if( percent == 0 )
{
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

// We just started, so draw the entire remaining rectangle.
// #1, #2, #3, and #4
m_2DRender->Add_Rect( RectClass( startX, startY, endX, endY ), 0, 0, color );
}
else if( percent < 25 )
{
Int triangleCount;
if (percent < 13)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, 2*QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, 2*QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

//1-25%
//-----

Expand Down Expand Up @@ -2753,6 +2817,17 @@ void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int h
}
else if( percent < 50 )
{
Int triangleCount;
if (percent < 38)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

//25-49%
//------

Expand Down Expand Up @@ -2787,6 +2862,17 @@ void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int h
}
else if( percent < 75 )
{
Int triangleCount;
if (percent < 63)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT + triangleCount*TRIANGLE_VERTEX_COUNT, QUAD_INDEX_COUNT + triangleCount*TRIANGLE_INDEX_COUNT);

//50-74%
//------

Expand Down Expand Up @@ -2821,6 +2907,17 @@ void W3DDisplay::drawRemainingRectClock(Int startX, Int startY, Int width, Int h
}
else
{
Int triangleCount;
if (percent < 87)
{
triangleCount = 2;
}
else
{
triangleCount = 1;
}
setup2DRenderState(nullptr, DRAW_IMAGE_ALPHA, FALSE, triangleCount*TRIANGLE_VERTEX_COUNT, triangleCount*TRIANGLE_INDEX_COUNT);

//75-99%
//------

Expand Down Expand Up @@ -2896,7 +2993,16 @@ void W3DDisplay::drawImage( const Image *image, Int startX, Int startY,
tex = WW3DAssetManager::Get_Instance()->Get_Texture(image->getFilename().str(), MIP_LEVELS_1);

Bool grayscale = (mode == DRAW_IMAGE_GRAYSCALE);
setup2DRenderState(tex, mode, grayscale);
Int vertexCount;
if (BitIsSet(image->getStatus(), IMAGE_STATUS_ROTATED_90_CLOCKWISE))
{
vertexCount = ROTATED_QUAD_VERTEX_COUNT;
}
else
{
vertexCount = QUAD_VERTEX_COUNT;
}
setup2DRenderState(tex, mode, grayscale, vertexCount, QUAD_INDEX_COUNT);

RectClass screen_rect(startX,startY,endX,endY);
RectClass uv_rect(uv->lo.x,uv->lo.y,uv->hi.x,uv->hi.y);
Expand Down Expand Up @@ -3120,7 +3226,7 @@ void W3DDisplay::drawVideoBuffer( VideoBuffer *buffer, Int startX, Int startY, I
{
W3DVideoBuffer *vbuffer = (W3DVideoBuffer*) buffer;

setup2DRenderState(vbuffer->texture(), DRAW_IMAGE_ALPHA, FALSE);
setup2DRenderState(vbuffer->texture(), DRAW_IMAGE_ALPHA, FALSE, QUAD_VERTEX_COUNT, QUAD_INDEX_COUNT);

m_2DRender->Add_Quad( RectClass( startX, startY, endX, endY ),
vbuffer->Rect( 0, 0, 1, 1) );
Expand Down
2 changes: 2 additions & 0 deletions Core/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class DynamicVBAccessClass
void Allocate_Sorting_Dynamic_Buffer();
void Allocate_DX8_Dynamic_Buffer();
public:
enum { MAX_VERTEX_COUNT = 0xffff }; ///< vertex_count is an unsigned short

// Type parameter can be either BUFFER_TYPE_DYNAMIC_DX8 or BUFFER_TYPE_DYNAMIC_SORTING.

// Note: Even though the constructor takes fvf as a parameter, currently the
Expand Down
10 changes: 10 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,22 @@ void Render2DClass::Add_Outline( const RectClass & rect, float width, const Rect
Add_Line (Vector2 (rect.Right, rect.Bottom), Vector2 (rect.Left + 1, rect.Bottom), width, color);
}

bool Render2DClass::Can_Add( int vertex_count, int index_count ) const
{
return Vertices.Count() + vertex_count <= DynamicVBAccessClass::MAX_VERTEX_COUNT
&& Indices.Count() + index_count <= DynamicIBAccessClass::MAX_INDEX_COUNT;
}

void Render2DClass::Render()
{
if ( !Indices.Count() || IsHidden) {
return;
}

if ( !Can_Add( 0, 0 ) ) {
return;
}

// save the view and projection matrices since we're nuking them
Matrix4x4 view,proj;
Matrix4x4 identity(true);
Expand Down
2 changes: 2 additions & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Render2DClass
virtual void Reset();
void Render();

bool Can_Add( int vertex_count, int index_count ) const;

void Set_Coordinate_Range( const RectClass & range );

void Set_Texture(TextureClass* tex);
Expand Down
10 changes: 10 additions & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,22 @@ void Render2DClass::Add_Outline( const RectClass & rect, float width, const Rect
Add_Line (Vector2 (rect.Right, rect.Bottom), Vector2 (rect.Left + 1, rect.Bottom), width, color);
}

bool Render2DClass::Can_Add( int vertex_count, int index_count ) const
{
return Vertices.Count() + vertex_count <= DynamicVBAccessClass::MAX_VERTEX_COUNT
&& Indices.Count() + index_count <= DynamicIBAccessClass::MAX_INDEX_COUNT;
}

void Render2DClass::Render()
{
if ( !Indices.Count() || IsHidden) {
return;
}

if ( !Can_Add( 0, 0 ) ) {
return;
}

// save the view and projection matrices since we're nuking them
Matrix4x4 view,proj;
Matrix4x4 identity(true);
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class Render2DClass
virtual void Reset();
void Render();

bool Can_Add( int vertex_count, int index_count ) const;

void Set_Coordinate_Range( const RectClass & range );

void Set_Texture(TextureClass* tex);
Expand Down
Loading