Example #1
0
	int GausBlur::init(xdl::xdl_uint width, xdl::xdl_uint height, xdl::XdevLFrameBufferColorFormat textureFormat) {

		PostProcessEffect::init(width, height);

		m_shaderProgram = m_rai->createShaderProgram();

		m_vs = m_rai->createVertexShader();
		m_vs->compileFromFile("resources/shaders/blurGaus_vs.glsl");

		m_fs = m_rai->createFragmentShader();
		m_fs->compileFromFile("resources/shaders/blurGaus_fs.glsl");

		m_shaderProgram->attach(m_vs);
		m_shaderProgram->attach(m_fs);
		m_shaderProgram->link();

		m_textureid 			=  	m_shaderProgram->getUniformLocation("texture0");
		m_blurDirectionid	=  	m_shaderProgram->getUniformLocation("blurDirection");
		m_blurSizeid 			= 	m_shaderProgram->getUniformLocation("blurSize");

		// Create Framebuffer.
		m_frameBuffer = m_rai->createFrameBuffer();
		if(m_frameBuffer->init(m_width, m_height) != xdl::ERR_OK) {
			std::cerr << "GBuffer::Could not create Framebuffer." << std::endl;
			return -1;
		}

		//
		// Create one Framebuffer with one color target to Blur horizontally.
		//
		m_frameBuffer->addColorTarget(0, textureFormat);

		auto texture = m_frameBuffer->getTexture(0);
		texture->lock();
		texture->setTextureFilter(xdl::XDEVL_TEXTURE_MAG_FILTER, xdl::XDEVL_LINEAR);
		texture->setTextureFilter(xdl::XDEVL_TEXTURE_MIN_FILTER, xdl::XDEVL_LINEAR);
		texture->setTextureWrap(xdl::XDEVL_TEXTURE_WRAP_S, xdl::XDEVL_CLAMP_TO_BORDER);
		texture->setTextureWrap(xdl::XDEVL_TEXTURE_WRAP_T, xdl::XDEVL_CLAMP_TO_BORDER);
		texture->unlock();

		//
		// Create one Framebuffer with one color target to Blur vertically.
		//
		m_frameBuffer2 = m_rai->createFrameBuffer();
		if(m_frameBuffer2->init(m_width, m_height) != xdl::ERR_OK) {
			std::cerr << "GBuffer::Could not create Framebuffer." << std::endl;
			return -1;
		}
		m_frameBuffer2->addColorTarget(0, textureFormat);

		auto texture2 = m_frameBuffer2->getTexture(0);
		texture2->lock();
		texture2->setTextureFilter(xdl::XDEVL_TEXTURE_MAG_FILTER, xdl::XDEVL_LINEAR);
		texture2->setTextureFilter(xdl::XDEVL_TEXTURE_MIN_FILTER, xdl::XDEVL_LINEAR);
		texture2->setTextureWrap(xdl::XDEVL_TEXTURE_WRAP_S, xdl::XDEVL_CLAMP_TO_BORDER);
		texture2->setTextureWrap(xdl::XDEVL_TEXTURE_WRAP_T, xdl::XDEVL_CLAMP_TO_BORDER);
		texture2->unlock();

		return 0;
	}
Example #2
0
void Image::setFilter(const Image::Filter &f)
{
	filter = f;

	bind();
	checkMipmapsCreated();
	setTextureFilter(f);
}