SFML community forums

General => Feature requests => Topic started by: BaneTrapper on August 26, 2014, 06:35:21 pm

Title: RenderTexture passes its texture ovenership to Texture
Post by: BaneTrapper on August 26, 2014, 06:35:21 pm
Hello.
Id like to request a possibility of sf::RenderTexture swapping ownership of its texture with sf::Texture.
Reasons being,
Code: [Select]
std::cout << sizeof(sf::RenderTexture) << std::endl;//488
std::cout << sizeof(sf::Texture) << std::endl;//32
My thought are that RenderTexture was supposed to be used as a drawing board and sf::Texture would be the paper that you actually draw on.

Related to topics:
http://en.sfml-dev.org/forums/index.php?topic=16178.0
http://en.sfml-dev.org/forums/index.php?topic=16174.0
Is it possible to expect such a feature?
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Stauricus on August 26, 2014, 06:48:38 pm
what do you mean by 'swapping ownership'?
and i think sf::Texture would be the drawing itself, not a paper where you draw.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Jesper Juhl on August 26, 2014, 06:50:15 pm
Copying (moving) a RenderTexture to a Texture is not enough?
Not sure I understand what you need/want that cannot already be done..
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 26, 2014, 07:59:55 pm
Would be nice to explain why you want such a feature.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: BaneTrapper on August 26, 2014, 08:51:14 pm
Copying (moving) a RenderTexture to a Texture is not enough?
Not sure I understand what you need/want that cannot already be done..
Moving renderTexture to texture, is that possible? i tested, and failed to accomplish that.
Example please.

Would be nice to explain why you want such a feature.
It looks like the "feature already exists" i just failed to see it.

what do you mean by 'swapping ownership'?
and i think sf::Texture would be the drawing itself, not a paper where you draw.
I mean that i cannot extract the texture from sf::RenderWindow to sf::Texture.
The sf::RenderTexture has to have the texture pointer in GPU, texture has none and is in "invalid" state by default afaik.
Setting sf::Texture texture to sf::RenderTexture texture (meaning now they share it)
Then sf::RenderTexture texture to nothing. Meaning we swapped ownership of texture from sf::RenderTexture to sf::Texture without having to copy the texture around.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Jesper Juhl on August 26, 2014, 08:54:48 pm
Copying is posible and if SFML 3.0 adds a move constructor and move assignment operator then we'll be all set for moving :)
But (besides performance implications) why is copying not enough? What super critical/performances sensitive operation are you doing?
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 26, 2014, 09:20:16 pm
Quote
Copying is posible and if SFML 3.0 adds a move constructor and move assignment operator then we'll be all set for moving
You can't move a const texture.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Jesper Juhl on August 26, 2014, 09:21:43 pm
Argh. My bad. I'm an idiot. I forgot that it is const.
Sorry.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: BaneTrapper on August 27, 2014, 07:17:52 pm
I no longer require such feature, tho having it would be improvement to performance.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Tank on August 28, 2014, 08:34:08 am
Also, copying (or even moving) an internally managed resource out of sf::RenderWindow sounds like a really bad idea. Instead I'd suggest something like this:

sf::Texture texture;
sf::RenderTexture renderTexture(texture);
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Hapax on August 28, 2014, 02:15:22 pm
sf::RenderTexture renderTexture(texture);
What does this do?  :o
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: zsbzsb on August 28, 2014, 02:17:27 pm
Isn't it clear?

