Querying which texture units are available

classic Classic list List threaded Threaded
3 messages Options
Hannes Naude Hannes Naude
Reply | Threaded
Open this post in threaded view
|

Querying which texture units are available

Hi all

I recently implemented a shader that does projective texturing onto the osgEarth terrain. It works just fine at the moment, but I used texture unit 8 at a whim, and when I tried to change the unit being used to a lower number it broke. This made me realise that my code is most likely brittle and may break if an earth file is loaded that causes osgEarth to use more than 7 of the texture units at a given time.

Is there a way for me to query which texture units are in use before binding my texture to a given unit, or another way to coordinate this resource usage with osgEarth code? Ideally I would not need to worry about which unit is being used at all. This feels like a very noobish question, but I could find nothing in the docs that I am aware of. I am perfectly happy to go read the code to figure this out, but would appreciate a pointer to where to start as the code base is sizeable and I am chasing a schedule here.

Regards
Hannes Naude
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Querying which texture units are available

Hello Hannes,

You can call MapNode->getTerrainEngine()->getResources() to get a pointer to the TerrainResources API. This interface lets you reserve texture image units, either globally or per-Layer. osgEarth uses this to allocate all its texture image units, so you can use it too and be assured that there won't be any overlap.

Hope this helps!
Glenn Waldron / Pelican Mapping
Hannes Naude Hannes Naude
Reply | Threaded
Open this post in threaded view
|

Re: Querying which texture units are available

Thanks Glenn

That is exactly what I was hoping for.

Regards
Hannes