Commit b946f8ab authored by Robert Menzel's avatar Robert Menzel
Browse files

Improved MatrixStack performance

parent ba4db533
...@@ -74,29 +74,42 @@ public: ...@@ -74,29 +74,42 @@ public:
// will replace the top matrix with the given matrix // will replace the top matrix with the given matrix
void loadMatrix( glm::mat4 matrixToLoad ) void loadMatrix( glm::mat4 matrixToLoad )
{ {
popMatrix(); if (!mStack.empty()) {
mStack.push( matrixToLoad ); mStack.top() = matrixToLoad;
} else {
mStack.push( matrixToLoad );
}
} }
// the top matrix will be multiplied with the given one and // the top matrix will be multiplied with the given one and
// will then replace the top matrix // will then replace the top matrix
void multMatrix( const glm::mat4 &rhs ) void multMatrix( const glm::mat4 &rhs )
{ {
mStack.push( popAndGetMatrix() * rhs ); if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() *= rhs;
}
// pushes the product of top and rhs
void pushAndMultMatrix( const glm::mat4 &rhs )
{
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.push( mStack.top() * rhs );
} }
// like glRotate rotates the top matrix around a given axis a given degree phi // like glRotate rotates the top matrix around a given axis a given degree phi
void rotate(const float phi, const float x, const float y, const float z) { rotate( phi, glm::vec3( x,y,z )); } void rotate(const float phi, const float x, const float y, const float z) { rotate( phi, glm::vec3( x,y,z )); }
void rotate(const float phi, const glm::vec3 &axis ) void rotate(const float phi, const glm::vec3 &axis )
{ {
mStack.push( glm::rotate( popAndGetMatrix(), phi, axis ) ); if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::rotate( mStack.top(), phi, axis );
} }
// like glTranslate // like glTranslate
void translate(float x, float y, float z) { translate( glm::vec3(x,y,z) ); } void translate(float x, float y, float z) { translate( glm::vec3(x,y,z) ); }
void translate( glm::vec3 vector ) void translate( glm::vec3 vector )
{ {
mStack.push( glm::translate( popAndGetMatrix(), vector) ); if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::translate( mStack.top(), vector );
} }
// like glScale // like glScale
...@@ -104,7 +117,8 @@ public: ...@@ -104,7 +117,8 @@ public:
void scale( float x, float y, float z ) { scale( glm::vec3(x,y,z)); } void scale( float x, float y, float z ) { scale( glm::vec3(x,y,z)); }
void scale( const glm::vec3 &factor ) void scale( const glm::vec3 &factor )
{ {
mStack.push( glm::scale( popAndGetMatrix(), factor ) ); if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::scale( mStack.top(), factor );
} }
private: private:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment