From ca26623d800685a36d7ef5bb34772f9d5af6e5cb Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Tue, 10 Apr 2007 15:51:49 +0000 Subject: Fixed the following issues: 348: Programmable shaders do not work for OffScreen Canvas3D 378: Shaders are not rendered when Canvas3D is created and destroyed git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@812 ba19aa83-45c5-6ac9-afd3-db810772062c --- src/classes/share/javax/media/j3d/Canvas3D.java | 12 ++- .../share/javax/media/j3d/MasterControl.java | 4 +- .../javax/media/j3d/ShaderProgramRetained.java | 108 ++++++++++++--------- .../share/javax/media/j3d/ShaderRetained.java | 87 +++++++++++++++-- .../javax/media/j3d/SourceCodeShaderRetained.java | 2 +- 5 files changed, 154 insertions(+), 59 deletions(-) (limited to 'src/classes/share') diff --git a/src/classes/share/javax/media/j3d/Canvas3D.java b/src/classes/share/javax/media/j3d/Canvas3D.java index 607c010..391fb00 100644 --- a/src/classes/share/javax/media/j3d/Canvas3D.java +++ b/src/classes/share/javax/media/j3d/Canvas3D.java @@ -1532,7 +1532,7 @@ public class Canvas3D extends Canvas { void setFrustumPlanes(Vector4d[] planes) { if(VirtualUniverse.mc.viewFrustumCulling) { - /* System.out.println("Canvas3D.setFrustumPlanes()"); */ + /* System.err.println("Canvas3D.setFrustumPlanes()"); */ viewFrustum.set(planes); } } @@ -1862,9 +1862,11 @@ public class Canvas3D extends Canvas { canvasId = VirtualUniverse.mc.getCanvasId(); canvasIdAlloc = true; - // NOTE: We are backing out the following part of the following fix for issues - // 347 and 348 due to a regression in texture mapping, and due - // to the fact that it is an incomplete fix. + // NOTE: We are backing out the following part of the + // following fix for issue 347 due to a regression in + // off-screen texture mapping, caused by a race condition. + // This does not affect issue 348 since the shader code + // uses the canvasId and not the canvasBit. // canvasBit = 1 << canvasId; } } @@ -4768,7 +4770,7 @@ public class Canvas3D extends Canvas { continue; } if (val >= textureIDResourceTable.size()) { - System.out.println("Error in freeResourcesInFreeList : ResourceIDTableSize = " + + System.err.println("Error in freeResourcesInFreeList : ResourceIDTableSize = " + textureIDResourceTable.size() + " val = " + val); } else { diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java index 25d5339..8b830ab 100644 --- a/src/classes/share/javax/media/j3d/MasterControl.java +++ b/src/classes/share/javax/media/j3d/MasterControl.java @@ -968,8 +968,8 @@ class MasterControl { break; } - if ( canvasFreeIndex >= canvasIds.length) { - throw new RuntimeException("Cannot render to more than 32 Canvas3Ds"); + if (i >= canvasIds.length) { + throw new RuntimeException("Cannot render to more than 32 Canvas3Ds"); } canvasIds[i] = true; diff --git a/src/classes/share/javax/media/j3d/ShaderProgramRetained.java b/src/classes/share/javax/media/j3d/ShaderProgramRetained.java index 3d3caf6..453cfca 100644 --- a/src/classes/share/javax/media/j3d/ShaderProgramRetained.java +++ b/src/classes/share/javax/media/j3d/ShaderProgramRetained.java @@ -54,6 +54,10 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { // need to synchronize access from multiple rendering threads Object resourceLock = new Object(); + + // Package-scope default constructor + ShaderProgramRetained() { + } /** * Sets the vertex attribute names array for this ShaderProgram @@ -378,7 +382,7 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { void setLive(boolean backgroundGroup, int refCount) { - // System.out.println("ShaderProgramRetained.setLive()"); + // System.err.println("ShaderProgramRetained.setLive()"); if (shaders != null) { for (int i = 0; i < shaders.length; i++){ @@ -393,7 +397,7 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { void clearLive(int refCount) { - // System.out.println("ShaderProgramRetained.clearLive()"); + // System.err.println("ShaderProgramRetained.clearLive()"); super.clearLive(refCount); @@ -469,14 +473,17 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { // ShaderProgram can't be modified once it is live. assert(false); - System.out.println("ShaderProgramRetained : updateMirrorObject NOT IMPLEMENTED YET"); + System.err.println("ShaderProgramRetained : updateMirrorObject NOT IMPLEMENTED YET"); } /** * Method to create a ShaderProgramData object for the specified - * canvas/renderer if it doesn't already exist + * canvas/renderer if it doesn't already exist. + * + * Issue 378 : reset the ShaderProgramData object if the context + * has been recreated for the particular canvas / renderer. */ - private void createShaderProgramData(int cvRdrIndex) { + private void createShaderProgramData(int cvRdrIndex, long ctxTimeStamp) { // Create shaderProgram resources if it has not been done. synchronized(resourceLock) { if(shaderProgramData == null) { @@ -494,7 +501,12 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { if(shaderProgramData[cvRdrIndex] == null) { shaderProgramData[cvRdrIndex] = new ShaderProgramData(); + } else if (shaderProgramData[cvRdrIndex].getCtxTimeStamp() != ctxTimeStamp) { + // Issue 378 - reset the shader program data for this canvas / renderer + // if the context has been recreated + shaderProgramData[cvRdrIndex].reset(); } + shaderProgramData[cvRdrIndex].setCtxTimeStamp(ctxTimeStamp); } } @@ -527,7 +539,7 @@ abstract class ShaderProgramRetained extends NodeComponentRetained { ShaderId[] shaderIds = new ShaderId[shaders.length]; for(int i=0; i