Пример #1
0
void Renderer::render(const RenderQueue& queue, const Camera& camera)
{
  ProfileNodeCall call("Renderer::render");

  m_context.setCurrentSharedProgramState(m_state);

  const Recti& viewportArea = m_context.viewportArea();
  m_state->setViewportSize(float(viewportArea.size.x),
                           float(viewportArea.size.y));

  m_state->setProjectionMatrix(camera.projectionMatrix());
  m_state->setViewMatrix(camera.viewTransform());

  if (camera.isPerspective())
  {
    m_state->setCameraProperties(camera.transform().position,
                                 camera.FOV(),
                                 camera.aspectRatio(),
                                 camera.nearZ(),
                                 camera.farZ());
  }

  renderOperations(queue.opaqueBucket());
  renderOperations(queue.blendedBucket());

  m_context.setCurrentSharedProgramState(nullptr);
}
Пример #2
0
int renderThread_AA(void* v) {
  RenderQueue* rq = (RenderQueue*)v;
  RenderQueue::Point p;
  while (rq->checkPop(p)) {
    traceAt_AA(*rq->scene, *rq->screen, p.r, p.c);
  }
  return 0;
}
Пример #3
0
	void    RenderWindow::Update()
	{
		// 设置当前渲染窗口
		m_pActiveRenderWindow = this;

		// 开始场景
		if ( m_pRenderer->BeginScene() )
		{
			// 更新当前帧
			m_dwCurFrame ++;

			// 更新渲染对象
			RenderTarget::Update();

			// 后处理
			PostProcessQueue::GetSingleton()->ProcessAll();

			// 更新缓存管理器
			ResourceManager::GetSingleton()->Update();

			// 计算时间
			m_fElapsedTime = (float) ( GetTickCount() - m_dwLastTime ) / 1000.0f;
			m_dwLastTime = GetTickCount();
			m_fSumTime += m_fElapsedTime;
			m_iFrameCount ++;
			
			// 渲染FPS
			if ( m_fSumTime > 1.0f )
			{
				m_iFPS = (int) ( m_iFrameCount / m_fSumTime );
				m_iFrameCount = 0;
				m_fSumTime = 0.0f;
			}

			wchar_t szText[32];
			_itow_s( m_iFPS, szText, 32, 10 );
			wstring szFPS = szText;
			m_pRenderer->RenderText( 5, 5, Vector4f( 1.0f, 1.0f, 0.0f, 1.0f ), szFPS );

			int iY = 25;
			RenderQueue * pQueue = m_pRenderer->GetRenderQueue( Renderer::RenderQueue_Visible );
			multimap< float, Entity * >::iterator VisibleIt = pQueue->GetEntityList()->begin();
			while ( VisibleIt != pQueue->GetEntityList()->end() )
			{
				Key szKey = (*VisibleIt).second->GetKey();
				m_pRenderer->RenderText( 5, iY, Vector4f( 1.0f, 1.0f, 0.0f, 1.0f ), szKey.GetName() );

				iY += 20;
				VisibleIt++;
			}

			// 结束场景
			m_pRenderer->EndScene();
		}

		// 缓冲交换
		m_pRenderer->Present();
	}
Пример #4
0
	void renderToTexture(const RenderQueue& renderQueue, FrameBufferObject* target)
	{
		target->bind();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		
		for(RenderQueue::const_iterator it = renderQueue.begin(); it != renderQueue.end(); ++it)
			(*it)();

		target->unbind();
	}
Пример #5
0
	void D3DRenderContext::Render(D3DMaterial* material, RenderQueue& renderableObjects) {
		for (RenderQueue::const_iterator i = renderableObjects.begin(); i != renderableObjects.end(); ++i) {
			uint passesCount = material->BeginPasses("RenderScene");
			for (uint passNo = 0; passNo < passesCount; ++passNo) {
				(*i)->ApplyTransformations();
				material->SetMatrices();
				material->BeginPass(passNo);
				(*i)->Render();
				(*i)->IdentityTransformation();
				material->EndPass();
			}
			material->EndPasses();
		}
	}
