Here are notes on code that I needed modify to allow me to move from XNA 3.1 to XNA 4:
The name ‘SpriteBlendMode’ does not exist in the current context
This is due to a change to SpriteBatch.Begin. The SpriteBlendMode enum is now gone and we should now specify the state object directly. Also SaveStateMode is now also not required.
XNA 3.1: spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
XNA 4: spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,null,null,null);
‘Microsoft.Xna.Framework.Graphics.RenderTarget2D’ does not contain a constructor that takes 5 arguments
XNA 3.1 :renderTarget = new RenderTarget2D(device, 512, 512, 1, SurfaceFormat.Color);
RenderTarget2D now inherits direct from Texture2D.
‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ does not contain a definition for ‘RenderState’ and no extension method ‘RenderState’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ could be found
XNA 3.1 :graphics.GraphicsDevice.RenderState.AlphaBlendEnable =false;
Error 10 ’Microsoft.Xna.Framework.Graphics.BasicEffect’ does not contain a definition for ‘Begin’ and no extension method ‘Begin’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.BasicEffect’ could be found
Error 15 ’Microsoft.Xna.Framework.Graphics.EffectPass’ does not contain a definition for ‘End’ and no extension method ‘End’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.EffectPass’ could be found
XNA 3.1: effectPass.Begin();
XNA 4: effectPass.Apply();
XNA 3.1: effectPass.End(); No longer required to begin and end the effect.
BasicEffect has been extended for XNA 4.0 to support 20 vertex shaders (was 12) and 10 pixel shaders (was 4), mainly due to the inclusion of Windows Phone 7 to be supported by the framework.
Error 35 ’Microsoft.Xna.Framework.Graphics.BasicEffect’ does not contain a constructor that takes 2 arguments Now only 1 argument
XNA 3.1: new BasicEffect(GraphicsDevice, null);
XNA 4: new BasicEffect(GraphicsDevice);
The EffectPool is no longer required, even if it was only ever null in my cases
Error 39 ’Microsoft.Xna.Framework.Graphics.EffectPass’ does not contain a definition for ‘Begin’ and no extension method ‘Begin’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.EffectPass’ could be found
XNA 3.1: effect.Begin();
XNA 3.1: effect.End(); No longer required to begin and end the effect.
Error 35 ’Microsoft.Xna.Framework.GameTime’ does not contain a definition for ‘ElapsedRealTime’ and no extension method ‘ElapsedRealTime’ accepting a first argument of type ‘Microsoft.Xna.Framework.GameTime’ could be found
Error 36 ’Microsoft.Xna.Framework.GameTime’ does not contain a definition for ‘TotalRealTime’ and no extension method ‘TotalRealTime’ accepting a first argument of type ‘Microsoft.Xna.Framework.GameTime’ could be found
ElapsedRealTime and TotalRealTime nolonger supported by the GameTime class. In my case it was OK to use ElapsedGameTime and TotalGameTime. Alternatively .Net timer API could be used if really need ‘real’ time.
Error 24 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘SizeInBytes’
VertexBuffer is now a stronly typed container using an associated VertexDeclation. This was not the case prior to XNA 4.0:
XNA 3.1: vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionTexture.SizeInBytes * hexVertices.Length, BufferUsage.WriteOnly);
XNA 4: vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionTexture), 36, BufferUsage.WriteOnly);
Error 88 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘VertexElements’
XNA 3.1: hexVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionTexture.VertexElements);
VertexDeclaration constructor no longer needs a GraphicsDevice.
Error 56 ’Microsoft.Xna.Framework.Graphics.GraphicsDevice’ does not contain a definition for ‘VertexDeclaration’ and no extension method ‘VertexDeclaration’ accepting a first argument of type ‘Microsoft.Xna.Framework.Graphics.GraphicsDevice’ could be found
XNA 3.1: graphics.GraphicsDevice.VertexDeclaration = hexTiles.hexVertexDeclaration;
No longer required at all as associated declaration will automatically be found by the associated device. We can now delete the above graphics.GraphicsDevice.VertexDeclarion.
Error 11 ’Microsoft.Xna.Framework.Graphics.VertexPositionTexture’ does not contain a definition for ‘VertexElements’
XNA 3.1: hexVertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionTexture.VertexElements);
The initial 165 compile ‘errors’ were soon reduced to zero by resolving the above.
Now all compiles well but still a few visual problems mainly with tile transparency. Previously this was controlled by GraphicsDevice.RenderState.AlphaBlendableEnable which is no more.