Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
OpenTK binding changes:
Browse files Browse the repository at this point in the history
Made the GL program handle public accessable via a property.
Exposed a method to retrieve the compiled GL source.
  • Loading branch information
WolfgangSt committed Sep 19, 2011
1 parent 25a5ac5 commit 7f2c0a8
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions IIS.SLSharp.Bindings.OpenTK/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
using System.Collections.Generic;
using IIS.SLSharp.Descriptions;
using OpenTK.Graphics.OpenGL;
using System.Linq;

namespace IIS.SLSharp.Bindings.OpenTK
{
sealed class Program: IProgram
{
private int _name;
public int Name { get; private set; }

public List<VariableDescription> VertexIns { get; private set; }

public Program(IEnumerable<Tuple<int, SourceDescription>> units)
{
_name = GL.CreateProgram();
Name = GL.CreateProgram();

var merged = SourceDescription.Empty;
foreach (var unit in units)
{
GL.AttachShader(_name, unit.Item1);
GL.AttachShader(Name, unit.Item1);
merged = merged.Merge(unit.Item2);
}
VertexIns = merged.VertexIns;

GL.LinkProgram(_name);
GL.LinkProgram(Name);
Utilities.CheckGL();
}

public void Dispose()
{
if (_name != 0)
GL.DeleteProgram(_name);
_name = 0;
if (Name != 0)
GL.DeleteProgram(Name);
Name = 0;
}

public void Activate()
{
GL.UseProgram(_name);
GL.UseProgram(Name);
Utilities.CheckGL();
}

Expand All @@ -47,16 +48,31 @@ public void Finish()

public int GetUniformIndex(string name)
{
var result = GL.GetUniformLocation(_name, name);
var result = GL.GetUniformLocation(Name, name);
Utilities.CheckGL();
return result;
}

public int GetAttributeIndex(string name)
{
var result = GL.GetAttribLocation(_name, name);
var result = GL.GetAttribLocation(Name, name);
Utilities.CheckGL();
return result;
}

public Tuple<byte[], BinaryFormat> GetBinary()
{
int length;
GL.GetProgram(Name, ProgramParameter.ProgramBinaryLength, out length);

var bin = new byte[length];
BinaryFormat format;
int numRead;
GL.GetProgramBinary(Name, length, out numRead, out format, bin);
if (numRead < length)
bin = bin.Take(length).ToArray();

return new Tuple<byte[], BinaryFormat>(bin, format);
}
}
}

0 comments on commit 7f2c0a8

Please sign in to comment.