[Committed] Fix for Exception when setting a uniform variable that doesn’t exist (7 posts)

  • Profile picture of dhdd dhdd2p said 1 year, 10 months ago:

    Hi guys,

    as mentioned in that thread:http://www.jmonkeyengine.com/forum/index.php?topic=14412.0

    The GLSL compiler optimizes stuff that isn't used away, which results in an exception when you try to set a removed uniform in your application code. Now jme will just ignore setting this.

    Also i formatted the three source files that have changes according to the standard Java CodeStyle Conventions (changed for 120 character lines instead of 80). Before the source was like … not … formatted  :|

    I hope that is ok, here's the patch:
    http://pastebin.com/EmxgMW9j

  • Profile picture of vear vear said 1 year, 10 months ago:

    Nice to see that changes are finally done, which should have been done years ago.  :roll:

    Another thing regarding this, is that you should set the uniform id to -2 if it is not found, and should not again check for uniform location if the id is -2. This avoids the slow and unnecessary glGetUniformLocation call each time uniforms are applied.

    Hints:

    http://code.google.com/p/vlengine/source/browse/trunk/vle_cleanup/src/com/vlengine/scene/state/shader/ShaderVariableLocation.java#74

    http://code.google.com/p/vlengine/source/browse/trunk/vle_cleanup/src/com/vlengine/scene/state/lwjgl/LWJGLShaderParameters.java#102

  • Profile picture of ttrocha ttrocha32p said 1 year, 10 months ago:

    Perfect there is progress in the shader-section. I didn't use it (yet) so I can't say much about it but I'm pleased to know that another bug is killed before I could stumble into it :D

  • Profile picture of dhdd dhdd2p said 1 year, 9 months ago:

    vear said:
    Another thing regarding this, is that you should set the uniform id to -2 if it is not found, and should not again check for uniform location if the id is -2. This avoids the slow and unnecessary glGetUniformLocation call each time uniforms are applied.

    Thanks for the suggestion, it was already in there  ;-)

  • Profile picture of MikOfClassX MikOfClassX2p said 1 year, 9 months ago:

    Many thanks. This feature was really missing..

    Now I patched the LWJGLSharderUtil again in order to fix this http://www.jmonkeyengine.com/forum/index.php?topic=13908.0

    here's the patch

    Index: LWJGLShaderUtil.java
    ===================================================================
    --- LWJGLShaderUtil.java   (revision 5670)
    +++ LWJGLShaderUtil.java   (working copy)
    @@ -48,6 +48,8 @@
     public class LWJGLShaderUtil {
     
         private static final Logger logger = Logger.getLogger(LWJGLShaderUtil.class.getName());
    +   
    +    private static ByteBuffer   nameBuf   = BufferUtils.createByteBuffer(2048);
     
         /**
          * Updates a uniform shadervariable.
    @@ -95,9 +97,9 @@
          */
         public static void updateUniformLocation(final ShaderVariable variable, final int programID) {
             if (variable.variableID == ShaderVariable.UNINITIALIZED) {
    -            final ByteBuffer nameBuf = BufferUtils.createByteBuffer(variable.name.getBytes().length + 1);
                 nameBuf.clear();
                 nameBuf.put(variable.name.getBytes());
    +            nameBuf.put((byte)0);
                 nameBuf.rewind();
     
                 variable.variableID = ARBShaderObjects.glGetUniformLocationARB(programID, nameBuf);
    @@ -203,9 +205,9 @@
          */
         public static void updateAttributeLocation(final ShaderVariable variable, final int programID) {
             if (variable.variableID == ShaderVariable.UNINITIALIZED) {
    -            final ByteBuffer nameBuf = BufferUtils.createByteBuffer(variable.name.getBytes().length + 1);
                 nameBuf.clear();
                 nameBuf.put(variable.name.getBytes());
    +            nameBuf.put((byte)0);
                 nameBuf.rewind();
     
                 variable.variableID = ARBVertexShader.glGetAttribLocationARB(programID, nameBuf);
    

    I hope that someone will commit this.

    Cheers,

    Mik

  • Profile picture of dhdd dhdd2p said 1 year, 9 months ago:

    MikOfClassX said:
    I hope that someone will commit this.

    I did. There are more fixes in the Shader department to come. We are working on a huge project and use jme2. So for all of you that use jme2 out there, we won't let jme2 die and it will continue to improve ;-)

  • Profile picture of MikOfClassX MikOfClassX2p said 1 year, 9 months ago:

    We are working on a huge project and use jme2.

    We too..  :wink: