Пример #1
0
	void update()
	{
		const auto& renderers = getRenderers();
		for(const auto& renderer : renderers)
		{
			for(const auto input : renderer->getInputDatas())
				input->updateIfDirty();
			renderer->updateIfDirty();
		}

		auto renderSize = getLayerSize();
		int w = renderSize.width(), h = renderSize.height();

		if(!m_renderFrameBuffer || m_renderFrameBuffer.size() != renderSize)
		{
			graphics::FramebufferFormat format;
			format.samples = 16;
			m_renderFrameBuffer = graphics::Framebuffer(renderSize, format);
			m_displayFrameBuffer = graphics::Framebuffer(renderSize);

			// Setting the image Data to the display Fbo
			m_image.getAccessor()->setFbo(m_displayFrameBuffer);
		}

		m_renderFrameBuffer.bind();
		
		glViewport(0, 0, w, h);
		auto& mvp = getMVPMatrix(); // Modify the matrix that will be used by the renderers
		mvp.ortho(0, static_cast<float>(w), static_cast<float>(h), 0, -10.f, 10.f);

		glClearColor(0, 0, 0, 0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for(auto iter = renderers.rbegin(); iter != renderers.rend(); ++iter)
		{
			auto renderer = *iter;
			helper::ScopedEvent log(helper::event_render, renderer);
			renderer->render();
			renderer->cleanDirty();
		}

		glDisable(GL_BLEND);

		m_renderFrameBuffer.release();

		auto acc = m_image.getAccessor();
		graphics::RectInt area(0, 0, renderSize.width(), renderSize.height());
		graphics::Framebuffer::blitFramebuffer(*acc->getFbo(), area, m_renderFrameBuffer, area);
	}
void ofxShaderGraph::initFbos(){
    ofPushStyle();
    ofFill();
    for(auto p:init){
        ofFloatColor c(p.second);
        ofFbo & fbo = getFbo(p.first);
        ofSetColor(c);
        fbo.begin();
        ofDrawRectangle(0,0,fbo.getWidth(),fbo.getHeight());
        fbo.end();
    }
    ofPopStyle();
}
Пример #3
0
// start rendering to texture
// pass -1 as texture ID to restore default render target
static int setRenderTarget(struct SaslGraphicsCallbacks *canvas, 
        int textureId)
{
    OglCanvas *c = (OglCanvas*)canvas;
    assert(canvas);

    dumpBuffers(c);

    if (! c->fboAvailable) {
        printf("fbo not available\n");
        return -1;
    }

    if (-1 != textureId) {
        // save state
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

        GLint w, h;
        glBindTexture(GL_TEXTURE_2D, textureId);
        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
        glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);

        // enable fbo
        c->defaultFbo = getCurrentFbo();
        GLuint fbo = getFbo(c, textureId);
        if ((GLuint)-1 == fbo) {
            printf("can't create fbo\n");
            return -1;
        }
        c->currentFboTex = textureId;
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
        glBindTexture(GL_TEXTURE_2D, 0);
        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 
                GL_TEXTURE_2D, textureId, 0); 
        
        prepareFbo(c, textureId, w, h);
    } else {
        // restore default fbo
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, c->defaultFbo);
        glBindTexture(GL_TEXTURE_2D, c->currentFboTex);
        glGenerateMipmap(GL_TEXTURE);
        glBindTexture(GL_TEXTURE_2D, 0);

        // restore x-plane state
        glPopClientAttrib();
        glPopAttrib();
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
    
        if (c->currentTexture)
            glBindTexture(GL_TEXTURE_2D, c->currentTexture);
        
        c->transform.pop_back();
    }

    return 0;
}