[Committed] Method for setting x and y offset in TextureRenderer Texture binding

Hey there, I am adding a method to the TextureRenderer Interface and implementations with default (0, 0) forwards to methods that are already there. With this overload the renderer lets you set a X and Y offset for the TextureRenderer.



Index: src/com/jme/renderer/jogl/JOGLTextureRenderer.java
===================================================================
--- src/com/jme/renderer/jogl/JOGLTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/jogl/JOGLTextureRenderer.java   (working copy)
@@ -815,6 +815,7 @@
         }
     }
 
+    
     /**
      * <code>copyToTexture</code> copies the FBO contents to the given
      * Texture. What is copied is up to the Texture object's rttSource field.
@@ -827,10 +828,29 @@
      *            the height of the texture image
      */
     public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+    
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         final GL gl = GLU.getCurrentGL();
 
         JOGLTextureState.doTextureBind(tex.getTextureId(), 0,
-      Texture.Type.TwoDimensional);
+            Texture.Type.TwoDimensional);
 
    int source = GL.GL_RGBA;
    switch (tex.getRTTSource()) {
@@ -979,7 +999,7 @@
        break;
    }
         gl
-                .glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, source, 0, 0, width,
+                .glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, source, x, y, width,
          height, 0);
     }
 
Index: src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java   (working copy)
@@ -578,18 +578,37 @@
     }
 
     /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+    
+    /**
      * <code>copyToTexture</code> copies the pbuffer contents to
      * the given Texture. What is copied is up to the Texture object's rttSource
      * field.
      *
      * @param tex
      *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
      * @param width
      *            the width of the texture image
      * @param height
      *            the height of the texture image
      */
-    public void copyToTexture(Texture tex, int width, int height) {
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         LWJGLTextureState.doTextureBind(tex.getTextureId(), 0, Texture.Type.TwoDimensional);
 
         int source = GL11.GL_RGBA;
@@ -738,7 +757,7 @@
             source = GL11.GL_LUMINANCE_ALPHA;
             break;
         }
-        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, 0, 0, width,
+        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, x, y, width,
                 height, 0);
     }
 
Index: src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java   (working copy)
@@ -806,6 +806,7 @@
         }
     }
 
+    
     /**
      * <code>copyToTexture</code> copies the FBO contents to the given
      * Texture. What is copied is up to the Texture object's rttSource field.
@@ -818,6 +819,26 @@
      *            the height of the texture image
      */
     public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+    
+    
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         LWJGLTextureState.doTextureBind(tex.getTextureId(), 0, Texture.Type.TwoDimensional);
 
         int source = GL11.GL_RGBA;
@@ -966,7 +987,7 @@
             source = GL11.GL_LUMINANCE_ALPHA;
             break;
         }
-        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, 0, 0, width,
+        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, x, y, width,
                 height, 0);
     }
 
@@ -979,9 +1000,13 @@
         oldHeight = parentRenderer.getHeight();
         parentRenderer.setCamera(getCamera());
 
+
+        float viewportWidthFactor = camera.getViewPortRight() - camera.getViewPortLeft();
+        float viewportHeightFactor = camera.getViewPortTop() - camera.getViewPortBottom();
+        
         // swap to rtt settings
         parentRenderer.getQueue().swapBuckets();
-        parentRenderer.reinit(width, height);
+        parentRenderer.reinit((int)(width / viewportWidthFactor), (int)(height / viewportHeightFactor));
 
         // clear the scene
         if (doClear) {
Index: src/com/jme/renderer/TextureRenderer.java
===================================================================
--- src/com/jme/renderer/TextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/TextureRenderer.java   (working copy)
@@ -199,6 +199,23 @@
      *            the height of the texture image
      */
     void copyToTexture(Texture tex, int width, int height);
+    
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height);
 
     /**
      * Any wrapping up and cleaning up of TextureRenderer information is performed here.

new patch, also has fix for camera viewports and TextureRenderer issue discussed http://www.jmonkeyengine.com/forum/index.php?topic=11653.0



Index: src/com/jme/renderer/TextureRenderer.java
===================================================================
--- src/com/jme/renderer/TextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/TextureRenderer.java   (working copy)
@@ -199,6 +199,23 @@
      *            the height of the texture image
      */
     void copyToTexture(Texture tex, int width, int height);
