Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation]: Add documentation to the Effect classes #8276

Merged
merged 3 commits into from May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 38 additions & 3 deletions MonoGame.Framework/Graphics/Effect/Effect.cs
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"/>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to know what kind of clone? A shallow one (just the Effect properties) or does it do a deep clone? That might be too much info.

/// </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
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
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to remove the reference to HLSL here. by the time the Effect is being used the onderlying shader will be platform specific , e.g GLSL HLSL, metal etc.

/// 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)
{
}
}
}

}