osg::ClusterViewBuffer Class Reference
[Cluster]

Viewbuffer functions. More...

#include <OSGClusterViewBuffer.h>

List of all members.

Classes

struct  RGBValue
 RGB Color value. More...

Public Types

enum  {
  RED = 1, GREEN = 2, BLUE = 4, ALPHA = 8,
  STENCIL = 16, DEPTH = 32, RGB = RED|GREEN|BLUE, RGBA = RED|GREEN|BLUE|ALPHA
}
 

Buffer component.

More...
typedef std::vector< Int8BufferT
 stl vector used as char buffer

Public Member Functions

Constructors / Destructor



 ClusterViewBuffer (void)
virtual ~ClusterViewBuffer (void)
send/recv



void recv (GroupConnection &connection)
void send (PointConnection &connection, UInt32 component, UInt32 x1, UInt32 y1, UInt32 x2, UInt32 y2, UInt32 toX, UInt32 toY)
void send (PointConnection &connection, UInt32 component, UInt32 toX, UInt32 toY)
set parameters



void setImgTransType (const char *mime=NULL)
void setSubtileSize (UInt32 size)
void setRGBADataType (UInt32 type, UInt32 size)
void setRGBDataType (UInt32 type, UInt32 size)
void setDepthDataType (UInt32 type, UInt32 size)
get



UInt32 getBufferWidth ()
UInt32 getBufferHeight ()

Public Attributes

enum osg::ClusterViewBuffer:: { ... }  Component
 Buffer component.

Protected Attributes

Fields



ImageFileType_imgTransType
UInt32 _subTileSize
UInt32 _rgbDataType
UInt32 _rgbDataSize
UInt32 _rgbaDataType
UInt32 _rgbaDataSize
UInt32 _depthDataType
UInt32 _depthDataSize

Private Member Functions

 ClusterViewBuffer (const ClusterViewBuffer &source)
void operator= (const ClusterViewBuffer &source)

Detailed Description

This class provides an interface to an OpenGL view buffer. The Buffer contents can be transfered over a Connection. All Image types can be used for image compression. The ClusterViewBuffer can access RGBA, Stencil and Z-Buffer values.

The whole imagebuffer is divided into subtiles. Each subtile is read from the buffer, compressed and send over the nertwork. In most cases, the buffer read and the network send of the previous tile is done in parallel.

todo: currently ClusterViewBuffer works on the activated window. Is this a good idea. Better WindowPtr as parameter and then call activate before send,recv? MR

Definition at line 56 of file OSGClusterViewBuffer.h.


Member Typedef Documentation

typedef std::vector<Int8> osg::ClusterViewBuffer::BufferT

Definition at line 73 of file OSGClusterViewBuffer.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
RED 
GREEN 
BLUE 
ALPHA 
STENCIL 
DEPTH 
RGB 
RGBA 

Definition at line 62 of file OSGClusterViewBuffer.h.

00062          {
00063         RED           =1,
00064         GREEN         =2,
00065         BLUE          =4,
00066         ALPHA         =8,
00067         STENCIL       =16,
00068         DEPTH         =32,
00069         RGB           =RED|GREEN|BLUE,
00070         RGBA          =RED|GREEN|BLUE|ALPHA
00071     } Component;


Constructor & Destructor Documentation

ClusterViewBuffer::ClusterViewBuffer ( void   ) 

Initialize a ClusterViewBuffer. By default, no image compression is set and the subtile size is set to 32. The viewbuffer contents is send in packages. If the package size is not too large, then network transmission of the last and graphics card read of the current package is done in parallel.

Definition at line 85 of file OSGClusterViewBuffer.cpp.

00085                                          :
00086     _imgTransType(NULL),
00087     _subTileSize(32),
00088     _rgbDataType(GL_UNSIGNED_BYTE),
00089     _rgbDataSize(3),
00090     _rgbaDataType(GL_UNSIGNED_BYTE),
00091     _rgbaDataSize(4),
00092     _depthDataType(GL_UNSIGNED_INT),
00093     _depthDataSize(4)
00094 {
00095 }

ClusterViewBuffer::~ClusterViewBuffer ( void   )  [virtual]

Destructor

Definition at line 99 of file OSGClusterViewBuffer.cpp.

00100 {
00101 }

osg::ClusterViewBuffer::ClusterViewBuffer ( const ClusterViewBuffer source  )  [private]

Member Function Documentation

void ClusterViewBuffer::recv ( GroupConnection connection  ) 

Receive image data from all channels of a conneciton. The receive is finished, when the last channel signals a transmission end.

Definition at line 109 of file OSGClusterViewBuffer.cpp.

