DynamicVertexBufferWriter.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #region License
  2. // Copyright 2016 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using Microsoft.Xna.Framework.Content.Pipeline;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
  19. using nkast.Aether.Content.Pipeline.Graphics;
  20. namespace nkast.Aether.Content.Pipeline.Serialization
  21. {
  22. [ContentTypeWriter]
  23. public class DynamicVertexBufferWriter : ContentTypeWriter<DynamicVertexBufferContent>
  24. {
  25. protected override void Write(ContentWriter output, DynamicVertexBufferContent buffer)
  26. {
  27. WriteVertexBuffer(output, buffer);
  28. output.Write(buffer.IsWriteOnly);
  29. return;
  30. }
  31. private void WriteVertexBuffer(ContentWriter output, DynamicVertexBufferContent buffer)
  32. {
  33. var vertexCount = buffer.VertexData.Length / buffer.VertexDeclaration.VertexStride;
  34. output.WriteRawObject(buffer.VertexDeclaration);
  35. output.Write((UInt32)vertexCount);
  36. output.Write(buffer.VertexData);
  37. }
  38. public override string GetRuntimeReader(TargetPlatform targetPlatform)
  39. {
  40. return "nkast.Aether.Graphics.Content.DynamicVertexBufferReader, Aether.Graphics";
  41. }
  42. }
  43. }