Пример #6
0
	void MirrorRenderLoop::DoRender(Camera * cam)
	{
		RenderSystem * render = RenderSystem::Instance();
		RenderQueue * rq = mScheme->GetMirrorRenderQueue();

		 // --->render terrain
        if (Environment::Instance()->GetTerrain())
            Environment::Instance()->GetTerrain()->RenderInMirror();

        // ---> render sky
        if (Environment::Instance()->GetSky2())
            Environment::Instance()->GetSky2()->RenderReflection(cam->GetMirrorPlane());

        // ---> render sun
        /*if (Environment::Instance()->GetSun())
            Environment::Instance()->GetSun()->Render();*/

        // ---> render moons
        if (Environment::Instance()->GetMoon())
            Environment::Instance()->GetMoon()->Render();

        // ---> render cloud
        //if (Environment::Instance()->GetCloud())
            //Environment::Instance()->GetCloud()->Render(false);

		// render solider
		{
			RenderSystem * render = RenderSystem::Instance();

			const Array<Renderer *> & objs = rq->GetSolidRender();

			for (int i = 0; i < objs.Size(); ++i)
			{
				Renderer * rd = objs[i];

				bool skined = (rd->GetBlendMatrix(NULL) > 0);
				Technique * tech = rd->GetTechnique(eRenderTechType::RTT_Mirror);

				if (!tech)
					tech = mScheme->GetMainShaderProvider()->GetTechnique(eRenderTechType::RTT_Mirror, skined);

				render->Render(tech, rd);
			}
		}

		RenderEvent::OnMirrorRenderSolid1(cam);
		RenderEvent::OnMirrorRenderSolid2(cam);
		RenderEvent::OnMirrorRenderSolid3(cam);
	}
Пример #7
0
void    Label::OnPaint(RenderTarget& target, RenderQueue& queue) const
{
    Widget::OnPaint(target, queue);

    queue.SetColor(GetTextColor());
    target.Draw(mCaption);
}
Пример #8
0
void Projector::appendRenderables( RenderQueue& queue, const Transform* transform )
{
	if( !geometry ) return;

	const Transform* geotransform = geometry->getEntity()->getTransform().get();
	const Matrix4x3& absoluteTransform = geotransform->getAbsoluteTransform();
	
	const RenderablesVector& renderables = geometry->getRenderables();
	
	for( size_t i = 0; i < renderables.size(); i++ )
	{
		RenderBatch* renderable = renderables[i].get();
		if( !renderable ) continue;

		renderable->onPreRender.Bind(this, &Projector::onPreRender);

		RenderState state;
		state.renderable = renderable;
		state.material = material.Resolve();
		state.modelMatrix = absoluteTransform;
		state.priority = renderable->getRenderPriority() + 1;

		queue.pushBack(state);
	}
}
Пример #9
0
void Entity::addToRenderQueue(const Matrix4f &transMatrix, RenderQueue &renderQueue)
{
	for(unsigned i=0; i<m_subEntityVec.size(); ++i)
	{
		renderQueue.addItem(transMatrix, m_subEntityVec[i]);
	}
}
Пример #10
0
	void DisplayNode::findVisible( Camera*cam, RenderQueue& display, a_vector<LightNode*>& light )
	{
		if(!cam->isInFrustrum(m_globalBbox))
			return;
		display.push_back(this);
		
		SceneNode::findVisible(cam,display,light);
	}
