Example #1
0
void RenderState::bindFramebuffer(const Framebuffer::Pointer& fbo, bool force)
{
#if !defined(ET_CONSOLE_APPLICATION)
	if (fbo.valid())
	{
		bindFramebuffer(static_cast<uint32_t>(fbo->apiHandle()), GL_FRAMEBUFFER, force);
		
		setViewportSize(fbo->size(), force);
		
		if (fbo->hasRenderTargets())
			setDrawBuffersCount(fbo->drawBuffersCount());
	}
	else 
	{
		bindFramebuffer(0, GL_FRAMEBUFFER, force);
		setViewportSize(_currentState.mainViewportSize, force);
	}
#endif
}
void RenderingSystemOgl::setFramebuffer(
    Framebuffer::Pointer framebuffer, bool preserveOutputRectangle )
{
    if( _framebuffer == framebuffer )
        return;

    auto nativeFramebuffer =
        std::static_pointer_cast< FramebufferOgl >( framebuffer );

    const GLint framebufferHandle =
        nativeFramebuffer ? nativeFramebuffer->getHandle() : 0;

    ::glBindFramebuffer( GL_FRAMEBUFFER, framebufferHandle );
    checkResult( "::glBindFramebuffer" );

    if( !preserveOutputRectangle ) {
        unsigned int width;
        unsigned int height;

        if( framebuffer ) {
            const Framebuffer::Buffer &buffer =
                framebuffer->getDescription().buffers.front();

            const Texture::MipLevelDimensions mipLevelDimensions =
                buffer.texture->getMipLevelDimensions( buffer.mipLevel );
            width = mipLevelDimensions.width;
            height = mipLevelDimensions.height;
        } else {
            if( const Window::Pointer window = getOutputWindow() ) {
                const Dimensions windowDimensions = window->getDimensions();

                width = windowDimensions.width;
                height = windowDimensions.height;
            } else {
                width = 0;
                height = 0;
            }
        }

        setOutputRectangle( {0, 0, width, height} );
    }

    _framebuffer = framebuffer;
}
Example #3
0
void Framebuffer::resolveMultisampledTo(Framebuffer::Pointer framebuffer, bool resolveColor, bool resolveDepth)
{
	vec2i sourceSize = _description.size.xy();
	vec2i targetSize = framebuffer->size();
	
	_rc->renderState().bindReadFramebuffer(static_cast<uint32_t>(apiHandle()));
	
#if (ET_DEBUG)
	GLint sourceSamples = 0;
	glGetIntegerv(GL_SAMPLES, &sourceSamples);
	checkOpenGLError("glGetIntegerv(GL_SAMPLES, ...)");
	
	GLint sourceSampleBuffers = 0;
	glGetIntegerv(GL_SAMPLE_BUFFERS, &sourceSampleBuffers);
	checkOpenGLError("glGetIntegerv(GL_SAMPLE_BUFFERS, ...)");
#endif
	
	_rc->renderState().bindDrawFramebuffer(static_cast<uint32_t>(framebuffer->apiHandle()));
	
#if (ET_DEBUG)
	GLint targetSamples = 0;
	glGetIntegerv(GL_SAMPLES, &targetSamples);
	checkOpenGLError("glGetIntegerv(GL_SAMPLES, ...)");
	
	GLint targetSampleBuffers = 0;
	glGetIntegerv(GL_SAMPLE_BUFFERS, &targetSampleBuffers);
	checkOpenGLError("glGetIntegerv(GL_SAMPLE_BUFFERS, ...)");
	
	if ((targetSamples != 0) && (targetSamples != sourceSamples))
	{
		log::info("glBlitFramebuffer will likely fail:\n"
			"GL_SAMPLES of target (%d) and source (%d) framebuffers are different", targetSamples, sourceSamples);
	}
	
	if (((sourceSampleBuffers > 0) || (targetSampleBuffers > 0)) && (sourceSize != targetSize))
	{
		log::info("glBlitFramebuffer will likely fail:\n"
			"GL_SAMPLE_BUFFERS of target (%d) and source (%d) framebuffers are greater than zero\n"
			"and dimensions are not identical (%dx%d and %dx%d", targetSampleBuffers, sourceSampleBuffers,
			targetSize.x, targetSize.y, sourceSize.x, sourceSize.y);
	}
#endif
	
#	if (ET_OPENGLES)
	if (OpenGLCapabilities::instance().version() < OpenGLVersion::Version_3x)
	{
		glResolveMultisampleFramebufferAPPLE();
		checkOpenGLError("glResolveMultisampleFramebuffer");
	}
#	endif
	
	if (resolveColor)
	{
		glBlitFramebuffer(0, 0, sourceSize.x, sourceSize.y, 0, 0, targetSize.x, targetSize.y,
			GL_COLOR_BUFFER_BIT, (sourceSize == targetSize) ? GL_NEAREST : GL_LINEAR);
		checkOpenGLError("glBlitFramebuffer");
	}

	if (resolveDepth)
	{
		glBlitFramebuffer(0, 0, sourceSize.x, sourceSize.y, 0, 0, targetSize.x, targetSize.y,
			GL_DEPTH_BUFFER_BIT, GL_NEAREST);
		checkOpenGLError("glBlitFramebuffer");
	}
}