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 return Int32(getParent()->getWidth() * getLeft());
00144 }
00145
00149 Int32 Viewport::getPixelRight(void) const
00150 {
00151
00152 if(getRight() > 1)
00153 return Int32(getRight());
00154
00155
00156 return Int32(getParent()->getWidth() * getRight() - 1);
00157 }
00158
00162 Int32 Viewport::getPixelBottom(void) const
00163 {
00164 if(getBottom() > 1)
00165 return Int32(getBottom());
00166
00167 return Int32(getParent()->getHeight() * getBottom());
00168 }
00169
00173 Int32 Viewport::getPixelTop(void) const
00174 {
00175
00176 if(getTop() > 1)
00177 return Int32(getTop());
00178
00179
00180 return Int32(getParent()->getHeight() * getTop() - 1);
00181 }
00182
00186 bool Viewport::isFullWindow(void) const
00187 {
00188 return getPixelBottom() == 0 &&
00189 getPixelLeft() == 0 &&
00190 getPixelTop() == getParent()->getHeight() - 1 &&
00191 getPixelRight() == getParent()->getWidth() - 1;
00192 }
00193
00194
00195
00210 void Viewport::draw(DrawAction * action)
00211 {
00212 if(getCamera() == NullFC)
00213 {
00214 SWARNING << "Viewport::draw: no camera!" << std::endl;
00215 return;
00216 }
00217 if(getBackground() == NullFC)
00218 {
00219 SWARNING << "Viewport::draw: no Background!" << std::endl;
00220 return;
00221 }
00222 if(getRoot() == NullFC)
00223 {
00224 SWARNING << "Viewport::draw: no root!" << std::endl;
00225 return;
00226 }
00227
00228 GLint pl=getPixelLeft(), pr=getPixelRight(), pb=getPixelBottom(),
00229 pt=getPixelTop();
00230 GLint pw=pr-pl+1,ph=pt-pb+1;
00231 bool full = isFullWindow();
00232
00233 glViewport(pl, pb, pw, ph);
00234 glScissor(pl, pb, pw, ph);
00235
00236 if(! full)
00237 glEnable(GL_SCISSOR_TEST);
00238
00239 action->setViewport (this);
00240 action->setCamera (getCamera ().getCPtr());
00241 action->setBackground(getBackground().getCPtr());
00242 action->setTravMask (getTravMask() );
00243
00244 getCamera ()->setup(action, *this);
00245 getBackground()->clear(action, this);
00246
00247 action->apply(getRoot());
00248
00249 for(UInt16 i=0; i < getForegrounds().size(); i++)
00250 getForegrounds(i)->draw(action, this);
00251
00252 if(! full)
00253 glDisable(GL_SCISSOR_TEST);
00254 }
00255
00256
00257 void Viewport::render(RenderActionBase *action)
00258 {
00259 if(getCamera() == NullFC)
00260 {
00261 SWARNING << "Viewport::render: no camera!" << std::endl;
00262 return;
00263 }
00264 if(getBackground() == NullFC)
00265 {
00266 SWARNING << "Viewport::render: no Background!" << std::endl;
00267 return;
00268 }
00269 if(getRoot() == NullFC)
00270 {
00271 SWARNING << "Viewport::render: no root!" << std::endl;
00272 return;
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 action->setCamera (getCamera ().getCPtr());
00289 action->setBackground(getBackground().getCPtr());
00290 action->setViewport (this );
00291 action->setTravMask (getTravMask() );
00292
00293
00294
00295
00296
00297
00298
00299
00300 action->apply(getRoot());
00301
00302 for(UInt16 i=0; i < getForegrounds().size(); i++)
00303 getForegrounds(i)->draw(action, this);
00304
00305
00306
00307
00308
00309 }
00310
00311
00312
00313 void Viewport::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00314 const BitVector OSG_CHECK_ARG(bvFlags)) const
00315 {
00316 SLOG << "Dump Viewport NI" << std::endl;
00317 }
00318
00319
00320
00321
00322
00323
00324
00325 #ifdef OSG_SGI_CC
00326 #pragma set woff 1174
00327 #endif
00328
00329 #ifdef OSG_LINUX_ICC
00330 #pragma warning( disable : 177 )
00331 #endif
00332
00333 namespace
00334 {
00335 static Char8 cvsid_cpp [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00336 static Char8 cvsid_hpp [] = OSGVIEWPORT_HEADER_CVSID;
00337 static Char8 cvsid_inl [] = OSGVIEWPORT_INLINE_CVSID;
00338
00339 static Char8 cvsid_fields_hpp[] = OSGVIEWPORTFIELDS_HEADER_CVSID;
00340 }
00341
00342 #ifdef __sgi
00343 #pragma reset woff 1174
00344 #endif
00345