Ejemplo n.º 1
0
void BinarySwapComposer::composeViewport(ViewportPtr port)
{
    // setup viewport
    GLint 
        pl=port->getPixelLeft(), 
        pr=port->getPixelRight(),
        pb=port->getPixelBottom(), 
        pt=port->getPixelTop();
    GLint pw=pr-pl+1,ph=pt-pb+1;
    bool full = port->isFullWindow();
    glViewport(pl, pb, pw, ph);
    glScissor(pl, pb, pw, ph);
    if(! full)
        glEnable(GL_SCISSOR_TEST);

    GLboolean depth = glIsEnabled(GL_DEPTH_TEST);
    GLboolean blend = glIsEnabled(GL_BLEND);

    glDisable(GL_DEPTH_TEST);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, port->getPixelWidth(),
            0, port->getPixelHeight(),-1,1);

//    printf("max %x,%x\n",_intDepthMax,_shortDepthMax);

    if(getAlpha())
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    _tilesX = port->getPixelWidth()  / getTileSize() + 1;
    _tilesY = port->getPixelHeight() / getTileSize() + 1;

    _tileBufferSize = getTileSize()*getTileSize()*8+sizeof(TileBuffer);
    _readTile.resize(_tileBufferSize);

    _statistics.bytesIn  = 0;
    _statistics.bytesOut = 0;

    if(isClient())
    {
        if(getShort())
        {
            UInt16 colorDummy;
            UInt32 depthDummy;
            recvFromServers(depthDummy,colorDummy,
                            GL_RGB,
                            GL_UNSIGNED_SHORT_5_6_5,
                            port);
        }
        else
        {
            if(getAlpha())
            {
                UInt32 colorDummy;
                UInt32 depthDummy;
                recvFromServers(depthDummy,colorDummy,
                                GL_RGBA,
                                GL_UNSIGNED_BYTE,
                                port);
            }
            else
            {
                RGBValue colorDummy;
                UInt32   depthDummy;
                recvFromServers(depthDummy,colorDummy,
                                GL_RGB,
                                GL_UNSIGNED_BYTE,
                                port);
            }
        }
        if(getStatistics())
        {
            UInt32      maxIn   = _statistics.bytesIn;
            UInt32      maxOut  = _statistics.bytesOut;
            UInt32      maxIO   = maxIn + maxOut;
            UInt32      sumOut  = _statistics.bytesOut;
            UInt32      missing = _usableServers;
            double      composeTime = 1e32;
            
            Connection *server;
            Statistics  statistics;
            for(UInt32 i=0 ; i<_usableServers ;++i)
            {
                server = clusterWindow()->getNetwork()->getConnection(i);
                server->selectChannel();
                server->get(&statistics,sizeof(Statistics));
                sumOut += statistics.bytesOut;
                if(statistics.composeTime < composeTime)
                    composeTime = statistics.composeTime;
                if(statistics.bytesOut > maxOut)
                    maxOut = statistics.bytesOut;
                if(statistics.bytesIn > maxIn)
                    maxIn = statistics.bytesIn;
                if(statistics.bytesIn + statistics.bytesOut > maxIO)
                    maxIO = statistics.bytesIn + statistics.bytesOut;
                missing--;
            }
            printf("compose Time     : %1.5lf\n",composeTime);
            printf("Transfered bytes : %10d\n",sumOut);
            printf("Max out          : %10d\n",maxOut);
            printf("Max in           : %10d\n",maxIn);
            printf("Max io           : %10d\n",maxIO);
        }
    }
    else
    {
        if(clusterId() < _usableServers)
        {
            _statistics.composeTime = -getSystemTime();
            _tile.resize(_tileBufferSize * _tilesX * _tilesY);
            if(getShort())
            {
                UInt16 colorDummy;
                UInt32 depthDummy=_shortDepthMax;
//                UInt32 depthDummy=_intDepthMax;
                startReader(depthDummy,colorDummy,
//                            GL_UNSIGNED_SHORT,
                            GL_UNSIGNED_INT,
                            GL_RGB,
                            GL_UNSIGNED_SHORT_5_6_5,
                            port);
            }
            else
            {
                if(getAlpha())
                {
                    UInt32 colorDummy;
                    UInt32 depthDummy=_intDepthMax;
                    startReader(depthDummy,colorDummy,
                                GL_UNSIGNED_INT,
                                GL_RGBA,
                                GL_UNSIGNED_BYTE,
                                port);
                }
                else
                {
                    RGBValue colorDummy;
                    UInt32   depthDummy=_intDepthMax;
                    startReader(depthDummy,colorDummy,
                                GL_UNSIGNED_INT,
                                GL_RGB,
                                GL_UNSIGNED_BYTE,
                                port);
                }
            }
            _statistics.composeTime += getSystemTime();
            if(getStatistics())
            {
                Connection *client = clusterWindow()->getNetwork()->getConnection(serverCount());
                client->put(&_statistics,sizeof(Statistics));
                client->flush();
            }
        }
/*
        // max depth value !! find a better way
        glClear(GL_DEPTH_BUFFER_BIT);
        glReadPixels(0, 0, 1, 1, 
                     GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
                     &_intDepthMax);
        glReadPixels(0, 0, 1, 1, 
                     GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,
                     &_shortDepthMax);
*/
    }

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);

    // reset state
    if(depth && !glIsEnabled(GL_DEPTH_TEST))
        glEnable(GL_DEPTH_TEST);
    if(!blend && glIsEnabled(GL_BLEND))
        glDisable(GL_BLEND);
}
void MultiDisplayWindow::serverRender(WindowPtr         serverWindow,
                                      UInt32            id,
                                      DrawActionBase *action )
{
    TileCameraDecoratorPtr deco;
    ViewportPtr serverPort;
    ViewportPtr clientPort;
    StereoBufferViewportPtr clientStereoPort;
    UInt32 sv,cv;
    Int32 l,r,t,b;
    Int32 cleft,cright,ctop,cbottom;

    // sync, otherwise viewports will be out of date

    if(!getHServers())
    {
        setHServers(getServers().size());
    }
    if(!getVServers())
    {
        setVServers(1);
    }

    UInt32 row   =id/getHServers();
    UInt32 column=id%getHServers();

    // calculate width and height from local width and height
    UInt32 width  = serverWindow->getWidth() ;
    UInt32 height = serverWindow->getHeight();

    if(getWidth()==0)
    {
        setWidth( width*getHServers() );
    }
    if(getHeight()==0)
    {
        setHeight( height*getVServers() );
    }

    Int32 left   = column * width  - column * getXOverlap();
    Int32 bottom = row    * height - row    * getYOverlap();
    Int32 right  = left   + width  - 1;
    Int32 top    = bottom + height - 1;
    Real64 scaleCWidth  =
        ((width - getXOverlap()) * (getHServers() - 1) + width) /
        (float)getWidth();
    Real64 scaleCHeight =
        ((height - getYOverlap())* (getVServers() - 1) + height)/
        (float)getHeight();

    bool   isVirtualPort = false;

    // duplicate viewports
    for(cv = 0, sv = 0; cv < getPort().size(); ++cv)
    {
        clientPort = getPort()[cv];

#if 0
        isVirtualPort = clientPort->getType().isDerivedFrom(FBOViewport::getClassType());

        if(isVirtualPort)
        {
            // TODO -- seems wrong to render this on all servers, though rendering
            // then transmitting the texture doesn't seem like a good idea either.
            if(serverWindow->getPort().size() <= sv)
            {
                serverPort = ViewportPtr::dcast(clientPort->shallowCopy());
                beginEditCP(serverWindow);
                serverWindow->addPort(serverPort);
                endEditCP(serverWindow);
            }
            else
            {
                serverPort = serverWindow->getPort()[sv];
                if(serverWindow->getPort()[sv]->getType() !=
                        clientPort->getType())
                {
                    // there is a viewport with the wrong type
                    subRefCP(serverWindow->getPort()[sv]);
                    serverPort = ViewportPtr::dcast(clientPort->shallowCopy());
                    beginEditCP(serverWindow);
                    {
                        serverWindow->getPort()[sv] = serverPort;
                    }
                    endEditCP(serverWindow);
                }
            }
            // update changed viewport fields
            updateViewport(serverPort,clientPort);
        }
        else
#endif
        {
            clientStereoPort =
                dynamic_cast<StereoBufferViewportPtr>(clientPort);

            cleft   = (Int32)(clientPort->getPixelLeft()      * scaleCWidth)   ;
            cbottom = (Int32)(clientPort->getPixelBottom()    * scaleCHeight)  ;
            cright  = (Int32)((clientPort->getPixelRight()+1) * scaleCWidth) -1;
            ctop    = (Int32)((clientPort->getPixelTop()+1)   * scaleCHeight)-1;

            if(cright  < left   ||
                    cleft   > right  ||
                    ctop    < bottom ||
                    cbottom > top      )
            {
                // invisible on this server screen
                continue;
            }

            // calculate overlapping viewport
            l = osgMax(cleft  ,left  ) - left;
            b = osgMax(cbottom,bottom) - bottom;
            r = osgMin(cright ,right ) - left;
            t = osgMin(ctop   ,top   ) - bottom;

            if(serverWindow->getPort().size() <= sv)
            {
                serverPort =
                    dynamic_cast<ViewportPtr>(clientPort->shallowCopy());

                deco = TileCameraDecorator::create();

                serverWindow->addPort(serverPort);

                serverPort->setCamera(deco);
            }
            else
            {
                serverPort = serverWindow->getPort()[sv];

                deco = dynamic_cast<TileCameraDecoratorPtr>(
                           serverPort->getCamera());

                if(serverWindow->getPort()[sv]->getType() !=
                        clientPort->getType())
                {
                    // there is a viewport with the wrong type
                    serverPort =
                        dynamic_cast<ViewportPtr>(clientPort->shallowCopy());

                    serverWindow->replacePort(sv,
                                              serverPort);//[sv] = serverPort;
                    serverPort->setCamera(deco);
                }
                else
                {
                    deco = dynamic_cast<TileCameraDecoratorPtr>(
                               serverPort->getCamera());
                }
            }

            // update changed viewport fields
            updateViewport(serverPort,clientPort);

            // set viewport size
            serverPort->setSize(Real32(l),Real32(b),Real32(r),Real32(t));

            // use pixel even if pixel = 1
            if(serverPort->getLeft() == 1.0)
                serverPort->setLeft(1.0001);

            if(serverPort->getRight() == 1.0)
                serverPort->setRight(1.0001);

            if(serverPort->getTop() == 1.0)
                serverPort->setTop(1.0001);

            if(serverPort->getBottom() == 1.0)
                serverPort->setBottom(1.0001);

            // calculate tile parameters
            deco->setFullWidth ( cright-cleft );
            deco->setFullHeight( ctop-cbottom );
            deco->setSize( ( l+left-cleft     ) / (float)( cright-cleft ),
                           ( b+bottom-cbottom ) / (float)( ctop-cbottom ),
                           ( r+left-cleft     ) / (float)( cright-cleft ),
                           ( t+bottom-cbottom ) / (float)( ctop-cbottom ) );
            deco->setDecoratee( clientPort->getCamera() );
        }
        sv++;
    }

    // remove unused ports
    while(serverWindow->getPort().size()>sv)
    {
        serverWindow->subPort(sv);
    }

    Inherited::serverRender(serverWindow,id,action);
}
Ejemplo n.º 3
0
void ParallelComposer::composeViewport(ViewportPtr port)
{
#ifdef OSG_WITH_PARALLEL
    // setup viewport
    GLint 
        pl=port->getPixelLeft(), 
        pr=port->getPixelRight(),
        pb=port->getPixelBottom(), 
        pt=port->getPixelTop();
    if(_wWidth != pr-pl+1 || _wHeight != pt-pb+1)
    {
        _wWidth = pr-pl+1;
        _wHeight= pt-pb+1;
        _createContext = true;
    }
    bool full = port->isFullWindow();
    glViewport(pl, pb, _wWidth, _wHeight);
    glScissor(pl, pb, _wWidth, _wHeight);
    if(! full)
        glEnable(GL_SCISSOR_TEST);

    GLboolean depth = glIsEnabled(GL_DEPTH_TEST);
    GLboolean blend = glIsEnabled(GL_BLEND);

    glDisable(GL_DEPTH_TEST);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, port->getPixelWidth(),
            0, port->getPixelHeight(),-1,1);

    if(_createContext)
    {
        createCtx(port);
        _createContext = false;
    }

    if(getAlpha())
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    if(isClient())
    {
        UInt32 id = beginFrame();
        renderRead();
        endFrame(id);
        drawFrame();
    }
    else
    {
        if(clusterId() < _usableServers)
        {
            UInt32 id = beginFrame();
            renderRead();
            endFrame(id);
            //drawFrame();
        }
    }
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);

    // reset state
    if(depth && !glIsEnabled(GL_DEPTH_TEST))
        glEnable(GL_DEPTH_TEST);
    if(!blend && glIsEnabled(GL_BLEND))
        glDisable(GL_BLEND);
