TextureRenderer changes

TextureRenderer has been updated to handle rendering to multiple textures at once.  It has also been updated to allow the user to determine what exactly you wish to put to the texture from the rendering (eg. color buffer contents, depth buffer contents, just the luminance data, etc.)



Another change is how you setup your textures for texture rendering.  Now you'll need to create your texture object and then send it to the texture renderer to be setup properly (makes more sense given the name).  Prior to sending it to be setup, you can set a new Texture object field called rttSource to let TextureRenderer know how you will use the texture.



Eg:

myTexture = new Texture();
myTexture.setRTTSource(Texture.RTT_SOURCE_DEPTH);
myTexRenderer.setupTexture(myTexture);



Rendering to multiple textures in one pass is simply a matter of passing an array of Texture objects, all properly setup as above, to the render method of your TextureRenderer.

One other enhancement to note, I've also exposed the copyTexture functionality of TextureRenderer so you can copy the main buffers contents to texture.  This can be used for various effects or to do RTT if you have low end cards that don't support pbuffer.  Obviously though you have to understand what is in the main buffer when you read and so forth, so it isn't something for beginners.  That said, the method looks like this:

public void copyToTexture(Texture tex, int width, int height);



And you can see an example of it in use via Debugger.drawBuffer  (Try hitting F3 in a simplegame based demo for an peek at the depth buffer.)

Enjoy.  And darkfrog, when you break it in the next 5 minutes, please tell me.  ;)

Wow, I make a wish, and poff, it's there! I will definitely try to brake it before darkfrog  XD

still, great work!

two things:

  • it's possible to get the depth buffer through the pbuffer right? that would be a great thing.
  • as it is now, a single texturerenderer can only write to multiple textures through copyToTexture and not with pbuffers(the automatic case when rendering to rgba-texture and pbuffers supported), so in those cases I have to create multiple texturerenderers… one idea would be to allow for creation of multiple pbuffers in the texturerenderer in some way, maybe through a setting in the Texture…setUseOwnPbufferIfSupported  XD

Well, you know, I would, but it would probably be something uniquely complicated like, "Renanse has an ATI card and decides to leave anyone with nVidia cards WITHOUT shadow support".  :-p



Or perhaps even more complex, "Renanse decided that he'd only check in part of his code and then point the finger at darkfrog saying he must be doing it wrong".  :-p



But I wouldn't say anything like that…it just wouldn't be the loving thing to do.  Instead I'll give Renanse a big hug and wish him a Merry Christmas!  :slight_smile:



darkfrog

@darkfrog  thanks df.  you too.  I have an nvidia test machine setup now, so hopefully there will be less of the first, but probably still some of the second.  :stuck_out_tongue:



@mrcoder  I'm not sure I understand your first question?  The first paragraph of my first post is all related to using the TextureRenderer classes' render methods.  So yes, depth can be grabbed from TR.  For example, you can set the RTTSource in TestCameraMan and have the little camera monitor show depth instead of color.



As to your second question…  I don't see how it is possible to render straight to multiple textures without rerendering for each texture - which would certainly be slower than rendering once and copying, would it not?  If I'm wrong, please enlighten me as I certainly would love to improve on the code.  :slight_smile:

I'll try to clearify a bit  :smiley:


  1. pbuffer render directly to texture is only used when rendering a normal rgba texture (tex.getRTTSource() != Texture.RTT_SOURCE_RGBA leads to the old copyToTexture)…I was thinking that the same "fast" way can be achieved with pbuffers when grabbing the depth through something like:

    pbuffer.bindTexImage(Pbuffer.DEPTH_BUFFER), if you catch my drift…


  2. what I want to achieve is this:
  • setup nodes and camera in some way
  • tRenderer.render(thenodes, firstTexture)
  • scale, move or change the nodes in some way
  • tRenderer.render(thenodes, secondTexture)



    if both textures uses pbuffer direct render, the second render will kill the pbuffer and thys kill the first texture…this does not happen with copyToTexture offcourse…



    hope that's at least a bit clearer…