66using System . Runtime . InteropServices ;
77
88using Stride . Core ;
9+ using Stride . Core . Serialization ;
910
1011namespace Stride . Graphics ;
1112
@@ -20,6 +21,7 @@ namespace Stride.Graphics;
2021/// </remarks>
2122/// <seealso cref="BlendStates"/>
2223[ DataContract ]
24+ [ DataSerializer ( typeof ( BlendStateDescription . Serializer ) ) ]
2325[ StructLayout ( LayoutKind . Sequential ) ]
2426public struct BlendStateDescription : IEquatable < BlendStateDescription >
2527{
@@ -116,8 +118,8 @@ private void SetDefaultRenderTargetDescriptions()
116118 /// If set to <see langword="true"/>, each of the <see cref="RenderTargets"/> can have its own blend settings.
117119 /// </para>
118120 /// <para>
119- /// If set to <see langword="false"/>, only the first Render Target (<see cref="RenderTarget0"/ >) is taken into account.
120- /// The others (<see cref="RenderTarget1"/ > to <see cref="RenderTarget7"/ >) are ignored.
121+ /// If set to <see langword="false"/>, only the first Render Target (<c>RenderTargets[0]</c >) is taken into account.
122+ /// The others (<c>RenderTargets[1]</c > to <c>RenderTargets[7]</c >) are ignored.
121123 /// </para>
122124 /// </remarks>
123125 public bool IndependentBlendEnable = DefaultIndependentBlendEnable ;
@@ -209,4 +211,24 @@ public override readonly int GetHashCode()
209211
210212 return hash . ToHashCode ( ) ;
211213 }
214+
215+ // Custom serializer needed because RenderTargetBlendStates uses [InlineArray] with a private
216+ // backing field, which Stride's auto-generated serializer cannot access.
217+ internal class Serializer : DataSerializer < BlendStateDescription >
218+ {
219+ private DataSerializer < BlendStateRenderTargetDescription > _renderTargetSerializer ;
220+
221+ public override void Initialize ( SerializerSelector serializerSelector )
222+ {
223+ _renderTargetSerializer = serializerSelector . GetSerializer < BlendStateRenderTargetDescription > ( ) ;
224+ }
225+
226+ public override void Serialize ( ref BlendStateDescription obj , ArchiveMode mode , SerializationStream stream )
227+ {
228+ stream . Serialize ( ref obj . AlphaToCoverageEnable ) ;
229+ stream . Serialize ( ref obj . IndependentBlendEnable ) ;
230+ for ( int i = 0 ; i < obj . RenderTargets . Count ; i ++ )
231+ _renderTargetSerializer . Serialize ( ref obj . RenderTargets [ i ] , mode , stream ) ;
232+ }
233+ }
212234}
0 commit comments