SFML community forums

General => Feature requests => Topic started by: lolz123 on April 29, 2013, 09:44:29 pm

Title: Texture ID Accessor
Post by: lolz123 on April 29, 2013, 09:44:29 pm
Hello,

I cannot seem to find the getTextureID function in the latest version of SFML anymore. Not having this function makes it rather difficult to use SFML with OpenGL. Why not have such an accessor?
Title: Re: Texture ID Accessor
Post by: eXpl0it3r on April 29, 2013, 10:30:03 pm
I'm not an expert on the whole OpenGL/SFML thingy, but can't you just use the bind() function?
Also you might want to give a clear example, why it's needed. ;)
Title: Re: Texture ID Accessor
Post by: Laurent on April 29, 2013, 10:36:07 pm
"anymore"? It has never existed.

The texture ID is almost never necessary, you access the texture properties by binding it (which you can do the bind function) and then calling texture-related functions.

There are also a few threads on this subject, you can do a forum search.
Title: Re: Texture ID Accessor
Post by: lolz123 on April 29, 2013, 11:23:20 pm
I thought there was one, I wasn't sure anymore though  :P. Sorry about that!

What if I wanted to use SFML textures as attachments for a framebuffer object? It would be nice if I could use SFML textures for that :)

Also, writing generic OpenGL code and then trying to integrate it with SFML can become more difficult, since you can't feed functions textureIDs anymore.

In addition, being able to get the texture ID makes it easier to find the texture in debugging programs such as gDEBugger.

I just don't see why the function shouldn't exist!
Title: Re: Texture ID Accessor
Post by: Laurent on April 29, 2013, 11:51:45 pm
You have valid points.
Title: Re: Texture ID Accessor
Post by: lolz123 on May 13, 2013, 12:44:16 am
So, will this feature be available in future versions? It would be much appreciated!
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 07:58:14 am
Maybe :P
Title: Re: Texture ID Accessor
Post by: Tank on May 13, 2013, 08:25:21 am
I'd need it too, so I can remove this workaround:

sf::Texture::bind( &grass_texture );
glGetIntegerv( GL_TEXTURE_BINDING_2D, &grass_texture_id );

;)
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 08:42:04 am
What do you do with the ID?
Title: Re: Texture ID Accessor
Post by: Tank on May 13, 2013, 09:14:11 am
I need the ID for a sampler2D uniform variable in a shader. I use sf::Texture for pure convenience, as it would be perfectly possible to generate the texture myself and load it with sf::Image::getPixelsPtr(). However that also means I can't reuse it with SFML's drawables anymore.
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 11:45:49 am
Why don't you use Shader::setParameter(Texture&)?
Title: Re: Texture ID Accessor
Post by: Tank on May 13, 2013, 11:54:08 am
Because I don't use SFML for shaders. :)
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 04:40:46 pm
Why? :P
Title: Re: Texture ID Accessor
Post by: lolz123 on May 13, 2013, 05:12:01 pm
While we are at it, I will also propose a method to get the ID for a shader program :).

Unfortunately, the lack of these functions is a reason I still use SDL for 3D  :P. I need these functions for shaders as well. IDK about Tank, but I use my own shader system because SFML doesn't allow you to arbitrarily link uniforms to binding ports, it doesn't have near enough uniform types (especially matrices), and you cannot use UBO's with it (since you cannot get the program ID).
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 05:24:39 pm
Look at Tank's code, the workaround is just 2 lines of code... so don't say that your completely blocked because of it ;)
Title: Re: Texture ID Accessor
Post by: lolz123 on May 13, 2013, 05:27:08 pm
I very much dislike glGet functions, they are really slow. Ugly, and high latency.

http://gamedev.stackexchange.com/questions/34944/glgetfloatv-should-it-be-avoided-can-it-be-replaced (http://gamedev.stackexchange.com/questions/34944/glgetfloatv-should-it-be-avoided-can-it-be-replaced)

And yes, the performance matters when designing a full 3D engine :). GL calls are a large speed impediment, and is the reason why debuggers like gDEBugger have counters for them.
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 06:30:06 pm
Yeah... but here you just have to do it once, the texture/shader ID never changes.
Title: Re: Texture ID Accessor
Post by: lolz123 on May 13, 2013, 07:58:35 pm
Quote
Yeah... but here you just have to do it once, the texture/shader ID never changes.

Having to cache it yourself when 4 more lines of code can be added to the SFML source to completely avoid this issue seems a bit silly to me. I know I could add it myself, but then nobody could use anything I write without compiling a custom version of SFML.

Why not just add the function for the next version of SFML? :P
Title: Re: Texture ID Accessor
Post by: Laurent on May 13, 2013, 10:41:06 pm
You misunderstood me. I'm not trying to argue for not adding this function. I'm just proving that what you say ("I cannot do that, I'm stuck, I have to use SDL") is overly exagerated because there's a 2 lines of code workaround.
Title: Re: Texture ID Accessor
Post by: lolz123 on May 13, 2013, 11:13:34 pm
Ah OK.

Title: Re: Texture ID Accessor
Post by: Tank on May 14, 2013, 08:59:18 am
I don't use SFML's shaders because I can't link multiple shaders to a program -- at least that's what I discovered last, and as far as I know, that part hasn't changed. SFML only allows to use one fragment and one vertex shader. I would have to change the sources in order to use combined shaders, whereas with raw OpenGL I can call glAttachShader whenever I want.

By the way, just like lolz123 I also use this for a custom 3D game library, and I wanted to use sf::Texture for convenience.
Title: Re: Texture ID Accessor
Post by: Laurent on May 14, 2013, 09:06:18 am
Ok, I see.
Title: Re: Texture ID Accessor
Post by: Roose Bolton of the Dreadfort on May 21, 2013, 03:52:06 pm
I came across this problem, the 2 line workaround is okay but I guess a texture ID accessor would be nice to have.. Laurent I will swap you a carton of orange juice for your time to implement it? I can ship it to metz np.
Title: Re: Texture ID Accessor
Post by: Laurent on May 21, 2013, 03:56:39 pm
It will be added as soon as possible (not in SFML 2.1 which is a bug-fix release).
Title: Re: Texture ID Accessor
Post by: FRex on January 04, 2015, 01:51:37 am
Quote
It will be added as soon as possible (not in SFML 2.1 which is a bug-fix release).
Bump?
Title: Re: Texture ID Accessor
Post by: binary1248 on January 04, 2015, 02:04:18 am
https://github.com/SFML/SFML/commit/1c3425744b405213335d40e08cc58d1ffcdd2302

It's coming soon™.