Access Pattern for VBO

Current VBO version only uses STATIC_DRAW.

My suggestion is specifying access pattern at VBOInfo.



Method name and enum type name may be weird.

Then please suggest another names.



Index: src/com/jme/renderer/lwjgl/LWJGLRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (revision 4105)
+++ src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (working copy)
@@ -1069,7 +1069,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getVertexBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1094,7 +1094,7 @@
                                 .glBufferDataARB(
                                         ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB,
                                         tb.getIndexBuffer(),
-                                        ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                        vbo.getAccessPattern());
 
                     }
                 }
@@ -1118,7 +1118,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getNormalBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1138,7 +1138,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getColorBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1158,7 +1158,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getFogBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1181,7 +1181,7 @@
                         rendRecord.setBoundVBO(vbo.getVBOTextureID(i));
                         ARBBufferObject.glBufferDataARB(
                                 ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, texC.coords,
-                                ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                vbo.getAccessPattern());
                     }
                 }
             }
Index: src/com/jme/scene/VBOInfo.java
===================================================================
--- src/com/jme/scene/VBOInfo.java   (revision 4105)
+++ src/com/jme/scene/VBOInfo.java   (working copy)
@@ -35,6 +35,8 @@
 import java.io.IOException;
 import java.io.Serializable;
 
+import org.lwjgl.opengl.ARBBufferObject;
+
 import com.jme.util.export.InputCapsule;
 import com.jme.util.export.JMEExporter;
 import com.jme.util.export.JMEImporter;
@@ -63,6 +65,16 @@
    private int vboFogCoordsID = -1;
    private int[] vboTextureIDs = null;
    private int vboIndexID = -1;
+   private ModificationType   modificationType = ModificationType.Static;
+   private AccessType   accessType = AccessType.DRAW;
+   
+   public enum ModificationType {
+      Static, Stream, Dynamic
+   }
+   
+   public enum AccessType {
+      DRAW, COPY, READ
+   }
 
    public VBOInfo() {
        this(false);
@@ -293,6 +305,47 @@
    public void setVBOIndexID(int id) {
       this.vboIndexID = id;
    }
+   
+   public void setAccessPattern(ModificationType mod, AccessType access) {
+      this.modificationType = mod;
+      this.accessType = access;
+   }
+   
+   public int getAccessPattern() {
+      switch (this.modificationType) {
+         case Static:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_STATIC_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_STATIC_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_STATIC_READ_ARB;
+            }
+            break;
+         case Stream:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_STREAM_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_STREAM_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_STREAM_READ_ARB;
+            }
+            break;
+         case Dynamic:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_DYNAMIC_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_DYNAMIC_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_DYNAMIC_READ_ARB;
+            }
+            break;
+      }
+      return ARBBufferObject.GL_STATIC_DRAW_ARB;
+   }
 
     public void write(JMEExporter e) throws IOException {
         OutputCapsule capsule = e.getCapsule(this);

I don't have any comments on this suggestion, as I have no knowledge of VBO.



But I can point out that your changes to VBOInfo.java now makes it depend on LWJGL, which is not good for those of the JOGL persuasion.  ;)  I think you're going to have split this into two implementations.

I forgot JOGL . sorry  :slight_smile:



Index: src/com/jme/renderer/lwjgl/LWJGLRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (revision 4105)
+++ src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (working copy)
@@ -1069,7 +1069,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getVertexBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1094,7 +1094,7 @@
                                 .glBufferDataARB(
                                         ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB,
                                         tb.getIndexBuffer(),
-                                        ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                        vbo.getAccessPattern());
 
                     }
                 }
@@ -1118,7 +1118,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getNormalBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1138,7 +1138,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getColorBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1158,7 +1158,7 @@
                     ARBBufferObject.glBufferDataARB(
                             ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, g
                                     .getFogBuffer(),
-                            ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                    vbo.getAccessPattern());
                 }
             }
         }
@@ -1181,7 +1181,7 @@
                         rendRecord.setBoundVBO(vbo.getVBOTextureID(i));
                         ARBBufferObject.glBufferDataARB(
                                 ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, texC.coords,
-                                ARBBufferObject.GL_STATIC_DRAW_ARB);
+                                vbo.getAccessPattern());
                     }
                 }
             }
Index: src/com/jme/scene/VBOInfo.java
===================================================================
--- src/com/jme/scene/VBOInfo.java   (revision 4105)
+++ src/com/jme/scene/VBOInfo.java   (working copy)
@@ -35,6 +35,8 @@
 import java.io.IOException;
 import java.io.Serializable;
 
+import org.lwjgl.opengl.ARBBufferObject;
+
 import com.jme.util.export.InputCapsule;
 import com.jme.util.export.JMEExporter;
 import com.jme.util.export.JMEImporter;
@@ -63,6 +65,16 @@
    private int vboFogCoordsID = -1;
    private int[] vboTextureIDs = null;
    private int vboIndexID = -1;
+   private ModificationType   modificationType = ModificationType.Static;
+   private AccessType   accessType = AccessType.DRAW;
+   
+   public enum ModificationType {
+      Static, Stream, Dynamic
+   }
+   
+   public enum AccessType {
+      DRAW, COPY, READ
+   }
 
    public VBOInfo() {
        this(false);
@@ -100,6 +112,8 @@
        copy.useVBONormal = useVBONormal;
        copy.useVBOIndex = useVBOIndex;
        copy.useVBOFogCoords = useVBOFogCoords;
+       copy.accessType = accessType;
+       copy.modificationType = modificationType;
        return copy;
    }
    
