diff options
author | Sven Gothel <[email protected]> | 2011-04-22 05:28:00 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-22 05:28:00 +0200 |
commit | 31d948b5f5432837c3a52e9891f60d9189011c91 (patch) | |
tree | 386d404ca30851aef7d6c1ffe99f1b698ec60df1 /src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java | |
parent | 0ad2f3f0b54ef0088cfbfef30c35144491effe30 (diff) |
Texture: Change method signatures: Pass GL context object if required (remove GLContext.getCurrentGL() usage.
Using function signatures explicitly require the GL [current] instance clarifies
that the context must be current.
Removing GLContext.getCurrentGL() reduces TLS access of current thread
and hence possible performance hits.
The Texture class has been chosen for this conversion [not TextureIO yet],
since the enable/bind methods maybe used within a rendering loop.
User already 'complained' about lack of current GLContext clarity as well.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java index 86dca59f4..922fc69c1 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextureRenderer.java @@ -307,7 +307,7 @@ public class TextureRenderer { */ public void dispose() throws GLException { if (texture != null) { - texture.dispose(); + texture.destroy(GLContext.getCurrentGL()); texture = null; } if (image != null) { @@ -576,23 +576,23 @@ public class TextureRenderer { gl.glEnable(GL2.GL_BLEND); gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE_MINUS_SRC_ALPHA); Texture texture = getTexture(); - texture.enable(); - texture.bind(); + texture.enable(gl); + texture.bind(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); // Change polygon color to last saved gl.glColor4f(r, g, b, a); if (smoothingChanged) { smoothingChanged = false; if (smoothing) { - texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); if (mipmap) { - texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR); } else { - texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); } } else { - texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); - texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); } } } @@ -600,7 +600,7 @@ public class TextureRenderer { private void endRendering(boolean ortho) { GL2 gl = GLContext.getCurrentGL().getGL2(); Texture texture = getTexture(); - texture.disable(); + texture.disable(gl); if (ortho) { gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); @@ -661,15 +661,16 @@ public class TextureRenderer { // OpenGL and Java 2D actually line up correctly for // updateSubImage calls, so we don't need to do any argument // conversion here (i.e., flipping the Y coordinate). - texture.updateSubImage(textureData, 0, x, y, x, y, width, height); + texture.updateSubImage(GLContext.getCurrentGL(), textureData, 0, x, y, x, y, width, height); } } // Returns true if the texture was newly allocated, false if not private boolean ensureTexture() { + GL gl = GLContext.getCurrentGL(); if (mustReallocateTexture) { if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } mustReallocateTexture = false; @@ -679,7 +680,7 @@ public class TextureRenderer { texture = TextureIO.newTexture(textureData); if (mipmap && !texture.isUsingAutoMipmapGeneration()) { // Only try this once - texture.dispose(); + texture.destroy(gl); mipmap = false; textureData.setMipmap(false); texture = TextureIO.newTexture(textureData); @@ -687,8 +688,8 @@ public class TextureRenderer { if (!smoothing) { // The TextureIO classes default to GL_LINEAR filtering - texture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); - texture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); + texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); } return true; } |