EOS 2  1.1.0
Einfache Objektbasierte Sprache
GLObjectBuffer.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.robot.gui;
2 
3 import java.awt.Color;
4 import java.util.HashMap;
5 import java.util.LinkedList;
6 
7 import com.jogamp.opengl.GL;
8 import com.jogamp.opengl.GL2;
9 
10 import de.lathanda.eos.robot.geom3d.Polyhedron;
11 
12 public class GLObjectBuffer {
13  // ***************** factory *****************
14  private static HashMap<Polyhedron, GLObjectBuffer> objbuffer = new HashMap<>();
15  public static synchronized GLObjectBuffer get(Polyhedron poly) {
16  GLObjectBuffer obj = objbuffer.get(poly);
17  if (obj == null) {
18  obj = new GLObjectBuffer(poly);
19  objbuffer.put(poly, obj);
20  }
21  return obj;
22  }
23  public static synchronized void clear(GL gl) {
24  for(GLObjectBuffer obj : objbuffer.values()) {
25  obj.destroy(gl);
26  }
27  }
28 
29  //****************** class *******************
30  private final Polyhedron data;
31  private HashMap<GL , LinkedList<GLRenderObject> > robuffer = new HashMap<>();
32 
33  private GLObjectBuffer(Polyhedron poly) {
34  this.data = poly;
35  }
36  public void destroy(GL gl) {
37  LinkedList<GLRenderObject> ro = robuffer.get(gl);
38  //free resources on graphic card
39  if (ro != null) {
40  ro.forEach( r->r.destroy(gl));
41  robuffer.remove(gl);
42  }
43  }
44  public void render(Color base, GL2 gl) {
45  LinkedList<GLRenderObject> ro = robuffer.get(gl);
46  if (ro == null) {
47  ro = new LinkedList<>();
48  final boolean VBOsupported = gl.isFunctionAvailable("glGenBuffersARB") &&
49  gl.isFunctionAvailable("glBindBufferARB") &&
50  gl.isFunctionAvailable("glBufferDataARB") &&
51  gl.isFunctionAvailable("glDeleteBuffersARB");
52  if (VBOsupported) {
53  ro = VertexBufferObject.create(data);
54  } else {
55  ro = new LinkedList<>();
56  ro.add(new GLBaseRenderObject(data));
57  }
58  robuffer.put(gl, ro);
59  }
60  ro.forEach( r -> r.render(gl, base));
61  }
62 
63 }
static synchronized void clear(GL gl)
static LinkedList< GLRenderObject > create(Polyhedron poly)
Impressum