@@ -293,6 +307,47 @@
    public void setVBOIndexID(int id) {
       this.vboIndexID = id;
    }
+   
+   public void setAccessPattern(ModificationType mod, AccessType access) {
+      this.modificationType = mod;
+      this.accessType = access;
+   }
+   
+   public int getAccessPattern() {
+      switch (this.modificationType) {
+         case Static:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_STATIC_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_STATIC_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_STATIC_READ_ARB;
+            }
+            break;
+         case Stream:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_STREAM_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_STREAM_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_STREAM_READ_ARB;
+            }
+            break;
+         case Dynamic:
+            switch (this.accessType) {
+               case DRAW:
+                  return ARBBufferObject.GL_DYNAMIC_DRAW_ARB;
+               case COPY:
+                  return ARBBufferObject.GL_DYNAMIC_COPY_ARB;
+               case READ:
+                  return ARBBufferObject.GL_DYNAMIC_READ_ARB;
+            }
+            break;
+      }
+      return ARBBufferObject.GL_STATIC_DRAW_ARB;
+   }
 
     public void write(JMEExporter e) throws IOException {
         OutputCapsule capsule = e.getCapsule(this);
Index: src/com/jme/renderer/jogl/JOGLRenderer.java
===================================================================
--- src/com/jme/renderer/jogl/JOGLRenderer.java   (revision 4105)
+++ src/com/jme/renderer/jogl/JOGLRenderer.java   (working copy)
@@ -1107,7 +1107,7 @@
                             GL.GL_ARRAY_BUFFER_ARB, g
                                     .getVertexBuffer().limit() * 4, g
                                     .getVertexBuffer(),
-                            GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                            vbo.getAccessPattern()); // TODO Check <sizeInBytes>
                 }
             }
         }
@@ -1133,7 +1133,7 @@
                                         GL.GL_ELEMENT_ARRAY_BUFFER_ARB,
                                         tb.getIndexBuffer().limit() * 4,
                                         tb.getIndexBuffer(),
-                                        GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                                        vbo.getAccessPattern()); // TODO Check <sizeInBytes>
 
                     }
                 }
@@ -1158,7 +1158,7 @@
                             GL.GL_ARRAY_BUFFER_ARB, g
                                     .getNormalBuffer().limit() * 4, g
                                     .getNormalBuffer(),
-                            GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                                    vbo.getAccessPattern()); // TODO Check <sizeInBytes>
                 }
             }
         }
@@ -1179,7 +1179,7 @@
                             GL.GL_ARRAY_BUFFER_ARB, g
                                     .getColorBuffer().limit() * 4, g
                                     .getColorBuffer(),
-                            GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                                    vbo.getAccessPattern()); // TODO Check <sizeInBytes>
                 }
             }
         }
@@ -1200,7 +1200,7 @@
                             GL.GL_ARRAY_BUFFER_ARB, g
                                     .getFogBuffer().limit() * 4, g
                                     .getFogBuffer(),
-                            GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                                    vbo.getAccessPattern()); // TODO Check <sizeInBytes>
                 }
             }
         }
@@ -1223,7 +1223,7 @@
                         rendRecord.setBoundVBO(vbo.getVBOTextureID(i));
                         gl.glBufferDataARB(
                                 GL.GL_ARRAY_BUFFER_ARB, texC.coords.limit() * 4, texC.coords,
-                                GL.GL_STATIC_DRAW_ARB); // TODO Check <sizeInBytes>
+                                vbo.getAccessPattern()); // TODO Check <sizeInBytes>
                     }
                 }
             }

Stream/Dynamic Mode doesn't seems to work correctly.

Updating VBO data seems to be needed.

I'll check it out more.

Yes very good. But we still need to address what my previous post was really about…  XD



Index: src/com/jme/scene/VBOInfo.java

===================================================================

— src/com/jme/scene/VBOInfo.java (revision 4105)

+++ src/com/jme/scene/VBOInfo.java (working copy)

@@ -35,6 +35,8 @@

import java.io.IOException;

import java.io.Serializable;



[glow=red,2,300]+import org.lwjgl.opengl.ARBBufferObject;[/glow]

+

import com.jme.util.export.InputCapsule;





You'll need renderer specific implementations of VBOInfo.

nymon said:

Yes very good. But we still need to address what my previous post was really about...  XD

Index: src/com/jme/scene/VBOInfo.java
===================================================================
--- src/com/jme/scene/VBOInfo.java (revision 4105)
+++ src/com/jme/scene/VBOInfo.java (working copy)
@@ -35,6 +35,8 @@
import java.io.IOException;
import java.io.Serializable;

[glow=red,2,300]+import org.lwjgl.opengl.ARBBufferObject;[/glow]
+
import com.jme.util.export.InputCapsule;


You'll need renderer specific implementations of VBOInfo.

I see  :)

If you want this for jME 2.0/2.1, then abstract away the access types, and add the renderer specific code/constants to LWJGLRender/JOGLRenderer. If you want this for jME 3.0, then wait till the the VBO handling is reworked (by whom?) to a whole new level.

Momoko_Fan said:

I have already finished VBO and shader handling for "jME3", one thing that I find very convenient is that everything is taken care of for you. You don't have to specify the engine to use VBO, all you do is create a mesh, specify it some geometry data and you can use it as you see fit. When the mesh is no longer used, its VBO IDs and data are all cleaned up for you without having to do any reference counting or manually destroying through the renderer.


Sounds fantastic! But I can't wait till jme3 comes up.  :'(
I'm working on the project scheduled to be released after a few months later.
Is there any schedule (even roughly) to release jme3?