Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Adding in MonoGame unit tests to cover what's left.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed May 22, 2020
1 parent 331b660 commit 9ae5a08
Show file tree
Hide file tree
Showing 77 changed files with 14,433 additions and 14,418 deletions.
26 changes: 13 additions & 13 deletions MonoGame/MonoGame.Framework/Graphics/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public Texture2D(GraphicsDevice graphicsDevice, int width, int height)
/// <param name="height"></param>
/// <param name="mipmap"></param>
/// <param name="format"></param>
// public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format)
// : this(graphicsDevice, width, height, mipmap, format, SurfaceType.Texture, false, 1)
// {
// }
public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipmap, SurfaceFormat format)
: this(graphicsDevice, width, height, mipmap, format, SurfaceType.Texture, false, 1)
{
}

/// <summary>
/// Creates a new texture array of a given size with a surface format and optional mipmaps.
Expand Down Expand Up @@ -169,15 +169,15 @@ public int Height
/// <param name="data">New data for the texture</param>
/// <param name="startIndex">Start position of data</param>
/// <param name="elementCount"></param>
// public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
// {
// Rectangle checkedRect;
// ValidateParams(level, 0, rect, data, startIndex, elementCount, out checkedRect);
// if (rect.HasValue)
// PlatformSetData(level, 0, checkedRect, data, startIndex, elementCount);
// else
// PlatformSetData(level, data, startIndex, elementCount);
// }
public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
Rectangle checkedRect;
ValidateParams(level, 0, rect, data, startIndex, elementCount, out checkedRect);
if (rect.HasValue)
PlatformSetData(level, 0, checkedRect, data, startIndex, elementCount);
else
PlatformSetData(level, data, startIndex, elementCount);
}

/// <summary>
/// Changes the texture's pixels
Expand Down
108 changes: 54 additions & 54 deletions MonoGame/MonoGame.Framework/Platform/Graphics/Texture2D.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,60 +137,60 @@ private void PlatformConstruct(int width, int height, bool mipmap, SurfaceFormat
});
}

// private void PlatformSetData<T>(int level, int arraySlice, Rectangle rect, T[] data, int startIndex, int elementCount) where T : struct
// {
// Threading.BlockOnUIThread(() =>
// {
// var elementSizeInByte = ReflectionHelpers.SizeOf<T>.Get();
// var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
// // Use try..finally to make sure dataHandle is freed in case of an error
// try
// {
// var startBytes = startIndex * elementSizeInByte;
// var dataPtr = new IntPtr(dataHandle.AddrOfPinnedObject().ToInt64() + startBytes);
// // Store the current bound texture.
// var prevTexture = GraphicsExtensions.GetBoundTexture2D();
//
// if (prevTexture != glTexture)
// {
// GL.BindTexture(TextureTarget.Texture2D, glTexture);
// GraphicsExtensions.CheckGLError();
// }
//
// GenerateGLTextureIfRequired();
// GL.PixelStore(PixelStoreParameter.UnpackAlignment, Math.Min(_format.GetSize(), 8));
//
// if (glFormat == (PixelFormat)GLPixelFormat.CompressedTextureFormats)
// {
// GL.CompressedTexSubImage2D(TextureTarget.Texture2D, level, rect.X, rect.Y, rect.Width, rect.Height,
// (PixelInternalFormat)glInternalFormat, elementCount * elementSizeInByte, dataPtr);
// }
// else
// {
// GL.TexSubImage2D(TextureTarget.Texture2D, level, rect.X, rect.Y,
// rect.Width, rect.Height, glFormat, glType, dataPtr);
// }
// GraphicsExtensions.CheckGLError();
//
// #if !ANDROID
// // Required to make sure that any texture uploads on a thread are completed
// // before the main thread tries to use the texture.
// GL.Finish();
// GraphicsExtensions.CheckGLError();
// #endif
// // Restore the bound texture.
// if (prevTexture != glTexture)
// {
// GL.BindTexture(TextureTarget.Texture2D, prevTexture);
// GraphicsExtensions.CheckGLError();
// }
// }
// finally
// {
// dataHandle.Free();
// }
// });
// }
private void PlatformSetData<T>(int level, int arraySlice, Rectangle rect, T[] data, int startIndex, int elementCount) where T : struct
{
Threading.BlockOnUIThread(() =>
{
var elementSizeInByte = ReflectionHelpers.SizeOf<T>.Get();
var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
// Use try..finally to make sure dataHandle is freed in case of an error
try
{
var startBytes = startIndex * elementSizeInByte;
var dataPtr = new IntPtr(dataHandle.AddrOfPinnedObject().ToInt64() + startBytes);
// Store the current bound texture.
var prevTexture = GraphicsExtensions.GetBoundTexture2D();
if (prevTexture != glTexture)
{
GL.BindTexture(TextureTarget.Texture2D, glTexture);
GraphicsExtensions.CheckGLError();
}
GenerateGLTextureIfRequired();
GL.PixelStore(PixelStoreParameter.UnpackAlignment, Math.Min(_format.GetSize(), 8));
if (glFormat == (PixelFormat)GLPixelFormat.CompressedTextureFormats)
{
GL.CompressedTexSubImage2D(TextureTarget.Texture2D, level, rect.X, rect.Y, rect.Width, rect.Height,
(PixelInternalFormat)glInternalFormat, elementCount * elementSizeInByte, dataPtr);
}
else
{
GL.TexSubImage2D(TextureTarget.Texture2D, level, rect.X, rect.Y,
rect.Width, rect.Height, glFormat, glType, dataPtr);
}
GraphicsExtensions.CheckGLError();
#if !ANDROID
// Required to make sure that any texture uploads on a thread are completed
// before the main thread tries to use the texture.
GL.Finish();
GraphicsExtensions.CheckGLError();
#endif
// Restore the bound texture.
if (prevTexture != glTexture)
{
GL.BindTexture(TextureTarget.Texture2D, prevTexture);
GraphicsExtensions.CheckGLError();
}
}
finally
{
dataHandle.Free();
}
});
}

private void PlatformGetData<T>(int level, int arraySlice, Rectangle rect, T[] data, int startIndex, int elementCount) where T : struct
{
Expand Down
38 changes: 19 additions & 19 deletions MonoGame/Tests/AssetTestUtility.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 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 System;
using System.IO;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.Tests
{
internal static class AssetTestUtility
{
public static Microsoft.Xna.Framework.Graphics.Effect LoadEffect(ContentManager content, string name)
{
return content.Load<Microsoft.Xna.Framework.Graphics.Effect>(Paths.CompiledEffect(name));
}
}
}
// // 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 System;
// using System.IO;
// using Microsoft.Xna.Framework.Content;
// using Microsoft.Xna.Framework.Graphics;
//
// namespace MonoGame.Tests
// {
// internal static class AssetTestUtility
// {
// public static Microsoft.Xna.Framework.Graphics.Effect LoadEffect(ContentManager content, string name)
// {
// return content.Load<Microsoft.Xna.Framework.Graphics.Effect>(Paths.CompiledEffect(name));
// }
// }
// }

0 comments on commit 9ae5a08

Please sign in to comment.