mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Allow changing Effect of Materials
+ TextureDimension Property for Texture
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
{_recentScenes=["Assets\\Scenes\\physics2D.scene"]}
|
||||||
@@ -60,8 +60,37 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
|
|||||||
if (material == null)
|
if (material == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ImGui.TextUnformatted("Effect: ");
|
||||||
|
ImGui.SameLine();
|
||||||
|
|
||||||
Effect effect = material?.Effect;
|
Effect effect = material?.Effect;
|
||||||
|
|
||||||
|
StringView effectName = (effect?.Identifier ?? "(None)");
|
||||||
|
|
||||||
|
ImGui.Button(effectName.ToScopeCStr!());
|
||||||
|
|
||||||
|
ImGui.AttachTooltip(effectName);
|
||||||
|
|
||||||
|
// Effect drop target
|
||||||
|
if (ImGui.BeginDragDropTarget())
|
||||||
|
{
|
||||||
|
ImGui.Payload* payload = ImGui.AcceptDragDropPayload(.ContentBrowserItem);
|
||||||
|
|
||||||
|
if (payload != null)
|
||||||
|
{
|
||||||
|
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
|
||||||
|
|
||||||
|
AssetHandle<Effect> newEffect = Content.LoadAsset(path);
|
||||||
|
|
||||||
|
material.Effect = newEffect;
|
||||||
|
|
||||||
|
//newTexture.Get().SamplerState = SamplerStateManager.AnisotropicWrap;
|
||||||
|
//material.SetTexture(texture.key, newTexture.Cast<Texture>());
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndDragDropTarget();
|
||||||
|
}
|
||||||
|
|
||||||
if (effect == null)
|
if (effect == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class ProjectUserSettings
|
|||||||
|
|
||||||
public void RestoreDefaults()
|
public void RestoreDefaults()
|
||||||
{
|
{
|
||||||
//_lastOpenedScene?.Clear();
|
|
||||||
if (_recentScenes != null)
|
if (_recentScenes != null)
|
||||||
ClearAndDeleteItems!(_recentScenes);
|
ClearAndDeleteItems!(_recentScenes);
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,27 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public enum ShaderVariableType
|
public enum ShaderVariableType
|
||||||
{
|
{
|
||||||
Bool,
|
case Bool;
|
||||||
Float,
|
case Float;
|
||||||
Int,
|
case Int;
|
||||||
UInt
|
case UInt;
|
||||||
// todo
|
// todo
|
||||||
|
|
||||||
|
public int ElementSizeInBytes()
|
||||||
|
{
|
||||||
|
switch (this)
|
||||||
|
{
|
||||||
|
case .Bool:
|
||||||
|
return 1;
|
||||||
|
case .Float:
|
||||||
|
return 4;
|
||||||
|
case .Int:
|
||||||
|
return 4;
|
||||||
|
case .UInt:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,31 +14,62 @@ public class Material : Asset
|
|||||||
|
|
||||||
private uint8[] _rawVariables ~ delete _;
|
private uint8[] _rawVariables ~ delete _;
|
||||||
|
|
||||||
private Dictionary<String, (AssetHandle<Texture> Handle, TextureDimension Dimension)> _textures = new .() ~ delete _;
|
private Dictionary<String, (AssetHandle<Texture> Handle, TextureDimension Dimension)> _textures = new .() ~ DeleteDictionaryAndKeys!(_);
|
||||||
|
|
||||||
private Dictionary<String, (uint32 Offset, BufferVariable Variable)> _variables = new .() ~ delete _;
|
private Dictionary<String, (uint32 Offset, BufferVariable Variable)> _variables = new .() ~ DeleteDictionaryAndKeys!(_);
|
||||||
|
|
||||||
public Effect Effect => _effect;
|
public Effect Effect
|
||||||
|
|
||||||
public this(Effect effect)
|
|
||||||
{
|
{
|
||||||
_effect = effect..AddRef();
|
get => _effect;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetReference!(_effect, value);
|
||||||
|
|
||||||
|
if (_effect == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: get variables from effect
|
// TODO: get variables from effect
|
||||||
|
decltype(_textures) newTextures = new .();
|
||||||
|
|
||||||
// Get texture slots from effect
|
// Get texture slots from effect
|
||||||
for(let (name, entry) in _effect.Textures)
|
for(let (name, effectTexture) in _effect.Textures)
|
||||||
{
|
{
|
||||||
// TODO: We need to be able to define default textures in the shader.
|
// TODO: We need to be able to define default textures in the shader.
|
||||||
// At least things like "Black", "White", "Normal"
|
// At least things like "Black", "White", "Normal"
|
||||||
// At best whole paths. Shouldn't be that hard to do...
|
// At best whole paths. Shouldn't be that hard to do...
|
||||||
/*var texture = entry.BoundTexture;*/
|
|
||||||
|
|
||||||
_textures.Add(name, (AssetHandle<Texture>.Invalid, entry.TextureDimension));
|
AssetHandle<Texture> textureHandle = .Invalid;
|
||||||
|
|
||||||
|
if (_textures.TryGetValue(name, let oldMaterialTexture))
|
||||||
|
{
|
||||||
|
textureHandle = oldMaterialTexture.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textureHandle.IsValid)
|
||||||
|
{
|
||||||
|
if (textureHandle.Dimension != effectTexture.TextureDimension)
|
||||||
|
textureHandle = .Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
_textures[new String(name)] = (textureHandle, effectTexture.TextureDimension);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteDictionaryAndKeys!(_textures);
|
||||||
|
_textures = newTextures;
|
||||||
|
|
||||||
InitRawData();
|
InitRawData();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public this()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public this(Effect effect)
|
||||||
|
{
|
||||||
|
Effect = effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief Initializes the raw data array for the variables.
|
/** @brief Initializes the raw data array for the variables.
|
||||||
@@ -47,14 +78,44 @@ public class Material : Asset
|
|||||||
{
|
{
|
||||||
uint32 bufferSize = 0;
|
uint32 bufferSize = 0;
|
||||||
|
|
||||||
|
decltype(_variables) newVariables = new Dictionary<String, (uint32 Offset, BufferVariable Variable)>();
|
||||||
|
|
||||||
for(let variable in _effect.Variables)
|
for(let variable in _effect.Variables)
|
||||||
{
|
{
|
||||||
_variables.Add(variable.Name, (bufferSize, variable));
|
newVariables.Add(new .(variable.Name), (bufferSize, variable));
|
||||||
|
|
||||||
bufferSize += variable._sizeInBytes;
|
bufferSize += variable._sizeInBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rawVariables = new uint8[bufferSize];
|
uint8[] newData = new uint8[bufferSize];
|
||||||
|
|
||||||
|
for (let (newKey, newValue) in newVariables)
|
||||||
|
{
|
||||||
|
if (_variables.TryGetValue(newKey, let oldEntry))
|
||||||
|
{
|
||||||
|
if (oldEntry.Variable.Type == newValue.Variable.Type)
|
||||||
|
{
|
||||||
|
int elementSize = newValue.Variable.Type.ElementSizeInBytes();
|
||||||
|
|
||||||
|
for (int r = 0; r < Math.Min(oldEntry.Variable.Rows, newValue.Variable.Rows); r++)
|
||||||
|
for (int c = 0; c < Math.Min(oldEntry.Variable.Columns, newValue.Variable.Columns); c++)
|
||||||
|
{
|
||||||
|
int oldElementIndex = r * oldEntry.Variable.Columns + c;
|
||||||
|
int newElementIndex = r * newValue.Variable.Columns + c;
|
||||||
|
|
||||||
|
Internal.MemCpy(newData.Ptr + (newValue.Offset + elementSize * oldElementIndex),
|
||||||
|
_rawVariables.Ptr + (oldEntry.Offset + elementSize * newElementIndex), elementSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: we could try to convert e.g. Int <-> Float
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _rawVariables;
|
||||||
|
_rawVariables = newData;
|
||||||
|
|
||||||
|
DeleteDictionaryAndKeys!(_variables);
|
||||||
|
_variables = newVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
public override uint32 MipLevels => _description.MipLevels;
|
public override uint32 MipLevels => _description.MipLevels;
|
||||||
public override Format Format => _description.PixelFormat;
|
public override Format Format => _description.PixelFormat;
|
||||||
|
|
||||||
|
public override TextureDimension Dimension => .Texture2D;
|
||||||
|
|
||||||
protected internal DepthStencilTarget _depthStenilTarget ~ _?.ReleaseRef();
|
protected internal DepthStencilTarget _depthStenilTarget ~ _?.ReleaseRef();
|
||||||
|
|
||||||
// TODO: DepthStencilTarget is just a renderTarget
|
// TODO: DepthStencilTarget is just a renderTarget
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
|
|
||||||
public abstract Format Format {get;}
|
public abstract Format Format {get;}
|
||||||
|
|
||||||
|
public abstract TextureDimension Dimension {get;}
|
||||||
|
|
||||||
public abstract TextureViewBinding GetViewBinding();
|
public abstract TextureViewBinding GetViewBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +84,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
//public override extern uint32 ArraySize {get;}
|
//public override extern uint32 ArraySize {get;}
|
||||||
//public override extern uint32 MipLevels {get;}
|
//public override extern uint32 MipLevels {get;}
|
||||||
|
|
||||||
|
public override TextureDimension Dimension => .Texture2D;
|
||||||
|
|
||||||
public this(Texture2DDesc desc)
|
public this(Texture2DDesc desc)
|
||||||
{
|
{
|
||||||
PrepareTexturePlatform(desc, false);
|
PrepareTexturePlatform(desc, false);
|
||||||
@@ -163,6 +167,8 @@ namespace GlitchyEngine.Renderer
|
|||||||
// public override extern uint32 ArraySize {get;}
|
// public override extern uint32 ArraySize {get;}
|
||||||
// public override extern uint32 MipLevels {get;}
|
// public override extern uint32 MipLevels {get;}
|
||||||
|
|
||||||
|
public override TextureDimension Dimension => .TextureCube;
|
||||||
|
|
||||||
public this(Texture2DDesc desc)
|
public this(Texture2DDesc desc)
|
||||||
{
|
{
|
||||||
PrepareTexturePlatform(desc, false);
|
PrepareTexturePlatform(desc, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user