Esempio n. 1
0
bool ScriptManager::loadFromStream(const std::string& name, sf::InputStream& stream, ScriptType type)
{
	auto len = size_t(stream.getSize());
	std::vector<char> data(len);
	stream.read(&data[0], len);

	return loadFromMemory(name, &data[0], len, type);
}
Esempio n. 2
0
bool Texture::loadDDS(sf::InputStream& stream)
{
    gli::gl GL;
    size_t size = stream.getSize();
    const char* buf = new const char[size];
    m_tex = gli::texture2D(gli::load_dds(buf, size));
    delete[] buf;
    
    if (m_tex.empty())
    {

        return false;
    }
      
    gli::gl::format const format = GL.translate(m_tex.format());

    glGenTextures(1, &m_id);  
    glBindTexture(GL_TEXTURE_2D, m_id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(m_tex.levels() - 1));
    glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA,reinterpret_cast<const GLint*>(format.Swizzle));
    glTexImage2D(GL_TEXTURE_2D, 0, format.Internal, m_tex.dimensions().x, m_tex.dimensions().y, 0, format.External, GL_UNSIGNED_BYTE, NULL);

    //uncompress texture in the gpu
    if (gli::is_compressed(m_tex.format()))
    {
        //fill all mipmap levels
        for (std::size_t Level = 0; Level < m_tex.levels(); ++Level)
        {
            glCompressedTexSubImage2D(GL_TEXTURE_2D, static_cast<GLint>(Level),
                0, 0,
                static_cast<GLsizei>(m_tex[Level].dimensions().x),
                static_cast<GLsizei>(m_tex[Level].dimensions().y),
                format.External,
                static_cast<GLsizei>(m_tex[Level].size()),
                m_tex[Level].data());
        }
    }
    else
    {
        //fill all mipmap levels
        for (std::size_t Level = 0; Level < m_tex.levels(); ++Level)
        {
            glTexSubImage2D(GL_TEXTURE_2D, static_cast<GLint>(Level),
                0, 0,
                static_cast<GLsizei>(m_tex[Level].dimensions().x),
                static_cast<GLsizei>(m_tex[Level].dimensions().y),
                format.External, format.Type,
                m_tex[Level].data());
        }
    }

    return true;
}