Skip to content

Commit

Permalink
Some cleanup.
Browse files Browse the repository at this point in the history
Fix texture cube set/get data.
  • Loading branch information
tomspilman committed Sep 2, 2024
1 parent a5f644d commit 71542f9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
20 changes: 20 additions & 0 deletions MonoGame.Framework/Platform/Native/Audio.Interop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.Runtime.InteropServices;


namespace MonoGame.Interop;


/// <summary>
/// MonoGame native calls for platform audio features.
/// </summary>
internal static unsafe partial class MGA
{

}


6 changes: 3 additions & 3 deletions MonoGame.Framework/Platform/Native/Media.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ internal static unsafe partial class MGM
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGM_Song_Create", StringMarshalling = StringMarshalling.Utf8)]
public static partial MGM_Song* Song_Create(string mediaFilePath);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGM_Song_Destroy", StringMarshalling = StringMarshalling.Utf8)]
public static partial void Song_Destroy(MGM_Song* song);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGM_Song_GetDuration", StringMarshalling = StringMarshalling.Utf8)]
public static partial ulong Song_GetDuration(MGM_Song* song);

Expand All @@ -52,9 +55,6 @@ internal static unsafe partial class MGM
[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGM_Song_Stop", StringMarshalling = StringMarshalling.Utf8)]
public static partial void Song_Stop(MGM_Song* song);

[LibraryImport(MonoGameNativeDLL, EntryPoint = "MGM_Song_Destroy", StringMarshalling = StringMarshalling.Utf8)]
public static partial void Song_Destroy(MGM_Song* song);

#endregion


Expand Down
51 changes: 49 additions & 2 deletions MonoGame.Framework/Platform/Native/TextureCube.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// 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.Runtime.InteropServices;
using MonoGame.Interop;
using static System.Net.Mime.MediaTypeNames;

namespace Microsoft.Xna.Framework.Graphics;

Expand All @@ -16,13 +19,57 @@ private unsafe void PlatformConstruct(GraphicsDevice graphicsDevice, int size, b
Handle = MGG.Texture_Create(GraphicsDevice.Handle, TextureType.Cube, format, size, size, 1, _levelCount, 6);
}

private void PlatformGetData<T>(CubeMapFace cubeMapFace, int level, Rectangle rect, T[] data, int startIndex, int elementCount) where T : struct
private unsafe void PlatformSetData<T>(CubeMapFace face, int level, Rectangle rect, T[] data, int startIndex, int elementCount)
{
var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
var elementSizeInByte = Marshal.SizeOf(typeof(T));
var startBytes = startIndex * elementSizeInByte;
var dataPtr = (IntPtr)(dataHandle.AddrOfPinnedObject().ToInt64() + startBytes);

var width = rect.Right - rect.Left;
var height = rect.Bottom - rect.Top;

MGG.Texture_SetData(
GraphicsDevice.Handle,
Handle,
level,
0,
rect.Left,
rect.Top,
(int)face,
width,
height,
1,
(byte*)dataPtr,
elementSizeInByte * elementCount);

dataHandle.Free();
}

private void PlatformSetData<T>(CubeMapFace face, int level, Rectangle rect, T[] data, int startIndex, int elementCount)
private unsafe void PlatformGetData<T>(CubeMapFace face, int level, Rectangle rect, T[] data, int startIndex, int elementCount) where T : struct
{
var dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
var elementSizeInByte = Marshal.SizeOf(typeof(T));
var startBytes = startIndex * elementSizeInByte;
var dataPtr = (IntPtr)(dataHandle.AddrOfPinnedObject().ToInt64() + startBytes);

var width = rect.Right - rect.Left;
var height = rect.Bottom - rect.Top;

MGG.Texture_GetData(
GraphicsDevice.Handle,
Handle,
level,
0,
rect.Left,
rect.Top,
(int)face,
width,
height,
1,
(byte*)dataPtr,
elementSizeInByte * elementCount);

dataHandle.Free();
}
}
4 changes: 3 additions & 1 deletion MonoGame.Framework/Platform/Native/WaveBank.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System;

namespace Microsoft.Xna.Framework.Audio;

partial class WaveBank
{
private SoundEffectInstance PlatformCreateStream(StreamInfo stream)
{
return new SoundEffectInstance();
throw new NotSupportedException();
}
}

0 comments on commit 71542f9

Please sign in to comment.