Johnny Ashcan

I am in the process of transitioning from my existing OpenGL kit, and I am a little miffed about the way transformation matrices are specified in XNA. In every example I have seen, the world, view, and projection matrices must be assigned to each effect of each mesh of each model, each frame.

For a scene with say, 100 models, this could easily result in tens or hundreds of thousands of completely redundant floating point assignments, as these matrices (esp the view and projection matrices) tend not to change during render.

Apart from taxing the processor unnecessarily, this adds significant bulk to the code. It also makes impossible the notion of a camera class that is isolated from and independant of the models, since the models must be 'aware' of the matrices the camera is assigned in order to render.

By comparison, OpenGL allows you to specify these three matrices one time at the beginning of the render function at a thread-global scope, where it is subsequentially applied to each rendered primitive implicitly. This allows simple, clean encapsulation of the otherwise messy matrix setup:

void Draw()



// ...

Is there no way to specify a global / default set of matrices for models to use, to avoid these untold thousands of unneccessary assignments per frame

Re: XNA Game Studio Express Setting Global Matrices for Models


Im not sure if this helps but there is an EffectPool I am not sure exactly what it does although I think its possible to use it to set global values that all effects referencing it will use (I think but not sure).

Re: XNA Game Studio Express Setting Global Matrices for Models


As Fluxtah mentions you can use EffectPool to share EffectParameters between instances of an Effect. Also, depending on how you are organising your effects, you don't need to set parameters every frame if the previous value is still valid - for example if you have an effect instance for every mesh then each instance has its own params (apart from any shared ones as mentioned) so you don't need to re-set them with the same value. If instead you were sharing instances of effects between many meshes then you would set those params that are the same for all meshes once and then change the mesh specific params (such as the world matrix) for each mesh.

By the way, this is not so much an OpenGL vs XNA issue as a fixed-function pipeline vs programmable pipeline issue.