コード例 #1
0
ファイル: GLTextureStage.cpp プロジェクト: arx/ArxLibertatis
void GLTextureStage::apply() {
	
	if(!tex && !current) {
		return;
	}
	
	if(mStage != 0) {
		glActiveTexture(GL_TEXTURE0 + mStage);
	}
	
	if(tex != current) {
		glBindTexture(GL_TEXTURE_2D, tex ? tex->tex : GL_NONE), current = tex;
	}
	
	if(tex) {
		
		bool apply = true;
		for(size_t i = 0; i < mStage; i++) {
			GLTextureStage * stage = renderer->GetTextureStage(i);
			if(stage->tex == tex && stage->isEnabled()) {
				apply = false;
				#ifdef ARX_DEBUG
				if(stage->getWrapMode() != getWrapMode()
				   || stage->getMinFilter() != getMinFilter() || stage->getMagFilter() != getMagFilter()) {
					static bool warned = false;
					if(!warned) {
						LogWarning << "Same texture used in multiple stages with different attributes.";
						warned = true;
					}
				}
				#else
				break;
				#endif
			}
		}
		
		if(apply) {
			tex->apply(this);
		}
		
	}

	if(mStage != 0) {
		glActiveTexture(GL_TEXTURE0);
	}
}
コード例 #2
0
ファイル: FontStyle.cpp プロジェクト: libavg/libavg
void FontStyle::setDefaultedArgs(const ArgList& args)
{
    // Warning: The ArgList here contains args that are for a different class originally,
    // so the member offsets are wrong.
    setDefaultedArg(m_sName, "font", args);
    setDefaultedArg(m_sVariant, "variant", args);
    setDefaultedArg(m_Color, "color", args);
    setDefaultedArg(m_AAGamma, "aagamma", args);
    setDefaultedArg(m_Size, "fontsize", args);
    setDefaultedArg(m_Indent, "indent", args);
    setDefaultedArg(m_LineSpacing, "linespacing", args);
    UTF8String s = getAlignment();
    setDefaultedArg(s, "alignment", args);
    setAlignment(s);
    s = getWrapMode();
    setDefaultedArg(s, "wrapmode", args);
    setWrapMode(s);
    setDefaultedArg(m_bJustify, "justify", args);
    setDefaultedArg(m_LetterSpacing, "letterspacing", args);
    setDefaultedArg(m_bHint, "hint", args);
}
コード例 #3
0
 osg::Node* traverseAIScene( const std::string& filename, const struct aiScene* aiScene, const struct aiNode* aiNode,
                             TextureMap& textures, const osgDB::Options* options ) const
 {
     osg::Geode* geode = new osg::Geode;
     for ( unsigned int n=0; n<aiNode->mNumMeshes; ++n )
     {
         // Create geometry basic properties
         const struct aiMesh* mesh = aiScene->mMeshes[ aiNode->mMeshes[n] ];
         osg::Geometry* geom = new osg::Geometry;
         geode->addDrawable( geom );
         
         osg::Vec3Array* va = new osg::Vec3Array(mesh->mNumVertices);
         osg::Vec3Array* na = (mesh->mNormals ? new osg::Vec3Array(mesh->mNumVertices) : NULL);
         osg::Vec4Array* ca = (mesh->mColors[0] ? new osg::Vec4Array(mesh->mNumVertices) : NULL);
         for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
         {
             const aiVector3D& v = mesh->mVertices[i];
             (*va)[i].set( v.x, v.y, v.z );
             if ( na )
             {
                 const aiVector3D& n = mesh->mNormals[i];
                 (*na)[i].set( n.x, n.y, n.z );
             }
             if ( ca )
             {
                 const aiColor4D& c = mesh->mColors[0][i];
                 (*ca)[i].set( c.r, c.g, c.b, c.a );
             }
         }
         
         geom->setVertexArray( va );
         if ( na )
         {
             geom->setNormalArray( na );
             geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
         }
         if ( ca )
         {
             geom->setColorArray( ca );
             geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
         }
         
         // Create geometry texture coordinates
         unsigned int unit = 0;
         const aiVector3D* aiTexCoords = mesh->mTextureCoords[unit];
         while ( aiTexCoords!=NULL )
         {
             switch ( mesh->mNumUVComponents[unit] )
             {
             case 1:
                 {
                     osg::FloatArray* ta = new osg::FloatArray(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                         (*ta)[i] = aiTexCoords[i].x;
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             case 2:
                 {
                     osg::Vec2Array* ta = new osg::Vec2Array(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                     {
                         const aiVector3D& t = aiTexCoords[i];
                         (*ta)[i].set( t.x, t.y );
                     }
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             case 3:
                 {
                     osg::Vec3Array* ta = new osg::Vec3Array(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                     {
                         const aiVector3D& t = aiTexCoords[i];
                         (*ta)[i].set( t.x, t.y, t.z );
                     }
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             }
             aiTexCoords = mesh->mTextureCoords[++unit];
         }
         
         // Create geometry primitives
         osg::ref_ptr<osg::DrawElementsUInt> de[5];
         de[1] = new osg::DrawElementsUInt(GL_POINTS);
         de[2] = new osg::DrawElementsUInt(GL_LINES);
         de[3] = new osg::DrawElementsUInt(GL_TRIANGLES);
         de[4] = new osg::DrawElementsUInt(GL_QUADS);
         de[0] = new osg::DrawElementsUInt(GL_POLYGON);
         
         osg::DrawElementsUInt* current = NULL;
         for ( unsigned int f=0; f<mesh->mNumFaces; ++f )
         {
             const struct aiFace& face = mesh->mFaces[f];
             if ( face.mNumIndices>4 ) current = de[0].get();
             else current = de[face.mNumIndices].get();
             
             for ( unsigned i=0; i<face.mNumIndices; ++i )
                 current->push_back( face.mIndices[i] );
         }
         
         for ( unsigned int i=0; i<5; ++i )
         {
             if ( de[i]->size()>0 )
                 geom->addPrimitiveSet( de[i].get() );
         }
         
         // Create textures
         osg::StateSet* ss = geom->getOrCreateStateSet();
         const aiMaterial* aiMtl = aiScene->mMaterials[mesh->mMaterialIndex];
         aiReturn texFound = AI_SUCCESS;
         aiTextureOp envOp = aiTextureOp_Multiply;
         aiTextureMapMode wrapMode[3] = {aiTextureMapMode_Clamp};
         unsigned int texIndex = 0;
         aiString path;
         
         while ( texFound==AI_SUCCESS )
         {
             texFound = aiMtl->GetTexture(
                 aiTextureType_DIFFUSE, texIndex++, &path, NULL, &unit, NULL, &envOp, &(wrapMode[0]) );
             if ( unit>0 ) unit--;  // The output UV seems to start at 1?
             if ( texFound!=AI_SUCCESS ) break;
             
             std::string texFile(path.data);
             if ( !osgDB::isAbsolutePath(texFile) ) texFile = getFullPath( filename, texFile );
             
             TextureMap::iterator itr = textures.find(texFile);
             if ( itr==textures.end() )
             {
                 osg::ref_ptr<osg::Texture2D> tex2D = new osg::Texture2D;
                 tex2D->setWrap( osg::Texture::WRAP_S, getWrapMode(wrapMode[0]) );
                 tex2D->setWrap( osg::Texture::WRAP_T, getWrapMode(wrapMode[1]) );
                 tex2D->setWrap( osg::Texture::WRAP_R, getWrapMode(wrapMode[2]) );
                 tex2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
                 tex2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
                 tex2D->setImage( osgDB::readImageFile(texFile, options) );
                 textures[texFile] = tex2D;
             }
             
             ss->setTextureAttributeAndModes( unit, textures[texFile].get() );
             if ( unit>0 ) ss->setTextureAttributeAndModes( unit, new osg::TexEnv(getEnvMode(envOp)) );
         }
         
         // Create materials
         createMaterialData( ss, aiMtl );
     }
     
     aiMatrix4x4 m = aiNode->mTransformation;
     m.Transpose();
     
     // Create the node and continue looking for children
     osg::ref_ptr<osg::MatrixTransform> mt;
     mt = new osg::MatrixTransform;
     mt->setMatrix( osg::Matrixf((float*)&m) );
     for ( unsigned int n=0; n<aiNode->mNumChildren; ++n )
     {
         osg::Node* child = traverseAIScene( filename, aiScene, aiNode->mChildren[n], textures, options );
         if ( child ) mt->addChild( child );
     }
     mt->addChild( geode );
     return mt.release();
 }