package com.peterhi.ui.gl;
import javax.media.opengl.GL;
import javax.media.opengl.GLException;
public abstract class GLObject {
private final GL gl;
private int id;
private boolean disposed;
public GLObject(GL gl) {
if (gl == null) {
throw new NullPointerException();
}
this.gl = gl;
}
public final GL getGL() {
if (isDisposed()) {
throw new GLException();
}
return gl;
}
public final int getId() {
if (isDisposed()) {
throw new GLException();
}
return id;
}
public final boolean isDisposed() {
return disposed;
}
public void dispose() {
if (isDisposed()) {
return;
}
disposed = true;
}
protected final void setId(int value) {
if (id != 0) {
throw new GLException();
}
id = value;
}
protected final Object glInvoke(String name, Class<?>[] types, Object[] args) {
return GLUtil.glInvoke(getGL(), name, types, args);
}
protected final Object glInvoke(String name, Object...typesAndArgs) {
return GLUtil.glInvoke(getGL(), name, typesAndArgs);
}
}