Bug 769 - Texturing has broken in going from rc11 to rc12
Summary: Texturing has broken in going from rc11 to rc12
Status: RESOLVED FIXED
Alias: None
Product: Jogl
Classification: JogAmp
Component: macosx (show other bugs)
Version: 2
Hardware: pc_x86_64 macosx
: --- critical
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2013-06-28 11:46 CEST by ralph
Modified: 2013-07-04 14:08 CEST (History)
0 users

See Also:
Type: ---
SCM Refs:
Workaround: ---


Attachments
Netbeans project (703.76 KB, application/octet-stream)
2013-06-28 11:48 CEST, ralph
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ralph 2013-06-28 11:46:06 CEST
I have some code which worked perfectly under rc11, and now with rc12 just displays a black window whenever I attempt to use a texture with an object.

I attach a complete Netbeans project (which assumes jogl libraries are in /Library/Java/Extensions, for simplicity).
Comment 1 ralph 2013-06-28 11:48:47 CEST
Created attachment 486 [details]
Netbeans project
Comment 2 Sven Gothel 2013-07-03 13:18:14 CEST
Pls provide a small self contained test case, best a unit test based upon one of ours.
It will take more time for me to install netbeans .. fiddle w/ things etc.

If this bug is _not_ platform agnostic,
pls add some information as stated in Wiki/FAQ/Bugreport,

I would appreciate, if you can do this ASAP, since the deadline for 2.0.2 is getting close.
Comment 3 Sven Gothel 2013-07-03 13:41:39 CEST
.. looking at your project now - still, next time pls provide a small unit test. Thank you.

Note: Nice test box.
Comment 4 Sven Gothel 2013-07-03 14:14:29 CEST
Ok .. culprit is GLJPanel's new GLSL based vertical flip,
which can be disabled via '-Djogl.gljpanel.noglsl'.
Nothing todo w/ textures .. will check how to mitigate problem.
Comment 5 Sven Gothel 2013-07-03 16:41:16 CEST
Fix below ..

I will refine Texture and GLJPanel class API doc in a bit ..

Good test case.

Invalid: B/c it's more like a feature .. not a bug.

I currently test setting GLJPanel's FBO/GLSL textureUnit by user, so such collisions would not happen.

-            //enable texturing
-            gl.glEnable(GL2.GL_TEXTURE_2D);
+            // Enable texturing, proper order is:
+            //   - Set active textureUnit via glActiveTexture(GL.GL_TEXTURE0 + textureUnit)
+            //   - Bind textureId -> textureTarget via glBindTexture(textureTarget, textureId)
+            //   - Enable active textureUnit's textureTarget via glEnable(textureTarget)
+            // Your orig code was 
+            //   - Enable textureTarget via glEnable
+            //   - Change texture-env and params of active texture unit
+            //   - Bind textureId -> textureTarget via glBindTexture
+            // Actual fix is to call bind + enable before changing the tex params/env.
+            
+            // gl.glActiveTexture(GL.GL_TEXTURE0 + 0); // defaults to unit 0
             Texture tex = textures.get(texture);
             if (tex == null) { //need to load texture
                 tex = loadTexture(TEXTURE_DIR + File.separator + texture);
                 textures.put(texture, tex);
             }
+            tex.bind(gl);
             tex.enable(gl);
             gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
             gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
@@ -339,7 +351,6 @@ public class ToyShader2 extends JFrame
             gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_BASE_LEVEL, 0);
             gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAX_LEVEL, 5);
             gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2ES1.GL_GENERATE_MIPMAP, GL2.GL_TRUE);
-            tex.bind(gl);
Comment 7 Sven Gothel 2013-07-03 17:11:57 CEST
To document the new textureUnit selection of GLJPanel
attached is a simple diff, illustrating texture setup only if required:

--- a/src/org/yourorghere/ToyShader2.java
+++ b/src/org/yourorghere/ToyShader2.java
@@ -78,7 +78,7 @@ public class ToyShader2 extends JFrame
         GLCapabilities caps = new GLCapabilities(glp);
          
         GLJPanel panel = new GLJPanel(caps);
-        // panel.setTextureUnit(3);
+        panel.setTextureUnit(3);
         
         setContentPane(panel);
 
@@ -302,7 +302,6 @@ public class ToyShader2 extends JFrame
             gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
         }
 
-
         if (useShader.isSelected()) {
             //use vertex and fragment shaders
             Integer programObject = programs.get(shader);
@@ -335,12 +334,14 @@ public class ToyShader2 extends JFrame
             //   - Bind textureId -> textureTarget via glBindTexture
             // Actual fix is to call bind + enable before changing the tex params/env.
             
-            // gl.glActiveTexture(GL.GL_TEXTURE0 + 0); // defaults to unit 0
+            gl.glActiveTexture(GL.GL_TEXTURE0 + 0); // defaults to unit 0
             Texture tex = textures.get(texture);
             if (tex == null) { //need to load texture
                 tex = loadTexture(TEXTURE_DIR + File.separator + texture);
                 textures.put(texture, tex);
+                texUnitNeedsSetup = true;
             }
+            if( texUnitNeedsSetup ) {
                 tex.bind(gl);
                 tex.enable(gl);
                 gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
@@ -351,14 +352,18 @@ public class ToyShader2 extends JFrame
                 gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_BASE_LEVEL, 0);
                 gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAX_LEVEL, 5);
                 gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2ES1.GL_GENERATE_MIPMAP, GL2.GL_TRUE);
+                texUnitNeedsSetup = false;
+            }
         } else {
             gl.glDisable(GL2.GL_TEXTURE_2D);
+            texUnitNeedsSetup = true;
         }
 
         shapeManager.display(gl, level, wireframe.isSelected());
 
         gl.glPopMatrix();
     }
+    boolean texUnitNeedsSetup = true;
Comment 8 ralph 2013-07-04 11:56:06 CEST
Thanks for looking at this, and sorry for getting the ordering wrong - it did work before!

Just one issue - if I now turn texturing off with the menu, the object remains textured. The call to gl.glDisable(GL2.GL_TEXTURE_2D); seems to have no effect.
Comment 9 ralph 2013-07-04 13:40:05 CEST
OK, needed to add
           gl.glActiveTexture(GL2.GL_TEXTURE0 + 0);
before
           gl.glDisable(GL2.GL_TEXTURE_2D);
and now texturing turns off. 

However, the object appearance is still not the same as it was before I turned the texturing on (the object now looks yellowish like the background). Something strange is going on...
Comment 10 Sven Gothel 2013-07-04 13:44:36 CEST
(In reply to comment #9)
> OK, needed to add
>            gl.glActiveTexture(GL2.GL_TEXTURE0 + 0);
> before
>            gl.glDisable(GL2.GL_TEXTURE_2D);
> and now texturing turns off. 
> 

right, disabling the active texture!

> However, the object appearance is still not the same as it was before I
> turned the texturing on (the object now looks yellowish like the
> background). Something strange is going on...

alpha blending ..
Comment 11 ralph 2013-07-04 13:51:04 CEST
? There's no call to anything to do with blending in the program ?
Comment 12 ralph 2013-07-04 14:08:02 CEST
OK, removing
panel.setTextureUnit(3);
fixed it. What does that do?