Пример #11
0
void DepthOfFieldEffect::preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt)
{

	float dofParams[4] = {mNearDepth, mFocalDepth, mFarDepth, mFarBlurCutoff};

	// Adjust fragment program parameters for depth pass
	GpuProgramParametersSharedPtr fragParams =
		mDepthTechnique->getPass(0)->getFragmentProgramParameters();
	if ((!fragParams.isNull())&&(fragParams->_findNamedConstantDefinition("dofParams")))
		fragParams->setNamedConstant("dofParams", dofParams,1,4);		

	evt.source->setVisibilityMask(~DEPTHMAP_DISABLED);

	// Add 'this' as a RenderableListener to replace the technique for all renderables
	RenderQueue* queue = evt.source->getCamera()->getSceneManager()->getRenderQueue();
	queue->setRenderableListener(this);
}
void Renderer::makeSingleRenderCommandList(RenderQueue& queue) {
	//_renderCommands->reserveElements(7);

	CustomCommand* begin = _customCommandPool1->pop();
	CustomCommand* end = _customCommandPool1->pop();

	begin->func = CC_CALLBACK_0(RenderQueue::saveRenderState, &queue);
	_renderCommands->push_back_resize(begin);

	std::vector<RenderCommand*> queueEntrys = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_NEG);
	if (queueEntrys.size() > 0) {
		_renderCommands->push_back_resize(_beginQueue2dCommand);
		_lastWasFlushCommand = true;
		makeSingleRenderCommandList(queueEntrys);
	}
	queueEntrys = queue.getSubQueue(RenderQueue::QUEUE_GROUP::OPAQUE_3D);
	if (queueEntrys.size() > 0) {
		_renderCommands->push_back_resize(_beginQueueOpaqueCommand);
		_lastWasFlushCommand = true;
		makeSingleRenderCommandList(queueEntrys);
	}
	queueEntrys = queue.getSubQueue(RenderQueue::QUEUE_GROUP::TRANSPARENT_3D);
	if (queueEntrys.size() > 0) {
		_renderCommands->push_back_resize(_beginQueueTransparentCommand);
		_lastWasFlushCommand = true;
		makeSingleRenderCommandList(queueEntrys);
	}
	queueEntrys = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_ZERO);
	if (queueEntrys.size() > 0) {
		_renderCommands->push_back_resize(_beginQueue2dCommand);
		_lastWasFlushCommand = true;
		makeSingleRenderCommandList(queueEntrys);
	}
	queueEntrys = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_POS);
	if (queueEntrys.size() > 0) {
		_renderCommands->push_back_resize(_beginQueue2dCommand);
		_lastWasFlushCommand = true;
		makeSingleRenderCommandList(queueEntrys);
	}

	end->func = CC_CALLBACK_0(RenderQueue::restoreRenderState, &queue);
	_renderCommands->push_back_resize(end);

	_customCommandPool2->push(begin);
	_customCommandPool2->push(end);
}
Пример #13
0
void Renderer::visitRenderQueue(const RenderQueue& queue)
{
    ssize_t size = queue.size();
    
    for (ssize_t index = 0; index < size; ++index)
    {
        auto command = queue[index];
        auto commandType = command->getType();
        if(RenderCommand::Type::QUAD_COMMAND == commandType)
        {
            auto cmd = static_cast<QuadCommand*>(command);
            //Batch quads
            if(_numQuads + cmd->getQuadCount() > VBO_SIZE)
            {
                CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
                
                //Draw batched quads if VBO is full
                drawBatchedQuads();
            }
            
            _batchedQuadCommands.push_back(cmd);
            
            memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
            convertToWorldCoordinates(_quads + _numQuads, cmd->getQuadCount(), cmd->getModelView());
            
            _numQuads += cmd->getQuadCount();

        }
        else if(RenderCommand::Type::GROUP_COMMAND == commandType)
        {
            flush();
            int renderQueueID = ((GroupCommand*) command)->getRenderQueueID();
            visitRenderQueue(_renderGroups[renderQueueID]);
        }
        else if(RenderCommand::Type::CUSTOM_COMMAND == commandType)
        {
            flush();
            auto cmd = static_cast<CustomCommand*>(command);
            cmd->execute();
        }
        else if(RenderCommand::Type::BATCH_COMMAND == commandType)
        {
            flush();
            auto cmd = static_cast<BatchCommand*>(command);
            cmd->execute();
        }
        else
        {
            CCLOGERROR("Unknown commands in renderQueue");
        }
    }
}
Пример #14
0
        void    Widget::Render(RenderTarget& target, RenderQueue& queue) const
        {
            OnPaint(target, queue);

            if (mUseScissor)
            {
                Area& area = ResourceManager::Get()->WidgetArea;
                area.PushArea(GetRect(true));
                const FloatRect& top = area.GetTopArea();

                target.Flush();

                RenderChildren(target, queue);

                queue.SetScissor(true, Vector2f(top.Left, target.GetHeight() - top.Bottom), Vector2f(top.GetSize().x, top.GetSize().y));
                target.Flush();
                area.PopArea();
            }
            else
            {
                queue.SetScissor(false);
                RenderChildren(target, queue);
            }
        }
