示例#1
0
TEST(ShaderLib,instance)
{
  auto shader = ngl::ShaderLib::instance();
  EXPECT_TRUE(shader !=nullptr);
  // we have Colour, Text, Diffuse and Checker (but vert and frag) so 8 shaders in total
  EXPECT_TRUE(shader->getNumShaders() ==8);
}
void Geometry::write(IResource* resource)
{
    ChunkHeader geometryHeader( BA_GEOMETRY, sizeof( Chunk ) );
    geometryHeader.write( resource );

    Chunk chunk;
    chunk.id = (auid)( this );
    memset( chunk.name, 0, engine::maxNameLength );
    if( _name.length() > engine::maxNameLength )
    {
        strncpy( chunk.name, _name.c_str(), engine::maxNameLength - 1 );
    }
    else
    {
        strcpy( chunk.name, _name.c_str() );
    }
    chunk.numShaders    = getNumShaders();
    chunk.numVertices   = getNumVertices();
    chunk.numUVSets     = getNumUVSets();
    chunk.numPrelights  = getNumPrelights();
    chunk.numTriangles  = getNumTriangles();
    chunk.sharedShaders = _sharedShaders;
    if( _ocTreeRoot )
    {
        chunk.numOcTreeSectors = _ocTreeRoot->getOcTreeSize();
    }
    else
    {
        chunk.numOcTreeSectors = 0;
    }
    chunk.hasEffect = ( _effect != NULL );

    fwrite( &chunk, sizeof( Chunk ), 1, resource->getFile() );

    // write shaders
    if( !_sharedShaders ) for( int i=0; i<getNumShaders(); i++ )
    {
        _shaders[i]->write( resource );
    }

    // write vertices
    ChunkHeader verticesHeader( BA_BINARY, sizeof(Vector) * getNumVertices() );
    verticesHeader.write( resource );
    fwrite( getVertices(), verticesHeader.size, 1, resource->getFile() );

    // write normals
    ChunkHeader normalsHeader( BA_BINARY, sizeof(Vector) * getNumVertices() );
    normalsHeader.write( resource );
    fwrite( getNormals(), normalsHeader.size, 1, resource->getFile() );

    // write UV-sets
	int i;
    for( i=0; i<getNumUVSets(); i++ )
    {
        ChunkHeader uvsHeader( BA_BINARY, sizeof(Flector) * getNumVertices() );
        uvsHeader.write( resource );
        fwrite( getUVSet(i), uvsHeader.size, 1, resource->getFile() );
    }

    // write prelights
    for( i=0; i< getNumPrelights(); i++ )
    {
        ChunkHeader prelightsHeader( BA_BINARY, sizeof(Color) * getNumVertices() );
        prelightsHeader.write( resource );
        fwrite( getPrelights(i), prelightsHeader.size, 1, resource->getFile() );
    }

    // write triangles
    ChunkHeader trianglesHeader( BA_BINARY, sizeof(Triangle) * getNumTriangles() );
    trianglesHeader.write( resource );
    fwrite( getTriangles(), trianglesHeader.size, 1, resource->getFile() );

    // write shaders
    if( !_sharedShaders )
    {
        ChunkHeader shadersHeader( BA_BINARY, sizeof(auid) * getNumShaders() );
        shadersHeader.write( resource );
        fwrite( _shaders, shadersHeader.size, 1, resource->getFile() );
    }

    // write octree
    if( _ocTreeRoot )
    {
        _ocTreeRoot->write( resource );
    }

    // write effect
    if( chunk.hasEffect )
    {
        reinterpret_cast<Effect*>( _effect )->write( resource );
    }
}