aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2008-02-16 07:47:38 +0000
committerKenneth Russel <[email protected]>2008-02-16 07:47:38 +0000
commitc52763f9ba6240fad8e53647bf7bfe927561ee93 (patch)
treebcc49a7cb3370330165ffcd12bbb997f0de89f58
parent56d195ba50655e27c69ba27bc80cfd34f398a6b4 (diff)
Fixed Issue 339: Add system properties to turn off VAs/VBOs in TextRenderer
Incorporated patch from emzic, slightly modified, to add set/getUseVertexArrays() as concession to graphics cards which do not perform well with small vertex arrays. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1527 232f8b59-042b-4e1e-8c03-345bb8c30851
-rwxr-xr-xsrc/classes/com/sun/opengl/util/j2d/TextRenderer.java97
1 files changed, 80 insertions, 17 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
index 12263806e..5ac297812 100755
--- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
+++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
@@ -193,6 +193,13 @@ public class TextRenderer {
// Debugging purposes only
private boolean debugged;
Pipelined_QuadRenderer mPipelinedQuadRenderer;
+
+ //emzic: added boolean flag
+ private boolean useVertexArrays = true;
+
+ //emzic: added boolean flag
+ private boolean isExtensionAvailable_GL_VERSION_1_5;
+ private boolean checkFor_isExtensionAvailable_GL_VERSION_1_5;
/** Creates a new TextRenderer with the given font, using no
antialiasing or fractional metrics, and the default
@@ -689,6 +696,13 @@ public class TextRenderer {
}
}
+ /**
+ * emzic: here the call to glBindBuffer crashes on certain graphicscard/driver combinations
+ * this is why the ugly try-catch block has been added, which falls back to the old textrenderer
+ *
+ * @param ortho
+ * @throws GLException
+ */
private void endRendering(boolean ortho) throws GLException {
flushGlyphPipeline();
@@ -702,8 +716,12 @@ public class TextRenderer {
// 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 (is15Available(gl)) {
+ try {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ } catch (Exception e) {
+ isExtensionAvailable_GL_VERSION_1_5 = false;
+ }
}
if (ortho) {
@@ -1292,8 +1310,12 @@ public class TextRenderer {
// 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 (is15Available(gl)) {
+ try {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ } catch (Exception e) {
+ isExtensionAvailable_GL_VERSION_1_5 = false;
+ }
}
if (isOrthoMode) {
@@ -1685,24 +1707,29 @@ public class TextRenderer {
mVertCoords = BufferUtil.newFloatBuffer(kTotalBufferSizeCoordsVerts);
mTexCoords = BufferUtil.newFloatBuffer(kTotalBufferSizeCoordsTex);
- usingVBOs = (gl.isExtensionAvailable("GL_VERSION_1_5"));
+ usingVBOs = is15Available(gl);
if (usingVBOs) {
- int[] vbos = new int[2];
- gl.glGenBuffers(2, IntBuffer.wrap(vbos));
+ try {
+ int[] vbos = new int[2];
+ gl.glGenBuffers(2, IntBuffer.wrap(vbos));
- mVBO_For_ResuableTileVertices = vbos[0];
- mVBO_For_ResuableTileTexCoords = vbos[1];
+ mVBO_For_ResuableTileVertices = vbos[0];
+ mVBO_For_ResuableTileTexCoords = vbos[1];
- 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_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
+ 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
+ } catch (Exception e) {
+ isExtensionAvailable_GL_VERSION_1_5 = false;
+ usingVBOs = false;
+ }
}
}
@@ -1724,6 +1751,14 @@ public class TextRenderer {
}
private void draw() {
+ if (useVertexArrays) {
+ drawVertexArrays();
+ } else {
+ drawIMMEDIATE();
+ }
+ }
+
+ private void drawVertexArrays() {
if (mOutstandingGlyphsVerticesPipeline > 0) {
GL gl = GLU.getCurrentGL();
@@ -1854,4 +1889,32 @@ public class TextRenderer {
boolean modeChanged, boolean deviceChanged) {
}
}
+
+ /**
+ * Indicates whether vertex arrays are being used internally for
+ * rendering, or whether text is rendered using the OpenGL
+ * immediate mode commands. Defaults to true.
+ */
+ public boolean getUseVertexArrays() {
+ return useVertexArrays;
+ }
+
+ /**
+ * Sets whether vertex arrays are being used internally for
+ * rendering, or whether text is rendered using the OpenGL
+ * immediate mode commands. This is provided as a concession for
+ * certain graphics cards which have poor vertex array
+ * performance. Defaults to true.
+ */
+ public void setUseVertexArrays(boolean useVertexArrays) {
+ this.useVertexArrays = useVertexArrays;
+ }
+
+ private boolean is15Available(GL gl) {
+ if (!checkFor_isExtensionAvailable_GL_VERSION_1_5) {
+ isExtensionAvailable_GL_VERSION_1_5 = gl.isExtensionAvailable("GL_VERSION_1_5");
+ checkFor_isExtensionAvailable_GL_VERSION_1_5 = true;
+ }
+ return isExtensionAvailable_GL_VERSION_1_5;
+ }
}