Skip to content

Commit

Permalink
UPBGE: Optimize process on culled objects.
Browse files Browse the repository at this point in the history
Previously the process does in the render for culled objects was too slow due to some reasons:
- The matrix was updated for culled objects.
- All the mesh user infos was updated for culled objects.

To solve all of this issues the culled boolean is removed in RAS_MeshUser which assume that
ActivateMeshSlots always add the mesh slots in the display array bucket.
By doing this we can move the culled check in KX_GameObject::UpdateBuckets and avoid
update all mesh user too.

Also the value checked to update in UpdateBuckets are reordered:
!m_bCulled && m_bVisible && m_meshUser

The UPBGE was slower than the BF BGE for culled objects. For example in a scene of 10000 objects
culled:
UPBGE: 2.32ms
BF BGE: 1.60ms

With this patch the istuation is reverted:
UPBGE: 0.51ms
BF BGE: 1.60ms

32% faster.
  • Loading branch information
panzergame committed Jun 20, 2016
1 parent 7e32845 commit 96517f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
7 changes: 4 additions & 3 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,13 @@ void KX_GameObject::AddMeshUser()

void KX_GameObject::UpdateBuckets()
{
if (GetSGNode() && m_meshUser) {
if (GetSGNode()->IsDirty())
// Update datas and add mesh slot to be rendered only if the object is not culled.
if (!m_bCulled && m_bVisible && m_meshUser) {
if (m_pSGNode->IsDirty()) {
GetOpenGLMatrix();
}

m_meshUser->SetColor(m_objectColor);
m_meshUser->SetCulled(m_bCulled || !m_bVisible);
m_meshUser->SetFrontFace(!m_bIsNegativeScaling);
m_meshUser->ActivateMeshSlots();
}
Expand Down
20 changes: 3 additions & 17 deletions source/gameengine/Rasterizer/RAS_MeshUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@

RAS_MeshUser::RAS_MeshUser(void *clientobj)
:m_frontFace(true),
m_culled(true),
m_color(MT_Vector4(0.0f, 0.0f, 0.0f, 0.0f)),
m_matrix(NULL),
m_clientObject(clientobj)
{

}

RAS_MeshUser::~RAS_MeshUser()
Expand All @@ -54,11 +52,6 @@ bool RAS_MeshUser::GetFrontFace() const
return m_frontFace;
}

bool RAS_MeshUser::GetCulled() const
{
return m_culled;
}

const MT_Vector4& RAS_MeshUser::GetColor() const
{
return m_color;
Expand All @@ -84,11 +77,6 @@ void RAS_MeshUser::SetFrontFace(bool frontFace)
m_frontFace = frontFace;
}

void RAS_MeshUser::SetCulled(bool culled)
{
m_culled = culled;
}

void RAS_MeshUser::SetColor(const MT_Vector4& color)
{
m_color = color;
Expand All @@ -101,10 +89,8 @@ void RAS_MeshUser::SetMatrix(float *matrix)

void RAS_MeshUser::ActivateMeshSlots()
{
if (!m_culled) {
for (RAS_MeshSlotList::iterator it = m_meshSlots.begin(), end = m_meshSlots.end(); it != end; ++it) {
RAS_MeshSlot *ms = *it;
ms->m_displayArrayBucket->ActivateMesh(ms);
}
for (RAS_MeshSlotList::iterator it = m_meshSlots.begin(), end = m_meshSlots.end(); it != end; ++it) {
RAS_MeshSlot *ms = *it;
ms->m_displayArrayBucket->ActivateMesh(ms);
}
}
4 changes: 0 additions & 4 deletions source/gameengine/Rasterizer/RAS_MeshUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class RAS_MeshUser
private:
/// OpenGL face wise.
bool m_frontFace;
/// Object culling flag.
bool m_culled;
/// Object color.
MT_Vector4 m_color;
/// Object transformation matrix.
Expand All @@ -54,14 +52,12 @@ class RAS_MeshUser

void AddMeshSlot(RAS_MeshSlot *meshSlot);
bool GetFrontFace() const;
bool GetCulled() const;
const MT_Vector4& GetColor() const;
float *GetMatrix() const;
void *GetClientObject() const;
RAS_MeshSlotList& GetMeshSlots();

void SetFrontFace(bool frontFace);
void SetCulled(bool culled);
void SetColor(const MT_Vector4& color);
void SetMatrix(float *matrix);

Expand Down

1 comment on commit 96517f7

@youle31
Copy link
Collaborator

@youle31 youle31 commented on 96517f7 Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool 👍

I confirm a slight performance increase in some of my test files :)

Please sign in to comment.