Beispiel #1
0
bool CTexture::Load_2D(std::string file, bool generateMipMap)
{
	if (loaded) Release();
	this->mipmap = generateMipMap;
	this->file = file;
	std::string ext = GetFileExtension(file);
	if (ext == "dds")
	{
		return load_DDS(file);
	}
	else
	{
		return load_SDL(file);
	}
}
Beispiel #2
0
// loads texture data from specified file
// TODO: wrap it in a workitem class, for the job system deferred loading
void
opengl_texture::load() {

    if( type == "make:" ) {
        // for generated texture we delay data creation until texture is bound
        // this ensures the script will receive all simulation data it might potentially want
        // as any binding will happen after simulation is loaded, initialized and running
        // until then we supply data for a tiny 2x2 grey stub
        make_stub();
    }
    else {

        WriteLog( "Loading texture data from \"" + name + type + "\"", logtype::texture );

        data_state = resource_state::loading;

             if( type == ".dds" ) { load_DDS(); }
        else if( type == ".tga" ) { load_TGA(); }
        else if( type == ".png" ) { load_PNG(); }
        else if( type == ".bmp" ) { load_BMP(); }
        else if( type == ".tex" ) { load_TEX(); }
        else { goto fail; }
    }

    // data state will be set by called loader, so we're all done here
    if( data_state == resource_state::good ) {

        has_alpha = (
            data_components == GL_RGBA ?
                true :
                false );

        size = data.size() / 1024;

        return;
    }

fail:
    data_state = resource_state::failed;
    ErrorLog( "Bad texture: failed to load texture \"" + name + type + "\"" );
    // NOTE: temporary workaround for texture assignment errors
    id = 0;
    return;
}