Jump to content
  • Advertisement
Sign in to follow this  
Tomasz Dabrowski

OpenGL Setting matrices in CG very slow

This topic is 3772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a performance issue in my OpenGL application. I am rendering objects using VBO but FPS is very low. I found that the code responsible for this slowdown is cgGLSetMatrixParameterfc. I used is to pass transformation matrix from physics engine to CG shader, to use it in such way:
void main_vs_shader(
	float4 pos : POSITION,
[...]
	out float4 opos : POSITION,
[...]
	uniform float4x4 vs_mat,
	uniform float4x4 mat_transform
)

[...]

opos = mul(vs_mat, mul(mat_transform, pos));
(vs_mat is modelviewprojection matrix) But this is very slow. My FPS drops from 90 to 30 when I uncomment cgGLSetMatrixParameterfc line. I also found that when NOT using custom matrix, just glMultMatrixf the FPS are low as well, because I have to update ModelViewProjection matrix for each object:
cgGLSetStateMatrixParameter(CObjectManager::instance->mModelMatrix[mode], CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
Why is it so slow? Is there another way to update matrix in CG?

Share this post


Link to post
Share on other sites
Advertisement
Sadly I don't know but could you tell me how I should get started using CG? Like how you learned to load the shaders and stuff. Also I found a sample but it's for one of the older versions.


It loads a vertex shader and a pixel shader but I would think the new version would put them in one shader since it's using the unified shader features of directx10. So do you still create a separate vertex and pixel shader in version 2.0?

[Edited by - EmptyVoid on July 24, 2008 4:53:56 AM]

Share this post


Link to post
Share on other sites
I don't know if this is any better or worse but I update the modelview matrix with -

glLoadMatrixf(pprim->p_matrix);

and then in my shader I use -

oposition = mul( glstate.matrix.mvp, float4(position, 1.0) );

I would be really interested to hear if this makes any significant difference in performance, better or worse.

Share this post


Link to post
Share on other sites
acadestuff: I just love you! ;) The "glstate" was the keyword I was so badly looking for. FPS increased by 30% so your way is much better.

EmptyVoid: maybe you should look for some tutorials? I know a good one, but it is in Polish. But here is a translation: :)

http://translate.google.com/translate?u=http%3A%2F%2Fwww.dimmension3.spine.pl%2Fmodules.php%3Fname%3DTutorials%26wtd%3Dshow_tutorial%26nr%3D76&hl=pl&ie=UTF8&sl=auto&tl=en

Share this post


Link to post
Share on other sites
Quote:
Original post by zorbad
acadestuff: I just love you! ;) The "glstate" was the keyword I was so badly looking for. FPS increased by 30% so your way is much better.

EmptyVoid: maybe you should look for some tutorials? I know a good one, but it is in Polish. But here is a translation: :)

http://translate.google.com/translate?u=http%3A%2F%2Fwww.dimmension3.spine.pl%2Fmodules.php%3Fname%3DTutorials%26wtd%3Dshow_tutorial%26nr%3D76&hl=pl&ie=UTF8&sl=auto&tl=en


It's basically what I was looking for. Thanks!

Share this post


Link to post
Share on other sites
MultMatrix is GPU-expensive. If your bottleneck is in the GPU, you might try doing some matrix calculations on the host and then using LoadMatrix. If not, I don't really know what to tell you, other than try to cut back on excessive matrix multiplies. If you're clever, you might be able to find a way to lump like primitives together. You might also be able to squeeze some performance out with judicious use of Push/Pops...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!