Skip to content

Commit

Permalink
Updated to NoesisGUI 3.1.7 version
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Feb 9, 2023
1 parent 094c881 commit c3e09b7
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 5 deletions.
133 changes: 129 additions & 4 deletions Src/Noesis/Core/Src/Core/RenderDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,8 +1311,12 @@ public static extern void Noesis_RenderDevice_UpdateTexture(HandleRef device, Ha
/// </summary>
public class RenderDeviceGL : NativeRenderDevice
{
public RenderDeviceGL() :
base(Noesis_RenderDeviceGL_Create(), true)
public RenderDeviceGL() : this(false)
{
}

public RenderDeviceGL(bool sRGB) :
base(Noesis_RenderDeviceGL_Create(sRGB), true)
{
}

Expand All @@ -1329,7 +1333,7 @@ public static Texture WrapTexture(object texture, IntPtr nativePointer,

#region Imports
[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceGL_Create();
static extern IntPtr Noesis_RenderDeviceGL_Create(bool sRGB);

[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceGL_WrapTexture(IntPtr nativePointer,
Expand Down Expand Up @@ -1499,16 +1503,25 @@ public class RenderDeviceGNM : NativeRenderDevice
{
public struct GPUAllocator
{
// IntPtr AllocateGarlic(uint size, uint alignment)
public Func<uint, uint, IntPtr> AllocateGarlic;
// void ReleaseGarlic(IntPtr ptr)
public Action<IntPtr> ReleaseGarlic;
// IntPtr AllocateOnion(uint size, uint alignment)
public Func<uint, uint, IntPtr> AllocateOnion;
// void ReleaseOnion(IntPtr ptr)
public Action<IntPtr> ReleaseOnion;
}

public RenderDeviceGNM(bool sRGB, GPUAllocator allocator) :
base(Noesis_RenderDeviceGNM_Create(sRGB, _garlicAlloc, _garlicFree, _onionAlloc, _onionFree), true)
base(CreateDevice(sRGB, allocator), true)
{
}

private static IntPtr CreateDevice(bool sRGB, GPUAllocator allocator)
{
_allocator = allocator;
return Noesis_RenderDeviceGNM_Create(sRGB, _garlicAlloc, _garlicFree, _onionAlloc, _onionFree);
}

/// <summary>
Expand Down Expand Up @@ -1608,4 +1621,116 @@ static extern IntPtr Noesis_RenderDeviceGNM_WrapTexture(IntPtr nativePointer,
static extern IntPtr Noesis_RenderDeviceGNM_SetContext(HandleRef device, IntPtr context);
#endregion
}

/// <summary>
/// Creates an AGC RenderDevice (PlayStation 5).
/// </summary>
public class RenderDeviceAGC : NativeRenderDevice
{
public struct GPUAllocator
{
// IntPtr Alloc(uint size, uint alignment)
public Func<uint, uint, IntPtr> Alloc;
// void Free(IntPtr ptr)
public Action<IntPtr> Free;
// void RegisterResource(IntPtr ptr, uint size, uint type, string label)
public Action<IntPtr, uint, uint, string> RegisterResource;
}

public RenderDeviceAGC(bool sRGB, GPUAllocator allocator) :
base(CreateDevice(sRGB, allocator), true)
{
}

private static IntPtr CreateDevice(bool sRGB, GPUAllocator allocator)
{
_allocator = allocator;
return Noesis_RenderDeviceAGC_Create(sRGB, _alloc, _free, _registerResource);
}

/// <summary>
/// Creates a Texture wrapper for the specified AGC texture native handle
/// </summary>
public static Texture WrapTexture(object texture, IntPtr nativePointer,
int width, int height, int numMipMaps, bool isInverted, bool hasAlpha)
{
return WrapTexture(texture, Noesis_RenderDeviceAGC_WrapTexture(nativePointer,
width, height, numMipMaps, isInverted, hasAlpha));
}

public void SetCommandBuffer(IntPtr drawCommandBuffer)
{
Noesis_RenderDeviceAGC_SetCommandBuffer(swigCPtr, drawCommandBuffer);
}

#region Allocator callbacks
[MonoPInvokeCallback(typeof(Callback_Alloc))]
private static IntPtr Alloc(IntPtr user, uint size, uint alignment)
{
try
{
return _allocator.Alloc(size, alignment);
}
catch (Exception e)
{
Error.UnhandledException(e);
}

return IntPtr.Zero;
}

[MonoPInvokeCallback(typeof(Callback_Free))]
private static void Free(IntPtr user, IntPtr address)
{
try
{
_allocator.Free(address);
}
catch (Exception e)
{
Error.UnhandledException(e);
}
}

[MonoPInvokeCallback(typeof(Callback_RegisterResource))]
private static void RegisterResource(IntPtr user, IntPtr ptr, uint size, uint type,
IntPtr labelPtr)
{
try
{
string label = Noesis.Extend.StringFromNativeUtf8(labelPtr);
_allocator.RegisterResource(ptr, size, type, label);
}
catch (Exception e)
{
Error.UnhandledException(e);
}
}

private delegate IntPtr Callback_Alloc(IntPtr user, uint size, uint alignment);
private delegate void Callback_Free(IntPtr user, IntPtr address);
private delegate void Callback_RegisterResource(IntPtr user, IntPtr ptr, uint size,
uint type, IntPtr label);

private static Callback_Alloc _alloc = Alloc;
private static Callback_Free _free = Free;
private static Callback_RegisterResource _registerResource = RegisterResource;

private static GPUAllocator _allocator;
#endregion

#region Imports
[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceAGC_Create(bool sRGB,
Callback_Alloc alloc, Callback_Free free, Callback_RegisterResource registerResource);

[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceAGC_WrapTexture(IntPtr nativePointer,
int width, int height, int numMipMaps, bool isInverted, bool hasAlpha);

[DllImport(Library.Name)]
static extern IntPtr Noesis_RenderDeviceAGC_SetCommandBuffer(HandleRef device,
IntPtr drawCommandBuffer);
#endregion
}
}
8 changes: 7 additions & 1 deletion Src/NoesisApp/Core/Src/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ private struct LicenseInfo

private LicenseInfo GetLicenseInfo()
{
Stream stream = GetAssemblyResource(GetType().Assembly, "", "NoesisLicense.txt");
Type app = GetType();
Stream stream = GetAssemblyResource(app.Assembly, app.Namespace, "NoesisLicense.txt");
if (stream == null)
{
stream = GetAssemblyResource(app.Assembly, "", "NoesisLicense.txt");
}

if (stream != null)
{
string name, key;
Expand Down

0 comments on commit c3e09b7

Please sign in to comment.