Example #1
0
void Pipeline::endFrame()
{
  GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, self->current_framebuffer->lbuffer_id));
  self->doRenderPass(Pipeline::PassPostEffect);
  GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0));
  GL_CHECK(glBlitFramebuffer(0, 0, self->current_framebuffer->width, self->current_framebuffer->height, 0, 0, self->width, self->height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
}
Example #2
0
void R_CopyToFBO(FBO_t *from, FBO_t *to, GLuint mask, GLuint filter)
{
	if (glConfig2.framebufferBlitAvailable)
	{
		vec2_t size;
		if (from)
		{
			glBindFramebuffer(GL_READ_FRAMEBUFFER, from->frameBuffer);
			size[0] = from->width;
			size[1] = from->height;
		}
		else
		{
			glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
			size[0] = glConfig.vidWidth;
			size[1] = glConfig.vidHeight;
		}

		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, to->frameBuffer);
		glBlitFramebuffer(0, 0, size[0], size[1], 0, 0, to->width, to->height, mask, filter);

		//Just set the read buffer to the target as well otherwise we might get fucked..
		glBindFramebuffer(GL_FRAMEBUFFER, to->frameBuffer);
		glState.currentFBO = to;
	}
	else
	{
		// FIXME add non EXT_framebuffer_blit code
		Ren_Fatal("R_CopyToFBO no framebufferblitting available");
	}
}
Example #3
0
void gd_egl_scanout_flush(DisplayChangeListener *dcl,
                          uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
    GdkWindow *window;
    int ww, wh, y1, y2;

    if (!vc->gfx.scanout_mode) {
        return;
    }
    if (!vc->gfx.fbo_id) {
        return;
    }

    eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
                   vc->gfx.esurface, vc->gfx.ectx);

    glBindFramebuffer(GL_READ_FRAMEBUFFER, vc->gfx.fbo_id);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

    window = gtk_widget_get_window(vc->gfx.drawing_area);
    gdk_drawable_get_size(window, &ww, &wh);
    glViewport(0, 0, ww, wh);
    y1 = vc->gfx.y0_top ? 0 : vc->gfx.h;
    y2 = vc->gfx.y0_top ? vc->gfx.h : 0;
    glBlitFramebuffer(0, y1, vc->gfx.w, y2,
                      0, 0, ww, wh,
                      GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, vc->gfx.fbo_id);

    eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
}
Example #4
0
bool
hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *fbo_options)
{
	bool pass = true;
	GLuint fbo = 0;

	piglit_require_extension("GL_ARB_framebuffer_object");

	/* Create and bind FBO. */
	fbo = hiz_make_fbo(fbo_options);
	assert(fbo != 0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);

	pass = hiz_run_test_stencil_read_common();

	if (!piglit_automatic) {
		/* Blit the FBO to the window FB so we can see the results. */
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
		glBlitFramebuffer(0, 0, piglit_width, piglit_height,
			          0, 0, piglit_width, piglit_height,
			          GL_COLOR_BUFFER_BIT, GL_NEAREST);
		piglit_present_results();
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
	}

	hiz_delete_fbo(fbo);

	return pass;
}
Example #5
0
void XFBSource::CopyEFB(float Gamma)
{
    g_renderer->ResetAPIState();

    // Copy EFB data to XFB and restore render target again
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferManager::GetXFBFramebuffer());

    for (int i = 0; i < m_layers; i++)
    {
        // Bind EFB and texture layer
        glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferManager::GetEFBFramebuffer(i));
        glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, i);

        glBlitFramebuffer(
            0, 0, texWidth, texHeight,
            0, 0, texWidth, texHeight,
            GL_COLOR_BUFFER_BIT, GL_NEAREST
        );
    }

    // Return to EFB.
    FramebufferManager::SetFramebuffer(0);

    g_renderer->RestoreAPIState();

}
/* virtual */
void
Hdx_UnitTestWindow::OnPaintGL()
{
    //
    // Update the draw target's size and execute the unit test with
    // the draw target bound.
    //
    _drawTarget->Bind();
    _drawTarget->SetSize(GfVec2i(GetWidth(), GetHeight()));

    _unitTest->DrawTest();

    _drawTarget->Unbind();

    //
    // Blit the resulting color buffer to the window (this is a noop
    // if we're drawing offscreen).
    //
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, _drawTarget->GetFramebufferId());

    glBlitFramebuffer(0, 0, GetWidth(), GetHeight(),
                      0, 0, GetWidth(), GetHeight(),
                      GL_COLOR_BUFFER_BIT,
                      GL_NEAREST);

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
Example #7
0
void PostProcessor::_preDraw(FrameBuffer * _pBuffer)
{
	_setGLState(_pBuffer);
	OGLVideo & ogl = video();

	m_pResultBuffer->m_width = _pBuffer->m_width;
	m_pResultBuffer->m_height = _pBuffer->m_height;
	m_pResultBuffer->m_scaleX = _pBuffer->m_scaleX;
	m_pResultBuffer->m_scaleY = _pBuffer->m_scaleY;
#ifdef GLES2
	m_pTextureOriginal = _pBuffer->m_pTexture;
#else
	if (config.video.multisampling != 0) {
		glBindFramebuffer(GL_READ_FRAMEBUFFER, _pBuffer->m_FBO);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO_resolved);
		glBlitFramebuffer(
			0, 0, ogl.getWidth(), ogl.getHeight(),
			0, 0, ogl.getWidth(), ogl.getHeight(),
			GL_COLOR_BUFFER_BIT, GL_LINEAR
			);
		m_pTextureOriginal = m_pTextureResolved;
	} else
		m_pTextureOriginal = _pBuffer->m_pTexture;