Пример #15
0
void PlanetAtmosphereNode::findVisible( Camera*cam, RenderQueue& display, a_vector<LightNode*>& light )
{
    if(!m_controller->m_use_atmosphere || !cam->isInFrustrum(m_globalBbox))
        return;

    PlanetModel* model = m_controller->m_model;
    m_controller->m_cam_position = cam->getPosition();

    vec4 my(0,0,0,1);
    my = m_transform->modelMatrix()*my;
    m_controller->m_cam_position = m_controller->m_cam_position-vec3(my);
    m_controller->m_cam_dist = length(m_controller->m_cam_position);
    display.push_back(this,RenderQueue::TRenderType::TYPE_BLEND);

    SceneNode::findVisible(cam,display,light);
}
//----------------------------------------------------------------------------//
void OgreRenderTarget::draw(const RenderQueue& queue)
{
    queue.draw();
}
Пример #17
0
void DepthOfFieldEffect::postViewportUpdate(const Ogre::RenderTargetViewportEvent& evt)
{
	// Reset the RenderableListener
	RenderQueue* queue = evt.source->getCamera()->getSceneManager()->getRenderQueue();
	queue->setRenderableListener(0);
}
Пример #18
0
 void    Widget::OnPaint(RenderTarget& target, RenderQueue& queue) const
 {
     queue.SetColor(GetColor());
     target.Draw(Shape::Rectangle(0, 0, mSize.x, mSize.y, GetColor(), 1.f, GetBorderColor()));
 }
