Effect API changes in XNA Game Studio 4.0

Effect API changes in XNA Game Studio 4.0

  • Comments 37

Where in previous XNA versions you used to write:

    effect.Begin();
    effect.CurrentTechnique.Passes[0].Begin();

    DrawStuff();

    effect.CurrentTechnique.Passes[0].End();
    effect.End();

With Game Studio 4.0 this becomes just:

    effect.CurrentTechnique.Passes[0].Apply();

    DrawStuff();

What in previous versions would be:

    effect.Begin();
    effect.CurrentTechnique.Passes[0].Begin();

    DrawStuff();

    effect.Parameters["lives"].SetValue(9);
    effect.CommitChanges();

    DrawOtherStuff();

    effect.CurrentTechnique.Passes[0].End();
    effect.End();

Is now:

    effect.CurrentTechnique.Passes[0].Apply();

    DrawStuff();

    effect.Parameters["lives"].SetValue(9);
    effect.CurrentTechnique.Passes[0].Apply();

    DrawOtherStuff();

Editors note: if you profile the new Apply method with the 4.0 CTP, you may notice it is slower than the old CommitChanges. Don't worry: this is just a temporary state of affairs due to some missing optimizations that didn't make it in time for the CTP release.

We also took out a bunch of stuff:

  • Removed the low level shader APIs (VertexShader, PixelShader, SetVertexShaderConstant, SetPixelShaderConstant, GetVertexShaderConstant, GetPixelShaderConstant, ShaderConstantTable, ShaderProfile, ShaderRegisterSet, and ShaderSemantic). These duplicated the same functionality that is also available using Effect and EffectParameter, but in a form that was closely tied to DirectX 9, and which could not be efficiently implemented with DirectX 10 or 11. Effects provide an abstraction that sits naturally on top of multiple native layers, and the vast majority of our customers preferred the Effect API in any case.

  • Removed EffectPool. This was confusing, and turned out to be nowhere near as useful as it seemed on the surface like it ought to be.

  • Removed EffectParameterBlock. This looked like it could be a useful optimization technique, but in fact always made things slower anytime anyone tried to use it :-) 

  • Removed assorted other boring and rarely used doodads (EffectFunction, Effect.Creator, EffectParameter.SetArrayRange, and EffectTechnique.IsParameterUsed).

Finally, we upgraded to a more recent version of the Windows HLSL compiler, which means that:

  • You can use newer HLSL features such as loop control attributes.

  • Shader model 1.x is no longer supported. Game Studio 4.0 requires at least shader model 2.0.
  • There is no such concept as "stop using an effect". You just apply whatever effect you want to use, then draw stuff. If you later want to draw stuff using a different effect, applying that other effect will replace the first (assuming both effects set the same underlying device states, anyway).

  • What happened to the "Border" address mode? It says that it's deprecated now in the compiler... "The effect state 'BorderColor' is obsolete and can no longer be used." Trying to assign "border" to the AddressU or AddressV values gives the error "The effect state 'AddressU' was assigned an invalid value." Did something change? The HLSL docs still list border as an address mode.

  • > What happened to the "Border" address mode?

    Border addressing is not supported in Game Studio 4. Details here:

    blogs.msdn.com/.../state-objects-in-xna-game-studio-4-0.aspx

    And some background here:

    blogs.msdn.com/.../breaking-changes-in-xna-game-studio-4-0.aspx

  • > There is no such concept as "stop using an effect". You just apply whatever effect you want to use, then draw stuff. If you later want to draw stuff using a different effect, applying that other effect will replace the first

    What should I do if I want to draw some stuff with an effect, and later want to draw stuff using no effect at all? Even if there is no such concept as "stop using an effect", I am sure you understand what I mean. :)

  • > later want to draw stuff using no effect at all?

    That makes no sense. You can't draw anything without using an effect, any more than a painter could paint something without using any paint or a printer could print something without any ink.

  • >That makes no sense. You can't draw anything without using an effect, any more than a painter could paint something without using any paint or a printer could print something without any ink.

    could I translate that as "call spriteBatch.End() and then spriteBatch.Begin() again"?

    I am sure my terminology is not precise... but that does achieve the effect of 'drawing with no special effect'...

  • SpriteBatch uses an effect internally, as does anything that draws graphics via the GPU.

Page 3 of 3 (37 items) 123
Leave a Comment
  • Please add 1 and 4 and type the answer here:
  • Post