| | 291 | TileCameraDecoratorPtr deco; |
|---|
| | 292 | ViewportPtr serverPort; |
|---|
| | 293 | ViewportPtr clientPort; |
|---|
| | 294 | StereoBufferViewportPtr clientStereoPort; |
|---|
| | 295 | UInt32 sv,cv; |
|---|
| | 296 | Int32 l,r,t,b; |
|---|
| | 297 | Int32 cleft,cright,ctop,cbottom; |
|---|
| | 298 | |
|---|
| | 299 | if(!getHServers()) |
|---|
| | 300 | { |
|---|
| | 301 | setHServers(getServers().size()); |
|---|
| | 302 | } |
|---|
| | 303 | if(!getVServers()) |
|---|
| | 304 | { |
|---|
| | 305 | setVServers(1); |
|---|
| | 306 | } |
|---|
| | 307 | |
|---|
| | 308 | UInt32 row =id/getHServers(); |
|---|
| | 309 | UInt32 column=id%getHServers(); |
|---|
| | 310 | |
|---|
| | 311 | // calculate width and height from local width and height |
|---|
| | 312 | UInt32 width = window->getWidth() ; |
|---|
| | 313 | UInt32 height = window->getHeight(); |
|---|
| | 314 | |
|---|
| | 315 | if(getWidth()==0) |
|---|
| | 316 | { |
|---|
| | 317 | setWidth( width*getHServers() ); |
|---|
| | 318 | } |
|---|
| | 319 | if(getHeight()==0) |
|---|
| | 320 | { |
|---|
| | 321 | setHeight( height*getVServers() ); |
|---|
| | 322 | } |
|---|
| | 323 | |
|---|
| | 324 | Int32 left = column * width - column * getXOverlap(); |
|---|
| | 325 | Int32 bottom = row * height - row * getYOverlap(); |
|---|
| | 326 | Int32 right = left + width - 1; |
|---|
| | 327 | Int32 top = bottom + height - 1; |
|---|
| | 328 | Real64 scaleCWidth = |
|---|
| | 329 | ((width - getXOverlap()) * (getHServers() - 1) + width) / |
|---|
| | 330 | (float)getWidth(); |
|---|
| | 331 | Real64 scaleCHeight = |
|---|
| | 332 | ((height - getYOverlap())* (getVServers() - 1) + height)/ |
|---|
| | 333 | (float)getHeight(); |
|---|
| | 334 | |
|---|
| | 335 | // duplicate viewports |
|---|
| | 336 | for(cv=0,sv=0;cv<getPort().size();cv++) |
|---|
| | 337 | { |
|---|
| | 338 | clientPort = getPort()[cv]; |
|---|
| | 339 | |
|---|
| | 340 | clientStereoPort = cast_dynamic<StereoBufferViewportPtr>(clientPort); |
|---|
| | 341 | |
|---|
| | 342 | cleft = (Int32)(clientPort->getPixelLeft() * scaleCWidth) ; |
|---|
| | 343 | cbottom = (Int32)(clientPort->getPixelBottom() * scaleCHeight) ; |
|---|
| | 344 | cright = (Int32)((clientPort->getPixelRight()+1) * scaleCWidth) -1; |
|---|
| | 345 | ctop = (Int32)((clientPort->getPixelTop()+1) * scaleCHeight)-1; |
|---|
| | 346 | |
|---|
| | 347 | if(cright < left || |
|---|
| | 348 | cleft > right || |
|---|
| | 349 | ctop < bottom || |
|---|
| | 350 | cbottom > top ) |
|---|
| | 351 | { |
|---|
| | 352 | // invisible on this server screen |
|---|
| | 353 | continue; |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | // calculate overlapping viewport |
|---|
| | 357 | l = osgMax(cleft ,left ) - left; |
|---|
| | 358 | b = osgMax(cbottom,bottom) - bottom; |
|---|
| | 359 | r = osgMin(cright ,right ) - left; |
|---|
| | 360 | t = osgMin(ctop ,top ) - bottom; |
|---|
| | 361 | |
|---|
| | 362 | if(window->getPort().size() <= sv) |
|---|
| | 363 | { |
|---|
| | 364 | serverPort = cast_dynamic<ViewportPtr>(clientPort->shallowCopy()); |
|---|
| | 365 | |
|---|
| | 366 | deco = TileCameraDecorator::create(); |
|---|
| | 367 | |
|---|
| | 368 | window->addPort(serverPort); |
|---|
| | 369 | |
|---|
| | 370 | serverPort->setCamera(deco); |
|---|
| | 371 | } |
|---|
| | 372 | else |
|---|
| | 373 | { |
|---|
| | 374 | serverPort = window->getPort()[sv]; |
|---|
| | 375 | |
|---|
| | 376 | deco = cast_dynamic<TileCameraDecoratorPtr>( |
|---|
| | 377 | serverPort->getCamera()); |
|---|
| | 378 | |
|---|
| | 379 | if(window->getPort()[sv]->getType() != clientPort->getType()) |
|---|
| | 380 | { |
|---|
| | 381 | // there is a viewport with the wrong type |
|---|
| | 382 | subRef(window->getPort()[sv]); |
|---|
| | 383 | |
|---|
| | 384 | serverPort = |
|---|
| | 385 | cast_dynamic<ViewportPtr>(clientPort->shallowCopy()); |
|---|
| | 386 | |
|---|
| | 387 | window->replacePort(sv, serverPort);//[sv] = serverPort; |
|---|
| | 388 | serverPort->setCamera(deco); |
|---|
| | 389 | } |
|---|
| | 390 | else |
|---|
| | 391 | { |
|---|
| | 392 | deco = cast_dynamic<TileCameraDecoratorPtr>( |
|---|
| | 393 | serverPort->getCamera()); |
|---|
| | 394 | } |
|---|
| | 395 | } |
|---|
| | 396 | |
|---|
| | 397 | // update changed viewport fields |
|---|
| | 398 | updateViewport(serverPort,clientPort); |
|---|
| | 399 | |
|---|
| | 400 | // set viewport size |
|---|
| | 401 | serverPort->setSize(Real32(l),Real32(b),Real32(r),Real32(t)); |
|---|
| | 402 | |
|---|
| | 403 | // use pixel even if pixel = 1 |
|---|
| | 404 | if(serverPort->getLeft() == 1.0) |
|---|
| | 405 | serverPort->setLeft(1.0001); |
|---|
| | 406 | |
|---|
| | 407 | if(serverPort->getRight() == 1.0) |
|---|
| | 408 | serverPort->setRight(1.0001); |
|---|
| | 409 | |
|---|
| | 410 | if(serverPort->getTop() == 1.0) |
|---|
| | 411 | serverPort->setTop(1.0001); |
|---|
| | 412 | |
|---|
| | 413 | if(serverPort->getBottom() == 1.0) |
|---|
| | 414 | serverPort->setBottom(1.0001); |
|---|
| | 415 | |
|---|
| | 416 | // calculate tile parameters |
|---|
| | 417 | deco->setFullWidth ( cright-cleft ); |
|---|
| | 418 | deco->setFullHeight( ctop-cbottom ); |
|---|
| | 419 | deco->setSize( ( l+left-cleft ) / (float)( cright-cleft ), |
|---|
| | 420 | ( b+bottom-cbottom ) / (float)( ctop-cbottom ), |
|---|
| | 421 | ( r+left-cleft ) / (float)( cright-cleft ), |
|---|
| | 422 | ( t+bottom-cbottom ) / (float)( ctop-cbottom ) ); |
|---|
| | 423 | deco->setDecoratee( clientPort->getCamera() ); |
|---|
| | 424 | |
|---|
| | 425 | sv++; |
|---|
| | 426 | } |
|---|
| | 427 | |
|---|
| | 428 | // remove unused ports |
|---|
| | 429 | while(window->getPort().size()>sv) |
|---|
| | 430 | { |
|---|
| | 431 | window->subPort(sv); |
|---|
| | 432 | } |
|---|
| | 433 | |
|---|
| | 434 | Inherited::serverRender(window,id,action); |
|---|