Author Topic: questions about render-to-texture  (Read 3437 times)

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
questions about render-to-texture
« on: July 10, 2016, 04:43:22 pm »
i am new to RTT, and i am now using FrameBuffer.setRenderTarget() to render into textures. (the FrameBuffer is the same one as the main window)

1) i blit white text into a texture after clearing FB with black color. when the texture is applied to a transparent Object3D, the black part is visible. but i have another texture loaded from a grayscale PNG file, where the black part is invisible. why isn't the RTT texture tranparent?
2) the doc says RTT must not use mipmaping. but if a texture will never be rendered into again after the first time, can it have mipmaping afterwards?
3) if a texture has size of 32x32 while the FB is 1280x800, when rendering into the texture, is the renderer doing work on 32x32 pixels or 1280x800 pixels? i mean the workload, is it small or large.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: questions about render-to-texture
« Reply #1 on: July 11, 2016, 08:37:16 am »
  • Because it has no alpha channel defined. If you load the texture that contains black parts, by default, the loader will generate an alpha channel that makes the black parts transparent. This isn't (it can't be) the case for render to texture. You would have to use a custom shader in some stage to make these parts transparent.
  • No, because mipmaps are generated on the client side, but the RTT exists on the server side (i.e. inside GPU memory)
  • 32*32. The FrameBuffer's size doesn't matter here.

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: questions about render-to-texture
« Reply #2 on: July 11, 2016, 10:14:06 am »
for question 1 and 2 , i guess if i obtain all pixel data from the RTT texture and put into another texture , then the other texture would be the same as ordinary textures , right?

edit: i read the doc again and seems like there is no api that obtains pixel data from a RTT texture.
« Last Edit: July 11, 2016, 11:09:08 am by MichaelJPCT »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: questions about render-to-texture
« Reply #3 on: July 11, 2016, 11:06:28 am »
Yes, but it depends on how you "put it into another texture". If you are using on of the constructors that don't take the useAlpha parameter (or set it to false), then yes. If you set it via an ITextureEffect implementation, you have to provide alpha yourself.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: questions about render-to-texture
« Reply #4 on: July 11, 2016, 11:08:18 am »
...but then again: How you plan to obtain the actual pixel data of that texture? You would have to blit it into the FrameBuffer and grab the pixels from there, which is certainly doable but too slow for real-time. It should be fine, it you only do it once (or every now and then).

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: questions about render-to-texture
« Reply #5 on: July 11, 2016, 01:47:55 pm »
i may create a software FB of small size when i need those effects.

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: questions about render-to-texture
« Reply #6 on: August 31, 2016, 07:04:10 pm »
i have some more questions about RTT.
rtt is only stored in vram, can i call unloadTexture on a rtt texture?
can a rtt texture be freed in order to save vram?
if a rtt is freed from vram, will calling setRenderTarget re-create the rtt ?
if vram is full, what will happen if one more texture is needed for render?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: questions about render-to-texture
« Reply #7 on: August 31, 2016, 08:18:26 pm »
rtt is only stored in vram, can i call unloadTexture on a rtt texture?
Yes, you can.
can a rtt texture be freed in order to save vram?
Yes. In the same way as any other texture. In fact, it is a normal texture, it's just used as a render target in addition to that.
if a rtt is freed from vram, will calling setRenderTarget re-create the rtt ?
Yes.
if vram is full, what will happen if one more texture is needed for render?
No idea. I guess it depends on the GPU and the drivers. Could be everything from a crash (most likely) to a white or undefined texture.