/**
 * Load texture from file.
 * @param vfs - virtual filesystem where we can load files from
 * @param name - name of the file to be loaded
 * @param width - return width of the file
 * @param height - return height of the file
 * @return smart array containing data of the file
 */
shared_array<byte> nrCTextureLoader::load(nrCFileSystem* vfs, const string& name,int &width,int &height) {
  	
	if(strstr(name.c_str(),".tga") || strstr(name.c_str(),".TGA")) return load_tga(vfs,name,width,height);
	if(strstr(name.c_str(),".png") || strstr(name.c_str(),".PNG")) return load_png(vfs,name,width,height);
	if(strstr(name.c_str(),".jpg") || strstr(name.c_str(),".JPG")) return load_jpeg(vfs,name,width,height);
	if(strstr(name.c_str(),".dds") || strstr(name.c_str(),".DDS")) return load_dds(vfs,name,width,height);
	
	nrLog.Log(NR_LOG_ENGINE, "nrCTextureLoader::load():unknown format of '%s' file",name.c_str());
	return shared_array<byte>(NULL);
}
Exemple #2
0
RENDERING_SERVICE_API int rs_load_simple_obj(SimpleStaticObject* obj)
{
    if (!IsValidStaticObject(obj))
    {
        return -1;
    }

    static std::unordered_map<std::string, GLuint> OnMemoryTextureResources;
    static std::unordered_map<std::string, VertexBuffer> OnMemoryStaticMeshResources;
    
    char resPath[1024];
    
    if (obj->objFileName)
    {
        auto vb = OnMemoryStaticMeshResources.find(obj->objFileName);
        if (vb == OnMemoryStaticMeshResources.end())
        {
            GetMmoResourcePath(resPath, _countof(resPath), obj->objFileName);
            load_obj(&obj->vb, resPath);

            OnMemoryStaticMeshResources[obj->objFileName] = obj->vb;
        }
        else
        {
            obj->vb = vb->second;
        }
    }

    if (obj->ddsFileName)
    {
        auto texId = OnMemoryTextureResources.find(obj->ddsFileName);
        if (texId == OnMemoryTextureResources.end())
        {
            GetMmoResourcePath(resPath, _countof(resPath), obj->ddsFileName);
            obj->texId = load_dds(resPath);

            OnMemoryTextureResources[obj->ddsFileName] = obj->texId;
        }
        else
        {
            obj->texId = texId->second;
        }
    }

    return 0;
}
Exemple #3
0
Uint32 load_image_data_file(el_file_ptr file, const Uint32 compression,
	const Uint32 unpack, const Uint32 strip_mipmaps,
	const Uint32 base_level, image_t* image)
{
	char buffer[128];
	el_file_ptr alpha_file;
	Uint32 dds, result;

	if (file == 0)
	{
		LOG_ERROR("Invalid file!");

		return 0;
	}

	dds = 0;

	if (el_get_size(file) >= 4)
	{
		if (check_dds(el_get_pointer(file)))
		{
			dds = 1;
		}
	}

	if (dds == 1)
	{
		result = load_dds(file, compression, unpack,
			strip_mipmaps, base_level, image);
	}
	else
	{
		result = load_image_SDL(file, image);
	}

	if ((result == 0) || (image->image == 0))
	{
		LOG_ERROR("Can't load file '%s'!", el_file_name(file));

		el_close(file);

		return 0;
	}

	if ((dds != 1) && (check_alpha_image_name(el_file_name(file),
		sizeof(buffer), buffer) != 0))
	{
		alpha_file = el_open_custom(buffer);

		if (alpha_file == 0)
		{
			LOG_ERROR("Can't load file '%s'!", buffer);

			el_close(file);

			return 0;
		}

		load_image_SDL_alpha(alpha_file, image);

		el_close(alpha_file);
	}

	el_close(file);

	return 1;
}