The render texture will instead of creating its own internal texture would use the texture passed in the overloaded constructor as the target for draw calls.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 28, 2014, 02:29:18 pm
This would be almost equivalent to the current code (the only difference is that you can change the texture properties before passing it to the RenderTexture). A more useful version would be a setTexture function, so that you can use the same RenderTexture to draw on multiple textures. But I wonder what kind of problem this would solve...
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Hapax on August 28, 2014, 02:33:28 pm
Isn't it clear?
It is not clear. It looks obvious, sure, but I wouldn't want to use it on an assumption.
I did try to find information on this in the documentation but, alas, I could not find any.
Does the render texture make a copy of the texture or point to the actual one?
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: binary1248 on August 28, 2014, 02:57:14 pm
Does the render texture make a copy of the texture or point to the actual one?
I take from the discussion that it will simply point to the actual one, hence the equivalence to a .setTexture() method that is already part of some other classes. I can already see all the "white square RenderTexture" threads rolling in ::).
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 28, 2014, 03:18:43 pm
To me, we don't need such a feature anyway and this discussion can thus be closed.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: binary1248 on August 28, 2014, 03:41:32 pm
Well, it depends really. If people, for whatever reason, want to use a single RenderTexture to draw to multiple texture destinations every frame because they only need a single "drawer" RenderTexture, then it makes sense to enable them to do so. Some time not so long ago, I even recommended reusing RenderTextures because it minimizes the number of contexts floating around, and in the end, it really doesn't make sense to store multiple of them if you can reuse the same one. OpenGL FBOs were designed to be easy to swap out attachments for for this purpose, so I don't see why we shouldn't pass that power on to SFML's users as well.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 28, 2014, 03:46:41 pm
Quote
If people, for whatever reason, want to use a single RenderTexture to draw to multiple texture destinations every frame because they only need a single "drawer" RenderTexture, [...]
Then let's find a relevant use case for this before deciding anything. You know the SFML philosophy, "don't do it if nobody needs it" ;)
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Hapax on August 28, 2014, 04:09:56 pm
I thought the philosophy was "don't do it if only one person needs it".  :P

A possible scenario that someone may possibly want to do is a group of television screens  ;D

EDIT: If this rendertexture(texture) thing works, I guess that would do that.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 28, 2014, 04:14:00 pm
Quote
I thought the philosophy was "don't do it if only one person needs it".
It has slightly evolved since then :P

Quote
A possible scenario that someone may possibly want to do is a group of television screens
I'd like answers without the words "possible", "may", "possibly", etc. Real use cases please.

Quote
If this rendertexture(texture) thing works, I guess that would do that.
Such a thing doesn't exist, it was just an idea. And no, it wouldn't do that since the RenderTexture would be tied to a unique Texture instance.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Hapax on August 28, 2014, 05:17:51 pm
It has slightly evolved since then :P
Good to know  :)

I'd like answers without the words "possible", "may", "possibly", etc. Real use cases please.
This means that you are waiting for someone to require it for a project before considering implementing it. In which case, SFML will not be able to provide for the requirement of their project. The "possibly" stuff is a way of saying that these things could happen and is one example of something people may require. If someone said that they were going to do the thing that I just suggested as a possibility, does that make it a real use case?

the RenderTexture would be tied to a unique Texture instance.
Tied? Does this mean that the texture cannot be used as a texture for anything else?  :o
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Laurent on August 28, 2014, 07:43:27 pm
Quote
This means that you are waiting for someone to require it for a project before considering implementing it. In which case, SFML will not be able to provide for the requirement of their project. The "possibly" stuff is a way of saying that these things could happen and is one example of something people may require. If someone said that they were going to do the thing that I just suggested as a possibility, does that make it a real use case?
Since this feature would be an optimization only, it won't block anyone. So yes, I'd really like to know if someone really needs this before doing it. If nobody cares, there's probably no point making the code more complicated.

Quote
Tied? Does this mean that the texture cannot be used as a texture for anything else?
No. I just said that since you pass the texture to the constructor, you won't be able to change it afterwards. So you end up with 1 RenderTexture = 1 Texture, which is exactly what the current API does. No point.
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Tank on August 28, 2014, 09:43:08 pm
Of course it shouldn't be fixed, that's why I wrote "like this". ;)
Title: Re: RenderTexture passes its texture ovenership to Texture
Post by: Hapax on August 29, 2014, 01:38:40 am
If nobody cares, there's probably no point making the code more complicated.
I didn't realise that it would, I'm sorry.

I just said...
I wasn't trying to trick you or question whether you stated anything correctly or anything. I genuinely just wanted to know. Sorry if you understood it that way  :(