References DEPTH, osg::BinaryDataHandler::get(), getBufferHeight(), getBufferWidth(), osg::GroupConnection::getChannelCount(), osg::BinaryDataHandler::getValue(), osg::GroupConnection::resetSelection(), osg::ImageFileType::restore(), RGBA, osg::Connection::selectChannel(), SFATAL, STENCIL, osg::subRefP(), and osg::GroupConnection::subSelection().

Referenced by osg::SortFirstWindow::clientSwap().

00110 {
00111     UInt32              tx, ty, tw, th;
00112     UInt32              missing;
00113     BufferT             data;
00114     BufferT             imageData;
00115     UInt32              dataSize;
00116     UInt32              component;
00117     GLenum              glformat;
00118     int                 componentCnt;
00119     Connection::Channel channel;
00120 
00121     missing = connection.getChannelCount();
00122 
00123     glPushMatrix();
00124     glLoadIdentity();
00125     glMatrixMode(GL_PROJECTION);
00126     glPushMatrix();
00127     glLoadIdentity();
00128     gluOrtho2D(0, getBufferWidth(), 0, getBufferHeight());
00129     glDisable(GL_DEPTH_TEST);
00130     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00131 
00132     // we expect tiles form all connected servers
00133     while(missing)
00134     {
00135         channel = connection.selectChannel();
00136         connection.getValue(component);
00137         if(!component)
00138         {
00139             connection.subSelection(channel);
00140             missing--;
00141             continue;
00142         }
00143 
00144         // get dimension
00145         connection.getValue(tx);
00146         connection.getValue(ty);
00147         connection.getValue(tw);
00148         connection.getValue(th);
00149         glRasterPos2i(tx, ty);
00150 
00151         // =========== recv stencil =====================================
00152         if(component & STENCIL)
00153         {
00154             data.resize(tw * th);
00155             connection.get(&data[0], tw * th);
00156             glDrawPixels(tw, th, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &data[0]);
00157             glEnable(GL_STENCIL_TEST);
00158         }
00159 
00160         // =========== recv depth =======================================
00161         if(component & DEPTH)
00162         {
00163             glEnable(GL_DEPTH_TEST);
00164             glEnable(GL_STENCIL_TEST);
00165             glStencilFunc(GL_ALWAYS, 1, 1);
00166             glStencilOp(GL_KEEP, GL_ZERO, GL_REPLACE);
00167             data.resize(tw * th * sizeof(float));
00168             connection.get(&data[0], tw * th * sizeof(float));
00169             glDrawPixels(tw, th, GL_DEPTH_COMPONENT, GL_FLOAT, &data[0]);
00170             glDisable(GL_DEPTH_TEST);
00171         }
00172 
00173         // =========== recv RGBA ========================================
00174         if(component & RGBA)
00175         {
00176             if(component & (DEPTH | STENCIL))
00177             {
00178                 glStencilFunc(GL_EQUAL, 1, 1);
00179             }
00180 
00181             switch(component & RGBA)
00182             {
00183             case RGB:
00184                 glformat = GL_RGB;
00185                 componentCnt = 3;
00186                 break;
00187             case RGBA:
00188                 glformat = GL_RGBA;
00189                 componentCnt = 4;
00190                 break;
00191             default:
00192                 SFATAL << "Component combination not supported" << std::endl;
00193                 return;
00194             }
00195 
00196             connection.getValue(dataSize);
00197 
00198             // compression ?
00199             if(dataSize > 0)
00200             {
00201 #if 0
00202                 pImage = new Image;
00203 
00204                 data.resize(dataSize);
00205                 connection.get(&data[0], dataSize);
00206                 imageData.resize(tw * th * componentCnt);
00207                 ImageFileType::restore(*pImage, (UChar8 *) &data[0], dataSize);
00208                 glDrawPixels(tw, th, glformat, GL_UNSIGNED_BYTE,
00209                                              pImage->getData());
00210 
00211                 subRefP(pImage);
00212 #endif
00213             }
00214             else
00215             {
00216                 data.resize(tw * th * componentCnt);
00217                 connection.get(&data[0], tw * th * componentCnt);
00218                 glDrawPixels(tw, th, glformat, GL_UNSIGNED_BYTE, &data[0]);
00219             }
00220         }
00221 
00222         if(component & (DEPTH | STENCIL))
00223         {
00224             glDisable(GL_STENCIL_TEST);
00225         }
00226     }
00227     connection.resetSelection();
00228     glPopMatrix();
00229     glMatrixMode(GL_MODELVIEW);
00230     glPopMatrix();
00231     glEnable(GL_DEPTH_TEST);
00232 }

