matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
494 stars 71 forks source link

Fail to bind texture to tex units with OGLPlus API #48

Closed sasmaster closed 10 years ago

sasmaster commented 10 years ago

Hi Matus.I have implemented DR in OGLPlus.But one thing I seems to be failed to do with the API and that's MRT bindings.For example:

   _gfboTex0.Active(0);
_gfboTex0.Bind();
_gfboTex1.Active(1);
_gfboTex1.Bind();

Doesn't bind correctly.Probably doesn't bind at all to units 0 and 1. While this works fine:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, Expose(_gfboTex0).Name());
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, Expose(_gfboTex1).Name());
matus-chochlik commented 10 years ago

Hi,

from the .Bind() without arguments I'm assuming that are DSA textures, right? If so did you set the target properly?

_gfboTex0.Active(0);
_gfboTex0.target = TextureTarget::_2D;
_gfboTex0.Bind();
_gfboTex1.Active(1);
_gfboTex1.target = TextureTarget::_2D;
_gfboTex1.Bind();

or equivalent but shorter:

_gfboTex0.Active(0);
_gfboTex0.Bind(TextureTarget::_2D);
_gfboTex1.Active(1);
_gfboTex1.Bind(TextureTarget::_2D);
sasmaster commented 10 years ago

I assumed this is done internally when. Active () is called. Will try it out, but why not to hide it behind Active and bind? Active can implicitly activate a unit and. Bind () would bind the id of the caller. Also it's clear if the texture is defined as 2d it's target is 2d. Setting it's target to anything else will probably cause driver exception . On Jan 17, 2014 8:59 PM, "Matus Chochlik" notifications@github.com wrote:

Hi,

from the .Bind() without arguments I'm assuming that are DSA textures, right? If so did you set the target properly?

_gfboTex0.Active(0); _gfboTex0.target = TextureTarget::_2D; _gfboTex0.Bind(); _gfboTex1.Active(1); _gfboTex1.target = TextureTarget::_2D; _gfboTex1.Bind();

or equivalent but shorter:

_gfboTex0.Active(0); _gfboTex0.Bind(TextureTarget::_2D); _gfboTex1.Active(1); _gfboTex1.Bind(TextureTarget::_2D);

— Reply to this email directly or view it on GitHubhttps://github.com/matus-chochlik/oglplus/issues/48#issuecomment-32636098 .

matus-chochlik commented 10 years ago

Well, after construction the target member variable of DSA texture is uninitialized and you must set it manually. Once you set it it is used automatically. It would be possible to set the target in the _Image_D() member functions in some cases but not always, you can for example use Texture2D to set cube map faces.

sasmaster commented 10 years ago

OK,I will clean up that code and then if you wish , you can add it to the examples. I took the reference from OpenGL superbible as it uses latest api approach. On Jan 17, 2014 9:12 PM, "Matus Chochlik" notifications@github.com wrote:

Well, after construction the target member variable of DSA texture is uninitialized and you must set it manually. Once you set it it is used automatically. It would be possible to set the target in the _Image_D() member functions in some cases but not always, you can for example use Texture2D to set cube map faces.

— Reply to this email directly or view it on GitHubhttps://github.com/matus-chochlik/oglplus/issues/48#issuecomment-32637212 .

matus-chochlik commented 10 years ago

Nice work, Thanks!

sasmaster commented 10 years ago

Since which version this

_gfboTex0.Bind(TextureTarget::_2D);

works?I am on .39 and it has no such an argument

On Fri, Jan 17, 2014 at 9:17 PM, Matus Chochlik notifications@github.comwrote:

Nice work, Thanks!

— Reply to this email directly or view it on GitHubhttps://github.com/matus-chochlik/oglplus/issues/48#issuecomment-32637625 .

Michael Ivanov Independent Pixel Commander onlygraphix.com Tel:+972 54 4962254

sasmaster commented 10 years ago

In fact,having updated to the latest one see no methods with such a signature...

matus-chochlik commented 10 years ago

Have a look here (line 160):

https://github.com/matus-chochlik/oglplus/blob/develop/include/oglplus/ext/EXT_direct_state_access/texture.hpp

The Target type is a typedef for TextureTarget. I don't remember exactly when I've added it but it's been there for some time.

sasmaster commented 10 years ago

Ah,you mean I need to use DSATextureEXT

Instead of Texture ?

On Fri, Jan 17, 2014 at 11:50 PM, Matus Chochlik notifications@github.comwrote:

Have a look here (line 160):

https://github.com/matus-chochlik/oglplus/blob/develop/include/oglplus/ext/EXT_direct_state_access/texture.hpp

The Target type is a typedef for TextureTarget. I don't remember exactly when I've added it but it's been there for some time.

— Reply to this email directly or view it on GitHubhttps://github.com/matus-chochlik/oglplus/issues/48#issuecomment-32651874 .

Michael Ivanov Independent Pixel Commander onlygraphix.com Tel:+972 54 4962254

matus-chochlik commented 10 years ago

Hmm, I assumed you already were using DSA texture. But anyway (non-DSA) Texture also has a Bind(Target) member function. Also note that, Texture::Active(i) is a static member function, it does not work on any particular instance of Texture.

Generally: If you are using Texture then you must make one of the texture units active by

Texture tex;
Texture::Active(i);

then you must bind the texture to one of the targets:

tex.Bind(TextureTarget::_2D);

and then you operate on the texture using static member functions and the same target

Texture::Image2D(TextureTarget::_2D, ...);
Texture::GenerateMipmaps(TextureTarget::_2D);

If you are using DSATextureEXT the you may operate on the texture instance directly without binding it, but you must specify a target:

DSATextureExt tex;
tex.target = TextureTarget::_2D;
tex.Image2D(...);
tex.GenerateMipmaps();

and if you want to access the texture in a GPU program then you must bind it to the (previously-specified) target on active texture unit:

Texture::Active(i);
tex.Bind();

Have a look at the examples/oglplus/*.cpp examples, quite lot of them use textures so you should be able to figure it out. HTH.

matus-chochlik commented 10 years ago

B.T.W. there is also a third option the Bound which tries to emulate DSA-textures by wrapping the (non-DSA) Texture class, but internally it still has to bind the texture instance to a texture unit before using it. Have a look for example at: https://github.com/matus-chochlik/oglplus/blob/develop/example/oglplus/020_texture_projection.cpp

lines 163-170.