Permalink
Browse files

fixed: move texture handling to separate function

git-svn-id: https://opensg.vrsource.org/svn/trunk@2252 4683daeb-ad0f-0410-a623-93161e962ae5
  • Loading branch information...
1 parent 2933d1e commit 3830d5e1ece7aa796bb1075a8b9f04fc00c2c157 cneumann committed Dec 29, 2009
@@ -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();
@@ -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
{
@@ -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
{
@@ -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
@@ -65,6 +65,11 @@ class domInstance_effect;
OSG_BEGIN_NAMESPACE
+// forward decl
+class ColladaInstanceEffect;
+class ChunkMaterial;
+
+
class OSG_FILEIO_DLLMAPPING ColladaEffect : public ColladaInstantiableElement
{
/*========================== PUBLIC =================================*/
@@ -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;
@@ -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;
@@ -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>();

0 comments on commit 3830d5e

Please sign in to comment.