#include <OSGClusterViewBuffer.h>
Public Types | |
| enum | Component { 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< Int8 > | BufferT |
| 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 Char8 *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 () |
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) |
Classes | |
| struct | RGBValue |
| RGB Color value. More... | |
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.
| typedef std::vector<Int8> OSG::ClusterViewBuffer::BufferT |
Definition at line 76 of file OSGClusterViewBuffer.h.
| ClusterViewBuffer::ClusterViewBuffer | ( | void | ) |
Definition at line 87 of file OSGClusterViewBuffer.cpp.
00087 : 00088 _imgTransType (NULL ), 00089 _subTileSize (32 ), 00090 _rgbDataType (GL_UNSIGNED_BYTE), 00091 _rgbDataSize (3 ), 00092 _rgbaDataType (GL_UNSIGNED_BYTE), 00093 _rgbaDataSize (4 ), 00094 _depthDataType(GL_UNSIGNED_INT ), 00095 _depthDataSize(4 ) 00096 { 00097 }
| ClusterViewBuffer::~ClusterViewBuffer | ( | void | ) | [virtual] |
| OSG::ClusterViewBuffer::ClusterViewBuffer | ( | const ClusterViewBuffer & | source | ) | [private] |
| void ClusterViewBuffer::recv | ( | GroupConnection & | connection | ) |
Definition at line 113 of file OSGClusterViewBuffer.cpp.
References DEPTH, OSG::ExceptionBinaryDataHandler::get(), getBufferHeight(), getBufferWidth(), OSG::GroupConnection::getChannelCount(), OSG::ExceptionBinaryDataHandler::getValue(), OSG::GroupConnection::resetSelection(), OSG::ImageFileType::restore(), RGB, RGBA, OSG::Connection::selectChannel(), SFATAL, STENCIL, and OSG::GroupConnection::subSelection().
Referenced by OSG::SortFirstWindow::clientSwap().
00114 { 00115 UInt32 tx, ty, tw, th; 00116 UInt32 missing; 00117 BufferT data; 00118 BufferT imageData; 00119 UInt32 dataSize; 00120 UInt32 component; 00121 GLenum glformat; 00122 int componentCnt; 00123 Connection::Channel channel; 00124 00125 missing = connection.getChannelCount(); 00126 00127 glPushMatrix(); 00128 glLoadIdentity(); 00129 glMatrixMode(GL_PROJECTION); 00130 glPushMatrix(); 00131 glLoadIdentity(); 00132 gluOrtho2D(0, getBufferWidth(), 0, getBufferHeight()); 00133 glDisable(GL_DEPTH_TEST); 00134 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 00135 00136 // we expect tiles form all connected servers 00137 while(missing) 00138 { 00139 channel = connection.selectChannel(); 00140 connection.getValue(component); 00141 if(!component) 00142 { 00143 connection.subSelection(channel); 00144 missing--; 00145 continue; 00146 } 00147 00148 // get dimension 00149 connection.getValue(tx); 00150 connection.getValue(ty); 00151 connection.getValue(tw); 00152 connection.getValue(th); 00153 glRasterPos2i(tx, ty); 00154 00155 // =========== recv stencil ===================================== 00156 if(component & STENCIL) 00157 { 00158 data.resize(tw * th); 00159 connection.get(&data[0], tw * th); 00160 glDrawPixels(tw, th, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &data[0]); 00161 glEnable(GL_STENCIL_TEST); 00162 } 00163 00164 // =========== recv depth ======================================= 00165 if(component & DEPTH) 00166 { 00167 glEnable(GL_DEPTH_TEST); 00168 glEnable(GL_STENCIL_TEST); 00169 glStencilFunc(GL_ALWAYS, 1, 1); 00170 glStencilOp(GL_KEEP, GL_ZERO, GL_REPLACE); 00171 data.resize(tw * th * sizeof(float)); 00172 connection.get(&data[0], tw * th * sizeof(float)); 00173 glDrawPixels(tw, th, GL_DEPTH_COMPONENT, GL_FLOAT, &data[0]); 00174 glDisable(GL_DEPTH_TEST); 00175 } 00176 00177 // =========== recv RGBA ======================================== 00178 if(component & RGBA) 00179 { 00180 if(component & (DEPTH | STENCIL)) 00181 { 00182 glStencilFunc(GL_EQUAL, 1, 1); 00183 } 00184 00185 switch(component & RGBA) 00186 { 00187 case RGB: 00188 glformat = GL_RGB; 00189 componentCnt = 3; 00190 break; 00191 case RGBA: 00192 glformat = GL_RGBA; 00193 componentCnt = 4; 00194 break; 00195 default: 00196 SFATAL << "Component combination not supported" 00197 << std::endl; 00198 return; 00199 } 00200 00201 connection.getValue(dataSize); 00202 00203 // compression ? 00204 if(dataSize > 0) 00205 { 00206 #if 0 00207 pImage = new Image; 00208 00209 data.resize(dataSize); 00210 connection.get(&data[0], dataSize); 00211 imageData.resize(tw * th * componentCnt); 00212 ImageFileType::restore(*pImage, (UChar8 *) &data[0], dataSize); 00213 glDrawPixels(tw, th, glformat, GL_UNSIGNED_BYTE, 00214 pImage->getData()); 00215 00216 subRefP(pImage); 00217 #endif 00218 } 00219 else 00220 { 00221 data.resize(tw * th * componentCnt); 00222 connection.get(&data[0], tw * th * componentCnt); 00223 glDrawPixels(tw, th, glformat, GL_UNSIGNED_BYTE, &data[0]); 00224 } 00225 } 00226 00227 if(component & (DEPTH | STENCIL)) 00228 { 00229 glDisable(GL_STENCIL_TEST); 00230 } 00231 } 00232 connection.resetSelection(); 00233 glPopMatrix(); 00234 glMatrixMode(GL_MODELVIEW); 00235 glPopMatrix(); 00236 glEnable(GL_DEPTH_TEST); 00237 }
| 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 246 of file OSGClusterViewBuffer.cpp.
References _imgTransType, _subTileSize, DEPTH, OSG::ExceptionBinaryDataHandler::flush(), OSG::osgMin(), OSG::ExceptionBinaryDataHandler::put(), OSG::ExceptionBinaryDataHandler::putValue(), RGB, RGBA, SFATAL, and STENCIL.
Referenced by send().
00254 { 00255 UInt32 tx, ty, tw, th; 00256 // Image *pImage; 00257 BufferT data; 00258 BufferT imageData; 00259 UInt32 dataSize; 00260 GLenum glformat; 00261 // Image::PixelFormat imgformat; 00262 int componentCnt; 00263 int imgtranssize = 0; 00264 00265 switch(component & RGBA) 00266 { 00267 case RGB: 00268 glformat = GL_RGB; 00269 // imgformat = Image::OSG_RGB_PF; 00270 componentCnt = 3; 00271 break; 00272 case RGBA: 00273 glformat = GL_RGBA; 00274 // imgformat = Image::OSG_RGBA_PF; 00275 componentCnt = 4; 00276 break; 00277 default: 00278 SFATAL << "Component combination not supported" 00279 << std::endl; 00280 return; 00281 } 00282 00283 // resize image buffer 00284 imageData.resize(_subTileSize * _subTileSize * componentCnt); 00285 00286 glPixelStorei(GL_PACK_ALIGNMENT, 1); 00287 00288 for(ty = y1; ty <= y2; ty += _subTileSize) 00289 { 00290 for(tx = x1; tx <= x2; tx += _subTileSize) 00291 { 00292 tw = osgMin(_subTileSize, x2 + 1 - tx); 00293 th = osgMin(_subTileSize, y2 + 1 - ty); 00294 00295 connection.putValue(component); 00296 connection.putValue(tx + toX); 00297 connection.putValue(ty + toY); 00298 connection.putValue(tw); 00299 connection.putValue(th); 00300 00301 // =========== send STENCIL ======================================= 00302 if(component & STENCIL) 00303 { 00304 // read stencil buffer 00305 data.resize(tw * th); 00306 glReadPixels(tx, 00307 ty, 00308 tw, 00309 th, 00310 GL_STENCIL_INDEX, 00311 GL_UNSIGNED_BYTE, 00312 &data[0]); 00313 00314 connection.put(&data[0], tw * th); 00315 } 00316 00317 // =========== send DEPTH ======================================= 00318 if(component & DEPTH) 00319 { 00320 // read stencil buffer 00321 data.resize(tw * th * sizeof(float)); 00322 glReadPixels(tx, ty, tw, th, GL_DEPTH_COMPONENT, GL_FLOAT, 00323 &data[0]); 00324 connection.put(&data[0], tw * th * sizeof(float)); 00325 } 00326 00327 // =========== send RGBA ======================================== 00328 if(component & RGBA) 00329 { 00330 // use compression ? 00331 if(_imgTransType) 00332 { 00333 #if 0 00334 // set image size 00335 pImage = new Image; 00336 00337 pImage->set(imgformat, tw, th, 1, 1, 1, 0.0, 00338 (UChar8 *) &imageData[0]); 00339 00340 // read buffer data into image 00341 glReadPixels(tx, ty, tw, th, glformat, GL_UNSIGNED_BYTE, 00342 pImage->getData()); 00343 00344 // bug maxsize is not big enugh 00345 data.resize(_imgTransType->maxBufferSize(*pImage) + 1000); 00346 dataSize = _imgTransType->store(*pImage, (UChar8 *) &data[0], 00347 data.size()); 00348 connection.putValue(dataSize); 00349 connection.put(&data[0], dataSize); 00350 imgtranssize += dataSize; 00351 00352 subRefP(pImage); 00353 #endif 00354 } 00355 else 00356 { 00357 data.resize(tw * th * componentCnt); 00358 00359 // read buffer data 00360 glReadPixels(tx, ty, tw, th, glformat, GL_UNSIGNED_BYTE, 00361 &data[0]); 00362 dataSize = 0; 00363 connection.putValue(dataSize); 00364 connection.put(&data[0], tw * th * componentCnt); 00365 imgtranssize += tw * th * componentCnt; 00366 } 00367 } 00368 00369 connection.flush(); 00370 } 00371 } 00372 00373 component = 0; 00374 connection.putValue(component); 00375 connection.flush(); 00376 }
| void ClusterViewBuffer::send | ( | PointConnection & | connection, | |
| UInt32 | component, | |||
| UInt32 | toX, | |||
| UInt32 | toY | |||
| ) |
Send parts of a view buffer to a Connection
Definition at line 380 of file OSGClusterViewBuffer.cpp.
References getBufferHeight(), getBufferWidth(), and send().
00384 { 00385 send(connection, 00386 component, 00387 0, 00388 0, 00389 getBufferWidth(), 00390 getBufferHeight(), toX, 00391 toY); 00392 }
| void ClusterViewBuffer::setImgTransType | ( | const Char8 * | mime = NULL |
) |
Definition at line 402 of file OSGClusterViewBuffer.cpp.
References _imgTransType.
00403 { 00404 if(mimeType == NULL) 00405 { 00406 _imgTransType = NULL; 00407 } 00408 else 00409 { 00410 _imgTransType = ImageFileHandler::the()->getFileType(mimeType); 00411 } 00412 }
| 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 420 of file OSGClusterViewBuffer.cpp.
References _subTileSize.
00421 { 00422 _subTileSize = size; 00423 }
| void ClusterViewBuffer::setRGBADataType | ( | UInt32 | type, | |
| UInt32 | size | |||
| ) |
Set opengl datatype for rgb tramsmission
Definition at line 428 of file OSGClusterViewBuffer.cpp.
References _rgbaDataSize, and _rgbaDataType.
00429 { 00430 _rgbaDataType = type; 00431 _rgbaDataSize = size; 00432 }
| void ClusterViewBuffer::setRGBDataType | ( | UInt32 | type, | |
| UInt32 | size | |||
| ) |
Set opengl datatype for rgba tramsmission
Definition at line 437 of file OSGClusterViewBuffer.cpp.
References _rgbDataSize, and _rgbDataType.
00438 { 00439 _rgbDataType = type; 00440 _rgbDataSize = size; 00441 }
| void ClusterViewBuffer::setDepthDataType | ( | UInt32 | type, | |
| UInt32 | size | |||
| ) |
Set opengl datatype for Z-Buffer tramsmission
Definition at line 446 of file OSGClusterViewBuffer.cpp.
References _depthDataSize, and _depthDataType.
00447 { 00448 _depthDataType = type; 00449 _depthDataSize = size; 00450 }
| UInt32 ClusterViewBuffer::getBufferWidth | ( | ) |
| UInt32 ClusterViewBuffer::getBufferHeight | ( | void | ) |
| void OSG::ClusterViewBuffer::operator= | ( | const ClusterViewBuffer & | source | ) | [private] |
ImageFileType* OSG::ClusterViewBuffer::_imgTransType [protected] |
UInt32 OSG::ClusterViewBuffer::_subTileSize [protected] |
UInt32 OSG::ClusterViewBuffer::_rgbDataType [protected] |
UInt32 OSG::ClusterViewBuffer::_rgbDataSize [protected] |
UInt32 OSG::ClusterViewBuffer::_rgbaDataType [protected] |
UInt32 OSG::ClusterViewBuffer::_rgbaDataSize [protected] |
UInt32 OSG::ClusterViewBuffer::_depthDataType [protected] |
UInt32 OSG::ClusterViewBuffer::_depthDataSize [protected] |