Added manual VAO usage, moved shader assignment to Trace log
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Diamond.Shaders
|
||||
}
|
||||
|
||||
GL.UseProgram(program?.Id ?? 0);
|
||||
Logger.Debug("Using {0}", (object) program ?? "default program");
|
||||
Logger.Trace("Using {0}", (object) program ?? "default program");
|
||||
|
||||
_current = program;
|
||||
}
|
||||
|
||||
@@ -20,32 +20,69 @@ namespace hexworld
|
||||
Y = (DisplayDevice.Default.Height - Height) / 2;
|
||||
}
|
||||
|
||||
private Program _pgm;
|
||||
private Buffer<float> _buf;
|
||||
private int _triVao;
|
||||
private Buffer<float> _triVbo;
|
||||
private Program _whitePgm;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUnload(EventArgs e)
|
||||
{
|
||||
base.OnUnload(e);
|
||||
|
||||
_pgm?.Dispose();
|
||||
}
|
||||
private int _recVao;
|
||||
private Buffer<float> _recVbo;
|
||||
private Program _redPgm;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
_pgm = Program.FromFiles("res/obj.fs.glsl", "res/obj.vs.glsl");
|
||||
var vs = Shader.FromFile("res/direct.vs.glsl");
|
||||
var red = Shader.FromFile("res/red.fs.glsl");
|
||||
var white = Shader.FromFile("res/white.fs.glsl");
|
||||
_whitePgm = Program.FromShaders(vs, red);
|
||||
_redPgm = Program.FromShaders(vs, white);
|
||||
|
||||
Program.Current = _pgm;
|
||||
|
||||
_buf = Buffer.FromData(new float[]
|
||||
_triVbo = Buffer.FromData(new float[]
|
||||
{
|
||||
-.8f, -.8f,
|
||||
+.8f, -.8f,
|
||||
+.0f, +.8f
|
||||
});
|
||||
_triVao = GL.GenVertexArray();
|
||||
GL.BindVertexArray(_triVao);
|
||||
Program.Current = _redPgm;
|
||||
Buffer.ArrayBuffer = _triVbo;
|
||||
GL.EnableVertexAttribArray(0);
|
||||
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, 0);
|
||||
|
||||
_recVbo = Buffer.FromData(new float[]
|
||||
{
|
||||
-.9f, -.5f,
|
||||
+.9f, -.5f,
|
||||
+.9f, +.5f,
|
||||
+.9f, +.5f,
|
||||
-.9f, +.5f,
|
||||
-.9f, -.5f,
|
||||
});
|
||||
_recVao = GL.GenVertexArray();
|
||||
GL.BindVertexArray(_recVao);
|
||||
Program.Current = _whitePgm;
|
||||
Buffer.ArrayBuffer = _recVbo;
|
||||
GL.EnableVertexAttribArray(0);
|
||||
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, 0);
|
||||
|
||||
vs?.Dispose();
|
||||
red?.Dispose();
|
||||
white?.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUnload(EventArgs e)
|
||||
{
|
||||
base.OnUnload(e);
|
||||
|
||||
_triVbo?.Dispose();
|
||||
_recVbo?.Dispose();
|
||||
|
||||
_whitePgm?.Dispose();
|
||||
_redPgm?.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -57,6 +94,14 @@ namespace hexworld
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
|
||||
Program.Current = _redPgm;
|
||||
GL.BindVertexArray(_triVao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
|
||||
|
||||
Program.Current = _whitePgm;
|
||||
GL.BindVertexArray(_recVao);
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,15 @@
|
||||
<None Include="res\obj.fs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="res\red.fs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="res\white.fs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="res\direct.vs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="res\obj.vs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
8
hexworld/res/direct.vs.glsl
Normal file
8
hexworld/res/direct.vs.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 440
|
||||
|
||||
in vec3 v;
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_Position = vec4(v, 1);
|
||||
}
|
||||
6
hexworld/res/red.fs.glsl
Normal file
6
hexworld/res/red.fs.glsl
Normal file
@@ -0,0 +1,6 @@
|
||||
#version 440
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_FragColor = vec4(1,0,0,1);
|
||||
}
|
||||
6
hexworld/res/white.fs.glsl
Normal file
6
hexworld/res/white.fs.glsl
Normal file
@@ -0,0 +1,6 @@
|
||||
#version 440
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_FragColor = vec4(1);
|
||||
}
|
||||
Reference in New Issue
Block a user