Migrating the Bastion (to XNA 4.0), part two
by shinali
I spoke a little too soon when I said I successfully replaced all use of ResolveTextures, as the game was drawing some strange artifacts that makes blocky patches of purple hue (the hue would also appear in screen transitions). I was originally using some other manager's sprite batch to draw the full screen quad at the end of the drawing cycle and I didn't set any sorting process. With my littl...
I spoke a little too soon when I said I successfully replaced all use of ResolveTextures, as the game was drawing some strange artifacts that makes blocky patches of purple hue (the hue would also appear in screen transitions). I was originally using some other manager's sprite batch to draw the full screen quad at the end of the drawing cycle and I didn't set any sorting process. With my little understanding of SpriteBatch I didn't realize there maybe other objects being draw with the fullscreen quad. The simple fix was to set the sorting mode to immediate, but a better fix would probably make a sprite batch especially for the fullscreen quad.
I've decided to go ahead and jump in on the XNA 4.0 conversion process, using the branch where I got rid of the ResolveTexture use as the base. There were more changes than I thought from 3.1 to 4.0.
The Effects API is changed somewhat significantly, but only to cut down on the number of function calls needed to apply the effects process. Still, removing so many function calls leaves me a little worried that something may go wrong. I've marked them just in case.
XNA 4.0 did away with saving states, at least in the SpriteBatch.Begin() function. Instead it is up to use to restore whatever states at the end of the SpriteBatch drawing process. Bastion often does not save states, but there are some places that it does. I think it's just a matter of writing a simple save/restore state functions and call them along with SpriteBatch.Begin() and SpriteBatch.End().
Blending seems to be separated between alpha and color. Most blending operations seemed to be just concerned with color so I've opted for that.
Most of the other fixes were little things, like changing to the new blending structs, creating colors that were culled from XNA 3.1, etc. I've been mostly making changes that I felt confident about to leave the portion that I require to be more careful on. One seems to be some way of vertex buffer objects, and I have no idea how XNA handles this from just looking at the code. It seems to be quite a bit different from the transition to 4.0; I'll need to look into how either version handles this.
The other is the depth stencil buffer issue, but my recent investigations made me confident that Bastion doesn't share a depth stencil buffer across multiple render targets. Regardless, if Bastion did need to share a depth stencil buffer, I think I can reference both targets within a shader and use one's stencil buffer anyways.
Here's a slight wrench that's been thrown in literally as I've been typing this post; I've contacted the most active contributor of the MonoXNA project and it seems like they're trying to finish work on 3.1 before they move onto 4.0. It makes me feel I've wasted some time doing this but I've gained some good knowledge on how XNA operates. I think I will continue this branch, just to keep my options open for either MonoGame (which seems focused on 4.0) and MonoXNA.
At least it gives me good reason to finally start on some OpenGL code.