コード例 #1
0
RenderResultPacket RenderServerRenderer::createRenderResultPacket(const RenderServerRenderRequest & request)
{
    QByteArray outputBuffer;
    int bufferSizeBytes = m_renderer.getScreenBufferSizeBytes();
    outputBuffer.resize(bufferSizeBytes);
    m_renderer.getOutputBuffer(outputBuffer.data());
    RenderResultPacket result = RenderResultPacket(request.getSequenceNumber(), request.getIterationNumbers(), outputBuffer);
    return result;
}
コード例 #2
0
void RenderServerRenderer::onNewRenderCommandInQueue()
{
    while(true)
    {
        // Process queued up events/slots, in case we quit
        QCoreApplication::processEvents();

        if(m_quit)
        {
            return;
        }

        // If queue is empty, we wait until we get a new request
        if(m_queue.size() == 0)
        {
            m_waitCondition.wait(&m_waitConditionMutex);
            continue;
        }
        // Process the next RenderServerRenderRequest

        RenderServerRenderRequest renderRequest = m_queue.dequeue();
        QString iterationNumbersInPacketString = "";

        for(int i = 0; i < renderRequest.getNumIterations(); i++)
        {
            // If the packet we are working has become old during this rendering for-loop, then break out of this loop
            if(m_currentSequenceNumber != renderRequest.getSequenceNumber())
            {
                break;
            }
            // Else we'll render this frame
            else
            {
                // This renderRequest has a new scene name, so we'll load the new scene
                if(m_scene == NULL || m_scene->getSceneName() != renderRequest.getDetails().getSceneName())
                {
                    loadNewScene(renderRequest.getDetails().getSceneName());
                }

                // Render the frame with local iteration number going from 0 to renderRequestsCurrentPacket.size()
                // We only need to create the output buffer for the last iteration of the packet
                bool createOutputBuffer = i == renderRequest.getNumIterations() - 1;
                renderFrame(renderRequest.getIterationNumbers().at(i), i, renderRequest.getPPMRadii().at(i), createOutputBuffer, renderRequest.getDetails());
                iterationNumbersInPacketString += " " + QString::number(renderRequest.getIterationNumbers().at(i));
            }
        }

        // If the packet we have just rendered is old (m_currentSequenceNumber is newer)
        // then we drop this packet. This can happen if we have started on a RenderServerRenderRequest but later found out about
        // a new sequence, in which case we have break-ed out of the loop above.

        if(renderRequest.getSequenceNumber() == m_currentSequenceNumber)
        {
            RenderResultPacket result = createRenderResultPacket(renderRequest);
            QString logString = QString("TRANSFERRING packet (%1 iteration:%2) in sequence %3 to client.")
                                .arg(result.getNumIterationsInPacket())
                                .arg(iterationNumbersInPacketString)
                                .arg(result.getSequenceNumber());
            emit newLogString(logString);
            emit newRenderResultPacket(result);
        }
        else
        {
            QString logString = QString("IGNORED package with %1 iterations since sequence %3 != %4.")
                                .arg(renderRequest.getNumIterations())
                                .arg(renderRequest.getSequenceNumber())
                                .arg(m_currentSequenceNumber);
            emit newLogString(logString);
        }
    }
}