void ClusterViewBuffer::send ( PointConnection connection,
UInt32  component,
UInt32  x1,
UInt32  y1,
UInt32  x2,
UInt32  y2,
UInt32  toX,
UInt32  toY 
)

Send parts of a view buffer to a Connection

connection defines the connection to use, component which color channels (RGB/RGBA) should be transferred, x1, y1, x2, y2 (inclusive) define the source area and toX and toY the lower left corner of the destination area.

Definition at line 241 of file OSGClusterViewBuffer.cpp.

References _imgTransType, _subTileSize, DEPTH, osg::BinaryDataHandler::flush(), osg::ImageFileType::maxBufferSize(), osg::osgMin(), osg::BinaryDataHandler::put(), osg::BinaryDataHandler::putValue(), RGBA, SFATAL, STENCIL, osg::ImageFileType::store(), and osg::subRefP().

Referenced by send(), and osg::SortFirstWindow::serverRender().

00245 {
00246     UInt32              tx, ty, tw, th;
00247 //    Image               *pImage;
00248     BufferT             data;
00249     BufferT             imageData;
00250     UInt32              dataSize;
00251     GLenum              glformat;
00252 //    Image::PixelFormat  imgformat;
00253     int                 componentCnt;
00254     int                 imgtranssize = 0;
00255 
00256     switch(component & RGBA)
00257     {
00258     case RGB:  glformat = GL_RGB;
00259 //               imgformat = Image::OSG_RGB_PF;
00260                componentCnt = 3;
00261                break;
00262     case RGBA: glformat = GL_RGBA;
00263 //               imgformat = Image::OSG_RGBA_PF;
00264                componentCnt = 4;
00265                break;
00266     default:   SFATAL << "Component combination not supported" << std::endl;
00267                return;
00268     }
00269 
00270     // resize image buffer
00271     imageData.resize(_subTileSize * _subTileSize * componentCnt);
00272 
00273     glPixelStorei(GL_PACK_ALIGNMENT, 1);
00274 
00275     for(ty = y1; ty <= y2; ty += _subTileSize)
00276     {
00277         for(tx = x1; tx <= x2; tx += _subTileSize)
00278         {
00279             tw = osgMin(_subTileSize, x2 + 1 - tx);
00280             th = osgMin(_subTileSize, y2 + 1 - ty);
00281 
00282             connection.putValue(component);
00283             connection.putValue(tx + toX);
00284             connection.putValue(ty + toY);
00285             connection.putValue(tw);
00286             connection.putValue(th);
00287 
00288             // =========== send STENCIL =======================================
00289             if(component & STENCIL)
00290             {
00291                 // read stencil buffer
00292                 data.resize(tw * th);
00293                 glReadPixels(tx, ty, tw, th, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
00294                                              &data[0]);
00295                 connection.put(&data[0], tw * th);
00296             }
00297 
00298             // =========== send DEPTH =======================================
00299             if(component & DEPTH)
00300             {
00301                 // read stencil buffer
00302                 data.resize(tw * th * sizeof(float));
00303                 glReadPixels(tx, ty, tw, th, GL_DEPTH_COMPONENT, GL_FLOAT,
00304                                              &data[0]);
00305                 connection.put(&data[0], tw * th * sizeof(float));
00306             }
00307 
00308             // =========== send RGBA ========================================
00309             if(component & RGBA)
00310             {
00311                 // use compression ?
00312                 if(_imgTransType)
00313                 {
00314 #if 0
00315                     // set image size
00316                     pImage = new Image;
00317 
00318                     pImage->set(imgformat, tw, th, 1, 1, 1, 0.0,
00319                                 (UChar8 *) &imageData[0]);
00320 
00321                     // read buffer data into image
00322                     glReadPixels(tx, ty, tw, th, glformat, GL_UNSIGNED_BYTE,
00323                                  pImage->getData());
00324 
00325                     // bug maxsize is not big enugh
00326                     data.resize(_imgTransType->maxBufferSize(*pImage) + 1000);
00327                     dataSize = _imgTransType->store(*pImage, (UChar8 *) &data[0],
00328                                                                         data.size());
00329                     connection.putValue(dataSize);
00330                     connection.put(&data[0], dataSize);
00331                     imgtranssize += dataSize;
00332 
00333                     subRefP(pImage);
00334 #endif
00335                 }
00336                 else
00337                 {
00338                     data.resize(tw * th * componentCnt);
00339 
00340                     // read buffer data
00341                     glReadPixels(tx, ty, tw, th, glformat, GL_UNSIGNED_BYTE,
00342                                                      &data[0]);
00343                     dataSize = 0;
00344                     connection.putValue(dataSize);
00345                     connection.put(&data[0], tw * th * componentCnt);
00346                     imgtranssize += tw * th * componentCnt;
00347                 }
00348             }
00349 
00350             connection.flush();
00351         }
00352     }
00353 
00354     component = 0;
00355     connection.putValue(component);
00356     connection.flush();
00357 }

