15.09.2020
Everything currently don't work / can't be tested. + Generic Shader-Implermentation + Mesh-System + Plate-Mesh
This commit is contained in:
parent
551d393ac2
commit
421d03f91d
24 changed files with 726 additions and 4 deletions
51
SM.Core/GLDebugging.cs
Normal file
51
SM.Core/GLDebugging.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Platform.Egl;
|
||||
|
||||
namespace SM.OGL
|
||||
{
|
||||
public static class GLDebugging
|
||||
{
|
||||
private static DebugProc _debugProc = DebugCallback;
|
||||
private static GCHandle _debugGcHandle;
|
||||
|
||||
public static Action<DebugSource, DebugType, DebugSeverity, string> DebugAction = DefaultDebugAction;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
private static void DebugCallback(DebugSource source, DebugType type, int id, DebugSeverity severity,
|
||||
int length, IntPtr message, IntPtr userparam)
|
||||
{
|
||||
string msg = Marshal.PtrToStringAnsi(message, length);
|
||||
DebugAction?.Invoke(source, type, severity, msg);
|
||||
}
|
||||
|
||||
public static void EnableDebugging()
|
||||
{
|
||||
try
|
||||
{
|
||||
_debugGcHandle = GCHandle.Alloc(_debugProc);
|
||||
|
||||
GL.DebugMessageCallback(_debugProc, IntPtr.Zero);
|
||||
GL.Enable(EnableCap.DebugOutput);
|
||||
GL.Enable(EnableCap.DebugOutputSynchronous);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Enableing proper GLDebugging failed. \n" +
|
||||
"Often it fails, because your hardware doesn't provied proper OpenGL 4 \n" +
|
||||
" or KHR_debug extension support.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void DefaultDebugAction(DebugSource source, DebugType type, DebugSeverity severity, string msg)
|
||||
{
|
||||
Console.WriteLine($"{severity}, {type}, {source} -> {msg}");
|
||||
|
||||
if (type == DebugType.DebugTypeError) throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
SM.Core/GLObject.cs
Normal file
33
SM.Core/GLObject.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL
|
||||
{
|
||||
public abstract class GLObject
|
||||
{
|
||||
protected int _id = -1;
|
||||
protected virtual bool AutoCompile { get; } = false;
|
||||
|
||||
public virtual int ID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AutoCompile && _id < 0) Compile();
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ObjectLabelIdentifier TypeIdentifier { get; }
|
||||
|
||||
protected virtual void Compile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Name(string name)
|
||||
{
|
||||
GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
|
||||
}
|
||||
|
||||
public static implicit operator int(GLObject glo) => glo.ID;
|
||||
}
|
||||
}
|
||||
44
SM.Core/Mesh/Mesh.cs
Normal file
44
SM.Core/Mesh/Mesh.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Mesh
|
||||
{
|
||||
public class Mesh : GLObject
|
||||
{
|
||||
public static int BufferSizeMultiplier = 3;
|
||||
|
||||
protected override bool AutoCompile { get; } = true;
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
|
||||
|
||||
public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles;
|
||||
|
||||
public virtual VBO Vertex { get; }
|
||||
public virtual VBO UVs { get; }
|
||||
public virtual VBO Normals { get; }
|
||||
|
||||
public virtual Dictionary<int, VBO> AttribDataIndex { get; }
|
||||
|
||||
public Mesh()
|
||||
{
|
||||
AttribDataIndex = new Dictionary<int, VBO>()
|
||||
{
|
||||
{0, Vertex},
|
||||
{1, UVs},
|
||||
{2, Normals},
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
_id = GL.GenVertexArray();
|
||||
GL.BindVertexArray(_id);
|
||||
|
||||
if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index.");
|
||||
|
||||
foreach (KeyValuePair<int, VBO> kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
SM.Core/Mesh/TypeDefinition.cs
Normal file
14
SM.Core/Mesh/TypeDefinition.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace SM.OGL.Mesh
|
||||
{
|
||||
public struct TypeDefinition
|
||||
{
|
||||
internal int PointerSize;
|
||||
|
||||
public TypeDefinition(int pointerSize)
|
||||
{
|
||||
PointerSize = pointerSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
SM.Core/Mesh/VBO.cs
Normal file
34
SM.Core/Mesh/VBO.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Mesh
|
||||
{
|
||||
public class VBO : List<float>
|
||||
{
|
||||
public BufferUsageHint BufferUsageHint = BufferUsageHint.StaticDraw;
|
||||
public VertexAttribPointerType PointerType = VertexAttribPointerType.Float;
|
||||
public int PointerSize = 3;
|
||||
public bool Normalised = false;
|
||||
public int PointerStride = 0;
|
||||
public int PointerOffset = 0;
|
||||
|
||||
public void Add(float x, float y) => AddRange(new[] {x,y});
|
||||
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
|
||||
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
|
||||
|
||||
public void BindBuffer(int attribID)
|
||||
{
|
||||
float[] data = ToArray();
|
||||
|
||||
int buffer = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * Mesh.BufferSizeMultiplier, data, BufferUsageHint);
|
||||
|
||||
GL.VertexAttribPointer(attribID, PointerSize, PointerType, Normalised, PointerStride, PointerOffset);
|
||||
GL.EnableVertexAttribArray(attribID);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
SM.Core/OpenTK.dll.config
Normal file
25
SM.Core/OpenTK.dll.config
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
|
||||
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
|
||||
<!-- XQuartz compatibility (X11 on Mac) -->
|
||||
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
|
||||
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
|
||||
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
|
||||
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
|
||||
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
|
||||
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
|
||||
</configuration>
|
||||
|
|
@ -7,8 +7,8 @@
|
|||
<ProjectGuid>{F604D684-BC1D-4819-88B5-8B5D03A17BE0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM.Core</RootNamespace>
|
||||
<AssemblyName>SM.Core</AssemblyName>
|
||||
<RootNamespace>SM.OGL</RootNamespace>
|
||||
<AssemblyName>SM.OGL</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
|
@ -31,6 +31,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK, Version=3.2.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.3.2\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
|
@ -41,7 +44,22 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GLDebugging.cs" />
|
||||
<Compile Include="GLObject.cs" />
|
||||
<Compile Include="Mesh\Mesh.cs" />
|
||||
<Compile Include="Mesh\TypeDefinition.cs" />
|
||||
<Compile Include="Mesh\VBO.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Shaders\GenericShader.cs" />
|
||||
<Compile Include="Shaders\ShaderFileCollection.cs" />
|
||||
<Compile Include="Shaders\ShaderFile.cs" />
|
||||
<Compile Include="Shaders\Uniform.cs" />
|
||||
<Compile Include="Shaders\UniformCollection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
50
SM.Core/Shaders/GenericShader.cs
Normal file
50
SM.Core/Shaders/GenericShader.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public class GenericShader : GLObject
|
||||
{
|
||||
protected ShaderFileCollection ShaderFileFiles;
|
||||
protected UniformCollection Uniforms;
|
||||
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
|
||||
|
||||
public GenericShader(ShaderFileCollection shaderFileFiles)
|
||||
{
|
||||
ShaderFileFiles = shaderFileFiles;
|
||||
}
|
||||
|
||||
public void Compile()
|
||||
{
|
||||
|
||||
_id = GL.CreateProgram();
|
||||
|
||||
ShaderFileFiles.Append(this);
|
||||
GL.LinkProgram(_id);
|
||||
this.Name(GetType().Name);
|
||||
ShaderFileFiles.Detach(this);
|
||||
|
||||
GL.GetProgram(_id, GetProgramParameterName.ActiveUniforms, out int uniformCount);
|
||||
if (uniformCount < 1)
|
||||
throw new Exception("[Critical] No uniforms has been found.");
|
||||
|
||||
Uniforms = new UniformCollection();
|
||||
for (int i = 0; i < uniformCount; i++)
|
||||
{
|
||||
string key = GL.GetActiveUniform(_id, i, out _, out _);
|
||||
int loc = GL.GetUniformLocation(_id, key);
|
||||
|
||||
if (key.StartsWith("[")) key = key.Split('[', ']')[0];
|
||||
Uniforms.Add(key, loc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DrawObject(Mesh.Mesh mesh, bool bindVAO)
|
||||
{
|
||||
if (bindVAO) GL.BindVertexArray(mesh);
|
||||
GL.DrawArrays(mesh.PrimitiveType, 0, mesh.Vertex.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
SM.Core/Shaders/ShaderFile.cs
Normal file
40
SM.Core/Shaders/ShaderFile.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public class ShaderFile : GLObject
|
||||
{
|
||||
private string _data;
|
||||
|
||||
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
|
||||
|
||||
public Dictionary<string, string> StringOverrides = new Dictionary<string, string>();
|
||||
public List<ShaderFile> GLSLExtensions = new List<ShaderFile>();
|
||||
|
||||
public ShaderFile(string data)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
private void GenerateSource()
|
||||
{
|
||||
foreach (KeyValuePair<string, string> kvp in StringOverrides)
|
||||
_data = _data.Replace("//! " + kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
internal void Compile(GenericShader shader, ShaderType type)
|
||||
{
|
||||
if (_id < 0)
|
||||
{
|
||||
GenerateSource();
|
||||
|
||||
_id = GL.CreateShader(type);
|
||||
GL.ShaderSource(_id, _data);
|
||||
GL.CompileShader(_id);
|
||||
}
|
||||
GL.AttachShader(_id, shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
SM.Core/Shaders/ShaderFileCollection.cs
Normal file
34
SM.Core/Shaders/ShaderFileCollection.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public struct ShaderFileCollection
|
||||
{
|
||||
public ShaderFile Vertex;
|
||||
public ShaderFile Geometry;
|
||||
public ShaderFile Fragment;
|
||||
|
||||
public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex), new ShaderFile(fragment)) {}
|
||||
|
||||
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
|
||||
{
|
||||
Vertex = vertex;
|
||||
Geometry = geometry;
|
||||
Fragment = fragment;
|
||||
}
|
||||
|
||||
internal void Append(GenericShader shader)
|
||||
{
|
||||
Vertex.Compile(shader, ShaderType.VertexShader);
|
||||
Geometry?.Compile(shader, ShaderType.GeometryShader);
|
||||
Fragment.Compile(shader, ShaderType.FragmentShader);
|
||||
}
|
||||
|
||||
internal void Detach(GenericShader shader)
|
||||
{
|
||||
GL.DetachShader(Vertex, shader);
|
||||
if (Geometry != null) GL.DetachShader(Geometry, shader);
|
||||
GL.DetachShader(Fragment, shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
164
SM.Core/Shaders/Uniform.cs
Normal file
164
SM.Core/Shaders/Uniform.cs
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public struct Uniform
|
||||
{
|
||||
/// <summary>
|
||||
/// This contains the location for the uniform.
|
||||
/// </summary>
|
||||
private int Location;
|
||||
/// <summary>
|
||||
/// This contains the Parent collection of this uniform.
|
||||
/// </summary>
|
||||
internal UniformCollection Parent;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This create a new uniform manager
|
||||
/// </summary>
|
||||
/// <param name="location">Location id</param>
|
||||
/// <param name="parent">Parent collection</param>
|
||||
public Uniform(int location, UniformCollection parent)
|
||||
{
|
||||
Location = location;
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
#region Uniform1
|
||||
|
||||
public void SetUniform1(bool value)
|
||||
{
|
||||
GL.Uniform1(Location, value ? 1 : 0);
|
||||
}
|
||||
|
||||
public void SetUniform1(int value) { GL.Uniform1(Location, value); }
|
||||
public void SetUniform1(int count, params int[] values) { GL.Uniform1(Location, count, values); }
|
||||
public void SetUniform1(int count, ref int values) { GL.Uniform1(Location, count, ref values); }
|
||||
|
||||
|
||||
public void SetUniform1(uint value) { GL.Uniform1(Location, value); }
|
||||
public void SetUniform1(int count, params uint[] values) { GL.Uniform1(Location, count, values); }
|
||||
public void SetUniform1(int count, ref uint values) { GL.Uniform1(Location, count, ref values); }
|
||||
|
||||
|
||||
public void SetUniform1(float value) { GL.Uniform1(Location, value); }
|
||||
public void SetUniform1(int count, params float[] values) { GL.Uniform1(Location, count, values); }
|
||||
public void SetUniform1(int count, ref float value) { GL.Uniform1(Location, count, ref value); }
|
||||
|
||||
|
||||
public void SetUniform1(double value) { GL.Uniform1(Location, value); }
|
||||
public void SetUniform1(int count, params double[] values) { GL.Uniform1(Location, count, values); }
|
||||
public void SetUniform1(int count, ref double value) { GL.Uniform1(Location, count, ref value); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Uniform2
|
||||
|
||||
public void SetUniform2(float x, float y) { GL.Uniform2(Location, x, y); }
|
||||
public void SetUniform2(double x, double y) { GL.Uniform2(Location, x, y); }
|
||||
public void SetUniform2(uint x, uint y) { GL.Uniform2(Location, x, y); }
|
||||
public void SetUniform2(int x, int y) { GL.Uniform2(Location, x, y); }
|
||||
|
||||
public void SetUniform2(int count, params float[] values) { GL.Uniform2(Location, count, values); }
|
||||
public void SetUniform2(int count, params double[] values) { GL.Uniform2(Location, count, values); }
|
||||
public void SetUniform2(int count, params int[] values) { GL.Uniform2(Location, count, values); }
|
||||
public void SetUniform2(int count, params uint[] values) { GL.Uniform2(Location, count, values); }
|
||||
|
||||
public void SetUniform2(int count, ref float values) { GL.Uniform2(Location, count, ref values); }
|
||||
public void SetUniform2(int count, ref double values) { GL.Uniform2(Location, count, ref values); }
|
||||
public void SetUniform2(int count, ref uint values) { GL.Uniform2(Location, count, ref values); }
|
||||
|
||||
public void SetUniform2(Vector2 vector2) { GL.Uniform2(Location, vector2); }
|
||||
public void SetUniform2(ref Vector2 vector2) { GL.Uniform2(Location, ref vector2); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Uniform3
|
||||
|
||||
public void SetUniform3(float x, float y, float z) { GL.Uniform3(Location, x, y, z); }
|
||||
public void SetUniform3(double x, double y, double z) { GL.Uniform3(Location, x, y, z); }
|
||||
public void SetUniform3(uint x, uint y, uint z) { GL.Uniform3(Location, x, y, z); }
|
||||
public void SetUniform3(int x, int y, int z) { GL.Uniform3(Location, x, y, z); }
|
||||
|
||||
public void SetUniform3(int count, params float[] values) { GL.Uniform3(Location, count, values); }
|
||||
public void SetUniform3(int count, params double[] values) { GL.Uniform3(Location, count, values); }
|
||||
public void SetUniform3(int count, params int[] values) { GL.Uniform3(Location, count, values); }
|
||||
public void SetUniform3(int count, params uint[] values) { GL.Uniform3(Location, count, values); }
|
||||
|
||||
public void SetUniform3(int count, ref float values) { GL.Uniform3(Location, count, ref values); }
|
||||
public void SetUniform3(int count, ref double values) { GL.Uniform3(Location, count, ref values); }
|
||||
public void SetUniform3(int count, ref uint values) { GL.Uniform3(Location, count, ref values); }
|
||||
|
||||
public void SetUniform3(Vector3 vector) { GL.Uniform3(Location, vector); }
|
||||
public void SetUniform3(ref Vector3 vector) { GL.Uniform3(Location, ref vector); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Uniform4
|
||||
|
||||
public void SetUniform4(float x, float y, float z, float w) { GL.Uniform4(Location, x, y, z, w); }
|
||||
public void SetUniform4(double x, double y, double z, double w) { GL.Uniform4(Location, x, y, z, w); }
|
||||
public void SetUniform4(uint x, uint y, uint z, uint w) { GL.Uniform4(Location, x, y, z, w); }
|
||||
public void SetUniform4(int x, int y, int z, int w) { GL.Uniform4(Location, x, y, z, w); }
|
||||
|
||||
public void SetUniform4(int count, params float[] values) { GL.Uniform4(Location, count, values); }
|
||||
public void SetUniform4(int count, params double[] values) { GL.Uniform4(Location, count, values); }
|
||||
public void SetUniform4(int count, params int[] values) { GL.Uniform4(Location, count, values); }
|
||||
public void SetUniform4(int count, params uint[] values) { GL.Uniform4(Location, count, values); }
|
||||
|
||||
public void SetUniform4(int count, ref float values) { GL.Uniform4(Location, count, ref values); }
|
||||
public void SetUniform4(int count, ref double values) { GL.Uniform4(Location, count, ref values); }
|
||||
public void SetUniform4(int count, ref uint values) { GL.Uniform4(Location, count, ref values); }
|
||||
|
||||
public void SetUniform4(Vector4 vector) { GL.Uniform4(Location, vector); }
|
||||
public void SetUniform4(ref Vector4 vector) { GL.Uniform4(Location, ref vector); }
|
||||
|
||||
public void SetUniform4(Color4 color) { GL.Uniform4(Location, color); }
|
||||
public void SetUniform4(Quaternion quaternion) { GL.Uniform4(Location, quaternion); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Matrix2
|
||||
|
||||
public void SetMatrix2(ref Matrix2 matrix, bool transpose = false) { GL.UniformMatrix2(Location, transpose, ref matrix); }
|
||||
|
||||
public void SetMatrix2(int count, ref double value, bool transpose = false) { GL.UniformMatrix2(Location, count, transpose, ref value); }
|
||||
public void SetMatrix2(int count, ref float value, bool transpose = false) { GL.UniformMatrix2(Location, count, transpose, ref value); }
|
||||
|
||||
public void SetMatrix2(int count, double[] value, bool transpose = false) { GL.UniformMatrix2(Location, count, transpose, value); }
|
||||
public void SetMatrix2(int count, float[] value, bool transpose = false) { GL.UniformMatrix2(Location, count, transpose, value); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Matrix3
|
||||
|
||||
public void SetMatrix3(ref Matrix3 matrix, bool transpose = false) { GL.UniformMatrix3(Location, transpose, ref matrix); }
|
||||
|
||||
public void SetMatrix3(int count, ref double value, bool transpose = false) { GL.UniformMatrix3(Location, count, transpose, ref value); }
|
||||
public void SetMatrix3(int count, ref float value, bool transpose = false) { GL.UniformMatrix3(Location, count, transpose, ref value); }
|
||||
|
||||
public void SetMatrix3(int count, double[] value, bool transpose = false) { GL.UniformMatrix3(Location, count, transpose, value); }
|
||||
public void SetMatrix3(int count, float[] value, bool transpose = false) { GL.UniformMatrix3(Location, count, transpose, value); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Matrix4
|
||||
|
||||
public void SetMatrix4(Matrix4 matrix, bool transpose = false)
|
||||
{
|
||||
GL.UniformMatrix4(Location, transpose, ref matrix);
|
||||
}
|
||||
public void SetMatrix4(ref Matrix4 matrix, bool transpose = false) { GL.UniformMatrix4(Location, transpose, ref matrix); }
|
||||
|
||||
public void SetMatrix4(int count, ref double value, bool transpose = false) { GL.UniformMatrix4(Location, count, transpose, ref value); }
|
||||
public void SetMatrix4(int count, ref float value, bool transpose = false) { GL.UniformMatrix4(Location, count, transpose, ref value); }
|
||||
|
||||
public void SetMatrix4(int count, double[] value, bool transpose = false) { GL.UniformMatrix4(Location, count, transpose, value); }
|
||||
public void SetMatrix4(int count, float[] value, bool transpose = false) { GL.UniformMatrix4(Location, count, transpose, value); }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
34
SM.Core/Shaders/UniformCollection.cs
Normal file
34
SM.Core/Shaders/UniformCollection.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL.Shaders
|
||||
{
|
||||
public class UniformCollection : Dictionary<string, Uniform>
|
||||
{
|
||||
internal GenericShader _parentShader;
|
||||
|
||||
public new Uniform this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return base[key];
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
Console.WriteLine("[Error] Uniform '"+key+"' was not found. Tried to recreate it.");
|
||||
Uniform u = new Uniform(GL.GetUniformLocation(_parentShader, key), this);
|
||||
Add(key, u);
|
||||
return u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(string key, int location)
|
||||
{
|
||||
base.Add(key, new Uniform(location, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
4
SM.Core/packages.config
Normal file
4
SM.Core/packages.config
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="3.2" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue