| Summary: | Texturing has broken in going from rc11 to rc12 | ||
|---|---|---|---|
| Product: | [JogAmp] Jogl | Reporter: | ralph |
| Component: | macosx | Assignee: | Sven Gothel <sgothel> |
| Status: | RESOLVED FIXED | ||
| Severity: | critical | ||
| Priority: | --- | ||
| Version: | 2 | ||
| Hardware: | pc_x86_64 | ||
| OS: | macosx | ||
| Type: | --- | SCM Refs: | |
| Workaround: | --- | ||
| Attachments: | Netbeans project | ||
|
Description
ralph
2013-06-28 11:46:06 CEST
Created attachment 486 [details]
Netbeans project
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. .. looking at your project now - still, next time pls provide a small unit test. Thank you. Note: Nice test box. 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. 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);
See git commits: - https://jogamp.org/git/?p=jogl.git;a=commit;h=92bd50ffee67d14566ffacacad3f9a3227025d21 - https://jogamp.org/git/?p=jogl.git;a=commit;h=de2905a6fce37e7caf69b148ef4cf7f347559530
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;
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. 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...
(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 .. ? There's no call to anything to do with blending in the program ? OK, removing panel.setTextureUnit(3); fixed it. What does that do? |