From 7318a096ac242d8caf5d2020d90167e817ad2874 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Wed, 17 Oct 2007 17:50:10 +0000 Subject: Fixed Issue 323: TextRenderer leaves VBOs bound Manually unbound VBOs because it appears that some graphics drivers do not push and pop the GL_ARRAY_BUFFER_BINDING and other state during glPushClientAttrib / glPopClientAttrib. This is an area where the OpenGL specification is ambiguous. Added a non-VBO code path using normal vertex arrays for graphics cards that don't support VBOs. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1404 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/opengl/util/j2d/TextRenderer.java | 53 ++++++++++++++++------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'src/classes') diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index b20a6c2b1..697d5068a 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -854,6 +854,12 @@ public class TextRenderer GL gl = GLU.getCurrentGL(); // Pop client attrib bits used by the pipelined quad renderer gl.glPopClientAttrib(); + // The OpenGL spec is unclear about whether this changes the + // buffer bindings, so preemptively zero out the GL_ARRAY_BUFFER + // binding + if (gl.isExtensionAvailable("GL_VERSION_1_5")) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } if (ortho) { getBackingStore().endOrthoRendering(); } else { @@ -1014,6 +1020,12 @@ public class TextRenderer GL gl = GLU.getCurrentGL(); // Pop client attrib bits used by the pipelined quad renderer gl.glPopClientAttrib(); + // The OpenGL spec is unclear about whether this changes the + // buffer bindings, so preemptively zero out the GL_ARRAY_BUFFER + // binding + if (gl.isExtensionAvailable("GL_VERSION_1_5")) { + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } if (isOrthoMode) { ((TextureRenderer) oldBackingStore).endOrthoRendering(); } else { @@ -1378,6 +1390,7 @@ public class TextRenderer FloatBuffer mTexCoords; FloatBuffer mVertCoords; + boolean usingVBOs; int mVBO_For_ResuableTileVertices; int mVBO_For_ResuableTileTexCoords; @@ -1387,17 +1400,21 @@ public class TextRenderer mVertCoords = BufferUtil.newFloatBuffer( kTotalBufferSizeCoordsVerts); mTexCoords = BufferUtil.newFloatBuffer( kTotalBufferSizeCoordsTex); - int[] vbos = new int[2]; - gl.glGenBuffersARB( 2, IntBuffer.wrap(vbos )); + usingVBOs = (gl.isExtensionAvailable("GL_VERSION_1_5")); - mVBO_For_ResuableTileVertices = vbos[0]; - mVBO_For_ResuableTileTexCoords = vbos[1]; + if (usingVBOs) { + int[] vbos = new int[2]; + gl.glGenBuffers( 2, IntBuffer.wrap(vbos )); - gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileVertices); - gl.glBufferData( GL.GL_ARRAY_BUFFER, kTotalBufferSizeBytesVerts,null, GL.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + mVBO_For_ResuableTileVertices = vbos[0]; + mVBO_For_ResuableTileTexCoords = vbos[1]; - gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileTexCoords); - gl.glBufferData( GL.GL_ARRAY_BUFFER, kTotalBufferSizeBytesTex,null, GL.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileVertices); + gl.glBufferData( GL.GL_ARRAY_BUFFER, kTotalBufferSizeBytesVerts,null, GL.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + + gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileTexCoords); + gl.glBufferData( GL.GL_ARRAY_BUFFER, kTotalBufferSizeBytesTex,null, GL.GL_STREAM_DRAW); // stream draw because this is a single quad use pipeline + } } public void glTexCoord2f ( float v, float v1 ) @@ -1432,17 +1449,25 @@ public class TextRenderer mVertCoords.rewind(); mTexCoords.rewind(); - gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileVertices); - gl.glBufferSubData( GL.GL_ARRAY_BUFFER, 0, mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_VertexData, mVertCoords ); // upload only the new stuff gl.glEnableClientState(GL.GL_VERTEX_ARRAY); - gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + if (usingVBOs) { + gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileVertices); + gl.glBufferSubData( GL.GL_ARRAY_BUFFER, 0, mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_VertexData, mVertCoords ); // upload only the new stuff + gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + } else { + gl.glVertexPointer(3, GL.GL_FLOAT, 0, mVertCoords); + } gl.glClientActiveTexture(GL.GL_TEXTURE0); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); - gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileTexCoords); - gl.glBufferSubData( GL.GL_ARRAY_BUFFER,0, mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_TexData, mTexCoords ); // upload only the new stuff - gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); + if (usingVBOs) { + gl.glBindBuffer( GL.GL_ARRAY_BUFFER, mVBO_For_ResuableTileTexCoords); + gl.glBufferSubData( GL.GL_ARRAY_BUFFER,0, mOutstandingGlyphsVerticesPipeline * kSizeInBytes_OneVertices_TexData, mTexCoords ); // upload only the new stuff + gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); + } else { + gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, mTexCoords); + } gl.glDrawArrays(GL.GL_QUADS,0, mOutstandingGlyphsVerticesPipeline ); -- cgit v1.2.3