Ejemplo n.º 1
0
bool Texture::initWithData(int32_t format, const uint8_t * buffer,
                           uint32_t width, uint32_t height, bool mipmaps, int pixelFormat)
{
    destroy();

    m_target = GL_TEXTURE_2D;
    m_format = format;
    m_pixelFormat = pixelFormat < 0 ? findPixelFormat(format) : pixelFormat;
    m_width = width;
    m_height = height;
    glGenTextures(1, &m_texture);
    glBindTexture(m_target, m_texture);
    int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1;
    glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height);
    glTexSubImage2D(m_target, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, buffer);

    setSampling();
    if (mipmaps) generateMipmaps();
    glBindTexture(m_target, 0);

    if (glCheckError())
    {
        destroy();
        return false;
    }

    m_isLoaded = true;
    return m_isLoaded;
}
Ejemplo n.º 2
0
void DepthOfField::setToDefaults( void )
{
    SingleAttribute::setToDefaults();
    setCameraModel( (THIN_LENS) );
    setFocus( (0.f) );
    setFocusToFar( (1.f) );
    setFocusToNear( (1.f) );
    setFarMaximumBlurriness( (0.5f) );
    setNearMaximumBlurriness( (0.5f) );
    setSampling( (8) );
}
Ejemplo n.º 3
0
void PixelCustomization::enableSampling(bool enable) {
	settings->settings_enableSampling = enable;
	setSampling(settings->settings_sampling);
}
Ejemplo n.º 4
0
bool Texture::initAsArray(const std::vector<std::string> & filenames, bool mipmaps)
{
    destroy();

    m_arraySize = (uint32_t)filenames.size();
    std::vector<uint8_t *> imageData;
    imageData.resize(m_arraySize, nullptr);
    auto cleanFunc = [&]()
    {
        for (uint32_t i = 0; i < m_arraySize; i++) if (imageData[i] != 0) stbi_image_free(imageData[i]);
    };

    int width = 0, height = 0, components = 0;
    for (uint32_t i = 0; i < m_arraySize; i++)
    {
        int w, h, c;
        imageData[i] = stbi_load(filenames[i].c_str(), &w, &h, &c, 0);
        if (!imageData[i])
        {
            common::Logger::toLogWithFormat("Error: could not load file '%s'.\n", filenames[i].c_str());
            cleanFunc();
            return false;
        }

        if (i > 0 && (width != w || height != h || components != c))
        {
            common::Logger::toLog("Error: could not create a cubemap, files have different properties (width, height, components).\n");
            cleanFunc();
            return false;
        }
        else
        {
            width = w;
            height = h;
            components = c;
        }
    }

    m_format = findFormat(components);
    if (m_format == -1)
    {
        common::Logger::toLog("Error: texture format is unknown.\n");
        cleanFunc();
        return false;
    }

    m_target = GL_TEXTURE_2D_ARRAY;
    m_width = width;
    m_height = height;
    m_pixelFormat = findPixelFormat(m_format);
    glGenTextures(1, &m_texture);
    glBindTexture(m_target, m_texture);
    int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1;
    glTexStorage3D(m_target, mipLevels, m_format, m_width, m_height, m_arraySize);
    for (uint32_t i = 0; i < m_arraySize; i++)
    {
        glTexSubImage3D(m_target, 0, 0, 0, i, m_width, m_height, 1, m_pixelFormat, GL_UNSIGNED_BYTE, imageData[i]);
    }
    setSampling();
    if (mipmaps) generateMipmaps();
    glBindTexture(m_target, 0);

    cleanFunc();

    if (glCheckError())
    {
        destroy();
        return false;
    }

    m_isLoaded = true;
    return m_isLoaded;
}
Ejemplo n.º 5
0
bool Texture::initAsCubemap(const std::string& frontFilename, const std::string& backFilename,
                            const std::string& leftFilename, const std::string& rightFilename,
                            const std::string& topFilename, const std::string& bottomFilename,
                            bool mipmaps)
{
    destroy();

    std::string filenames[6] = { rightFilename, leftFilename, topFilename, bottomFilename, frontFilename, backFilename };
    uint8_t * imageData[6] = { 0, 0, 0, 0, 0, 0 };
    auto cleanFunc = [&]()
    {
        for (size_t i = 0; i < 6; i++) if (imageData[i] != 0) stbi_image_free(imageData[i]);
    };

    int width = 0, height = 0, components = 0;
    for (size_t i = 0; i < 6; i++)
    {
        int w, h, c;
        imageData[i] = stbi_load(filenames[i].c_str(), &w, &h, &c, 0);
        if (!imageData[i])
        {
            common::Logger::toLogWithFormat("Error: could not load file '%s'.\n", filenames[i].c_str());
            cleanFunc();
            return false;
        }

        if (i > 0 && (width != w || height != h || components != c))
        {
            common::Logger::toLog("Error: could not create a cubemap, files have different properties (width, height, components).\n");
            cleanFunc();
            return false;
        }
        else
        {
            width = w;
            height = h;
            components = c;
        }
    }

    m_format = findFormat(components);
    if (m_format == -1)
    {
        common::Logger::toLog("Error: texture format is unknown.\n");
        cleanFunc();
        return false;
    }

    m_target = GL_TEXTURE_CUBE_MAP;
    m_width = width;
    m_height = height;
    m_pixelFormat = findPixelFormat(m_format);
    glGenTextures(1, &m_texture);
    glBindTexture(m_target, m_texture);
    int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1;
    glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height);
    for (uint32_t i = 0; i < 6; i++)
    {
        glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, imageData[i]);
    }
    setSampling();
    if (mipmaps) generateMipmaps();
    glBindTexture(m_target, 0);

    cleanFunc();

    if (glCheckError())
    {
        destroy();
        return false;
    }

    m_isLoaded = true;
    return m_isLoaded;
}