initial commit

main
cosmonaut 2021-01-14 00:31:03 -08:00
commit dab4c57284
7 changed files with 187 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs/
bin/
obj/

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/RefreshCS"]
path = lib/RefreshCS
url = https://github.com/thatcosmonaut/RefreshCS.git

15
Campari.csproj Normal file
View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>x64</Platforms>
</PropertyGroup>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);lib\**\*</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="lib\RefreshCS\RefreshCS.csproj" />
</ItemGroup>
</Project>

31
Campari.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Campari", "Campari.csproj", "{55485ED3-E08A-4827-B7CF-5028287D4AE3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RefreshCS", "lib\RefreshCS\RefreshCS.csproj", "{2EFA491B-EDAF-4983-A3E4-A24D014E4B6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{55485ED3-E08A-4827-B7CF-5028287D4AE3}.Debug|x64.ActiveCfg = Debug|x64
{55485ED3-E08A-4827-B7CF-5028287D4AE3}.Debug|x64.Build.0 = Debug|x64
{55485ED3-E08A-4827-B7CF-5028287D4AE3}.Release|x64.ActiveCfg = Release|x64
{55485ED3-E08A-4827-B7CF-5028287D4AE3}.Release|x64.Build.0 = Release|x64
{2EFA491B-EDAF-4983-A3E4-A24D014E4B6E}.Debug|x64.ActiveCfg = Debug|x64
{2EFA491B-EDAF-4983-A3E4-A24D014E4B6E}.Debug|x64.Build.0 = Debug|x64
{2EFA491B-EDAF-4983-A3E4-A24D014E4B6E}.Release|x64.ActiveCfg = Release|x64
{2EFA491B-EDAF-4983-A3E4-A24D014E4B6E}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4F656977-F01D-4BBD-9E72-0FD6CD077717}
EndGlobalSection
EndGlobal

52
RefreshDevice.cs Normal file
View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using RefreshCS;
namespace Campari
{
public class RefreshDevice : IDisposable
{
public IntPtr Handle { get; }
public bool IsDisposed { get; private set; }
public RefreshDevice(
Refresh.PresentationParameters presentationParameters,
bool debugMode
) {
Handle = Refresh.Refresh_CreateDevice(
ref presentationParameters,
(byte) (debugMode ? 1 : 0)
);
}
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
Refresh.Refresh_DestroyDevice(Handle);
IsDisposed = true;
}
}
// TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
~RefreshDevice()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

82
Texture.cs Normal file
View File

@ -0,0 +1,82 @@
using System;
using RefreshCS;
namespace Campari
{
public class Texture : IDisposable
{
public RefreshDevice Device { get; }
public IntPtr Handle { get; }
public uint Height { get; }
public uint Width { get; }
public bool IsDisposed { get; private set; }
public static Texture Load(RefreshDevice device, string path)
{
var pixels = Refresh.Refresh_Image_Load(path, out var width, out var height, out var channels);
IntPtr textureHandle = Refresh.Refresh_CreateTexture2D(
device.Handle,
Refresh.ColorFormat.R8G8B8A8,
(uint) width,
(uint) height,
1,
(uint) Refresh.TextureUsageFlagBits.SamplerBit
);
Refresh.TextureSlice textureSlice;
textureSlice.texture = textureHandle;
textureSlice.rectangle.x = 0;
textureSlice.rectangle.y = 0;
textureSlice.rectangle.w = width;
textureSlice.rectangle.h = height;
textureSlice.level = 0;
textureSlice.layer = 0;
textureSlice.depth = 0;
Refresh.Refresh_SetTextureData(
device.Handle,
ref textureSlice,
pixels,
(uint) (width * height * 4)
);
return new Texture(
device,
textureHandle,
(uint) width,
(uint) height
);
}
public Texture(RefreshDevice device, IntPtr handle, uint width, uint height)
{
Device = device;
Handle = handle;
Width = width;
Height = height;
}
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)
{
Refresh.Refresh_QueueDestroyTexture(Device.Handle, Handle);
IsDisposed = true;
}
}
~Texture()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

1
lib/RefreshCS Submodule

@ -0,0 +1 @@
Subproject commit c33e62b9e46f9c86c40fffe56bce461739b71bf8