• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #ActualDanicco

Posted 22 March 2013 - 05:56 PM

First off, these two options are not equal, at least in terms of the source code you pasted. First one also calculates perspective projection and lookat - both which can be calculated lazily and only when certain parameters change. If you do this every frame then its one thing thats wrong. In second example you don't even mention lookat or perspective matrix - where are these calculations?

The way you measure it is also wrong, as you said you're using frames/s and you should be using ms/frame.

Using proper matrices and sending them as uniforms (or UBO) is the right way. Plus, as you mentioned, use of glRotate and similar calls is deprecated, and thats perfect reason not to use that kind of code.

In the second example I use the basic glLoadIdentity()glTranslatef() and glRotate() as in the last code of block with my camera object to get where I'm looking at. In the 2nd example I don't think there's any perspective projection calculation in my draw function, other than the glutPerspective() call in my initialization.

My FPS for a teapot was at about 2500ish with the 2nd option and deprecated calls, and it dropped to 2000~2100ish with the new matrices calculations. I'm going to do what @wintertime's suggested and calculate the time per function so I get better measurements.

This site explains a bit of the advantages of using matrices (Q4), though I didn't really understand the last part as I still don't get matrices at all: "However, while this may seem extravagant, the savings come from processing each vertex. Using matrix multiplication, the savings made from processing just 4 vertices, will outweigh the additional set-up cost." (I think I understand the concept, but I don't quite see it in my code yet).

This is what I think it's going on my code:



void Game::Draw()
{
glTranslatef(); //go to camera target (center)
glRotatef(); //rotate according to the camera view in X
glRotatef(); //rotate according to the camera view in Y
glTranslatef(); //go to the camera's position (eye)

//loop to draw all objects
//I just draw the object, each of their vertexes' xyz is already defined
}


I think of this as 5 matrix calculations, and then I just draw the objects, compared to the 1st option I mentioned:



mat4 mProjection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
void Game::Draw()
{
mat4 mView = glm::lookAt(
glm::vec3(0, 0, 0), //Camera Position
glm::vec3(0, 0, 0), //Looking to Position
);
mat4 mModel = glm::mat4(1.0f); //model values
mat4 mMVP = mProjection * mView * mModel;

//loop to draw all objects
//each vertex is multiplied by mMVP
}


This looks like at least 3 matrix calculations, but it's calculated for every single vertex of the objects, since I send it to the shader calculate the final xyz of each vertex by multiplying it for the MVP I sent.

It looks there's much more overhead in the 2nd example, but I can't be sure as I don't know what's happening when I draw after calling the (deprecated) glMatrixFunctions(), and this is what I'm asking in this thread.

Since it's deprecated now, I think it means my assumptions about being heavier are wrong, or the performance loss is negligible, but I'd like to understand what's going on.

It's that programmer "I need to understand what's happening!" thing, I think...

### #1Danicco

Posted 22 March 2013 - 05:55 PM

First off, these two options are not equal, at least in terms of the source code you pasted. First one also calculates perspective projection and lookat - both which can be calculated lazily and only when certain parameters change. If you do this every frame then its one thing thats wrong. In second example you don't even mention lookat or perspective matrix - where are these calculations?

The way you measure it is also wrong, as you said you're using frames/s and you should be using ms/frame.

Using proper matrices and sending them as uniforms (or UBO) is the right way. Plus, as you mentioned, use of glRotate and similar calls is deprecated, and thats perfect reason not to use that kind of code.

In the second example I use the basic glLoadIdentity()glTranslatef() and glRotate() as in the last code of block with my camera object to get where I'm looking at. In the 2nd example I don't think there's any perspective projection calculation in my draw function, other than the glutPerspective() call in my initialization.

My FPS for a teapot was at about 2500ish with the 2nd option and deprecated calls, and it dropped to 2000~2100ish with the new matrices calculations. I'm going to do what @wintertime's suggested and calculate the time per function so I get better measurements.

This site explains a bit of the advantages of using matrices (Q4), though I didn't really understand the last part as I still don't get matrices at all: "However, while this may seem extravagant, the savings come from processing each vertex. Using matrix multiplication, the savings made
from processing just 4 vertices, will outweigh the additional set-up cost."
(I think I understand the concept, but I don't quite see it in my code yet).

This is what I think it's going on my code:

void Game::Draw()
{
glTranslatef(); //go to camera target (center)
glRotatef(); //rotate according to the camera view in X
glRotatef(); //rotate according to the camera view in Y
glTranslatef(); //go to the camera's position (eye)

//loop to draw all objects
//I just draw the object, each of their vertexes' xyz is already defined
}


I think of this as 5 matrix calculations, and then I just draw the objects, compared to the 1st option I mentioned:

mat4 mProjection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
void Game::Draw()
{
mat4 mView = glm::lookAt(
glm::vec3(0, 0, 0), //Camera Position
glm::vec3(0, 0, 0), //Looking to Position
);
mat4 mModel = glm::mat4(1.0f); //model values
mat4 mMVP = mProjection * mView * mModel;

//loop to draw all objects
//each vertex is multiplied by mMVP
}


This looks like at least 3 matrix calculations, but it's calculated for every single vertex of the objects, since I send it to the shader calculate the final xyz of each vertex by multiplying it for the MVP I sent.

It looks there's much more overhead in the 2nd example, but I can't be sure as I don't know what's happening when I draw after calling the (deprecated) glMatrixFunctions(), and this is what I'm asking in this thread.

Since it's deprecated now, I think it means my assumptions about being heavier are wrong, or the performance loss is negligible, but I'd like to understand what's going on.

It's that programmer "I need to understand what's happening!" thing, I think...

PARTNERS