Crappy hot reloading of textures and Properties editor for textures

This commit is contained in:
Simon Lübeß
2023-01-03 22:21:26 +01:00
parent 427323744b
commit ee30920b56
17 changed files with 707 additions and 70 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ namespace GlitchyEngine.Content
return true;
}
}
interface IAssetLoader
{
static List<StringView> FileExtensions { get; }
@@ -36,4 +36,25 @@ extension Path
Runtime.NotImplemented();
#endif
}
public static void Fixup(String path)
{
path.Replace(AltDirectorySeparatorChar, DirectorySeparatorChar);
path.Replace(scope $".{DirectorySeparatorChar}", "");
path.Replace(scope $"{DirectorySeparatorChar}.", "");
if (path.StartsWith(DirectorySeparatorChar))
path.Remove(0, 1);
}
public static void Combine(String target, params StringView[] components)
{
for (var component in components)
{
if ((target.Length > 0) && (!target.EndsWith("\\")) && (!target.EndsWith("/")) &&
(!component.StartsWith("\\")) && (!component.StartsWith("/")))
target.Append(Path.DirectorySeparatorChar);
target.Append(component);
}
}
}
@@ -17,5 +17,11 @@ namespace System
target[copiedChars] = '\0';
}
/// Converts camel case and delimiter-separated words to normal words.
public void ToHumanReadable()
{
// TODO!
}
}
}
+104
View File
@@ -2,6 +2,7 @@ using GlitchyEngine.Math;
using GlitchyEngine.Renderer;
using System;
using GlitchyEngine;
using System.Collections;
namespace GlitchyEngine.Math
{
@@ -215,5 +216,108 @@ namespace ImGui
{
ImGui.GetForegroundDrawList().AddRect(min, max, ImGui.GetColorU32(color.Value));
}
/// Provides a combo Box to select an enum value.
public static bool EnumCombo<T>(StringView label, ref T selectedValue) where T : enum
{
String selectedValueString = scope .();
selectedValue.ToString(selectedValueString);
// TODO: make selectedValue human readable
bool changed = false;
if (ImGui.BeginCombo(label.ToScopeCStr!(), selectedValueString))
{
for (let (name, value) in Enum.GetEnumerator<T>())
{
ImGui.PushID(name);
if (ImGui.Selectable(name.ToScopeCStr!(), selectedValue == value))
{
selectedValue = value;
changed = true;
}
ImGui.PopID();
}
ImGui.EndCombo();
}
return changed;
}
/// Provides a tooltip that will be show when the previously defined Widget is hovered.
public static void AttachTooltip(StringView tooltip)
{
if (!ImGui.IsItemHovered())
return;
ImGui.BeginTooltip();
ImGui.TextUnformatted(tooltip);
ImGui.EndTooltip();
}
[Comptime]
private static DataType GetDataType<T>()
{
DataType dataType = .COUNT;
switch (typeof(T))
{
case typeof(int8):
dataType = .S8;
case typeof(int16):
dataType = .S16;
case typeof(int32):
dataType = .S32;
case typeof(int64):
dataType = .S64;
case typeof(int):
if (sizeof(int) == 8)
dataType = .S64;
else if (sizeof(int) == 4)
dataType = .S32;
case typeof(uint8):
dataType = .U8;
case typeof(uint16):
dataType = .U16;
case typeof(uint32):
dataType = .U32;
case typeof(uint64):
dataType = .U64;
case typeof(uint):
if (sizeof(uint) == 8)
dataType = .U64;
else if (sizeof(uint) == 4)
dataType = .U32;
//default:
// Runtime.Assert(dataType != .COUNT);
//Log.EngineLogger.Assert(dataType != .COUNT, "Unknown data type.");
}
return dataType;
}
// TODO: Add support for floats
public static bool DragScalar<T>(char8* label, ref T value, float dragSpeed = (float) 1.0f, T minValue = typeof(T).MinValue, T maxValue = typeof(T).MaxValue, char8* format = null, SliderFlags sliderFlags = .None) where T : IInteger
{
DataType dataType = GetDataType<T>();
#unwarn
return DragScalar(label, dataType, &value, dragSpeed, &minValue, &maxValue, format, sliderFlags);
}
// TODO: Add support for floats
public static bool SliderScalar<T>(char8* label, ref T value, T minValue = typeof(T).MinValue, T maxValue = typeof(T).MaxValue, char8* format = null, SliderFlags sliderFlags = .None) where T : IInteger
{
DataType dataType = GetDataType<T>();
#unwarn
return SliderScalar(label, dataType, &value, &minValue, &maxValue, format, sliderFlags);
}
}
}
@@ -125,6 +125,17 @@ namespace GlitchyEngine.Renderer
{
return .(_nativeResourceView, _samplerState.nativeSamplerState);
}
protected override void PlatformSneakySwappyTexture(RenderTarget2D otherTexture)
{
Swap!(_description, otherTexture._description);
// Consider sneaky swapping _depthStencilTarget too...
Swap!(_depthStenilTarget, otherTexture._depthStenilTarget);
Swap!(_nativeTexture, otherTexture._nativeTexture);
Swap!(_nativeRenderTargetView, otherTexture._nativeRenderTargetView);
}
}
extension RenderTargetFormat
@@ -261,6 +261,13 @@ namespace GlitchyEngine.Renderer
{
return .(_nativeResourceView, _samplerState?.nativeSamplerState);
}
protected override void PlatformSneakySwappyTexture(Texture2D otherTexture)
{
Swap!(nativeDesc, otherTexture.nativeDesc);
Swap!(nativeTexture, otherTexture.nativeTexture);
Swap!(_nativeResourceView, otherTexture._nativeResourceView);
}
}
extension TextureCube
@@ -78,6 +78,17 @@ namespace GlitchyEngine.Renderer
}
protected extern TextureViewBinding PlatformGetViewBinding();
protected internal override void SneakySwappyTexture(Texture otherTexture)
{
Log.EngineLogger.AssertDebug(otherTexture is RenderTarget2D, "Swapping texture must be a RenderTarget2D!");
SamplerState = otherTexture.SamplerState;
PlatformSneakySwappyTexture(otherTexture as RenderTarget2D);
}
protected extern void PlatformSneakySwappyTexture(RenderTarget2D otherTexture);
}
[AllowDuplicates]
+21
View File
@@ -29,6 +29,11 @@ namespace GlitchyEngine.Renderer
public abstract uint32 MipLevels {get;}
public abstract TextureViewBinding GetViewBinding();
/// Very dirtily swaps the internals with the given texture.
/// TODO: Please do this differently!!!!!!!!!!!!!!!!!!!!!!
/// This is for texture hot reloading POC, I know... it's bad...
protected internal abstract void SneakySwappyTexture(Texture otherTexture);
}
public struct Texture2DDesc
@@ -198,6 +203,17 @@ namespace GlitchyEngine.Renderer
}
protected extern TextureViewBinding PlatformGetViewBinding();
protected internal override void SneakySwappyTexture(Texture otherTexture)
{
Log.EngineLogger.AssertDebug(otherTexture is Texture2D, "Swapping texture must be a Texture2D!");
SamplerState = otherTexture.SamplerState;
PlatformSneakySwappyTexture(otherTexture as Texture2D);
}
protected extern void PlatformSneakySwappyTexture(Texture2D otherTexture);
}
public class TextureCube : Texture
@@ -234,5 +250,10 @@ namespace GlitchyEngine.Renderer
}
protected extern TextureViewBinding PlatformGetViewBinding();
protected internal override void SneakySwappyTexture(Texture otherTexture)
{
Runtime.NotImplemented();
}
}
}