-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLObject.cs
98 lines (90 loc) · 3.22 KB
/
GLObject.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using GLGraphics.Helpers;
using System;
using OpenTK.Graphics.OpenGL4;
using System.Text;
using System.Diagnostics;
namespace GLGraphics
{
public abstract class GLObject : IDisposable
{
public static bool SuppressGC = false;
protected GLObject(GLObjectType ObjectType)
{
GLObjectType = ObjectType;
}
public GLObjectType GLObjectType { get; protected set; }
public int Handle { get; protected set; }
private bool disposed;
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
GLObjectCleaner.Clean((GLObjectType, Handle));
}
else
{
//Delegate cleanup to the object cleaner in order to avoid threading issues
GLObjectCleaner.ObjectsToBeCleaned.Add((GLObjectType, Handle));
}
disposed = true;
}
}
public void SetLabel(string label)
{
switch (GLObjectType)
{
case GLObjectType.VertexArray:
GL.ObjectLabel(ObjectLabelIdentifier.VertexArray, Handle, label.Length, label);
break;
case GLObjectType.Program:
GL.ObjectLabel(ObjectLabelIdentifier.Program, Handle, label.Length, label);
break;
case GLObjectType.FrameBuffer:
GL.ObjectLabel(ObjectLabelIdentifier.Framebuffer, Handle, label.Length, label);
break;
case GLObjectType.Sampler:
GL.ObjectLabel(ObjectLabelIdentifier.Sampler, Handle, label.Length, label);
break;
case GLObjectType.ProgramPipeline:
GL.ObjectLabel(ObjectLabelIdentifier.ProgramPipeline, Handle, label.Length, label);
break;
case GLObjectType.Buffer:
GL.ObjectLabel(ObjectLabelIdentifier.Buffer, Handle, label.Length, label);
break;
case GLObjectType.Shader:
GL.ObjectLabel(ObjectLabelIdentifier.Shader, Handle, label.Length, label);
break;
case GLObjectType.Texture:
GL.ObjectLabel(ObjectLabelIdentifier.Texture, Handle, label.Length, label);
break;
case GLObjectType.RenderBuffer:
GL.ObjectLabel(ObjectLabelIdentifier.Renderbuffer, Handle, label.Length, label);
break;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public override bool Equals(object? obj)
{
return obj is GLObject @object &&
GLObjectType == @object.GLObjectType &&
Handle == @object.Handle;
}
public override int GetHashCode()
{
return HashCode.Combine(GLObjectType, Handle);
}
~GLObject()
{
if (!SuppressGC)
{
Dispose(false);
}
}
}
}