1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
12 */
13 #include <osg/GL>
14 #include <osg/TexMat>
15 #include <osg/Notify>
16 #include <osg/TextureRectangle>
17 
18 using namespace osg;
19 
TexMat()20 TexMat::TexMat():
21     _scaleByTextureRectangleSize(false)
22 {
23 }
24 
25 
~TexMat()26 TexMat::~TexMat()
27 {
28 }
29 
apply(State & state) const30 void TexMat::apply(State& state) const
31 {
32 #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
33     glMatrixMode( GL_TEXTURE );
34     glLoadMatrix(_matrix.ptr());
35 
36     if (_scaleByTextureRectangleSize)
37     {
38         const osg::TextureRectangle* tex = dynamic_cast<const osg::TextureRectangle*>(state.getLastAppliedTextureAttribute(state.getActiveTextureUnit(), osg::StateAttribute::TEXTURE));
39         if (tex)
40         {
41             glScalef(tex->getTextureWidth(),tex->getTextureHeight(),1.0f);
42         }
43     }
44 
45     glMatrixMode( GL_MODELVIEW );
46 #else
47     OSG_NOTICE<<"Warning: TexMat::apply(State&) - not supported."<<std::endl;
48 #endif
49 }
50