#endif
}
Ejemplo n.º 4
0
void PipelineComposer::composeViewport(ViewportPtr port)
{
    UInt32 s;

    // setup viewport
    GLint
    pl=port->getPixelLeft(),
    pr=port->getPixelRight(),
    pb=port->getPixelBottom(),
    pt=port->getPixelTop();
    GLint pw=pr-pl+1,ph=pt-pb+1;
    bool full = port->isFullWindow();
    glViewport(pl, pb, pw, ph);
    glScissor(pl, pb, pw, ph);
    if(! full)
        glEnable(GL_SCISSOR_TEST);

    GLboolean depth = glIsEnabled(GL_DEPTH_TEST);
    GLboolean blend = glIsEnabled(GL_BLEND);

//    glDisable(GL_DEPTH_TEST);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, port->getPixelWidth(),
            0, port->getPixelHeight(),-1,1);
    if(getAlpha())
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    // only one buffer for the client
    if(isClient())
        _composeTilePtr = _readTilePtr;

    _readTilesX = (port->getPixelWidth()  - 1) / getTileSize() + 1;
    _readTilesY = (port->getPixelHeight() - 1) / getTileSize() + 1;

    _tileBufferSize = getTileSize()*getTileSize()*8+sizeof(TileBuffer);
    _workingTile.resize(_tileBufferSize);

    // resize
    _readTilePtr->resize(_tileBufferSize * _readTilesX * _readTilesY);

    if(isClient())
    {
        while(_groupInfo.size() < serverCount())
        {
            _groupInfoPool.push_back(GroupInfo());
            _groupInfo.push_back(&(*_groupInfoPool.rbegin()));
        }
        _groupInfo.resize(serverCount());
    }

    _statistics.bytesIn  = 0;
    _statistics.bytesOut = 0;
    _statistics.occluded = 0;
    _statistics.noDepth  = 0;
    _statistics.noGeo    = 0;
    _statistics.clipped  = 0;

    if(!getPipelined())
    {
        _composeTilesX  = _readTilesX;
        _composeTilesY  = _readTilesY;
    }
    if(getShort())
    {
        UInt16 colorDummy;
//        UInt16 depthDummy;
        UInt32 depthDummy;
//        _depthType   = GL_UNSIGNED_SHORT;
        _depthType   = GL_UNSIGNED_INT;
        _colorFormat = GL_RGB;
        _colorType   = GL_UNSIGNED_SHORT_5_6_5;

        readBuffer(depthDummy,colorDummy,port);
        if(!getPipelined() || isClient())
            composeBuffer(depthDummy,colorDummy);
    }
    else
    {
        if(getAlpha())
        {
            UInt32 colorDummy;
            UInt32 depthDummy;
            _depthType   = GL_UNSIGNED_INT;
            _colorFormat = GL_RGBA;
            _colorType   = GL_UNSIGNED_BYTE;
            readBuffer(depthDummy,colorDummy,port);
            if(!getPipelined() || isClient())
                composeBuffer(depthDummy,colorDummy);
        }
        else
        {
            RGBValue colorDummy;
            UInt32   depthDummy;
            _depthType   = GL_UNSIGNED_INT;
            _colorFormat = GL_RGB;
            _colorType   = GL_UNSIGNED_BYTE;
            readBuffer(depthDummy,colorDummy,port);
            if(!getPipelined() || isClient())
                composeBuffer(depthDummy,colorDummy);
        }
    }

    if(getStatistics())
    {
        if(isClient())
        {
            double      pixelReadTime = 0;
            double      sortTime      = 0;
            UInt32      maxIn      = _statistics.bytesIn;
            UInt32      maxOut     = _statistics.bytesOut;
            UInt32      maxIO      = maxIn + maxOut;
            UInt32      sumOut     = _statistics.bytesOut;
            UInt32      clipped    = 0;
            Connection::Channel channel;
            GroupConnection *server;
            Statistics  statistics;
            server = clusterWindow()->getNetwork()->getMainGroupConnection();
            for(UInt32 i=0 ; i<serverCount() ; ++i)
            {
                channel = server->selectChannel();
                server->subSelection(channel);
                server->get(&statistics,sizeof(Statistics));
                sumOut += statistics.bytesOut;
                if(statistics.pixelReadTime > pixelReadTime) {
                    pixelReadTime = statistics.pixelReadTime;
                    sortTime = statistics.sortTime;
                }
                if(statistics.bytesOut > maxOut)
                    maxOut = statistics.bytesOut;
                if(statistics.bytesIn > maxIn)
                    maxIn = statistics.bytesIn;
                if(statistics.bytesIn + statistics.bytesOut > maxIO)
                    maxIO = statistics.bytesIn + statistics.bytesOut;
                clipped += statistics.clipped;
            }
            server->resetSelection();
            printf("pixel read time  : %1.5lf\n",pixelReadTime);
            printf("sort Time        : %1.5lf\n",sortTime);
            printf("compose Time     : %1.5lf\n",_statistics.composeTime);
            printf("Transfered bytes : %10d\n",sumOut);
            printf("Max out          : %10d\n",maxOut);
            printf("Max in           : %10d\n",maxIn);
            printf("Max io           : %10d\n",maxIO);
            printf("occluded         : %10d\n",_statistics.occluded);
            printf("Layerd           : %10d\n",_statistics.noDepth);
            printf("Empty            : %10d\n",_statistics.noGeo-clipped);
            printf("Clipped          : %10d\n",clipped);
            printf("DepthAndColor    : %10d\n",serverCount()*_composeTilesX*_composeTilesY-
                   _statistics.occluded-
                   _statistics.noDepth-
                   _statistics.noGeo);
        }
        else
        {
            Connection *client = clusterWindow()->getNetwork()->getMainConnection();
            client->put(&_statistics,sizeof(Statistics));
            client->flush();
        }
    }

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);

    // reset state
    if(depth && !glIsEnabled(GL_DEPTH_TEST))
        glEnable(GL_DEPTH_TEST);
    if(!blend && glIsEnabled(GL_BLEND))
        glDisable(GL_BLEND);
}