#endif

	glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
void FramebufferImplementation_Legacy::blit(const Framebuffer * sourceFbo, const Framebuffer * targetFbo, gl::GLint srcX0, gl::GLint srcY0, gl::GLint srcX1, gl::GLint srcY1, gl::GLint destX0, gl::GLint destY0, gl::GLint destX1, gl::GLint destY1, gl::ClearBufferMask mask, gl::GLenum filter) const
{
    sourceFbo->bind(GL_READ_FRAMEBUFFER);
    targetFbo->bind(GL_DRAW_FRAMEBUFFER);

    glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, destX0, destY0, destX1, destY1, mask, filter);
}
Example #9
0
void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen) {

	ERR_FAIL_COND(storage->frame.current_rt);

	RasterizerStorageGLES3::RenderTarget *rt = storage->render_target_owner.getornull(p_render_target);
	ERR_FAIL_COND(!rt);

#if 1

	Size2 win_size = OS::get_singleton()->get_window_size();
	glBindFramebuffer(GL_READ_FRAMEBUFFER, rt->fbo);
	glReadBuffer(GL_COLOR_ATTACHMENT0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
	glBlitFramebuffer(0, 0, rt->width, rt->height, p_screen_rect.position.x, win_size.height - p_screen_rect.position.y - p_screen_rect.size.height, p_screen_rect.position.x + p_screen_rect.size.width, win_size.height - p_screen_rect.position.y, GL_COLOR_BUFFER_BIT, GL_NEAREST);

#else
	canvas->canvas_begin();
	glDisable(GL_BLEND);
	glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, rt->color);
	//glBindTexture(GL_TEXTURE_2D, rt->effects.mip_maps[0].color);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, storage->resources.normal_tex);

	canvas->draw_generic_textured_rect(p_screen_rect, Rect2(0, 0, 1, -1));
	glBindTexture(GL_TEXTURE_2D, 0);
	canvas->canvas_end();
#endif
}
Example #10
0
	void RenderSystem::v_Render()
	{
		static const float bgColor[4] = {0.2f, 0.3f, 0.4f, 1.0f};
		glClearBufferfv(GL_COLOR, 0, bgColor);
		static const float one = 1.0f;
		glClearBufferfv(GL_DEPTH, 0, &one);

		update();

		static ogl::MvpMatrix matrix;
		matrix.view  = m_Camera.GetViewMatrix();
		matrix.proj  = glm::perspective(glm::radians(m_Camera.GetZoom() ), getAspect(), 0.1f, 1000.0f);
		matrix.model = glm::mat4(1.0f);

		// 1. Draw scene as normal in multisampled buffers
         
		m_Framebuffer.Bind();

		glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	    m_Cube.Render(matrix);

		// 2. Now blit multisampled buffer(s) to default framebuffers
		glBindFramebuffer(GL_READ_FRAMEBUFFER, m_Framebuffer.GetFbo());
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);				
		glBlitFramebuffer(0, 0, GetScreenWidth(), GetScreenWidth(), 0, 0, GetScreenWidth(), GetScreenWidth(), GL_COLOR_BUFFER_BIT, GL_NEAREST);     
	}