Пример #19
0
//--------------------------------------------------------------------------------------------------
/// Render the configured scene using the current Camera
//--------------------------------------------------------------------------------------------------
void Rendering::render(OpenGLContext* oglContext)
{
    CVF_ASSERT(m_camera.notNull() && m_camera->viewport());

    bool debugLogging = CVF_SHOULD_LOG_RENDER_DEBUG(oglContext);
    if (debugLogging)
    {
        CVF_LOG_RENDER_DEBUG(oglContext, String("Entering Rendering::render(), renderingName='%1'").arg(m_renderingName));
    }

    CVF_CHECK_OGL(oglContext);

    m_performanceInfo.clear();

    ref<Timer> renderTimer;
    if (m_enablePerformanceTiming)
    {
        renderTimer = new Timer;
    }

    // Update any transforms and bounding boxes if a transform tree is used
    if (m_scene.notNull())
    {
        m_scene->updateTransformTree(m_camera.p());
    }

    // Compute visible parts
    // -------------------------------------------------------------------------
    m_visibleParts->setCountZero();
    if (m_scene.notNull())
    {
        m_scene->findVisibleParts(m_visibleParts.p(), *m_camera.p(), *m_cullSettings, m_enableMask);
    }

    if (renderTimer.notNull())
    {
        m_performanceInfo.computeVisiblePartsTime = renderTimer->lapTime();
    }

    m_performanceInfo.visiblePartsCount = m_visibleParts->count();

    // Setup FBO
    // -------------------------------------------------------------------------
    if (m_targetFramebuffer.notNull())
    {
        // Option to sync FBO size to viewport size
        m_targetFramebuffer->applyOpenGL(oglContext);

        String failReason;
        if (!m_targetFramebuffer->isFramebufferComplete(oglContext, &failReason))
        {
            Trace::show(failReason);
            return;
        }
    }
    else
    {
#ifndef CVF_OPENGL_ES
        if (FramebufferObject::supportedOpenGL(oglContext))
        {
            FramebufferObject::useDefaultWindowFramebuffer(oglContext);
        }
#endif
    }

    // Setup camera and view
    // -------------------------------------------------------------------------
    m_camera->viewport()->applyOpenGL(oglContext, m_clearMode);
    m_camera->applyOpenGL();

    // Update dynamic uniforms and dynamic uniform sets
    // -------------------------------------------------------------------------
    updateDynamicUniformSets();
    updateAndCombineGlobalDynamicUniformSets();


    // Build the render queue
    // -------------------------------------------------------------------------
    RenderQueueBuilder builder(m_visibleParts.p(), oglContext, m_camera.p());
    builder.setFixedEffect(m_effectOverride.p());
    if (m_renderQueueSorter.notNull())
    {
        builder.setRequireDistance(m_renderQueueSorter->requireDistance());
        builder.setRequirePixelArea(m_renderQueueSorter->requirePixelArea());
    }

    RenderQueue renderQueue;
    builder.populateRenderQueue(&renderQueue);

    if (renderTimer.notNull())
    {
        m_performanceInfo.buildRenderQueueTime = renderTimer->lapTime();
    }


    // Sort the render queue
    // -------------------------------------------------------------------------
    if (m_renderQueueSorter.notNull())
    {
        m_renderQueueSorter->sort(&renderQueue);

        if (renderTimer.notNull())
        {
            m_performanceInfo.sortRenderQueueTime = renderTimer->lapTime();
        }
    }


    // Render the scene
    // -------------------------------------------------------------------------
    const UniformSet* globalUniformSet = m_combinedGlobalUniformSet.p();
    size_t numPartsToDraw = std::min(m_maxNumPartsToDraw, renderQueue.count());
    m_renderEngine.render(oglContext, &renderQueue, numPartsToDraw, *m_camera, globalUniformSet);

    if (renderTimer.notNull())
    {
        m_performanceInfo.renderEngineTime = renderTimer->lapTime();
    }

    // Render the overlay items
    // Use software rendering if forced or if no support for Shader Programs
    bool useSoftwareRendering = m_renderEngine.isForcedImmediateModeEnabled() || !ShaderProgram::supportedOpenGL(oglContext);
    renderOverlayItems(oglContext, useSoftwareRendering);

    // Update counters
    m_performanceInfo.renderedPartsCount        = m_renderEngine.renderedPartCount();
    m_performanceInfo.vertexCount               = m_renderEngine.renderedVertexCount();
    m_performanceInfo.triangleCount             = m_renderEngine.renderedTriangleCount();
    m_performanceInfo.openGLPrimitiveCount      = m_renderEngine.renderedOpenGLPrimitiveCount();
    m_performanceInfo.applyRenderStateCount     = m_renderEngine.applyRenderStateCount();
    m_performanceInfo.shaderProgramChangesCount = m_renderEngine.shaderProgramChangesCount();

    // Last update before we exit, total render time for this rendering
    if (renderTimer.notNull())
    {
        m_performanceInfo.totalDrawTime = renderTimer->time();
    }

    CVF_CHECK_OGL(oglContext);

    if (debugLogging)
    {
        CVF_LOG_RENDER_DEBUG(oglContext, String("Exiting Rendering::render(), renderingName='%1'").arg(m_renderingName));
    }
}
Пример #20
0
void Renderer::visitRenderQueue(RenderQueue& queue)
{
    queue.saveRenderState();
    
    //
    //Process Global-Z < 0 Objects
    //
    const auto& zNegQueue = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_NEG);
    if (zNegQueue.size() > 0)
    {
        if(_isDepthTestFor2D)
        {
            glEnable(GL_DEPTH_TEST);
            glDepthMask(true);
            RenderState::StateBlock::_defaultState->setDepthTest(true);
            RenderState::StateBlock::_defaultState->setDepthWrite(true);
        }
        else
        {
            glDisable(GL_DEPTH_TEST);
            glDepthMask(false);
            RenderState::StateBlock::_defaultState->setDepthTest(false);
            RenderState::StateBlock::_defaultState->setDepthWrite(false);
        }
        for (auto it = zNegQueue.cbegin(); it != zNegQueue.cend(); ++it)
        {
            processRenderCommand(*it);
        }
        flush();
    }
    
    //
    //Process Opaque Object
    //
    const auto& opaqueQueue = queue.getSubQueue(RenderQueue::QUEUE_GROUP::OPAQUE_3D);
    if (opaqueQueue.size() > 0)
    {
        //Clear depth to achieve layered rendering
        glEnable(GL_DEPTH_TEST);
        glDepthMask(true);
        RenderState::StateBlock::_defaultState->setDepthTest(true);
        RenderState::StateBlock::_defaultState->setDepthWrite(true);


        for (auto it = opaqueQueue.cbegin(); it != opaqueQueue.cend(); ++it)
        {
            processRenderCommand(*it);
        }
        flush();
    }
    
    //
    //Process 3D Transparent object
    //
    const auto& transQueue = queue.getSubQueue(RenderQueue::QUEUE_GROUP::TRANSPARENT_3D);
    if (transQueue.size() > 0)
    {
        glEnable(GL_DEPTH_TEST);
        glDepthMask(false);

        RenderState::StateBlock::_defaultState->setDepthTest(true);
        RenderState::StateBlock::_defaultState->setDepthWrite(false);


        for (auto it = transQueue.cbegin(); it != transQueue.cend(); ++it)
        {
            processRenderCommand(*it);
        }
        flush();
    }
    
    //
    //Process Global-Z = 0 Queue
    //
    const auto& zZeroQueue = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_ZERO);
    if (zZeroQueue.size() > 0)
    {
        if(_isDepthTestFor2D)
        {
            glEnable(GL_DEPTH_TEST);
            glDepthMask(true);

            RenderState::StateBlock::_defaultState->setDepthTest(true);
            RenderState::StateBlock::_defaultState->setDepthWrite(true);

        }
        else
        {
            glDisable(GL_DEPTH_TEST);
            glDepthMask(false);

            RenderState::StateBlock::_defaultState->setDepthTest(false);
            RenderState::StateBlock::_defaultState->setDepthWrite(false);

        }
        for (auto it = zZeroQueue.cbegin(); it != zZeroQueue.cend(); ++it)
        {
            processRenderCommand(*it);
        }
        flush();
    }
    
    //
    //Process Global-Z > 0 Queue
    //
    const auto& zPosQueue = queue.getSubQueue(RenderQueue::QUEUE_GROUP::GLOBALZ_POS);
    if (zPosQueue.size() > 0)
    {
        for (auto it = zPosQueue.cbegin(); it != zPosQueue.cend(); ++it)
        {
            processRenderCommand(*it);
        }
        flush();
    }
    
    queue.restoreRenderState();
}
Пример #21
0
void Renderer::render()
{
    //Uncomment this once everything is rendered by new renderer
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //TODO setup camera or MVP

    if (_glViewAssigned)
    {
        // cleanup
        _drawnBatches = _drawnVertices = 0;

        //Process render commands
        //1. Sort render commands based on ID
        for (auto &renderqueue : _renderGroups)
        {
            renderqueue.sort();
        }
        
        while(!_renderStack.empty())
        {
            RenderQueue currRenderQueue = _renderGroups[_renderStack.top().renderQueueID];
            size_t len = currRenderQueue.size();
            
            //Process RenderQueue
            for(size_t i = _renderStack.top().currentIndex; i < len; i++)
            {
                _renderStack.top().currentIndex = i;
                auto command = currRenderQueue[i];

                auto commandType = command->getType();
                
                if(commandType == RenderCommand::Type::QUAD_COMMAND)
                {
                    auto cmd = static_cast<QuadCommand*>(command);
                    CCASSERT(nullptr!= cmd, "Illegal command for RenderCommand Taged as QUAD_COMMAND");
                    
                    //Batch quads
                    if(_numQuads + cmd->getQuadCount() > VBO_SIZE)
                    {
                        CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");

                        //Draw batched quads if VBO is full
                        drawBatchedQuads();
                    }
                    
                    _batchedQuadCommands.push_back(cmd);
                    
                    memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
                    convertToWorldCoordinates(_quads + _numQuads, cmd->getQuadCount(), cmd->getModelView());

                    _numQuads += cmd->getQuadCount();
                }
                else if(commandType == RenderCommand::Type::CUSTOM_COMMAND)
                {
                    flush();
                    auto cmd = static_cast<CustomCommand*>(command);
                    cmd->execute();
                }
                else if(commandType == RenderCommand::Type::BATCH_COMMAND)
                {
                    flush();
                    auto cmd = static_cast<BatchCommand*>(command);
                    cmd->execute();
                }
                else if(commandType == RenderCommand::Type::GROUP_COMMAND)
                {
                    flush();
                    auto cmd = static_cast<GroupCommand*>(command);
                    
                    _renderStack.top().currentIndex = i + 1;
                    
                    //push new renderQueue to renderStack
                    RenderStackElement element = {cmd->getRenderQueueID(), 0};
                    _renderStack.push(element);
                    
                    //Exit current loop
                    break;
                }
                else
                {
                    CCASSERT(true, "Invalid command");
                    flush();
                }
            }
            
            //Draw the batched quads
            drawBatchedQuads();
            
            currRenderQueue = _renderGroups[_renderStack.top().renderQueueID];
            len = currRenderQueue.size();
            //If pop the render stack if we already processed all the commands
            if(_renderStack.top().currentIndex + 1 >= len)
            {
                _renderStack.pop();
            }
        }
    }

    for (size_t j = 0 ; j < _renderGroups.size(); j++)
    {
        //commands are owned by nodes
        // for (const auto &cmd : _renderGroups[j])
        // {
        //     cmd->releaseToCommandPool();
        // }
        _renderGroups[j].clear();
    }
    
    //Clear the stack incase gl view hasn't been initialized yet
    while(!_renderStack.empty())
    {
        _renderStack.pop();
    }
    RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0};
    _renderStack.push(element);
    _lastMaterialID = 0;
}
void Renderer::visitRenderQueue(const RenderQueue& queue)
{
    ssize_t size = queue.size();
    
    for (ssize_t index = 0; index < size; ++index)
    {
        auto command = queue[index];
        auto commandType = command->getType();
        if( RenderCommand::Type::TRIANGLES_COMMAND == commandType)
        {
            flush3D();
            if(_numberQuads > 0)
            {
                drawBatchedQuads();
                _lastMaterialID = 0;
            }
            
            auto cmd = static_cast<TrianglesCommand*>(command);
            //Batch Triangles
            if( _filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE)
            {
                CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command");
                CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command");
                //Draw batched Triangles if VBO is full
                drawBatchedTriangles();
            }
            
            _batchedCommands.push_back(cmd);
            
            fillVerticesAndIndices(cmd);

        }
        else if ( RenderCommand::Type::QUAD_COMMAND == commandType )
        {
            flush3D();
            if(_filledIndex > 0)
            {
                drawBatchedTriangles();
                _lastMaterialID = 0;
            }
            auto cmd = static_cast<QuadCommand*>(command);
            //Batch quads
            if( (_numberQuads + cmd->getQuadCount()) * 4 > VBO_SIZE )
            {
                CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() * 4 < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command");
                //Draw batched quads if VBO is full
                drawBatchedQuads();
            }
            
            _batchQuadCommands.push_back(cmd);
            
            fillQuads(cmd);

        }
        else if(RenderCommand::Type::GROUP_COMMAND == commandType)
        {
            flush();
            int renderQueueID = ((GroupCommand*) command)->getRenderQueueID();
            visitRenderQueue(_renderGroups[renderQueueID]);
        }
        else if(RenderCommand::Type::CUSTOM_COMMAND == commandType)
        {
            flush();
            auto cmd = static_cast<CustomCommand*>(command);
            cmd->execute();
        }
        else if(RenderCommand::Type::BATCH_COMMAND == commandType)
        {
            flush();
            auto cmd = static_cast<BatchCommand*>(command);
            cmd->execute();
        }
        else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType)
        {
            flush();
            auto cmd = static_cast<PrimitiveCommand*>(command);
            cmd->execute();
        }
        else if (RenderCommand::Type::MESH_COMMAND == commandType)
        {
            flush2D();
            auto cmd = static_cast<MeshCommand*>(command);
            if (_lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID())
            {
                flush3D();
                cmd->preBatchDraw();
                cmd->batchDraw();
                _lastBatchedMeshCommand = cmd;
            }
            else
            {
                cmd->batchDraw();
            }
        }
        else
        {
            CCLOGERROR("Unknown commands in renderQueue");
        }
    }
}
Пример #23
0
	void FlowVRCegRenderTarget::draw(const RenderQueue& queue)
	{
		queue.draw();
	}
