modules/graphics/src/main/java/com/sun/prism/impl/VertexBuffer.java

Print this page

        

@@ -48,18 +48,27 @@
     protected byte r, g, b, a;
 
     protected byte  colorArray[];
     protected float coordArray[];
 
+    protected BaseContext owner;
+
     public VertexBuffer(int maxQuads) {
         capacity = maxQuads * VERTS_PER_QUAD;
         index = 0;
 
         colorArray = new byte [capacity * BYTES_PER_VERT];
         coordArray = new float[capacity * FLOATS_PER_VERT];
     }
 
+    public void setOwner(BaseContext owner) {
+        if (this.owner != null) {
+            throw new InternalError("Only one owner per VertexBuffer allowed");
+        }
+        this.owner = owner;
+    }
+
     protected void drawQuads(int numVertices) {
         throw new Error ("flush not implemented for lightweight");
     }
 
     // it had better be the case if this method be moved to Graphics

@@ -99,10 +108,18 @@
      * destination render target.  This operation only applies to heavyweight
      * buffers; calling flush() on a lightweight buffer will result in an
      * exception.
      */
     public final void flush() {
+        if (owner == null) {
+            ownerFlush();
+        } else {
+            owner.flushVertexBuffer();
+        }
+    }
+
+    public final void ownerFlush() {
         if (index > 0) {
             drawQuads(index);
             index = 0;
         }
     }

@@ -207,12 +224,11 @@
         drawTriangles(numVerts/3, vb.coordArray, vb.colorArray);
     }
 
     private void ensureCapacityForQuad() {
         if (index + VERTS_PER_QUAD > capacity) {
-            drawQuads(index);
-            index = 0;
+            flush();
         }
     }
 
     public final void addQuad(float dx1, float dy1, float dx2, float dy2) {
         ensureCapacityForQuad();

@@ -289,13 +305,12 @@
             boolean isText)
     {
 //        ensureCapacityForQuad();
         int idx = index;
         if (idx + VERTS_PER_QUAD > capacity) {
-//            grow();
-            drawQuads(idx);
-            idx = index = 0;
+            flush();
+            idx = index;
         }
 
         int i = FLOATS_PER_VERT * idx;
         float farr[] = coordArray;
 

@@ -335,12 +350,12 @@
             float tx1, float ty1, float tx2, float ty2)
     {
 //        ensureCapacityForQuad();
         int idx = index;
         if (idx + VERTS_PER_QUAD > capacity) {
-            drawQuads(idx);
-            idx = index = 0;
+            flush();
+            idx = index;
         }
 
         int i = FLOATS_PER_VERT * idx;
         float farr[] = coordArray;
 

@@ -375,12 +390,12 @@
             float dx1, float dy1, float dx2, float dy2,
             float tx1, float ty1, float tx2, float ty2)
     {
         int idx = index;
         if (idx + VERTS_PER_QUAD > capacity) {
-            drawQuads(idx);
-            idx = index = 0;
+            flush();
+            idx = index;
         }
 
         int i = FLOATS_PER_VERT * idx;
         float farr[] = coordArray;
 

@@ -446,12 +461,12 @@
             float ux12, float uy12, float ux22, float uy22,
             float vx, float vy)
     {
         int idx = index;
         if (idx + VERTS_PER_QUAD > capacity) {
-            drawQuads(idx);
-            idx = index = 0;
+            flush();
+            idx = index;
         }
 
         int i = FLOATS_PER_VERT * idx;
         float farr[] = coordArray;
 

@@ -494,12 +509,12 @@
             float vx11, float vy11, float vx21, float vy21,
             float vx12, float vy12, float vx22, float vy22)
     {
         int idx = index;
         if (idx + VERTS_PER_QUAD > capacity) {
-            drawQuads(idx);
-            idx = index = 0;
+            flush();
+            idx = index;
         }
 
         int i = FLOATS_PER_VERT * idx;
         float farr[] = coordArray;