Skip to content

Commit

Permalink
[Documentation]: Add documentation to the Effect classes (#8276)
Browse files Browse the repository at this point in the history
* Add documentation to the Effect classes

* Added IEffectMatrices

* Minor cleanup

---------

Co-authored-by: Simon (Darkside) Jackson <[email protected]>
  • Loading branch information
Maniekko and SimonDarksideJ committed May 17, 2024
1 parent 681e91d commit 4c77896
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 62 deletions.
41 changes: 38 additions & 3 deletions MonoGame.Framework/Graphics/Effect/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace Microsoft.Xna.Framework.Graphics
{
/// <summary>
/// Used to set and query shader effects, and to choose techniques.
/// </summary>
public class Effect : GraphicsResource
{
struct MGFXHeader
Expand All @@ -35,10 +38,23 @@ struct MGFXHeader
public int HeaderSize;
}

/// <summary>
/// Gets a collection of shader parameters used for this effect.
/// </summary>
public EffectParameterCollection Parameters { get; private set; }

/// <summary>
/// Gets a collection of shader techniques that are defined for this effect.
/// </summary>
public EffectTechniqueCollection Techniques { get; private set; }

/// <summary>
/// Gets or sets the active technique.
/// </summary>
/// <remarks>
/// If there are multiple techiques in an effect and you want to use a new technique in the next pass,
/// you must set <b>CurrentTechnique</b> to the new technique before making the rendering pass.
/// </remarks>
public EffectTechnique CurrentTechnique { get; set; }

internal ConstantBuffer[] ConstantBuffers { get; private set; }
Expand All @@ -55,20 +71,32 @@ internal Effect(GraphicsDevice graphicsDevice)
}
this.GraphicsDevice = graphicsDevice;
}


/// <summary>
/// Creates a clone of the <see cref="Effect"/>.
/// </summary>
/// <param name="cloneSource"><see cref="Effect"/> to clone.</param>
protected Effect(Effect cloneSource)
: this(cloneSource.GraphicsDevice)
{
_isClone = true;
Clone(cloneSource);
}

/// <inheritdoc cref="Effect(GraphicsDevice, byte[], int, int)"/>
public Effect(GraphicsDevice graphicsDevice, byte[] effectCode)
: this(graphicsDevice, effectCode, 0, effectCode.Length)
{
}


/// <summary>
/// Creates a new instance of <see cref="Effect"/>.
/// </summary>
/// <param name="graphicsDevice">Graphics device</param>
/// <param name="effectCode">The effect code.</param>
/// <param name="index"></param>
/// <param name="count"></param>
/// <exception cref="ArgumentException">This <paramref name="effectCode"/> is invalid.</exception>
public Effect (GraphicsDevice graphicsDevice, byte[] effectCode, int index, int count)
: this(graphicsDevice)
{
Expand Down Expand Up @@ -192,10 +220,14 @@ public virtual Effect Clone()
return new Effect(this);
}

/// <summary>
/// Applies the effect state just prior to rendering the effect.
/// </summary>
protected internal virtual void OnApply()
{
}

/// <inheritdoc cref="IDisposable.Dispose()"/>
protected override void Dispose(bool disposing)
{
if (!IsDisposed)
Expand Down Expand Up @@ -224,6 +256,9 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

/// <summary>
/// The GraphicsDevice is resetting, so GPU resources must be recreated.
/// </summary>
internal protected override void GraphicsDeviceResetting()
{
for (var i = 0; i < ConstantBuffers.Length; i++)
Expand Down Expand Up @@ -451,4 +486,4 @@ private static EffectParameterCollection ReadParameters(BinaryReader reader)

#endregion // Effect File Reader
}
}
}
24 changes: 22 additions & 2 deletions MonoGame.Framework/Graphics/Effect/EffectAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace Microsoft.Xna.Framework.Graphics
{
// TODO: This class needs to be finished!

/// <summary>
/// Represents an annotation to an <see cref="EffectParameter"/>.
/// </summary>
public class EffectAnnotation
{
internal EffectAnnotation (
Expand Down Expand Up @@ -33,12 +36,29 @@ internal EffectAnnotation (EffectParameter parameter)
Semantic = parameter.Semantic;
}

/// <summary>
/// Gets the parameter class of this effect annotation.
/// </summary>
public EffectParameterClass ParameterClass {get; private set;}
/// <summary>
/// Gets the parameter type of this effect annotation.
/// </summary>
public EffectParameterType ParameterType {get; private set;}
/// <summary>
/// Gets the name of the effect annotation.
/// </summary>
public string Name {get; private set;}
/// <summary>
/// Gets the row count of this effect annotation.
/// </summary>
public int RowCount {get; private set;}
/// <summary>
/// Gets the number of columns in this effect annotation.
/// </summary>
public int ColumnCount {get; private set;}
/// <summary>
/// Gets the semantic of this effect annotation.
/// </summary>
public string Semantic {get; private set;}
}
}

}
16 changes: 14 additions & 2 deletions MonoGame.Framework/Graphics/Effect/EffectMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@
using System;
namespace Microsoft.Xna.Framework.Graphics
{
/// <summary>
/// Contains an effect subclass which is used to load data for an EffectMaterialContent type.
/// </summary>
/// <remarks>
/// For most purposes, this type can be ignored, and treated exactly like a regular effect.
/// When an EffectMaterial type is loaded from .xnb format, its parameter values and textures
/// are also loaded and automatically set on the effect, in addition to the HLSL shader code.
/// Use this class to write a content pipeline extension to store materials inside a custom data type.
/// </remarks>
public class EffectMaterial : Effect
{
/// <summary>
/// Creates a new instance of <see cref="EffectMaterial"/>.
/// </summary>
/// <param name="cloneSource">An instance of an object to copy initialization data from.</param>
public EffectMaterial (Effect cloneSource) : base(cloneSource)
{
}
}
}

}

0 comments on commit 4c77896

Please sign in to comment.