void ClusterViewBuffer::send ( PointConnection connection,
UInt32  component,
UInt32  toX,
UInt32  toY 
)

Send parts of a view buffer to a Connection

Definition at line 361 of file OSGClusterViewBuffer.cpp.

References getBufferHeight(), getBufferWidth(), and send().

00363 {
00364     send(connection, component, 0, 0, getBufferWidth(), getBufferHeight(), toX,
00365          toY);
00366 }

void ClusterViewBuffer::setImgTransType ( const char *  mimeType = NULL  ) 

Set compression type. By default, no compression is used for image transmission. The given mime type identifies an ImageType e.g. "JPEG". This image type is used for compression.

Definition at line 375 of file OSGClusterViewBuffer.cpp.

References _imgTransType, osg::ImageFileHandler::getFileType(), and osg::ImageFileHandler::the().

Referenced by osg::SortFirstWindow::serverRender().

00376 {
00377     if(mimeType == NULL)
00378     {
00379         _imgTransType = NULL;
00380     }
00381     else
00382     {
00383         _imgTransType = ImageFileHandler::the().getFileType(mimeType);
00384     }
00385 }

void ClusterViewBuffer::setSubtileSize ( UInt32  size  ) 

Set subtile size. The whole buffer is transfered as small subtiles. Increasing or decreasing the subtile size will result in changes to the performance. The best size depends on network package size and the ration between network performance and buffer read/write performance.

Definition at line 392 of file OSGClusterViewBuffer.cpp.

References _subTileSize.

Referenced by osg::SortFirstWindow::serverRender().

00393 {
00394     _subTileSize = size;
00395 }

void ClusterViewBuffer::setRGBADataType ( UInt32  type,
UInt32  size 
)

Set opengl datatype for rgb tramsmission

Definition at line 400 of file OSGClusterViewBuffer.cpp.

References _rgbaDataSize, and _rgbaDataType.

00401 {
00402     _rgbaDataType = type;
00403     _rgbaDataSize = size;
00404 }

void ClusterViewBuffer::setRGBDataType ( UInt32  type,
UInt32  size 
)

Set opengl datatype for rgba tramsmission

Definition at line 408 of file OSGClusterViewBuffer.cpp.

References _rgbDataSize, and _rgbDataType.

00409 {
00410     _rgbDataType = type;
00411     _rgbDataSize = size;
00412 }

void ClusterViewBuffer::setDepthDataType ( UInt32  type,
UInt32  size 
)

Set opengl datatype for Z-Buffer tramsmission

Definition at line 416 of file OSGClusterViewBuffer.cpp.

References _depthDataSize, and _depthDataType.

00417 {
00418     _depthDataType = type;
00419     _depthDataSize = size;
00420 }

UInt32 ClusterViewBuffer::getBufferWidth ( void   ) 

Get buffer width

Definition at line 427 of file OSGClusterViewBuffer.cpp.

Referenced by recv(), and send().

00428 {
00429     GLint   view[4];
00430     glGetIntegerv(GL_VIEWPORT, view);
00431     return view[2];
00432 }

UInt32 ClusterViewBuffer::getBufferHeight ( void   ) 

Get buffer width

Definition at line 436 of file OSGClusterViewBuffer.cpp.

Referenced by recv(), and send().

00437 {
00438     GLint   view[4];
00439     glGetIntegerv(GL_VIEWPORT, view);
00440     return view[3];
00441 }

void osg::ClusterViewBuffer::operator= ( const ClusterViewBuffer source  )  [private]

Member Data Documentation

Definition at line 134 of file OSGClusterViewBuffer.h.

Referenced by send(), and setImgTransType().

Definition at line 135 of file OSGClusterViewBuffer.h.

Referenced by send(), and setSubtileSize().

Definition at line 136 of file OSGClusterViewBuffer.h.

Referenced by setRGBDataType().

Definition at line 137 of file OSGClusterViewBuffer.h.

Referenced by setRGBDataType().

Definition at line 138 of file OSGClusterViewBuffer.h.

Referenced by setRGBADataType().

Definition at line 139 of file OSGClusterViewBuffer.h.

Referenced by setRGBADataType().

Definition at line 140 of file OSGClusterViewBuffer.h.

Referenced by setDepthDataType().

Definition at line 141 of file OSGClusterViewBuffer.h.

Referenced by setDepthDataType().


The documentation for this class was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1