Пример #1
0
ITexture*
TextureMgr::loadTexture (const std::string& filename,
                         Ctr::PixelFormat format)
{
    if (filename.length() == 0)
        return nullptr;
    LOG ("Attempting to load texture " << filename);

    ITexture* texture = findTexture (filename);
    if (!texture)
    {
        std::vector<std::string>       filenames;
        filenames.push_back(filename);
        TextureParameters resource = 
            TextureParameters(filenames, loadImages(filenames),Ctr::TwoD);

        if (texture = _deviceInterface->createTexture(&resource))
        {
            _textures.insert (std::make_pair(std::string(filename),
                              texture));
            LOG ("Loaded texture " << filename);
        }
        else
        {
            LOG ("Failed  " << filename);

        }
    }
    return texture;
}
Пример #2
0
			void GLFramebuffer2D::resizeTexture(uint32 sizeX, uint32 sizeY) {
				this->m_width = sizeX;
				this->m_height = sizeY;

				TE_OGL(glBindRenderbuffer(GL_RENDERBUFFER, m_handle_db));
				if (m_samples > 1)
				{
					TE_OGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_samples, GL_DEPTH_COMPONENT16, m_width, m_height));
				}
				else
				{
					TE_OGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_width, m_height));
				}
				TE_OGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_handle_db));

				std::vector<uint32> tmp;

				for (size_t i = 0; i < m_texture.size(); i++) {
					auto params = TextureParameters(TextureFormat::RGBA, TextureFilterMode::LINEAR, TextureWrapMode::CLAMP, TextureDataType::UNSIGNED_BYTE, m_samples);
					m_texture[i].texture = new GLTexture2D(m_width, m_height, nullptr, params);

					TE_OGL(glBindFramebuffer(GL_FRAMEBUFFER, m_handle_fb));
					TE_OGL(glFramebufferTexture2D(GL_FRAMEBUFFER, AttachmentToGL(m_texture[i].attachment), m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D, m_texture[i].texture->getHandle(), 0));
					tmp.push_back(AttachmentToGL(m_texture[i].attachment));
				}

				if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
					std::cout << "Failed to resize framebuffer properly!" << std::endl;

				TE_OGL(glDrawBuffers(tmp.size(), &tmp[0]));

				TE_OGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
				TE_OGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
			}
Пример #3
0
PostEffect::PostEffect (Ctr::IDevice* device, 
                        PixelFormat format,
                        LensDistortionType distortionType) :
Ctr::RenderTargetQuad (device),
_technique(0),
_shader(0),
_textureIn(0),
_postEffectTexture(nullptr),
_format (format),
_verticalPass (false)
{
    _name = "";
    
    RenderTargetQuad::initialize (Region2f());
    // This still needs work, and needs to be recalced when
    // when the backbuffer size changes
    if (_format != Ctr::PF_UNKNOWN)
    {
        Ctr::TextureParameters textureData  = 
            TextureParameters ("PostEffectTexture",
                             Ctr::TextureImagePtr(),
                             Ctr::TwoD,
                             Ctr::RenderTarget,
                             _format,
                             Ctr::Vector3i(MIRROR_BACK_BUFFER, MIRROR_BACK_BUFFER, 1));

        _postEffectTexture = _device->createTexture(&textureData);
    }

    _postEffectBounds = Ctr::Region2i(Ctr::Vector2i(0,0), Ctr::Vector2i(_device->backbuffer()->width(), _device->backbuffer()->height()));
}
Пример #4
0
Ibl::ITexture* 
IDevice::sharedRenderTarget(int width, int height, Ibl::PixelFormat format, bool useUAV)
{
    for (auto it = _temporaryTexturePool.begin(); it != _temporaryTexturePool.end(); it++)
    {
        if (!(*it)->inUse() &&
            (*it)->resource()->format() == format &&
            (*it)->resource()->width() == width  &&
            (*it)->resource()->height() == height &&
            (*it)->resource()->useUAV() == useUAV)
        {
            (*it)->setInUse(true);
            return *it;
        }
    }

    Ibl::ITexture* texture = 
        createTexture(&TextureParameters ("tempTex",
                      Ibl::TwoD,
                      Ibl::RenderTarget,
                      format,
                      Ibl::Vector3i(width, height, 1),
                      false,
                      1, 1, 0, 1, useUAV));
    if (texture)
    {
        _temporaryTexturePool.push_back(texture);
        texture->setInUse(true);
        return texture;
    }
    else
    {
        return nullptr;
    }
}
Пример #5
0
ITexture*
TextureMgr::loadTextureSet (const std::string& key, 
                            const std::vector<std::string>      & filenames)
{
    ITexture* texture = findTexture (key);
    if (!texture)
    {
        TextureParameters resource = TextureParameters(filenames, loadImages(filenames), Ctr::TwoD);
        if (texture = _deviceInterface->createTexture(&resource))
        {
            _textures.insert (std::make_pair(std::string(key),
                              texture));

            LOG ("Loaded texture array from: ")
            for (size_t i = 0;i < filenames.size(); i++)
            {
                LOG ("    " << filenames[i].c_str());
            }
        }
Пример #6
0
			void GLFramebuffer2D::Init()
			{
				TE_OGL(glGenFramebuffers(1, &m_handle_fb));
				TE_OGL(glGenRenderbuffers(1, &m_handle_db));

				auto params = TextureParameters(TextureFormat::RGBA, TextureFilterMode::LINEAR, TextureWrapMode::CLAMP, TextureDataType::UNSIGNED_BYTE, m_samples);
				m_texture.push_back(TextureInfo());
				m_texture[0].texture = new GLTexture2D(m_width, m_height, nullptr, params);
				m_texture[0].attachment = TE_ATTACHMENT_0;

				TE_OGL(glBindRenderbuffer(GL_RENDERBUFFER, m_handle_db));
				if (m_samples > 1)
				{
					TE_OGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_samples, GL_DEPTH_COMPONENT24, m_width, m_height));
				}
				else
				{
					TE_OGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_width, m_height));
				}

				TE_OGL(glBindFramebuffer(GL_FRAMEBUFFER, m_handle_fb));

				TE_OGL(glFramebufferTexture2D(GL_FRAMEBUFFER, AttachmentToGL(m_texture[0].attachment), m_samples > 1 ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D, m_texture[0].texture->getHandle(), 0));

				TE_OGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_handle_db));

				if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
				{
					std::cout << "Failed to create framebuffer properly!" << std::endl;
				}

				uint32 attachments[] = { GL_COLOR_ATTACHMENT0 };
				TE_OGL(glDrawBuffers(1, attachments));

				TE_OGL(glBindFramebuffer(GL_FRAMEBUFFER, 0));
				TE_OGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
			}