Skip to content

Commit

Permalink
UPBGE: Optimize update of matrix in RAS_MeshSlot rendering.
Browse files Browse the repository at this point in the history
Previously the test to apply/update or not the matrix was complex and made
only in RAS_MeshSlot even if the operand of the test were know at
RAS_DisplayArrayBucket level. To optimize this check we cached its value
in the display array node data in RAS_DisplayArrayBucket::UpdateActiveMeshSlots.

Test with 40*40 objects of 2 meshes:
Before: 2.20ms
After: 2.10ms (4.5%)
  • Loading branch information
panzergame committed Jul 8, 2017
1 parent 3dd96ff commit 9864f03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions source/gameengine/Rasterizer/Node/RAS_RenderNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct RAS_MaterialNodeData
struct RAS_DisplayArrayNodeData
{
RAS_IStorageInfo *m_storageInfo;
bool m_applyMatrix;
};

struct RAS_MeshSlotNodeData
Expand Down
1 change: 1 addition & 0 deletions source/gameengine/Rasterizer/RAS_DisplayArrayBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void RAS_DisplayArrayBucket::UpdateActiveMeshSlots(RAS_Rasterizer *rasty)

// Update node data.
m_nodeData.m_storageInfo = m_storageInfo;
m_nodeData.m_applyMatrix = (!m_deformer || !m_deformer->SkipVertexTransform());
}

void RAS_DisplayArrayBucket::DestructStorageInfo()
Expand Down
25 changes: 13 additions & 12 deletions source/gameengine/Rasterizer/RAS_MeshSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,22 @@ void RAS_MeshSlot::RunNode(const RAS_MeshSlotNodeTuple& tuple)

rasty->PushMatrix();

const bool istext = materialData->m_text;
if ((!m_pDeformer || !m_pDeformer->SkipVertexTransform()) && !istext) {
float mat[16];
rasty->GetTransform(m_meshUser->GetMatrix(), materialData->m_drawingMode, mat);
rasty->MultMatrix(mat);
}

if (istext) {
if (materialData->m_text) {
rasty->IndexPrimitivesText(this);
}
else if (m_pDerivedMesh) {
rasty->IndexPrimitivesDerivedMesh(this);
}
else {
rasty->IndexPrimitives(displayArrayData->m_storageInfo);
if (displayArrayData->m_applyMatrix) {
float mat[16];
rasty->GetTransform(m_meshUser->GetMatrix(), materialData->m_drawingMode, mat);
rasty->MultMatrix(mat);
}

if (m_pDerivedMesh) {
rasty->IndexPrimitivesDerivedMesh(this);
}
else {
rasty->IndexPrimitives(displayArrayData->m_storageInfo);
}
}

rasty->PopMatrix();
Expand Down

0 comments on commit 9864f03

Please sign in to comment.