+   
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height);
 
     /**
      * Any wrapping up and cleaning up of TextureRenderer information is performed here.
Index: src/com/jme/renderer/jogl/JOGLTextureRenderer.java
===================================================================
--- src/com/jme/renderer/jogl/JOGLTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/jogl/JOGLTextureRenderer.java   (working copy)
@@ -815,6 +815,7 @@
         }
     }
 
+   
     /**
      * <code>copyToTexture</code> copies the FBO contents to the given
      * Texture. What is copied is up to the Texture object's rttSource field.
@@ -827,10 +828,29 @@
      *            the height of the texture image
      */
     public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+   
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         final GL gl = GLU.getCurrentGL();
 
         JOGLTextureState.doTextureBind(tex.getTextureId(), 0,
-      Texture.Type.TwoDimensional);
+            Texture.Type.TwoDimensional);
 
    int source = GL.GL_RGBA;
    switch (tex.getRTTSource()) {
@@ -979,7 +999,7 @@
        break;
    }
         gl
-                .glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, source, 0, 0, width,
+                .glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, source, x, y, width,
          height, 0);
     }
 
@@ -994,9 +1014,12 @@
         oldHeight = parentRenderer.getHeight();
         parentRenderer.setCamera(getCamera());
 
+        float viewportWidthFactor = camera.getViewPortRight() - camera.getViewPortLeft();
+        float viewportHeightFactor = camera.getViewPortTop() - camera.getViewPortBottom();
+       
         // swap to rtt settings
         parentRenderer.getQueue().swapBuckets();
-        parentRenderer.reinit(width, height);
+        parentRenderer.reinit((int)(width / viewportWidthFactor), (int)(height / viewportHeightFactor));
 
         // clear the scene
         if (doClear) {
Index: src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/lwjgl/LWJGLPbufferTextureRenderer.java   (working copy)
@@ -578,18 +578,37 @@
     }
 
     /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+   
+    /**
      * <code>copyToTexture</code> copies the pbuffer contents to
      * the given Texture. What is copied is up to the Texture object's rttSource
      * field.
      *
      * @param tex
      *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
      * @param width
      *            the width of the texture image
      * @param height
      *            the height of the texture image
      */
-    public void copyToTexture(Texture tex, int width, int height) {
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         LWJGLTextureState.doTextureBind(tex.getTextureId(), 0, Texture.Type.TwoDimensional);
 
         int source = GL11.GL_RGBA;
@@ -738,7 +757,7 @@
             source = GL11.GL_LUMINANCE_ALPHA;
             break;
         }
-        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, 0, 0, width,
+        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, x, y, width,
                 height, 0);
     }
 
Index: src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java   (revision 4644)
+++ src/com/jme/renderer/lwjgl/LWJGLTextureRenderer.java   (working copy)
@@ -806,6 +806,7 @@
         }
     }
 
+   
     /**
      * <code>copyToTexture</code> copies the FBO contents to the given
      * Texture. What is copied is up to the Texture object's rttSource field.
@@ -818,6 +819,26 @@
      *            the height of the texture image
      */
     public void copyToTexture(Texture tex, int width, int height) {
+        copyToTexture(tex, 0, 0, width, height);
+    }
+   
+   
+    /**
+     * <code>copyToTexture</code> copies the FBO contents to the given
+     * Texture. What is copied is up to the Texture object's rttSource field.
+     *
+     * @param tex
+     *            The Texture to copy into.
+     * @param x
+     *            the x offset on the texture image
+     * @param y
+     *            the y offset on the texture image
+     * @param width
+     *            the width of the texture image
+     * @param height
+     *            the height of the texture image
+     */
+    public void copyToTexture(Texture tex, int x, int y, int width, int height) {
         LWJGLTextureState.doTextureBind(tex.getTextureId(), 0, Texture.Type.TwoDimensional);
 
         int source = GL11.GL_RGBA;
@@ -966,7 +987,7 @@
             source = GL11.GL_LUMINANCE_ALPHA;
             break;
         }
-        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, 0, 0, width,
+        GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, source, x, y, width,
                 height, 0);
     }
 
@@ -979,9 +1000,13 @@
         oldHeight = parentRenderer.getHeight();
         parentRenderer.setCamera(getCamera());
 
+
+        float viewportWidthFactor = camera.getViewPortRight() - camera.getViewPortLeft();
+        float viewportHeightFactor = camera.getViewPortTop() - camera.getViewPortBottom();
+       
         // swap to rtt settings
         parentRenderer.getQueue().swapBuckets();
-        parentRenderer.reinit(width, height);
+        parentRenderer.reinit((int)(width / viewportWidthFactor), (int)(height / viewportHeightFactor));
 
         // clear the scene
         if (doClear) {