OpenTK GetActiveUniform句柄无效

时间:2017-12-30 06:43:10

标签: c# glsl opentk

我试图在GLSL程序中获得所有制服,但GL.GetActiveUniform正在抛出错误:

  

{System.Runtime.InteropServices.COMException(0x80070006):句柄无效。 (来自HRESULT的异常:0x80070006(E_HANDLE))System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo),位于System.Runtime.InteropServices.Marshal的System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)。 FreeHGlobal(IntPtr hglobal)at OpenTK.Graphics.OpenGL.GL.GetActiveUniform(UInt32 program,UInt32 index,Int32 bufSize,Int32& length,Int32& size,ActiveUniformType& type,StringBuilder name)}

这是我的代码:

int count = 0;

GL.GetProgram(_shader.id, GetProgramParameterName.ActiveUniforms, out count);

for (uint i = 0; i < count; i++)
{
    System.Text.StringBuilder name = new System.Text.StringBuilder();
    int length = 0,
    size = 0;
    ActiveUniformType uniformType;

    GL.GetActiveUniform((uint)(_shader.id), i, 120, out length, out size, out uniformType, name);
    int location = GL.GetUniformLocation(_shader.id, name.ToString());

    AddUniform(name.ToString().Replace(" ", ""), new Uniform(location, uniformType));
}

0 个答案:

没有答案