internal void DeleteProgram(glProgram Program) { int programHandle = Program.Handle; lock (this) { #if NET_STANDARD_13 _glDeleteProgram(programHandle); #else if (_CurrentThreadId == Thread.CurrentThread.ManagedThreadId) { _glDeleteProgram(programHandle); } else { if (_PendingProgramDeleteCount == _PendingProgramDelete.Length) { Array.Resize <int>(ref _PendingProgramDelete, _PendingProgramDelete.Length * 2); } _PendingProgramDelete[_PendingProgramDeleteCount] = programHandle; _PendingProgramDeleteCount++; } #endif } }
internal int GetUniformLocation(glProgram Program, string Name) { byte[] NameData = System.Text.UTF8Encoding.UTF8.GetBytes(Name); byte[] ZeroTerminated = new byte[NameData.Length + 1]; for (int n = 0; n < NameData.Length; n++) { ZeroTerminated[n] = NameData[n]; } ZeroTerminated[ZeroTerminated.Length - 1] = 0; fixed(byte *pNameData = &ZeroTerminated[0]) { return(_glGetUniformLocation(Program.Handle, new IntPtr(pNameData))); } }
internal void BindAttribLocation(glProgram Program, int Index, string Name) { byte[] NameData = System.Text.UTF8Encoding.UTF8.GetBytes(Name); byte[] ZeroTerminated = new byte[NameData.Length + 1]; for (int n = 0; n < NameData.Length; n++) { ZeroTerminated[n] = NameData[n]; } ZeroTerminated[ZeroTerminated.Length - 1] = 0; fixed(byte *pNameData = &ZeroTerminated[0]) { _glBindAttribLocation(Program.Handle, Index, new IntPtr(pNameData)); } }
internal void LinkProgram(glProgram Program) { _glLinkProgram(Program.Handle); int linkStatus = 0; _glGetProgramiv(Program.Handle, (int)glProgram.SymbolicName.GL_LINK_STATUS, new IntPtr(&linkStatus)); if (linkStatus == 0) { int logSize = 0; _glGetProgramiv(Program.Handle, (int)glProgram.SymbolicName.GL_INFO_LOG_LENGTH, new IntPtr(&logSize)); if (logSize <= 0) { throw new Exception("Failed to link the program"); } IntPtr infoLogBuffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(logSize); if (infoLogBuffer.ToInt64() == 0) { throw new Exception("Failed to link the program"); } string log = ""; try { IntPtr sizeTLogSize = new IntPtr(logSize); _glGetProgramInfoLog(Program.Handle, sizeTLogSize, new IntPtr(&sizeTLogSize), infoLogBuffer); if (sizeTLogSize.ToInt32() > 0) { byte * pLog = (byte *)infoLogBuffer.ToPointer(); byte[] data = new byte[sizeTLogSize.ToInt32()]; for (int n = 0; n < data.Length && *pLog != 0; n++) { data[n] = *pLog; pLog++; } log = System.Text.Encoding.UTF8.GetString(data); } } finally { System.Runtime.InteropServices.Marshal.FreeHGlobal(infoLogBuffer); } throw new Exception("Failed to link the program: " + log); } }
internal void UseProgram(glProgram Program) { _glUseProgram(Program.Handle); }
internal void AttachShader(glProgram Program, glShader Shader) { _glAttachShader(Program.Handle, Shader.Handle); }