Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Load part of texture to image  (Read 2267 times)

0 Members and 1 Guest are viewing this topic.

Xyst

  • Guest
Load part of texture to image
« on: February 07, 2016, 10:56:10 pm »
Hi, I need to draw a lot of shapes to a RenderTexture, and then get the image of the drawing to analyse the colours. The thing is, I only need to analyse a small part of the image. The loop is pretty fast, except for one thing: loading the texture to an image. Is there any way to only load a portion of the texture, as I do not need the whole one?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Load part of texture to image
« Reply #1 on: February 08, 2016, 12:41:31 am »
Since the texture is on the graphics card memory, it might be quicker to crop it there.
Try creating an extra render texture that is the size of the part that you want to analyse and then draw the original texture to it, offsetting so that it draws the part you need. This smaller render texture should be much quicker to copy to an image.
If you always analyse the same sized section, you can easily re-use a render texture without re-creation.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Xyst

  • Guest
Re: Load part of texture to image
« Reply #2 on: February 09, 2016, 12:35:42 am »
The area being analysed changes position and size, so I created a couple of differently sized rendertextures so I wouldn't have to create new ones for differently sized areas (creating new rendertextures also takes a considerable amount of time), and then I just changed the view around. Thanks to your tip it now runs about 30x faster!

But it seems to me that this kind of solution is quite bulky and unnecessary. Is there a reason for not being able to only get part of the texture, or is it simply because it hasn't been a requested feature?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Load part of texture to image
« Reply #3 on: February 09, 2016, 02:41:29 am »
You're welcome! Glad it helped  :)

Maybe it is that it's never really been necessary, requested, or just common enough.
I just took a look at the source and it looks like it could be added with only a few modifications without breaking any previous code but I may be wrong as it does seem to sometimes need to copy the entire pixel data before preparing it.

It may be simpler to just access the OpenGL texture directly. Some use will probably be found of Texture::getNativeHandle()
« Last Edit: February 09, 2016, 02:55:53 am by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*