Fixed Shader Instancing (with that particles and Text, aswell)
This commit is contained in:
parent
57fb71d01b
commit
fd53c73fa7
8 changed files with 60 additions and 61 deletions
|
|
@ -28,6 +28,15 @@ namespace SM.OGL.Shaders
|
|||
{
|
||||
}
|
||||
|
||||
public Uniform(string name, GenericShader shader) : this(GL.GetUniformLocation(shader, name), null)
|
||||
{
|
||||
|
||||
}
|
||||
public Uniform(string name, GenericShader shader, UniformCollection parent) : this(GL.GetUniformLocation(shader, name), parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This create a new uniform manager
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,50 +1,33 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public class UniformArray : IUniform
|
||||
{
|
||||
internal UniformCollection collection;
|
||||
private Dictionary<int, Dictionary<string, Uniform>> storedUniforms = new Dictionary<int, Dictionary<string, Uniform>>();
|
||||
internal List<string> uniformNames = new List<string>();
|
||||
|
||||
internal Dictionary<string, int> Offsets = new Dictionary<string, int>();
|
||||
internal int Size;
|
||||
|
||||
internal bool Struct = false;
|
||||
public int Location { get; internal set; }
|
||||
public GenericShader Parent { get; internal set; }
|
||||
public string Name { get; internal set; }
|
||||
public UniformCollection Parent { get; internal set; }
|
||||
public GenericShader ParentShader { get; internal set; }
|
||||
|
||||
public UniformArray()
|
||||
public Dictionary<string, Uniform> this[int index] => Get(index);
|
||||
|
||||
public Dictionary<string, Uniform> Get(int index)
|
||||
{
|
||||
collection = new UniformCollection()
|
||||
if (!storedUniforms.ContainsKey(index))
|
||||
{
|
||||
ParentShader = Parent
|
||||
};
|
||||
}
|
||||
Dictionary<string, Uniform> dic = storedUniforms[index] = new Dictionary<string, Uniform>();
|
||||
|
||||
public void Set(Action<int, Uniform> setAction)
|
||||
{
|
||||
for (var i = 0; i < Size; i++) setAction(i, new Uniform(Location + i));
|
||||
}
|
||||
|
||||
public void Set(Func<int, UniformCollection, bool> setAction)
|
||||
{
|
||||
collection.ParentShader ??= Parent;
|
||||
|
||||
for (var i = 0; i < Size; i++)
|
||||
{
|
||||
collection.KeyString = $"{Name}[{i}]";
|
||||
|
||||
foreach (var pair in Offsets)
|
||||
collection.Set(pair.Key, new Uniform(Location + pair.Value + i));
|
||||
|
||||
if (!setAction(i, collection)) break;
|
||||
for (int i = 0; i < uniformNames.Count; i++)
|
||||
{
|
||||
dic.Add(uniformNames[i], new Uniform(Name + $"[{index}]." + uniformNames[i], ParentShader, Parent));
|
||||
}
|
||||
}
|
||||
|
||||
return storedUniforms[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -82,20 +82,16 @@ namespace SM.OGL.Shaders
|
|||
{
|
||||
Location = loc,
|
||||
Name = keySplits[0],
|
||||
Parent = ParentShader,
|
||||
Struct = keySplits.Length > 2
|
||||
Parent = this,
|
||||
ParentShader = ParentShader
|
||||
};
|
||||
|
||||
arrayFilled = true;
|
||||
lastArrayKey = keySplits[0];
|
||||
}
|
||||
|
||||
var curIndex = int.Parse(keySplits[1]);
|
||||
if (array.Size < curIndex) array.Size = curIndex;
|
||||
|
||||
if (array.Struct)
|
||||
if (!array.Offsets.ContainsKey(keySplits[2].Trim('.')))
|
||||
array.Offsets.Add(keySplits[2].Trim('.'), loc - array.Location);
|
||||
if (keySplits[1] == "0")
|
||||
array.uniformNames.Add(keySplits[2].Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue