HI Michael, With a well constrained problem like tile textures I wouldn't bother with using the TextureAtlasBuilder, it's crude compared to what a human can create as the human knows all the constraints up front and has a brain that can understand the usage model and the in's and outs of optimizing the graphics pipeline. You should always consider tools like osgUtil::Optimizer as crude approximations to what a engineer can do with a scene graph.
For you it's simply, just place all your images in a regular pattern in your osg::Image and create your tiles with osg::Geometry that have the texture coordinates that reference them, or use a single osg::Geometry and use an osg::TextMat to apply a texture matrix to the coordinates. If you are writing shaders then you can compute the texture coord scale and offsets yourself based on a tileX,tileY. However, I have to say that 43 tiles is a tiny number, even if you triple that for all your themes, so I can't imagine that you'll see a CPU bottleneck in cull or draw dispatch or down on the GPU. So personally I'd just go do some benchmarking and see if I'm getting the performance I need and if I'm not go look at the bottlenecks and then do something about them rather than deciding up front what the problem might be and fixing some possible problem than an actual problem. Robert. On 15 February 2013 04:13, michael kapelko <[email protected]> wrote: > Hi, Robert. > > I'll try to explain my intentions. > I develop Mahjong game ( > http://opengamestudio.org/wp-content/gallery/ogs-mahjong/mj-bin-2012-09-10-20-35_1.png > ). > To create tiles on the table, I use single Tile.mesh and several Texture.png > files. Since Mahjong rules require 43 different tiles, I need 43 textures. > Also, one can switch among different tile themes. Those are currently > organized simply as directories of textures, so you can imagine the file > bloat when there are 3 themes: it's 43 * 3 = 129 files! > I want to have a single tile theme texture (atlas) which will contain all 43 > textures. > > Do I understand correctly that I should do something like that: > // Reading atlas. > std::vector<osg::Texture2D*> textures = readMyAtlasFile(fileName); > osgUtil::Optimizer::TextureAtlasBuilder atlasBuilder; > for (each texture) > atlasBuilder.addSource(texture); > // Using atlas. > for (i in atlasBuilder) > tileNodes[i]->getOrCreateStateSet()->setTextureAttributeAndModes(0, > atlasBuilder.getSourceTexture(i)); > > Is it so? > Thanks. > > 2013/2/15 Robert Osfield <[email protected]> >> >> Hi Michael, >> >> There really isn't much to do with texture atlas once you have built >> the scene graph - the osg::Geometry and osg::Texture/osg::Image you >> use are all the same type as you'd use for none texture atlas usage, >> the only difference is the contents of the osg::Image and the texture >> coordinates used on the osg::Geometry. You can create and save out >> texture atlas and associated geometry just as normal OSG scene graphs. >> >> Texture atlases are useful for enabling one to group all the geometry >> and imagery together for particular objects together as a single unit, >> for instance a house rendered with separate textures for each of the >> walls and the roof would require 5 images, 5 textures and 5 >> geometries, while a texture atlas would allow you to use a single >> image, single texture and a single geometry. As CPU overhead of cull >> and draw is often a bottleneck then merging 5 sets of state and >> geometry into a single unit can be a big saving. If you aren't CPU or >> GPU batch limited then using a texture atlas will help very little. >> >> Robert. >> >> On 14 February 2013 09:23, michael kapelko <[email protected]> wrote: >> > Hi. >> > I want to be able to have to specify several textures which will be >> > mapped >> > using the same UV, a collection of textures. >> > I want to put them into a single file, texture atlas. >> > I've grepped OSG examples on 'tlas' word. Didn't find any example. >> > I've googled for OSG atlas and only found >> > osgUtil::Optimizer::Optimizer::TextureAtlasBuilder. >> > As I understood, I can only build a runtime atlas (not save it) with OSG >> > from separate textures. >> > Can I use the builder to create an OSG texture atlas from my atlas file? >> > Will OSG texture atlas usage reduce draw calls/increase draw >> > performance? >> > Thanks. >> > >> > _______________________________________________ >> > osg-users mailing list >> > [email protected] >> > >> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >> > >> _______________________________________________ >> osg-users mailing list >> [email protected] >> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