Example #11
0
QSGTexture* GuiTexture::removedFromAtlas() const {
	if (this->isAtlasTexture()) {
		if (!this->standalone) {
			auto tex = this->texture_handle.texture;
			auto sub = tex->get_subtexture(this->texture_handle.subid);

			GLuint sub_texture_id = create_compatible_texture(tex->get_texture_id(), sub->w, sub->h);

			std::array<GLuint, 2>  fbo;
			glGenFramebuffers(fbo.size(), &fbo.front());

			glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[0]);
			glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->textureId(), 0);
			glReadBuffer(GL_COLOR_ATTACHMENT0);

			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[1]);
			glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sub_texture_id, 0);
			glDrawBuffer(GL_COLOR_ATTACHMENT0);

			glBlitFramebuffer(sub->x, sub->y, sub->x + sub->w, sub->y + sub->h, 0, 0, sub->w, sub->h, GL_COLOR_BUFFER_BIT, GL_NEAREST);

			glBindFramebuffer(GL_FRAMEBUFFER, 0);

			glDeleteFramebuffers(fbo.size(), &fbo.front());

			this->standalone = make_standalone_subtexture(sub_texture_id, QSize(sub->w, sub->h));
		}

		return this->standalone.get();
	}

	return nullptr;
}
Example #12
0
        void Frame() override {
            glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
            glUseProgram(mDepthProgram);

            GLfloat vertices[] = {
                -1.0f, -1.0f, 0.0f, 1.0f,
                -1.0f,  1.0f, 0.0f, 1.0f,
                 1.0f, -1.0f, 0.0f, 1.0f,
                 1.0f,  1.0f, 0.0f, 1.0f,
            };

            glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, vertices);
            glEnableVertexAttribArray(0);

            glViewport(0, 0, 640, 480);

            glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
            glClearDepth(1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glDepthFunc(GL_EQUAL);
            glEnable(GL_DEPTH_TEST);

            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

            glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
            glBlitFramebuffer(0, 0, 640, 480, 0, 0, 640, 480, GL_COLOR_BUFFER_BIT, GL_NEAREST);
            assert(glGetError() == GL_NO_ERROR);
        }
Example #13
0
void shader::copy_buffer(rtt::fbo* src_buffer, rtt::fbo* dest_buffer, unsigned int src_attachment, unsigned int dest_attachment) {
#if !defined(FLOOR_IOS)
	if((src_buffer->target[src_attachment] != GL_TEXTURE_2D && src_buffer->target[src_attachment] != GL_TEXTURE_RECTANGLE) ||
	   (dest_buffer->target[dest_attachment] != GL_TEXTURE_2D && dest_buffer->target[dest_attachment] != GL_TEXTURE_RECTANGLE)) {
		log_error("non-2D buffers aren't allowed to be copied at the moment!");
	}
	
	glBindFramebuffer(GL_READ_FRAMEBUFFER, src_buffer->fbo_id);
	glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+src_attachment, src_buffer->target[src_attachment], src_buffer->tex[src_attachment], 0);
	glReadBuffer(GL_COLOR_ATTACHMENT0+src_attachment);
	
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dest_buffer->fbo_id);
	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+dest_attachment, dest_buffer->target[dest_attachment], dest_buffer->tex[dest_attachment], 0);
	glDrawBuffer(GL_COLOR_ATTACHMENT0+dest_attachment);
	
	glBlitFramebuffer(0, 0, (GLint)src_buffer->width, (GLint)src_buffer->height,
					  0, 0, (GLint)dest_buffer->width, (GLint)dest_buffer->height,
					  GL_COLOR_BUFFER_BIT | ((src_buffer->depth_type != rtt::DEPTH_TYPE::NONE && dest_buffer->depth_type != rtt::DEPTH_TYPE::NONE) ? GL_DEPTH_BUFFER_BIT : 0),
					  GL_NEAREST);
	
	glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
#else
	// TODO: implement framebuffer blitting on iOS
#endif
}
	bool render()
	{
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glBindProgramPipeline(PipelineName);

		// Pass 1, render the scene in a multisampled framebuffer
		glEnable(GL_MULTISAMPLE);
		glEnable(GL_SAMPLE_SHADING);
		glMinSampleShading(4.0f);

		//glEnable(GL_SAMPLE_MASK);
		//glSampleMaski(0, 0xFF);

		renderFBO();
		glDisable(GL_MULTISAMPLE);

		// Resolved multisampling
		glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName);
		glBlitFramebuffer(
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
			GL_COLOR_BUFFER_BIT, GL_NEAREST);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		// Pass 2, render the colorbuffer from the multisampled framebuffer
		glm::vec2 WindowSize(this->getWindowSize());
		glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]);
		renderFB();

		return true;
	}
CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer)
{
#ifdef GL_MULTISAMPLING_SUPPORT
	if (config.video.multisampling == 0)
		return m_pDepthBufferTexture;
	if (m_resolved)
		return m_pResolveDepthBufferTexture;
	glScissor(0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, _pBuffer->m_FBO);
	glReadBuffer(GL_COLOR_ATTACHMENT0);
	GLuint attachment = GL_COLOR_ATTACHMENT0;
	glDrawBuffers(1, &attachment);
	assert(checkFBO());
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_resolveFBO);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pResolveDepthBufferTexture->glName, 0);
	assert(checkFBO());
	glBlitFramebuffer(
		0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight,
		0, 0, m_pResolveDepthBufferTexture->realWidth, m_pResolveDepthBufferTexture->realHeight,
		GL_DEPTH_BUFFER_BIT, GL_NEAREST
		);
	glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_FBO);
	m_resolved = true;
	gDP.changed |= CHANGED_SCISSOR;
	return m_pResolveDepthBufferTexture;
#else
	return m_pDepthBufferTexture;
#endif
}
Example #16
0
void ofFbo::updateTexture(int attachmentPoint) {
	// TODO: flag to see if this is dirty or not
#ifndef TARGET_OPENGLES
	if(fbo != fboTextures && dirty) {
		glGetIntegerv( GL_FRAMEBUFFER_BINDING, &savedFramebuffer );

		// save current drawbuffer
		glPushAttrib(GL_COLOR_BUFFER_BIT);

		// save current readbuffer
		GLint readBuffer;
		glGetIntegerv(GL_READ_BUFFER, &readBuffer);

		glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboTextures);
		glDrawBuffer(GL_COLOR_ATTACHMENT0 + attachmentPoint);
		glReadBuffer(GL_COLOR_ATTACHMENT0 + attachmentPoint);
		glBlitFramebuffer(0, 0, settings.width, settings.height, 0, 0, settings.width, settings.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);

		glBindFramebuffer(GL_READ_FRAMEBUFFER, savedFramebuffer);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, savedFramebuffer);
		glBindFramebuffer( GL_FRAMEBUFFER, savedFramebuffer );

		// restore readbuffer
		glReadBuffer(readBuffer);

		// restore drawbuffer
		glPopAttrib();
		dirty = false;

	}
#endif
}
Example #17
0
//----------------------------------------------------------
void ofFbo::updateTexture(int attachmentPoint) {
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
	if(fbo != fboTextures && dirty[attachmentPoint]) {
		
		// if fbo != fboTextures, we are dealing with an MSAA enabled FBO.
		// and we need to blit one fbo into another to see get the texture
		// content

		if (!ofIsGLProgrammableRenderer()){
			// save current drawbuffer
			glPushAttrib(GL_COLOR_BUFFER_BIT);
		}

		auto renderer = settings.renderer.lock();
		if(renderer){
			renderer->bindForBlitting(*this,*this,attachmentPoint);
			glBlitFramebuffer(0, 0, settings.width, settings.height, 0, 0, settings.width, settings.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
			renderer->unbind(*this);
		
			glReadBuffer(GL_BACK);
		}

		if(!ofIsGLProgrammableRenderer()){
			// restore current drawbuffer
			glPopAttrib();
		}
		dirty[attachmentPoint] = false;
	}
#endif
}
	void GLES2FrameBufferObject::swapBuffers()
	{
		if (mMultisampleFB)
		{
#if OGRE_NO_GLES3_SUPPORT == 1
            if(getGLES2SupportRef()->checkExtension("GL_APPLE_framebuffer_multisample"))
            {
                // Blit from multisample buffer to final buffer, triggers resolve
                OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, mMultisampleFB));
                OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, mFB));
            }
#else
            GLint oldfb = 0;
            OGRE_CHECK_GL_ERROR(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldfb));

			// Blit from multisample buffer to final buffer, triggers resolve
			uint32 width = mColour[0].buffer->getWidth();
			uint32 height = mColour[0].buffer->getHeight();
			OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_READ_FRAMEBUFFER, mMultisampleFB));
			OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFB));
			OGRE_CHECK_GL_ERROR(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
			// Unbind
			OGRE_CHECK_GL_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, oldfb));
