Implemented Materials

- Shaders get Textureslots via reflection
- added Textureslots to Effect
This commit is contained in:
Simon Lübeß
2021-08-09 18:03:47 +02:00
parent 2326e69c0c
commit 344accea60
10 changed files with 463 additions and 75 deletions
@@ -0,0 +1,65 @@
using System;
using System.Collections;
namespace GlitchyEngine.Renderer
{
public class ShaderTextureCollection : IEnumerable<(String Name, uint32 Index, Texture Texture)>
{
public typealias ResourceEntry = (String Name, uint32 Index, Texture Texture);
List<ResourceEntry> _textures ~ DeleteTextureEntries!(_);
Dictionary<String, ResourceEntry*> _strToBuf ~ delete _;
Dictionary<int, ResourceEntry*> _idxToBuf ~ delete _;
public this()
{
let textures = new List<ResourceEntry>();
let strToBuf = new Dictionary<String, ResourceEntry*>();
let idxToBuf = new Dictionary<int, ResourceEntry*>();
_textures = textures;
_strToBuf = strToBuf;
_idxToBuf = idxToBuf;
}
mixin DeleteTextureEntries(List<ResourceEntry> entries)
{
if(entries == null)
return;
for(let entry in entries)
{
delete entry.Name;
entry.Texture?.ReleaseRef();
}
delete entries;
}
// TODO: finish implementation (like BufferCollection)
public void Add(String name, uint32 index, Texture texture)
{
Add((name, index, texture));
}
public void Add(ResourceEntry entry)
{
ResourceEntry copy = (new String(entry.Name), entry.Index, entry.Texture);
entry.Texture?.AddRef();
_textures.Add(copy);
ResourceEntry* copyRef = &_textures.Back;
_strToBuf.Add(copy.Name, copyRef);
_idxToBuf.Add(copy.Index, copyRef);
}
public List<ResourceEntry>.Enumerator GetEnumerator()
{
return _textures.GetEnumerator();
}
}
}