00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <OSGGL.h>
00049
00050 #include <OSGField.h>
00051 #include <OSGFieldContainer.h>
00052 #include <OSGAction.h>
00053 #include <OSGDrawAction.h>
00054 #include <OSGRenderAction.h>
00055 #include "OSGBackground.h"
00056 #include "OSGViewport.h"
00057 #include "OSGWindow.h"
00058 #include "OSGCamera.h"
00059 #include "OSGForeground.h"
00060
00061 OSG_USING_NAMESPACE
00062
00063
00064
00065
00066
00067
00096
00097
00098
00099
00100
00101
00102
00103
00104 void Viewport::initMethod(void)
00105 {
00106 }
00107
00108
00109
00110
00111
00112
00113
00114 Viewport::Viewport(void) :
00115 Inherited()
00116 {
00117 }
00118
00119 Viewport::Viewport(const Viewport &source) :
00120 Inherited(source)
00121 {
00122 }
00123
00124 Viewport::~Viewport(void)
00125 {
00126 }
00127
00128 void Viewport::changed(BitVector whichField, UInt32 origin)
00129 {
00130 Inherited::changed(whichField, origin);
00131 }
00132
00133
00134
00138 Int32 Viewport::getPixelLeft(void) const
00139 {
00140 if(getLeft() > 1)
00141 return Int32(getLeft());
00142
00143 if(getParent() == NullFC)
00144 {
00145 SWARNING << "Viewport::getPixelLeft: viewport has no parent window!" << std::endl;
00146 return 0;
00147 }
00148
00149 return Int32(getParent()->getWidth() * getLeft());
00150 }
00151
00155 Int32 Viewport::getPixelRight(void) const
00156 {
00157
00158 if(getRight() > 1)
00159 return Int32(getRight());
00160
00161 if(getParent() == NullFC)
00162 {
00163 SWARNING << "Viewport::getPixelRight: viewport has no parent window!" << std::endl;
00164 return 0;
00165 }
00166
00167
00168 return Int32(getParent()->getWidth() * getRight() - 1);
00169 }
00170
00174 Int32 Viewport::getPixelBottom(void) const
00175 {
00176 if(getBottom() > 1)
00177 return Int32(getBottom());
00178
00179 if(getParent() == NullFC)
00180 {
00181 SWARNING << "Viewport::getPixelBottom: viewport has no parent window!" << std::endl;
00182 return 0;
00183 }
00184
00185 return Int32(getParent()->getHeight() * getBottom());
00186 }
00187
00191 Int32 Viewport::getPixelTop(void) const
00192 {
00193
00194 if(getTop() > 1)
00195 return Int32(getTop());
00196
00197 if(getParent() == NullFC)
00198 {
00199 SWARNING << "Viewport::getPixelTop: viewport has no parent window!" << std::endl;
00200 return 0;
00201 }
00202
00203
00204 return Int32(getParent()->getHeight() * getTop() - 1);
00205 }
00206
00210 bool Viewport::isFullWindow(void) const
00211 {
00212 if(getParent() == NullFC)
00213 {
00214 SWARNING << "Viewport::isFullWindow: viewport has no parent window!" << std::endl;
00215 return false;
00216 }
00217
00218 return getPixelBottom() == 0 &&
00219 getPixelLeft() == 0 &&
00220 getPixelTop() == getParent()->getHeight() - 1 &&
00221 getPixelRight() == getParent()->getWidth() - 1;
00222 }
00223
00224 void Viewport::clearForegrounds(void)
00225 {
00226 for(UInt32 i = 0; i < _mfForegrounds.size(); ++i)
00227 {
00228 subRefCP(_mfForegrounds[i]);
00229 }
00230
00231 _mfForegrounds.clear();
00232
00233 }
00234
00235 void Viewport::addForeground(ForegroundPtr pForeground)
00236 {
00237 addRefCP(pForeground);
00238
00239 _mfForegrounds.push_back(pForeground);
00240 }
00241
00242
00243
00244
00245
00246 void Viewport::activateSize(void)
00247 {
00248 GLint pl=getPixelLeft();
00249 GLint pr=getPixelRight();
00250 GLint pb=getPixelBottom();
00251 GLint pt=getPixelTop();
00252 GLint pw=pr-pl+1;
00253 GLint ph=pt-pb+1;
00254
00255 glViewport(pl, pb, pw, ph);
00256
00257 if(!isFullWindow())
00258 {
00259 glScissor(pl, pb, pw, ph);
00260 glEnable(GL_SCISSOR_TEST);
00261 }
00262 else
00263 glDisable(GL_SCISSOR_TEST);
00264
00265 }
00266
00267 void Viewport::activate(void)
00268 {
00269 activateSize();
00270 }
00271
00272 void Viewport::deactivate(void)
00273 {
00274 }
00275
00276
00291 void Viewport::draw(DrawAction * action)
00292 {
00293 if(getCamera() == NullFC)
00294 {
00295 SWARNING << "Viewport::draw: no camera!" << std::endl;
00296 return;
00297 }
00298 if(getBackground() == NullFC)
00299 {
00300 SWARNING << "Viewport::draw: no Background!" << std::endl;
00301 return;
00302 }
00303 if(getRoot() == NullFC)
00304 {
00305 SWARNING << "Viewport::draw: no root!" << std::endl;
00306 return;
00307 }
00308
00309 activate();
00310
00311 action->setViewport (this);
00312 action->setCamera (getCamera ().getCPtr());
00313 action->setBackground(getBackground().getCPtr());
00314 action->setTravMask (getTravMask() );
00315
00316 getCamera ()->setup(action, *this);
00317 getBackground()->clear(action, this);
00318
00319 action->apply(getRoot());
00320
00321 for(UInt16 i=0; i < getForegrounds().size(); i++)
00322 getForegrounds(i)->draw(action, this);
00323
00324 deactivate();
00325 }
00326
00327
00328 void Viewport::render(RenderActionBase *action)
00329 {
00330 if(getCamera() == NullFC)
00331 {
00332 SWARNING << "Viewport::render: no camera!" << std::endl;
00333 return;
00334 }
00335 if(getBackground() == NullFC)
00336 {
00337 SWARNING << "Viewport::render: no Background!" << std::endl;
00338 return;
00339 }
00340 if(getRoot() == NullFC)
00341 {
00342 SWARNING << "Viewport::render: no root!" << std::endl;
00343 return;
00344 }
00345
00346 activate();
00347
00348 action->setCamera (getCamera ().getCPtr());
00349 action->setBackground(getBackground().getCPtr());
00350 action->setViewport (this );
00351 action->setTravMask (getTravMask() );
00352
00353
00354
00355
00356
00357
00358
00359
00360 action->apply(getRoot());
00361
00362 for(UInt16 i=0; i < getForegrounds().size(); i++)
00363 getForegrounds(i)->draw(action, this);
00364
00365 deactivate();
00366 }
00367
00368
00369
00370 void Viewport::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00371 const BitVector OSG_CHECK_ARG(bvFlags)) const
00372 {
00373 SLOG << "Dump Viewport NI" << std::endl;
00374 }
00375
00376
00377
00378
00379
00380
00381
00382 #ifdef OSG_SGI_CC
00383 #pragma set woff 1174
00384 #endif
00385
00386 #ifdef OSG_LINUX_ICC
00387 #pragma warning( disable : 177 )
00388 #endif
00389
00390 namespace
00391 {
00392 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00393 static Char8 cvsid_hpp [] = OSGVIEWPORT_HEADER_CVSID;
00394 static Char8 cvsid_inl [] = OSGVIEWPORT_INLINE_CVSID;
00395
00396 static Char8 cvsid_fields_hpp[] = OSGVIEWPORTFIELDS_HEADER_CVSID;
00397 }
00398
00399 #ifdef __sgi
00400 #pragma reset woff 1174
00401 #endif
00402