Permalink
Browse files

Added bitmap content classes for DXT1,3,5.

DxtBitmapContent is now abstract.
Removed DxtBitmapContent.TryGetFormat (implemented by derived classes).
Added Bgr565, Bgra4444, Byte4 packed vector classes to all projects.
  • Loading branch information...
1 parent 9026eb3 commit 6036814850371fef36a12e094b5101487b0eb879 @KonajuGames KonajuGames committed Apr 26, 2013
Showing with 623 additions and 30 deletions.
  1. +10 −4 MonoGame.Framework.Content.Pipeline.Windows.sln
  2. +17 −1 MonoGame.Framework.Content.Pipeline/ExternalReference.cs
  3. +27 −0 MonoGame.Framework.Content.Pipeline/Graphics/Dxt1BitmapContent.cs
  4. +27 −0 MonoGame.Framework.Content.Pipeline/Graphics/Dxt3BitmapContent.cs
  5. +27 −0 MonoGame.Framework.Content.Pipeline/Graphics/Dxt5BitmapContent.cs
  6. +23 −17 MonoGame.Framework.Content.Pipeline/Graphics/GraphicsUtil.cs
  7. +6 −1 MonoGame.Framework.Content.Pipeline/Graphics/IndexCollection.cs
  8. +5 −2 MonoGame.Framework.Content.Pipeline/MonoGame.Framework.Content.Pipeline.MacOS.csproj
  9. +6 −3 MonoGame.Framework.Content.Pipeline/MonoGame.Framework.Content.Pipeline.Windows.csproj
  10. +2 −2 MonoGame.Framework.Content.Pipeline/Processors/VertexBufferContent.cs
  11. +138 −0 MonoGame.Framework/Graphics/PackedVector/Bgr565.cs
  12. +147 −0 MonoGame.Framework/Graphics/PackedVector/Bgra4444.cs
  13. +158 −0 MonoGame.Framework/Graphics/PackedVector/Byte4.cs
  14. +3 −0 MonoGame.Framework/MonoGame.Framework.Android.csproj
  15. +3 −0 MonoGame.Framework/MonoGame.Framework.Linux.csproj
  16. +3 −0 MonoGame.Framework/MonoGame.Framework.MacOS.csproj
  17. +3 −0 MonoGame.Framework/MonoGame.Framework.Ouya.csproj
  18. +3 −0 MonoGame.Framework/MonoGame.Framework.PSMobile.csproj
  19. +3 −0 MonoGame.Framework/MonoGame.Framework.Windows.csproj
  20. +3 −0 MonoGame.Framework/MonoGame.Framework.Windows8.csproj
  21. +3 −0 MonoGame.Framework/MonoGame.Framework.WindowsGL.csproj
  22. +3 −0 MonoGame.Framework/MonoGame.Framework.WindowsPhone.csproj
  23. +3 −0 MonoGame.Framework/MonoGame.Framework.iOS.csproj
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Content.Pipeline.Windows", "MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj", "{B950DE10-AC5D-4BD9-B817-51247C4A732D}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Windows", "MonoGame.Framework\MonoGame.Framework.Windows.csproj", "{7DE47032-A904-4C29-BD22-2D235E8D91BA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -13,12 +15,16 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|x86.ActiveCfg = Debug|x86
- {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|x86.Build.0 = Debug|x86
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|x86.ActiveCfg = Debug|Any CPU
{B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.Build.0 = Release|Any CPU
- {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|x86.ActiveCfg = Release|x86
- {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|x86.Build.0 = Release|x86
+ {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|x86.ActiveCfg = Release|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -52,7 +52,23 @@ public ExternalReference(string filename, ContentIdentity relativeToContent)
throw new ArgumentNullException("relativeToContent");
if (string.IsNullOrEmpty(relativeToContent.SourceFilename))
throw new ArgumentNullException("relativeToContent.SourceFilename");
- Filename = Path.Combine(relativeToContent.SourceFilename, filename);
+
+#if WINRT
+ const char notSeparator = '/';
+ const char separator = '\\';
+#else
+ const char notSeparator = '\\';
+ var separator = Path.DirectorySeparatorChar;
+#endif
+ // Get a uri for the asset path using the file:// schema and no host
+ var src = new Uri("file:///" + relativeToContent.SourceFilename.Replace(notSeparator, separator));
+
+ // Add the relative path to the external reference
+ var dst = new Uri(src, filename.Replace(notSeparator, separator));
+
+ // The uri now contains the path to the external reference
+ // Get the local path and skip the first character (the path separator)
+ Filename = dst.LocalPath.Substring(1);
}
}
}
@@ -0,0 +1,27 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics
+{
+ public class Dxt1BitmapContent : DxtBitmapContent
+ {
+ public Dxt1BitmapContent(int width, int height)
+ : base(8, width, height)
+ {
+ }
+
+ /// <summary>
+ /// Gets the corresponding GPU texture format for the specified bitmap type.
+ /// </summary>
+ /// <param name="format">Format being retrieved.</param>
+ /// <returns>The GPU texture format of the bitmap type.</returns>
+ public override bool TryGetFormat(out SurfaceFormat format)
+ {
+ format = SurfaceFormat.Dxt1;
+ return true;
+ }
+ }
+}
@@ -0,0 +1,27 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics
+{
+ public class Dxt3BitmapContent : DxtBitmapContent
+ {
+ public Dxt3BitmapContent(int width, int height)
+ : base(16, width, height)
+ {
+ }
+
+ /// <summary>
+ /// Gets the corresponding GPU texture format for the specified bitmap type.
+ /// </summary>
+ /// <param name="format">Format being retrieved.</param>
+ /// <returns>The GPU texture format of the bitmap type.</returns>
+ public override bool TryGetFormat(out SurfaceFormat format)
+ {
+ format = SurfaceFormat.Dxt3;
+ return true;
+ }
+ }
+}
@@ -0,0 +1,27 @@
+// MonoGame - Copyright (C) The MonoGame Team
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE.txt', which is part of this source code package.
+
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics
+{
+ public class Dxt5BitmapContent : DxtBitmapContent
+ {
+ public Dxt5BitmapContent(int width, int height)
+ : base(16, width, height)
+ {
+ }
+
+ /// <summary>
+ /// Gets the corresponding GPU texture format for the specified bitmap type.
+ /// </summary>
+ /// <param name="format">Format being retrieved.</param>
+ /// <returns>The GPU texture format of the bitmap type.</returns>
+ public override bool TryGetFormat(out SurfaceFormat format)
+ {
+ format = SurfaceFormat.Dxt5;
+ return true;
+ }
+ }
+}
@@ -3,20 +3,14 @@
// file 'LICENSE.txt', which is part of this source code package.
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework.Graphics;
-using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
-using System.IO;
-
+using System.Runtime.InteropServices;
using Nvidia.TextureTools;
namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics
{
- class DXTDataHandler
+ class DxtDataHandler
{
private TextureContent _content;
private int _currentMipLevel;
@@ -27,7 +21,7 @@ class DXTDataHandler
public OutputOptions.WriteDataDelegate WriteData { get; private set; }
public OutputOptions.ImageDelegate BeginImage { get; private set; }
- public DXTDataHandler(TextureContent content, Format format)
+ public DxtDataHandler(TextureContent content, Format format)
{
_content = content;
@@ -53,7 +47,19 @@ protected bool writeData(IntPtr data, int length)
Marshal.Copy(data, dataBuffer, 0, length);
- var texContent = new DXTBitmapContent(_format == Format.DXT1 ? 8 : 16, _levelWidth, _levelHeight);
+ DxtBitmapContent texContent = null;
+ switch (_format)
+ {
+ case Format.DXT1:
+ texContent = new Dxt1BitmapContent(_levelWidth, _levelHeight);
+ break;
+ case Format.DXT3:
+ texContent = new Dxt3BitmapContent(_levelWidth, _levelHeight);
+ break;
+ case Format.DXT5:
+ texContent = new Dxt5BitmapContent(_levelWidth, _levelHeight);
+ break;
+ }
if (_content.Faces[0].Count == _currentMipLevel)
_content.Faces[0].Add(texContent);
@@ -87,7 +93,7 @@ public static byte[] GetData(this Bitmap bmp)
// NOTE: According to http://msdn.microsoft.com/en-us/library/dd183449%28VS.85%29.aspx
// and http://stackoverflow.com/questions/8104461/pixelformat-format32bppargb-seems-to-have-wrong-byte-order
- // Image data from any GDI based function are stored in memory as BGRA/BGR, even if the format says RBGA.
+ // Image data from any GDI based function are stored in memory as BGRA/BGR, even if the format says RGBA.
// Because of this we flip the R and B channels.
BGRAtoRGBA(output);
@@ -164,19 +170,19 @@ public static void CompressTexture(TextureContent content, TargetPlatform platfo
case TargetPlatform.MacOSX:
case TargetPlatform.NativeClient:
case TargetPlatform.Xbox360:
- CompressDXT(content, generateMipmaps);
+ CompressDxt(content, generateMipmaps);
break;
case TargetPlatform.iOS:
- CompressPVRTC(content, generateMipmaps, premultipliedAlpha);
+ CompressPvrtc(content, generateMipmaps, premultipliedAlpha);
break;
default:
- throw new NotImplementedException(string.Format("Texture Compression it not implemented for {0}", platform));
+ throw new NotImplementedException(string.Format("Texture compression is not implemented for {0}", platform));
}
}
- private static void CompressPVRTC(TextureContent content, bool generateMipmaps, bool premultipliedAlpha)
+ private static void CompressPvrtc(TextureContent content, bool generateMipmaps, bool premultipliedAlpha)
{
// TODO: Once uncompressed mipmap generation is supported, first use NVTT to generate mipmaps,
// then compress them withthe PVRTC tool, so we have the same implementation of mipmap generation
@@ -234,7 +240,7 @@ private static void CompressPVRTC(TextureContent content, bool generateMipmaps,
}
}
- private static void CompressDXT(TextureContent content, bool generateMipmaps)
+ private static void CompressDxt(TextureContent content, bool generateMipmaps)
{
var texData = content.Faces[0][0];
@@ -263,7 +269,7 @@ private static void CompressDXT(TextureContent content, bool generateMipmaps)
var outputFormat = containsFracAlpha ? Format.DXT5 : Format.DXT1;
- var handler = new DXTDataHandler(content, outputFormat);
+ var handler = new DxtDataHandler(content, outputFormat);
outputOptions.SetOutputHandler(handler.BeginImage, handler.WriteData);
var compressionOptions = new CompressionOptions();
@@ -3,6 +3,7 @@
// file 'LICENSE.txt', which is part of this source code package.
using System.Collections.ObjectModel;
+using System.Collections.Generic;
namespace Microsoft.Xna.Framework.Content.Pipeline.Graphics
{
@@ -18,7 +19,11 @@ public IndexCollection()
{
}
- internal void AddRange(int[] indices)
+ /// <summary>
+ /// Add a range of indices to the collection.
+ /// </summary>
+ /// <param name="indices">A collection of indices to add.</param>
+ public void AddRange(IEnumerable<int> indices)
{
foreach (var t in indices)
Add(t);
@@ -195,8 +195,11 @@
<Compile Include="Serialization\Compiler\Vector2Writer.cs" />
<Compile Include="Serialization\Compiler\Vector3Writer.cs" />
<Compile Include="Serialization\Compiler\Vector4Writer.cs" />
- <Compile Include="Graphics\DXTBitmapContent.cs" />
- <Compile Include="Graphics\PVRTCBitmapContent.cs" />
+ <Compile Include="Graphics\Dxt1BitmapContent.cs" />
+ <Compile Include="Graphics\Dxt3BitmapContent.cs" />
+ <Compile Include="Graphics\Dxt5BitmapContent.cs" />
+ <Compile Include="Graphics\DxtBitmapContent.cs" />
+ <Compile Include="Graphics\PvrtcBitmapContent.cs" />
<Compile Include="Graphics\BasicMaterialContent.cs" />
<Compile Include="Graphics\FontHelper.cs" />
</ItemGroup>
@@ -93,7 +93,10 @@
<Compile Include="Graphics\BoneContent.cs" />
<Compile Include="Graphics\BoneWeight.cs" />
<Compile Include="Graphics\BoneWeightCollection.cs" />
- <Compile Include="Graphics\DXTBitmapContent.cs" />
+ <Compile Include="Graphics\Dxt1BitmapContent.cs" />
+ <Compile Include="Graphics\Dxt3BitmapContent.cs" />
+ <Compile Include="Graphics\Dxt5BitmapContent.cs" />
+ <Compile Include="Graphics\DxtBitmapContent.cs" />
<Compile Include="Graphics\EffectContent.cs" />
<Compile Include="Graphics\FontDescription.cs" />
<Compile Include="Graphics\FontDescriptionStyle.cs" />
@@ -111,7 +114,7 @@
<Compile Include="Graphics\NodeContentCollection.cs" />
<Compile Include="Graphics\PixelBitmapContent.cs" />
<Compile Include="Graphics\PositionCollection.cs" />
- <Compile Include="Graphics\PVRTCBitmapContent.cs" />
+ <Compile Include="Graphics\PvrtcBitmapContent.cs" />
<Compile Include="Graphics\Texture2DContent.cs" />
<Compile Include="Graphics\TextureContent.cs" />
<Compile Include="Graphics\TextureReferenceDictionary.cs" />
@@ -261,4 +264,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project>
@@ -25,10 +25,10 @@ public class VertexBufferContent : ContentItem
public byte[] VertexData { get { return stream.ToArray(); } }
/// <summary>
- /// Gets the associated VertexDeclarationContent object.
+ /// Gets and sets the associated VertexDeclarationContent object.
/// </summary>
/// <value>The associated VertexDeclarationContent object.</value>
- public VertexDeclarationContent VertexDeclaration { get; private set; }
+ public VertexDeclarationContent VertexDeclaration { get; set; }
/// <summary>
/// Initializes a new instance of VertexBufferContent.
Oops, something went wrong.

0 comments on commit 6036814

Please sign in to comment.