Added osg::TexMat::s/getScaleByTextureRectangleSize feature that allows
one to use the osg::TexMat to automatically scale non dimensional tex coordinats to the size of the last texture rectangle applied.
This commit is contained in:
@@ -12,10 +12,13 @@
|
||||
*/
|
||||
#include <osg/GL>
|
||||
#include <osg/TexMat>
|
||||
#include <osg/Notify>
|
||||
#include <osg/TextureRectangle>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
TexMat::TexMat()
|
||||
TexMat::TexMat():
|
||||
_scaleByTextureRectangleSize(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,9 +27,20 @@ TexMat::~TexMat()
|
||||
{
|
||||
}
|
||||
|
||||
void TexMat::apply(State&) const
|
||||
void TexMat::apply(State& state) const
|
||||
{
|
||||
|
||||
glMatrixMode( GL_TEXTURE );
|
||||
glLoadMatrix(_matrix.ptr());
|
||||
|
||||
if (_scaleByTextureRectangleSize)
|
||||
{
|
||||
const osg::TextureRectangle* tex = dynamic_cast<const osg::TextureRectangle*>(state.getLastAppliedTextureAttribute(state.getActiveTextureUnit(), osg::StateAttribute::TEXTURE));
|
||||
if (tex)
|
||||
{
|
||||
glScalef(tex->getTextureWidth(),tex->getTextureHeight(),1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
#define VERSION_0014 14
|
||||
#define VERSION_0015 15
|
||||
#define VERSION_0016 16
|
||||
#define VERSION_0017 17
|
||||
|
||||
#define VERSION VERSION_0016
|
||||
#define VERSION VERSION_0017
|
||||
|
||||
/* The BYTE_SEX tag is used to check the endian
|
||||
of the IVE file being read in. The IVE format
|
||||
|
||||
@@ -32,6 +32,12 @@ void TexMat::write(DataOutputStream* out){
|
||||
|
||||
// Write mode
|
||||
out->writeMatrixf(getMatrix());
|
||||
|
||||
if ( out->getVersion() >= VERSION_0017 )
|
||||
{
|
||||
out->writeBool(getScaleByTextureRectangleSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TexMat::read(DataInputStream* in){
|
||||
@@ -51,6 +57,11 @@ void TexMat::read(DataInputStream* in){
|
||||
|
||||
// Read matrix
|
||||
setMatrix(in->readMatrixf());
|
||||
|
||||
if ( in->getVersion() >= VERSION_0017 )
|
||||
{
|
||||
setScaleByTextureRectangleSize(in->readBool());
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -53,6 +53,22 @@ bool TexMat_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("scaleByTextureRectangleSize"))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
{
|
||||
texmat.setScaleByTextureRectangleSize(true);
|
||||
fr +=2 ;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("FALSE"))
|
||||
{
|
||||
texmat.setScaleByTextureRectangleSize(false);
|
||||
fr +=2 ;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -65,5 +81,11 @@ bool TexMat_writeLocalData(const Object& obj, Output& fw)
|
||||
fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl;
|
||||
fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl;
|
||||
fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl;
|
||||
|
||||
if (texmat.getScaleByTextureRectangleSize())
|
||||
{
|
||||
fw.indent() << "scaleByTextureRectangleSize TRUE"<<std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user