Skip to content

Commit

Permalink
fixed: move texture handling to separate function
Browse files Browse the repository at this point in the history
git-svn-id: https://opensg.vrsource.org/svn/trunk@2252 4683daeb-ad0f-0410-a623-93161e962ae5
  • Loading branch information
cneumann committed Dec 29, 2009
1 parent 2933d1e commit 3830d5e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 43 deletions.
78 changes: 36 additions & 42 deletions Source/System/FileIO/Collada/OSGColladaEffect.cpp
Expand Up @@ -96,8 +96,8 @@ ColladaEffect::read(void)
continue;
}

// must read surface params before sampler params, because their <source>
// element can refer to a surface
// must read surface params before sampler params, because
// a samplers <source> can refer to a surface
domFx_surface_commonRef paramSurface =
newParams[i]->getFx_basic_type_common()->getSurface();

Expand Down Expand Up @@ -469,31 +469,16 @@ ColladaEffect::createInstanceProfileCommon(
}
else if(texture != NULL)
{
xsNCName texId = texture->getTexture ();
xsNCName tcSemantic = texture->getTexcoord();
std::string texId = texture->getTexture ();
std::string tcSemantic = texture->getTexcoord();

ParamSampler2DMapConstIt paramIt = _sampler2DParams.find(texId);

if(paramIt != _sampler2DParams.end())
{
mat->addChunk(paramIt->second.colSampler2D->getTexture(),
texCount );

TextureEnvChunkUnrecPtr texEnv = TextureEnvChunk::create();
texEnv->setEnvMode(GL_REPLACE);

mat->addChunk(texEnv, texCount);

OSG_COLLADA_LOG(("ColladaEffect::createInstanceProfileCommon: "
"texCoord symbol [%s] in slot [%d]\n",
tcSemantic,
Geometry::TexCoordsIndex + texCount));

// record the texture slot that is associated with
// the symbolic name
colInstEffect->editTCMap()[tcSemantic] =
Geometry::TexCoordsIndex + texCount;
++texCount;
addTexture(texId, tcSemantic, colInstEffect,
paramIt->second.colSampler2D, mat, GL_REPLACE,
texCount );
}
else
{
Expand Down Expand Up @@ -530,31 +515,16 @@ ColladaEffect::createInstanceProfileCommon(
}
else if(texture != NULL)
{
xsNCName texId = texture->getTexture ();
xsNCName tcSemantic = texture->getTexcoord();
std::string texId = texture->getTexture ();
std::string tcSemantic = texture->getTexcoord();

ParamSampler2DMapConstIt paramIt = _sampler2DParams.find(texId);

if(paramIt != _sampler2DParams.end())
{
mat->addChunk(paramIt->second.colSampler2D->getTexture(),
texCount );

TextureEnvChunkUnrecPtr texEnv = TextureEnvChunk::create();
texEnv->setEnvMode(GL_MODULATE);

mat->addChunk(texEnv, texCount);

OSG_COLLADA_LOG(("ColladaEffect::createInstanceProfileCommon: "
"texCoord symbol [%s] in slot [%d]\n",
tcSemantic,
Geometry::TexCoordsIndex + texCount));

// record the texture slot that is associated with
// the symbolic name
colInstEffect->editTCMap()[tcSemantic] =
Geometry::TexCoordsIndex + texCount;
++texCount;
addTexture(texId, tcSemantic, colInstEffect,
paramIt->second.colSampler2D, mat, GL_MODULATE,
texCount );
}
else
{
Expand Down Expand Up @@ -692,6 +662,30 @@ ColladaEffect::fillFloatParam(
}
}

void
ColladaEffect::addTexture(
const std::string &texId, const std::string &tcSemantic,
ColladaInstanceEffect *colInstEffect, ColladaSampler2D *colSampler2D,
ChunkMaterial *mat, GLenum envMode,
UInt32 &texCount )
{
TextureEnvChunkUnrecPtr texEnv = TextureEnvChunk::create();
texEnv->setEnvMode(envMode);

mat->addChunk(colSampler2D->getTexture(), texCount);
mat->addChunk(texEnv, texCount);

OSG_COLLADA_LOG(("ColladaEffect::addTexture: "
"texCoord symbol [%s] in slot [%d]\n",
tcSemantic.c_str(),
Geometry::TexCoordsIndex + texCount));

colInstEffect->editTCMap()[tcSemantic] =
Geometry::TexCoordsIndex + texCount;

++texCount;
}

OSG_END_NAMESPACE

#endif // OSG_WITH_COLLADA
15 changes: 15 additions & 0 deletions Source/System/FileIO/Collada/OSGColladaEffect.h
Expand Up @@ -65,6 +65,11 @@ class domInstance_effect;

OSG_BEGIN_NAMESPACE

// forward decl
class ColladaInstanceEffect;
class ChunkMaterial;


class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
{
/*========================== PUBLIC =================================*/
Expand Down Expand Up @@ -109,12 +114,14 @@ class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
/*! \name Types */
/*! \{ */

// <sampler2D> DOM and loader objects
struct ParamSampler2D
{
ColladaSampler2DRefPtr colSampler2D;
domFx_sampler2D_commonRef sampler2D;
};

// <surface> DOM and loader objects
struct ParamSurface
{
ColladaSurfaceRefPtr colSurface;
Expand Down Expand Up @@ -170,6 +177,14 @@ class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
domCommon_float_or_param_type::domFloatRef &floatOut,
domCommon_float_or_param_type::domParamRef &paramOut );

void addTexture(const std::string &texId,
const std::string &tcSemantic,
ColladaInstanceEffect *colInstEffect,
ColladaSampler2D *colSampler2D,
ChunkMaterial *mat,
GLenum envMode,
UInt32 &texCount );

static ColladaElementRegistrationHelper _regHelper;

ParamSampler2DMap _sampler2DParams;
Expand Down
2 changes: 1 addition & 1 deletion Source/System/FileIO/Collada/OSGColladaMaterial.cpp
Expand Up @@ -85,7 +85,7 @@ ColladaMaterial::read(void)
Material *
ColladaMaterial::createInstance(ColladaInstanceElement *colInstElem)
{
SWARNING << "ColladaMaterial::craeteInstance: NIY" << std::endl;
OSG_COLLADA_LOG(("ColladaMaterial::createInstance\n"));

MaterialUnrecPtr retVal = NULL;
domMaterialRef material = getDOMElementAs<domMaterial>();
Expand Down

0 comments on commit 3830d5e

Please sign in to comment.