//----------------------------------------------------------------------------//
void Direct3D10RenderTarget::draw(const RenderQueue& queue)
{
    queue.draw();
}
Пример #25
0
void ConsoleRenderer::RenderSkybox(QStringList param)
{
    if (param.size()!=5) {
        qDebug() << param.size();
        cout << "Incorrect usage/parameters for galaxy. Usage: " << endl;
        PrintUsage();
        exit(1);

    }
    m_rasterizer = nullptr;
    if (param[1].toLower()=="omp") {
        m_rasterizer = new Rasterizer();
    }
    if (param[1].toLower()=="thread") {
        m_rasterizer = new RasterThread(&m_renderingParams);
    }
    if (m_rasterizer==nullptr) {
        cout << "ERROR! Cannot recognize " << param[1].toStdString() << endl;
        cout << "Must be 'omp' or 'thread'" << endl;
        exit(1);

    }
    Util::path = "";
    m_renderingParams.Load(Util::path + param[2]);
    QString galaxyFile = param[3];
    m_renderingParams.setSize(param[4].toFloat());

    Galaxy galaxy;
    galaxy.Load(galaxyFile);

    m_rasterizer->setRenderingParams(&m_renderingParams);
    m_rasterizer->AddGalaxy(new GalaxyInstance(&galaxy, galaxy.galaxyParams().name(),
                                              QVector3D(0,0,0), QVector3D(0,1,0).normalized(), 1, 0)  );


    RenderQueue rq;
    rq.RenderSkybox(m_rasterizer, m_renderingParams);

    cout << "Starting rendering on " <<  QString::number(std::thread::hardware_concurrency()).toStdString() << " cores." << endl;
    Q_TIMER_START();
    rq.Update();
    while (rq.isRendering()) {
        if (rq.current()== nullptr) {

        }
          else {
        Rasterizer* rast = &rq.current()->rasterizer();
        int prevP = 0;
        while (rast->getState()!= Rasterizer::State::done) {
            int curP = (rast->getPercentDone()*1000.0);
            if (curP!=prevP) {

                float time = ttimer.elapsed();
                float percentage = rast->getPercentDone();
                float timeLeft = time/(percentage) - time;
                QString t;
                t.sprintf("%2.1f", curP*0.1);
                cout << "\r[ " << t.toStdString() <<  "% ]  with ETA in " << Util::MilisecondToString(timeLeft).toStdString() <<   std::flush;
                prevP = curP;

            }
        }
        cout << endl;

        rast->AssembleImage();
        rast->getImageShadowBuffer()->save(rq.current()->filename()+ ".png");
        cout << "Image saved to file " << rq.current()->filename().toStdString() << ".png" << endl;

    }
        rq.Update();
        rq.Update();

}
    Q_TIMER_ELAPSED("Rendering");

}
Пример #26
0
//----------------------------------------------------------------------------//
void OpenGLRenderTarget::draw(const RenderQueue& queue)
{
    queue.draw();
}