#endif
		}
	}
Example #19
0
void Framebuffer::debugPass(GraphicsWindow& graphicsWindow, std::vector<unsigned int> attachmentIndices)
{
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	bindForReading();

	unsigned int windowWidth = graphicsWindow.getWindowWidth();
	unsigned int windowHeight = graphicsWindow.getWindowHeight();

	GLsizei oneThirdWidth = (GLsizei)(windowWidth / 3.0f);
	GLsizei oneThirdHeight = (GLsizei)(windowHeight / 3.0f);

	if (attachmentIndices.size() > 8)
	{
		Logger::GetInstance().Log("Color attachment count out of bounds!");
		return;
	}

	for (unsigned int i = 0; i < attachmentIndices.size(); i++)
	{
		glReadBuffer(GL_COLOR_ATTACHMENT0 + attachmentIndices[i]);

		glBlitFramebuffer(0, 0, windowWidth, windowHeight,
			oneThirdWidth*((i)%3), oneThirdHeight*((i)/3), oneThirdWidth*(((i)%3)+1), oneThirdHeight*(((i+3))/3), GL_COLOR_BUFFER_BIT, GL_LINEAR);
	}

	check_gl_error();
}
Example #20
0
void Scene::PresentScreenFBO()
{
	glBindFramebuffer(GL_READ_FRAMEBUFFER, m_ScreenFBO);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

	glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
void FrameBufferObjectMultisample::blitDepth(const std::shared_ptr<FrameBufferObject> &fbo)
{
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->id());
	glBindFramebuffer(GL_READ_FRAMEBUFFER, m_handle);
	glBlitFramebuffer(0, 0, m_target->width(), m_target->height(), 0, 0, m_target->width(), m_target->height(), GL_DEPTH_BUFFER_BIT, m_filtering);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void display()
{
	glProgramUniform1i(ProgramName, UniformDiffuse, 0);

	// Clear the framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	glUseProgram(ProgramName);

	// Pass 1
	// Render the scene in a multisampled framebuffer
	glEnable(GL_MULTISAMPLE);
	renderFBO(ProgramName, FramebufferRenderName);
	glDisable(GL_MULTISAMPLE);

	// Resolved multisampling
	glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName);
	glBlitFramebuffer(
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		GL_COLOR_BUFFER_BIT, GL_LINEAR);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// Pass 2
	// Render the colorbuffer from the multisampled framebuffer
	renderFB(ProgramName, ColorTextureName);

	glf::checkError("display");
	glf::swapBuffers();
}
Example #23
0
GLuint FramebufferManager::GetEFBDepthTexture(const EFBRectangle& sourceRc)
{
    if (m_msaaSamples <= 1)
    {
        return m_efbDepth;
    }
    else
    {
        // Transfer the EFB to a resolved texture.

        TargetRectangle targetRc = g_renderer->ConvertEFBRectangle(sourceRc);
        targetRc.ClampUL(0, 0, m_targetWidth, m_targetHeight);

        // Resolve.
        for (unsigned int i = 0; i < m_EFBLayers; i++)
        {
            glBindFramebuffer(GL_READ_FRAMEBUFFER, m_efbFramebuffer[i]);
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_resolvedFramebuffer[i]);
            glBlitFramebuffer(
                targetRc.left, targetRc.top, targetRc.right, targetRc.bottom,
                targetRc.left, targetRc.top, targetRc.right, targetRc.bottom,
                GL_DEPTH_BUFFER_BIT, GL_NEAREST
            );
        }

        // Return to EFB.
        glBindFramebuffer(GL_FRAMEBUFFER, m_efbFramebuffer[0]);

        return m_resolvedDepthTexture;
    }
}
Example #24
0
static void gl_copy_backbuffer(GLuint dst)
{
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, data.fbo);
	if (gl_error("gl_copy_backbuffer", "failed to bind FBO")) {
		return;
	}

	glBindTexture(GL_TEXTURE_2D, dst);
	if (gl_error("gl_copy_backbuffer", "failed to bind texture")) {
		return;
	}

	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			GL_TEXTURE_2D, dst, 0);
	if (gl_error("gl_copy_backbuffer", "failed to set frame buffer")) {
		return;
	}

	glReadBuffer(GL_BACK);
	if (gl_error("gl_copy_backbuffer", "failed to set read buffer")) {
		return;
	}

	glDrawBuffer(GL_COLOR_ATTACHMENT0);
	if (gl_error("gl_copy_backbuffer", "failed to set draw buffer")) {
		return;
	}

	glBlitFramebuffer(0, 0, data.base_cx, data.base_cy,
			0, 0, data.cx, data.cy, GL_COLOR_BUFFER_BIT, GL_LINEAR);
	gl_error("gl_copy_backbuffer", "failed to blit");
}
Example #25
0
void fhFramebuffer::BlitDepthToCurrentFramebuffer() {
	if (currentDrawBuffer && currentDrawBuffer != this) {
		glBindFramebuffer( GL_READ_FRAMEBUFFER, name );
		glReadBuffer( GL_NONE );

		const int src_x2 = width;
		const int src_y2 = height;

		const int dst_x2 = currentDrawBuffer->GetWidth();
		const int dst_y2 = currentDrawBuffer->GetHeight();

		if (src_x2 != dst_x2 ||
			src_y2 != dst_y2) {
			common->Warning( "size mismatch!?" );
		}

		glBlitFramebuffer(
			0, 0, src_x2, src_y2,
			0, 0, dst_x2, dst_y2,
			GL_DEPTH_BUFFER_BIT, GL_NEAREST );

		glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
	}
	else {
		common->Warning( "no current framebuffer!?" );
	}
}
void display()
{
	// Clear the framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	glBindProgramPipeline(PipelineName);

	// Step 1: Render the scene in a multisampled framebuffer
	glEnable(GL_MULTISAMPLE);
	renderFBO(FramebufferRenderName);
	glDisable(GL_MULTISAMPLE);

	// Step 2: Resolved multisampling
	glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName);
	glBlitFramebuffer(
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		GL_COLOR_BUFFER_BIT, GL_NEAREST);

	// Step 3: Generated mipmaps
	glGenerateTextureMipmapEXT(ColorTextureName, GL_TEXTURE_2D);

	// Step 4: Render the colorbuffer from the multisampled framebuffer
	renderFB(ColorTextureName);

	glf::checkError("display");
	glf::swapBuffers();
}
void GeometryBuffer::CopyDepthBuffer()
{
	glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Write to default framebuffer
	glBlitFramebuffer(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Example #28
0
void Renderer::renderLightPass(Render::Camera& camera)
{
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if(activeRenderState > 0){
        gBuffer.bindForReading();
        gBuffer.setReadBuffer(activeRenderState-1);
        glBlitFramebuffer(0, 0, screenSize.x, screenSize.y, 0, 0, screenSize.x, screenSize.y, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    } else{

        // Enable blending

        glEnable(GL_BLEND);
        glBlendEquation(GL_FUNC_ADD);
        glBlendFunc(GL_ONE, GL_ONE);

        // Clear the color buffer
        glClear(GL_COLOR_BUFFER_BIT);

        // Bind the gbuffer

        gBuffer.bindForLightPass();
        
        for(auto lightIter = lightsList.begin(); lightIter < lightsList.end(); lightIter++){
            (*lightIter)->update(camera);
            (*lightIter)->render();
        }

    }
}
	bool render()
	{
		// Clear the framebuffer
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glUseProgram(ProgramName);
		glUniform1i(UniformDiffuse, 0);

		// Pass 1
		// Render the scene in a multisampled framebuffer
		glEnable(GL_MULTISAMPLE);
		renderFBO(FramebufferRenderName);
		glDisable(GL_MULTISAMPLE);

		// Resolved multisampling
		glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName);
		glBlitFramebuffer(
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
			GL_COLOR_BUFFER_BIT, GL_LINEAR);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		glm::ivec2 WindowSize(this->getWindowSize());

		// Pass 2
		// Render the colorbuffer from the multisampled framebuffer
		glViewport(0, 0, WindowSize.x, WindowSize.y);
		renderFB(ColorTextureName);

		return true;
	}
void display()
{
	// Clear the framebuffer
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	// Pass 1
	// Render the scene in a multisampled framebuffer
	glEnable(GL_MULTISAMPLE);
	renderFBO(FramebufferName[framebuffer::RENDER]);
	glDisable(GL_MULTISAMPLE);

	// Resolved multisampling
	glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferName[framebuffer::RESOLVE]);
	glBlitFramebuffer(
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
		GL_COLOR_BUFFER_BIT, GL_NEAREST);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// Pass 2
	// Render the colorbuffer from the multisampled framebuffer
	renderFB(TextureName[texture::COLORBUFFER]);

	glf::checkError("display");
	glf::swapBuffers();
}