-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenGL_Object.cs
More file actions
51 lines (42 loc) · 1.39 KB
/
OpenGL_Object.cs
File metadata and controls
51 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using OpenGL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Licenta_ver1
{
/// <summary>
/// Shader object abstraction.
/// </summary>
public class OpenGL_Object : IDisposable
{
public OpenGL_Object(ShaderType shaderType, string[] source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
// Create
ShaderName = Gl.CreateShader(shaderType);
// Submit source code
Gl.ShaderSource(ShaderName, source);
// Compile
Gl.CompileShader(ShaderName);
// Check compilation status
int compiled;
Gl.GetShader(ShaderName, ShaderParameterName.CompileStatus, out compiled);
if (compiled != 0)
return;
// Throw exception on compilation errors
const int logMaxLength = 1024;
StringBuilder infolog = new StringBuilder(logMaxLength);
int infologLength;
Gl.GetShaderInfoLog(ShaderName, logMaxLength, out infologLength, infolog);
throw new InvalidOperationException($"unable to compile shader: {infolog}");
}
public readonly uint ShaderName;
public void Dispose()
{
Gl.DeleteShader(ShaderName);
}
}
}