Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #214 from 3vi1/monogame-sdl2
Browse files Browse the repository at this point in the history
Comment Cleanup - Graphics/*.cs
  • Loading branch information
flibitijibibo committed May 2, 2014
2 parents 7f8cddc + 0668921 commit 8dbe420
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 103 deletions.
96 changes: 57 additions & 39 deletions MonoGame.Framework/Graphics/GraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public bool IsContentLost
{
get
{
// We will just return IsDisposed, as that
// is the only case I can see for now.
/* We will just return IsDisposed, as that
* is the only case I can see for now.
*/
return IsDisposed;
}
}
Expand Down Expand Up @@ -161,8 +162,9 @@ public Viewport Viewport
OpenGLDevice.Instance.DepthRangeMin.Set(value.MinDepth);
OpenGLDevice.Instance.DepthRangeMax.Set(value.MaxDepth);

// In OpenGL we have to re-apply the special "posFixup"
// vertex shader uniform if the viewport changes.
/* In OpenGL we have to re-apply the special "posFixup"
* vertex shader uniform if the viewport changes.
*/
vertexShaderDirty = true;
}
}
Expand Down Expand Up @@ -422,7 +424,9 @@ protected virtual void Dispose(bool disposing)
// Invoke the Disposing Event
OnDisposing();

// Dispose of all remaining graphics resources before disposing of the GraphicsDevice
/* Dispose of all remaining graphics resources before
* disposing of the GraphicsDevice.
*/
GraphicsResource.DisposeAll();

// Free all the cached shader programs.
Expand All @@ -438,8 +442,9 @@ protected virtual void Dispose(bool disposing)
#region Internal Resource Disposal Method

