forked from skeeto/sample-java-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlBuffer.java
More file actions
52 lines (43 loc) · 1.24 KB
/
GlBuffer.java
File metadata and controls
52 lines (43 loc) · 1.24 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
52
package com.nullprogram.lwjgl;
import java.nio.Buffer;
import lombok.Getter;
import org.lwjgl.opengl.GL15;
/**
* An OpenGL buffer object, the abstract base class. Because the LWJGL
* API depends highly on the <i>type</i> of the underlying Buffer, it
* is generic and each subclass takes on a different Buffer subclass.
*/
public abstract class GlBuffer {
/** OpenGL handle for this buffer. */
@Getter
private final int handle;
/** True of this buffer has been disposed. */
private boolean disposed = false;
/** Native buffer that backs this buffer. */
@Getter
private final Buffer buffer;
/**
* Create a new buffer.
* @param id the buffer's handle
* @param data the native buffer backing this buffer
*/
protected GlBuffer(final int id, final Buffer data) {
handle = id;
buffer = data;
}
/**
* Disposes of this shader and the system resources it is
* using. This can be safely called multiple times, but it is not
* thread-safe.
*/
public void dispose() {
if (!disposed) {
GL15.glDeleteBuffers(handle);
disposed = true;
}
}
@Override
protected void finalize() {
dispose();
}
}