Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGSortFirstWindow.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <OSGConfig.h>
00046 #include <OSGGL.h>
00047 #include <OSGNodePtr.h>
00048 #include <OSGTileCameraDecorator.h>
00049 #include <OSGViewport.h>
00050 #include <OSGGeometry.h>
00051 #include <OSGStereoBufferViewport.h>
00052 #include <OSGRenderAction.h>
00053 #include "OSGSortFirstWindow.h"
00054 #include "OSGClusterViewBuffer.h"
00055 #include "OSGConnection.h"
00056 #include "OSGRenderNode.h"
00057 #include "OSGTileGeometryLoad.h"
00058 
00059 OSG_USING_NAMESPACE
00060 
00061 ClusterViewBuffer SortFirstWindow::_bufferHandler;
00062 
00063 // #define USE_VPORT_SLICES
00064 
00070 /*----------------------- constructors & destructors ----------------------*/
00071 
00073 
00074 SortFirstWindow::SortFirstWindow(void) :
00075     Inherited(),
00076     _tileLoadBalancer(NULL),
00077     _renderNode(NULL)
00078 {
00079 }
00080 
00082 
00083 SortFirstWindow::SortFirstWindow(const SortFirstWindow &source) :
00084     Inherited(source),
00085     _tileLoadBalancer(NULL),
00086     _renderNode(NULL)
00087 {
00088 }
00089 
00091 
00092 SortFirstWindow::~SortFirstWindow(void)
00093 {
00094     if(_tileLoadBalancer)
00095         delete _tileLoadBalancer;
00096     if(_renderNode)
00097         delete _renderNode;
00098 }
00099 
00100 /*----------------------------- class specific ----------------------------*/
00101 
00103 
00104 void SortFirstWindow::initMethod (void)
00105 {
00106 }
00107 
00109 
00110 void SortFirstWindow::changed(BitVector whichField, UInt32 origin)
00111 {
00112     Inherited::changed(whichField, origin);
00113 }
00114 
00116 
00117 void SortFirstWindow::dump(      UInt32    , 
00118                            const BitVector ) const
00119 {
00120     SLOG << "Dump SortFirstWindow NI" << std::endl;
00121 }
00122 
00123 /*----------------------------- server methods ----------------------------*/
00124 
00128 void SortFirstWindow::serverInit( WindowPtr serverWindow,
00129                                   UInt32 id)
00130 {
00131 #if USE_VPORT_SLICES
00132 
00133 #else
00134     UInt32 sync;
00135     RenderNode renderNode;
00136     Connection *connection=getNetwork()->getMainConnection();
00137 
00138     // create cluster node information
00139     // get performance
00140     renderNode.determinePerformance(serverWindow);
00141     renderNode.dump();
00142     // transfer to client for load balancing
00143     connection->putValue(id);
00144     renderNode.copyToBin(*connection);
00145     connection->flush();
00146     connection->selectChannel();
00147     connection->getValue(sync);
00148 #endif
00149 }
00150 
00155 void SortFirstWindow::serverRender( WindowPtr serverWindow,
00156                                     UInt32 id,
00157                                     RenderActionBase *action )
00158 {
00159     TileCameraDecoratorPtr deco;
00160     ViewportPtr serverPort;
00161     ViewportPtr clientPort;
00162     UInt32 sv,cv,regionStart;
00163     UInt32 vpWidth;
00164     UInt32 vpHeight;
00165 
00166     // duplicate viewports
00167     for(cv=0,sv=0;cv<getPort().size();cv++)
00168     {
00169         clientPort = getPort()[cv];
00170         if(serverWindow->getPort().size() <= sv)
00171         {
00172             // create new port
00173             serverPort = StereoBufferViewport::create();
00174             deco=TileCameraDecorator::create();
00175             beginEditCP(serverWindow);
00176             serverWindow->addPort(serverPort);
00177             serverPort->setCamera(deco);
00178             endEditCP(serverWindow);
00179         }
00180         else
00181         {
00182             serverPort = serverWindow->getPort()[sv];
00183             deco=TileCameraDecoratorPtr::dcast(serverPort->getCamera());
00184         }
00185 
00186         // duplicate values
00187         beginEditCP(serverPort);
00188         regionStart=cv * getServers().size() * 4 + id * 4;
00189         serverPort->setSize( 
00190             Real32(getRegion()[regionStart+0] + clientPort->getPixelLeft()),
00191             Real32(getRegion()[regionStart+1] + clientPort->getPixelBottom()),
00192             Real32(getRegion()[regionStart+2] + clientPort->getPixelLeft()),
00193             Real32(getRegion()[regionStart+3] + clientPort->getPixelBottom()));
00194 
00195         serverPort->setRoot      ( clientPort->getRoot()       );
00196         serverPort->setBackground( clientPort->getBackground() );
00197         serverPort->getMFForegrounds()->setValues( clientPort->getForegrounds() );
00198         serverPort->setTravMask  ( clientPort->getTravMask()   );
00199         endEditCP(serverPort);
00200 
00201         // calculate tile parameters
00202         vpWidth =clientPort->getPixelWidth();
00203         vpHeight=clientPort->getPixelHeight();
00204         beginEditCP(deco);
00205         deco->setFullWidth ( vpWidth );
00206         deco->setFullHeight( vpHeight );
00207         deco->setSize( getRegion()[ regionStart+0 ]/(float)vpWidth,
00208                        getRegion()[ regionStart+1 ]/(float)vpHeight,
00209                        getRegion()[ regionStart+2 ]/(float)vpWidth,
00210                        getRegion()[ regionStart+3 ]/(float)vpHeight );
00211         deco->setDecoratee( clientPort->getCamera() );
00212         endEditCP(deco);
00213         sv++;
00214     }
00215     // remove unused ports
00216     while(serverWindow->getPort().size()>sv)
00217     {
00218         serverWindow->subPort(sv);
00219     }
00220     // compression type
00221     if(getCompose())
00222     {
00223         if(getCompression().empty())
00224         {
00225             _bufferHandler.setImgTransType(NULL);
00226         }
00227         else
00228         {
00229             _bufferHandler.setImgTransType(getCompression().c_str());
00230         }
00231         if(getSubtileSize())
00232         {
00233             _bufferHandler.setSubtileSize(getSubtileSize());
00234         }
00235     }
00236 #if 1
00237     glDisable(GL_SCISSOR_TEST);
00238     glClearColor(0,0,0,0);
00239     glClear(GL_COLOR_BUFFER_BIT);
00240 #endif
00241 
00242     // render the viewports
00243     serverWindow->activate();
00244     serverWindow->frameInit();
00245     action->setWindow( serverWindow.getCPtr() );
00246     for(sv=0;sv<serverWindow->getPort().size();++sv)
00247     {
00248         ViewportPtr vp=serverWindow->getPort()[sv];
00249         vp->render( action );
00250         // send resulting image
00251         if(getCompose())
00252         {
00253             // send image
00254             _bufferHandler.send(
00255                 *getNetwork()->getMainPointConnection(),
00256                 ClusterViewBuffer::RGB,
00257                 vp->getPixelLeft(),
00258                 vp->getPixelBottom(),
00259                 vp->getPixelRight(),
00260                 vp->getPixelTop(),
00261                 0,0);
00262         }
00263     }
00264 }
00265 
00268 void SortFirstWindow::serverSwap( WindowPtr window,
00269                                   UInt32 )
00270 {
00271     if(!getCompose())
00272     {
00273         Connection *connection=getNetwork()->getMainConnection();
00274         connection->signal();
00275         connection->wait();
00276     }
00277     window->swap();
00278 }
00279 
00280 /*----------------------------- client methods ----------------------------*/
00281 
00285 void SortFirstWindow::clientInit( void )
00286 {
00287 #if USE_VPORT_SLICES
00288 
00289 #else
00290     UInt32               id;
00291     RenderNode           renderNode;
00292     GroupConnection     *connection = getNetwork()->getMainGroupConnection();
00293     Connection::Channel  channel;
00294 
00295     _tileLoadBalancer=new TileLoadBalancer(getUseFaceDistribution());
00296     // read all node infos
00297     for(UInt32 i=0;i<connection->getChannelCount();++i)
00298     {
00299         printf("%d\n",i);
00300         channel = connection->selectChannel();
00301         connection->subSelection(channel);
00302         connection->getValue(id);
00303         renderNode.copyFromBin(*connection);
00304         renderNode.dump();
00305         _tileLoadBalancer->addRenderNode(renderNode,id);    
00306     }
00307     connection->resetSelection();
00308     printf("end\n");
00309     // sync servers
00310     connection->putValue(id);
00311     connection->flush();
00312 #endif
00313 }
00314 
00318 void SortFirstWindow::clientPreSync( void )
00319 {
00320     SortFirstWindowPtr ptr=SortFirstWindowPtr(this);
00321     if(getCompose())
00322     {
00323         // get window size from client window
00324         if(getClientWindow() != NullFC)
00325         {
00326             if(getWidth()  != getClientWindow()->getWidth() ||
00327                getHeight() != getClientWindow()->getHeight())
00328             {
00329                 beginEditCP(ptr,
00330                             Window::WidthFieldMask|
00331                             Window::HeightFieldMask);
00332                 {
00333                     setSize(getClientWindow()->getWidth(),
00334                             getClientWindow()->getHeight());
00335                 }
00336                 endEditCP(ptr,
00337                           Window::WidthFieldMask|
00338                           Window::HeightFieldMask);
00339             }
00340         }
00341     }
00342 #if 0
00343     else
00344     {
00345         beginEditCP(ptr,
00346                     Window::WidthFieldMask|
00347                     Window::HeightFieldMask);
00348         {
00349             setSize(1280,
00350                     1024);
00351         }
00352         endEditCP(ptr,
00353                   Window::WidthFieldMask|
00354                   Window::HeightFieldMask);
00355     }
00356 #endif
00357     UInt32 i;
00358     UInt32 cv;
00359     TileLoadBalancer::ResultT region;
00360     
00361     beginEditCP(ptr,SortFirstWindow::RegionFieldMask);
00362     getRegion().clear();
00363 #if USE_VPORT_SLICES
00364     for(cv=0;cv<getPort().size();cv++)
00365     {
00366         int s=getServers().size();
00367         for(i=0;i<s;i++)
00368         {
00369             getRegion().push_back(i/float(s)*getWidth());
00370             getRegion().push_back(0);
00371             getRegion().push_back((i+1)/float(s)*getWidth());
00372             getRegion().push_back(1*getHeight());
00373         }
00374     }
00375 #else
00376     for(cv=0;cv<getPort().size();cv++)
00377     {
00378         _tileLoadBalancer->update( getPort()[cv]->getRoot() );
00379         _tileLoadBalancer->balance(getPort()[cv],
00380                               false,
00381                               region);
00382         for(i=0;i<getServers().size();i++)
00383         {
00384             getRegion().push_back(region[i].x1);
00385             getRegion().push_back(region[i].y1);
00386             getRegion().push_back(region[i].x2);
00387             getRegion().push_back(region[i].y2);
00388         }
00389     }
00390 #endif
00391 
00392     endEditCP(ptr,SortFirstWindow::RegionFieldMask);
00393 }
00394 
00400 void SortFirstWindow::clientRender( RenderActionBase *  /* action */ )
00401 {
00402 //    Inherited::clientRender(action);
00403 }
00404 
00408 void SortFirstWindow::clientSwap( void )
00409 {
00410     UInt32 cv;
00411     GroupConnection *connection=getNetwork()->getMainGroupConnection();
00412     if(getCompose())
00413     {
00414         if(getClientWindow()!=NullFC)
00415         {
00416             glDisable(GL_SCISSOR_TEST);
00417             glViewport(0,0,
00418                        getClientWindow()->getWidth(),
00419                        getClientWindow()->getHeight());
00420             // receive all viewports
00421             for(cv=0;cv<getPort().size();++cv)
00422             {
00423                 _bufferHandler.recv(*connection);
00424             }
00425             Inherited::clientSwap();
00426         }
00427     }
00428     else
00429     {
00430         connection->wait();
00431         connection->signal();
00432     }
00433 }
00434 
00435 
00436 /*-------------------------------------------------------------------------*/
00437 /*                              cvs id's                                   */
00438 
00439 #ifdef __sgi
00440 #pragma set woff 1174
00441 #endif
00442 
00443 #ifdef OSG_LINUX_ICC
00444 #pragma warning( disable : 177 )
00445 #endif
00446 
00447 namespace
00448 {
00449     static char cvsid_cpp[] = "@(#)$Id:$";
00450     static char cvsid_hpp[] = OSGSORTFIRSTWINDOW_HEADER_CVSID;
00451     static char cvsid_inl[] = OSGSORTFIRSTWINDOW_INLINE_CVSID;
00452 }

Generated on Thu Aug 25 04:10:30 2005 for OpenSG by  doxygen 1.4.3