/// <summary>
/// Adds a dispose action to the list of pending dispose actions. These are executed at the end of each call to Present().
/// This allows GL resources to be disposed from other threads, such as the finalizer.
/// Adds a dispose action to the list of pending dispose actions. These are executed
/// at the end of each call to Present(). This allows GL resources to be disposed
/// from other threads, such as the finalizer.
/// </summary>
/// <param name="disposeAction">The action to execute for the dispose.</param>
internal static void AddDisposeAction(Action disposeAction)
Expand Down Expand Up @@ -723,12 +728,22 @@ public void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)
/// Draw geometry by indexing into the vertex buffer.
/// </summary>
/// <param name="primitiveType">The type of primitives in the index buffer.</param>
/// <param name="baseVertex">Used to offset the vertex range indexed from the vertex buffer.</param>
/// <param name="minVertexIndex">A hint of the lowest vertex indexed relative to baseVertex.</param>
/// <param name="baseVertex">
/// Used to offset the vertex range indexed from the vertex buffer.
/// </param>
/// <param name="minVertexIndex">
/// A hint of the lowest vertex indexed relative to baseVertex.
/// </param>
/// <param name="numVertices">An hint of the maximum vertex indexed.</param>
/// <param name="startIndex">The index within the index buffer to start drawing from.</param>
/// <param name="primitiveCount">The number of primitives to render from the index buffer.</param>
/// <remarks>Note that minVertexIndex and numVertices are unused in MonoGame and will be ignored.</remarks>
/// <param name="startIndex">
/// The index within the index buffer to start drawing from.
/// </param>
/// <param name="primitiveCount">
/// The number of primitives to render from the index buffer.
/// </param>
/// <remarks>
/// Note that minVertexIndex and numVertices are unused in MonoGame and will be ignored.
/// </remarks>
public void DrawIndexedPrimitives(
PrimitiveType primitiveType,
int baseVertex,
Expand All @@ -743,7 +758,7 @@ int primitiveCount
// Unsigned short or unsigned int?
bool shortIndices = Indices.IndexElementSize == IndexElementSize.SixteenBits;

// Set up the vertex buffers
// Set up the vertex buffers.
foreach (VertexBufferBinding vertBuffer in vertexBufferBindings)
{
if (vertBuffer.VertexBuffer != null)
Expand Down Expand Up @@ -888,7 +903,7 @@ public void DrawPrimitives(PrimitiveType primitiveType, int vertexStart, int pri
// Flush the GL state before moving on!
ApplyState();

// Set up the vertex buffers
// Set up the vertex buffers.
foreach (VertexBufferBinding vertBuffer in vertexBufferBindings)
{
if (vertBuffer.VertexBuffer != null)
Expand Down Expand Up @@ -1227,31 +1242,34 @@ private void ActivateShaderProgram()
return;
}

// Apply vertex shader fix:
// The following two lines are appended to the end of vertex shaders
// to account for rendering differences between OpenGL and DirectX:
//
// gl_Position.y = gl_Position.y * posFixup.y;
// gl_Position.xy += posFixup.zw * gl_Position.ww;
//
// (the following paraphrased from wine, wined3d/state.c and wined3d/glsl_shader.c)
//
// - We need to flip along the y-axis in case of offscreen rendering.
// - D3D coordinates refer to pixel centers while GL coordinates refer
// to pixel corners.
// - D3D has a top-left filling convention. We need to maintain this
// even after the y-flip mentioned above.
// In order to handle the last two points, we translate by
// (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
// translating slightly less than half a pixel. We want the difference to
// be large enough that it doesn't get lost due to rounding inside the
// driver, but small enough to prevent it from interfering with any
// anti-aliasing.
//
// OpenGL coordinates specify the center of the pixel while d3d coords specify
// the corner. The offsets are stored in z and w in posFixup. posFixup.y contains
// 1.0 or -1.0 to turn the rendering upside down for offscreen rendering. PosFixup.x
// contains 1.0 to allow a mad.
/* Apply vertex shader fix:
* The following two lines are appended to the end of vertex shaders
* to account for rendering differences between OpenGL and DirectX:
*
* gl_Position.y = gl_Position.y * posFixup.y;
* gl_Position.xy += posFixup.zw * gl_Position.ww;
*
* (the following paraphrased from wine, wined3d/state.c and
* wined3d/glsl_shader.c)
*
* - We need to flip along the y-axis in case of offscreen rendering.
* - D3D coordinates refer to pixel centers while GL coordinates refer
* to pixel corners.
* - D3D has a top-left filling convention. We need to maintain this
* even after the y-flip mentioned above.
*
* In order to handle the last two points, we translate by
* (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
* translating slightly less than half a pixel. We want the difference to
* be large enough that it doesn't get lost due to rounding inside the
* driver, but small enough to prevent it from interfering with any
* anti-aliasing.
*
* OpenGL coordinates specify the center of the pixel while d3d coords
* specify the corner. The offsets are stored in z and w in posFixup.
* posFixup.y contains 1.0 or -1.0 to turn the rendering upside down for
* offscreen rendering.
*/

posFixup[0] = 1.0f;
posFixup[1] = 1.0f;
Expand Down
15 changes: 10 additions & 5 deletions MonoGame.Framework/Graphics/GraphicsResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public Object Tag
// Resources may be added to and removed from the list from many threads.
private static object resourcesLock = new object();

// Use WeakReference for the global resources list as we do not know when a resource
// may be disposed and collected. We do not want to prevent a resource from being
// collected by holding a strong reference to it in this list.
/* Use WeakReference for the global resources list as we do not know when a resource
* may be disposed and collected. We do not want to prevent a resource from being
* collected by holding a strong reference to it in this list.
*/
private static List<WeakReference> resources = new List<WeakReference>();

#endregion
Expand Down Expand Up @@ -126,10 +127,14 @@ internal protected virtual void GraphicsDeviceResetting()
#region Protected Dispose Method

/// <summary>
/// The method that derived classes should override to implement disposing of managed and native resources.
/// The method that derived classes should override to implement disposing of
/// managed and native resources.
/// </summary>
/// <param name="disposing">True if managed objects should be disposed.</param>
/// <remarks>Native resources should always be released regardless of the value of the disposing parameter.</remarks>
/// <remarks>
/// Native resources should always be released regardless of the value of the
/// disposing parameter.
/// </remarks>
protected virtual void Dispose(bool disposing)
{
// FIXME: What was this? No, really, what? -flibit
Expand Down
3 changes: 1 addition & 2 deletions MonoGame.Framework/Graphics/ModelBone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
namespace Microsoft.Xna.Framework.Graphics
{
/// <summary>
/// Represents bone data for a model. Reference page contains links to related
/// conceptual articles.
/// Represents bone data for a model.
/// </summary>
public sealed class ModelBone
{
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/OpenGLDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ public void ResetFramebuffer(int width, int height, DepthFormat depthFormat)
Width = width;
Height = height;
#else
// Update our color attachment to the new resolution
// Update our color attachment to the new resolution.
GL.BindTexture(TextureTarget.Texture2D, colorAttachment);
GL.TexImage2D(
TextureTarget.Texture2D,
Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/RenderTargetBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Microsoft.Xna.Framework.Graphics
{
// http://msdn.microsoft.com/en-us/library/ff434403.aspx
// RenderTargetBinding structure: http://msdn.microsoft.com/en-us/library/ff434403.aspx
public struct RenderTargetBinding
{
#region Public Properties
Expand Down
13 changes: 9 additions & 4 deletions MonoGame.Framework/Graphics/RenderTargetCube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ int IRenderTarget.Height
/// </summary>
/// <param name="graphicsDevice">The graphics device.</param>
/// <param name="size">The width and height of a texture cube face in pixels.</param>
/// <param name="mipMap"><see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.</param>
/// <param name="mipMap">
/// <see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.
/// </param>
/// <param name="preferredFormat">The preferred format of the surface.</param>
/// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param>
public RenderTargetCube(
Expand All @@ -106,7 +108,9 @@ DepthFormat preferredDepthFormat
/// </summary>
/// <param name="graphicsDevice">The graphics device.</param>
/// <param name="size">The width and height of a texture cube face in pixels.</param>
/// <param name="mipMap"><see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.</param>
/// <param name="mipMap">
/// <see langword="true"/> to generate a full mipmap chain; otherwise <see langword="false"/>.
/// </param>
/// <param name="preferredFormat">The preferred format of the surface.</param>
/// <param name="preferredDepthFormat">The preferred format of the depth-stencil buffer.</param>
/// <param name="preferredMultiSampleCount">The preferred number of multisample locations.</param>
Expand Down Expand Up @@ -137,8 +141,9 @@ RenderTargetUsage usage
#region Protected Dispose Method

/// <summary>
/// Releases the unmanaged resources used by an instance of the <see cref="RenderTargetCube"/> class
/// and optionally releases the managed resources.
/// Releases the unmanaged resources used by an instance of the
/// <see cref="RenderTargetCube"/> class and optionally releases the managed
/// resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true"/> to release both managed and unmanaged resources;
Expand Down
31 changes: 17 additions & 14 deletions MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Matrix transformMatrix
);
}

// defaults
// Defaults
_sortMode = sortMode;
_blendState = blendState ?? BlendState.AlphaBlend;
_samplerState = samplerState ?? SamplerState.LinearClamp;
Expand Down Expand Up @@ -267,39 +267,40 @@ Color color
);
}

// Overload for calling Draw() with named parameters
/// <summary>
/// This is a MonoGame Extension method for calling Draw() using named parameters. It is not available in the standard XNA Framework.
/// This is a MonoGame Extension method for calling Draw() using named parameters.
/// It is not available in the standard XNA Framework.
/// </summary>
/// <param name='texture'>
/// The Texture2D to draw. Required.
/// The Texture2D to draw. Required.
/// </param>
/// <param name='position'>
/// The position to draw at. If left empty, the method will draw at drawRectangle instead.
/// The position to draw at. If left empty, the method will draw at drawRectangle
/// instead.
/// </param>
/// <param name='drawRectangle'>
/// The rectangle to draw at. If left empty, the method will draw at position instead.
/// The rectangle to draw at. If left empty, the method will draw at position instead.
/// </param>
/// <param name='sourceRectangle'>
/// The source rectangle of the texture. Default is null
/// The source rectangle of the texture. Default is null
/// </param>
/// <param name='origin'>
/// Origin of the texture. Default is Vector2.Zero
/// Origin of the texture. Default is Vector2.Zero
/// </param>
/// <param name='rotation'>
/// Rotation of the texture. Default is 0f
/// Rotation of the texture. Default is 0f
/// </param>
/// <param name='scale'>
/// The scale of the texture as a Vector2. Default is Vector2.One
/// The scale of the texture as a Vector2. Default is Vector2.One
/// </param>
/// <param name='color'>
/// Color of the texture. Default is Color.White
/// Color of the texture. Default is Color.White
/// </param>
/// <param name='effect'>
/// SpriteEffect to draw with. Default is SpriteEffects.None
/// SpriteEffect to draw with. Default is SpriteEffects.None
/// </param>
/// <param name='depth'>
/// Draw depth. Default is 0f.
/// Draw depth. Default is 0f.
/// </param>
public void Draw(
Texture2D texture,
Expand Down Expand Up @@ -329,7 +330,9 @@ Color color
scale = Vector2.One;
}

// If both drawRectangle and position are null, or if both have been assigned a value, raise an error
/* If both drawRectangle and position are null, or if both have been
* assigned a value, raise an error
*/
if ((drawRectangle.HasValue) == (position.HasValue))
{
throw new InvalidOperationException(
Expand Down
Loading

0 comments on commit 8dbe420

Please sign in to comment.