Hi!
The patch below fixes almost all known remaining bugs of the JOGL renderer and the AWT input system except those concerning the shaders (already fixed by Woody). I thank Mathias "cylab" Henze for his huge contribution. There is stil a problem when the angle is near zero (he is going to fix it as soon as possible). I'm building my game now to allow you to test the result in real conditions. Let me know your opinion about it.
Edit.: the patch is too long, I split it into 3 messages.
Index: /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLRenderer.java
===================================================================
--- /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLRenderer.java (revision 4383)
+++ /home/julien/workspace/jme/src/com/jme/renderer/jogl/JOGLRenderer.java (working copy)
@@ -113,6 +113,7 @@
import com.jme.util.geom.BufferUtils;
import com.jme.util.stat.StatCollector;
import com.jme.util.stat.StatType;
+import javax.swing.SwingUtilities;
/**
* <code>JOGLRenderer</code> provides an implementation of the
@@ -428,6 +429,7 @@
* the color to set the background color to.
*/
public void setBackgroundColor(ColorRGBA c) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
// if color is null set background to white.
@@ -449,6 +451,7 @@
* @see com.jme.renderer.Renderer#clearZBuffer()
*/
public void clearZBuffer() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (Renderer.defaultStateList[RenderState.StateType.ZBuffer.ordinal()] != null)
@@ -462,6 +465,7 @@
* @see com.jme.renderer.Renderer#clearColorBuffer()
*/
public void clearColorBuffer() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
@@ -473,6 +477,7 @@
* @see com.jme.renderer.Renderer#clearStencilBuffer()
*/
public void clearStencilBuffer() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
// Clear the stencil buffer
@@ -491,6 +496,7 @@
* @see com.jme.renderer.Renderer#clearBuffers()
*/
public void clearBuffers() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
// make sure no funny business is going on in the z before clearing.
@@ -508,6 +514,7 @@
* @see com.jme.renderer.Renderer#clearBuffers()
*/
public void clearStrictBuffers() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glDisable(GL.GL_DITHER);
@@ -525,6 +532,7 @@
* @see com.jme.renderer.Renderer#displayBackBuffer()
*/
public void displayBackBuffer() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
renderQueue();
@@ -547,6 +555,13 @@
vboMap.expunge();
+ // MHENZE (cylab) - FIX Issue 24: Release the context to give the controlled surface back to AWT, if JOGL is not driven from the EDT!
+ if(!SwingUtilities.isEventDispatchThread())
+ {
+ GLContext context = GLContext.getCurrent();
+ if(context!=null) context.release();
+ }
+
if (Debug.stats) {
StatCollector.addStat(StatType.STAT_FRAMES, 1);
}
@@ -562,6 +577,25 @@
return inOrthoMode;
}
+ // MHENZE (cylab) - FIX Issue 24: Make sure, the context is current!
+ // This is only a workaround in the hope, that at least one the JOGLRenderer
+ // methods gets called, before other GL operations occur
+ private void ensureCurrentContext()
+ {
+ GLContext context = display.getGLContext();
+ if(context!=null && context!=GLContext.getCurrent())
+ {
+ // Make the GLContext the current.
+ while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException interruption) {
+ logger.warning("Interruped while waiting for makeCurrent()");
+ }
+ }
+ }
+ }
+
/**
* <code>setOrtho</code> sets the display system to be in orthographic
* mode. If the system has already been set to orthographic mode a
@@ -569,6 +603,7 @@
* left of the screen.
*/
public void setOrtho() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
final GLU glu = new GLU();
@@ -591,6 +626,7 @@
}
public void setOrthoCenter() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
final GLU glu = new GLU();
@@ -617,6 +653,7 @@
* center of the screen.
*/
public void unsetOrtho() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!inOrthoMode) {
@@ -697,6 +734,7 @@
*/
public void grabScreenContents(ByteBuffer buff, Image.Format format, int x,
int y, int w, int h) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
int pixFormat = TextureStateRecord.getGLPixelFormat(format);
@@ -710,6 +748,7 @@
* the curve object to render.
*/
public void draw(Curve curve) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
// set world matrix
@@ -777,6 +816,7 @@
* the lines to render.
*/
public void draw(Line lines) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!lines.predraw(this))
@@ -854,6 +894,7 @@
* the points to render.
*/
public void draw(Point points) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!points.predraw(this))
@@ -920,6 +961,7 @@
* the mesh to render.
*/
public void draw(QuadMesh quads) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!quads.predraw(this))
@@ -987,6 +1029,7 @@
* the mesh to render.
*/
public void draw(TriMesh tris) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!tris.predraw(this))
@@ -1053,6 +1096,7 @@
}
private synchronized void renderDisplayList(Geometry geom) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
applyStates(geom.states, geom);
@@ -1088,6 +1132,7 @@
* the geometry to initialize VBO for.
*/
protected void prepVBO(Geometry g) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!supportsVBO())
@@ -1317,6 +1362,7 @@
* commands in the buffer.
*/
public void flush() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glFlush();
@@ -1327,6 +1373,7 @@
* waiting OpenGL commands have been finished.
*/
public void finish() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glFinish();
@@ -1341,6 +1388,7 @@
* @return true if VBO is used for indicis, false if not
*/
protected boolean predrawGeometry(Geometry g) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
RenderContext<GLContext> context = display
@@ -1569,6 +1617,7 @@
}
private void applyNormalMode(Spatial.NormalsMode normMode, Geometry t) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
switch (normMode) {
@@ -1620,6 +1669,7 @@
}
protected boolean doTransforms(Spatial t) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
// set world matrix
@@ -1662,6 +1712,7 @@
}
protected void undoTransforms(Spatial t) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
if (!generatingDisplayList
@@ -1675,6 +1726,7 @@
// inherited documentation
public int createDisplayList(Geometry g) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
int listID = gl.glGenLists(1);
@@ -1704,6 +1756,7 @@
// inherited documentation
public void releaseDisplayList(int listId) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glDeleteLists(listId, 1);
@@ -1711,6 +1764,7 @@
// inherited documentation
public void setPolygonOffset(float factor, float offset) {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
@@ -1719,6 +1773,7 @@
// inherited documentation
public void clearPolygonOffset() {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
@@ -1814,6 +1869,7 @@
final int dstY, final Image srcImage, final int srcX,
final int srcY, final int width, final int height)
throws JmeException {
+ ensureCurrentContext();
GL gl = GLU.getCurrentGL();
// Check that the texture type is supported.
@@ -1885,6 +1941,7 @@
@Override
public void checkCardError() throws JmeException {
+ ensureCurrentContext();
final GL gl = GLU.getCurrentGL();
final GLU glu = new GLU();
@@ -1901,6 +1958,7 @@
@Override
public void cleanup() {
+ ensureCurrentContext();
// clear vbos
RendererRecord rendRecord = (RendererRecord) DisplaySystem
.getDisplaySystem().getCurrentContext().getRendererRecord();