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

DDSLoader can now load 32-bit floating point textures. #5191

Merged
merged 1 commit into from Sep 26, 2016
Merged
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
45 changes: 31 additions & 14 deletions MonoGame.Framework.Content.Pipeline/DdsLoader.cs
Expand Up @@ -74,6 +74,7 @@ static uint MakeFourCC(string cc)

enum FourCC : uint
{
A32B32G32R32F = 116,
Dxt1 = 0x31545844,
Dxt2 = 0x32545844,
Dxt3 = 0x33545844,
Expand Down Expand Up @@ -113,9 +114,10 @@ static SurfaceFormat GetSurfaceFormat(ref DdsPixelFormat pixelFormat, out bool r
rbSwap = false;
if (pixelFormat.dwFlags.HasFlag(Ddpf.FourCC))
{
// It is a compressed format
switch (pixelFormat.dwFourCC)
{
case FourCC.A32B32G32R32F:
return SurfaceFormat.Vector4;
case FourCC.Dxt1:
return SurfaceFormat.Dxt1;
case FourCC.Dxt2:
Expand Down Expand Up @@ -162,6 +164,10 @@ static SurfaceFormat GetSurfaceFormat(ref DdsPixelFormat pixelFormat, out bool r
throw new ContentLoadException("Unsupported RGB pixel format");
}
}
//else if (pixelFormat.dwFlags.HasFlag(Ddpf.Luminance))
//{
// return SurfaceFormat.Alpha8;
//}
throw new ContentLoadException("Unsupported pixel format");
}

Expand Down Expand Up @@ -189,6 +195,9 @@ static BitmapContent CreateBitmapContent(SurfaceFormat format, int width, int he

case SurfaceFormat.Dxt5:
return new Dxt5BitmapContent(width, height);

case SurfaceFormat.Vector4:
return new PixelBitmapContent<Vector4>(width, height);
}
throw new ContentLoadException("Unsupported SurfaceFormat " + format);
}
Expand All @@ -199,21 +208,29 @@ static int GetBitmapSize(SurfaceFormat format, int width, int height)
// https://msdn.microsoft.com/en-us/library/bb943991.aspx
int pitch = 0;
int rows = 0;
if (format == SurfaceFormat.Dxt1)
{
pitch = MathHelper.Max(1, ((width + 3) / 4)) * 8;
rows = (height + 3) / 4;
}
else if (format == SurfaceFormat.Dxt3 || format == SurfaceFormat.Dxt5)
{
pitch = MathHelper.Max(1, ((width + 3) / 4)) * 16;
rows = (height + 3) / 4;
}
else if (format == SurfaceFormat.Color)

switch (format)
{
pitch = (width * 32 + 7) / 8;
rows = height;
case SurfaceFormat.Color:
case SurfaceFormat.Bgra4444:
case SurfaceFormat.Bgra5551:
case SurfaceFormat.Bgr565:
case SurfaceFormat.Vector4:
pitch = width * format.GetSize();
rows = height;
break;

case SurfaceFormat.Dxt1:
case SurfaceFormat.Dxt3:
case SurfaceFormat.Dxt5:
pitch = ((width + 3) / 4) * format.GetSize();
rows = (height + 3) / 4;
break;

default:
throw new ContentLoadException("Unsupported SurfaceFormat " + format);
}

return pitch * rows;
}

Expand Down