Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGViewport.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright(C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
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  *                            Description                                  *
00066 \***************************************************************************/
00067 
00096 /***************************************************************************\
00097  *                           Class methods                                 *
00098 \***************************************************************************/
00099 
00100 /*-------------------------------------------------------------------------*\
00101  -  public                                                                 -
00102 \*-------------------------------------------------------------------------*/
00103 
00104 void Viewport::initMethod(void)
00105 {
00106 }
00107 
00108 /***************************************************************************\
00109  *                           Instance methods                              *
00110 \***************************************************************************/
00111 
00112 /*------------- constructors & destructors --------------------------------*/
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 /*---------------------------- properties ---------------------------------*/
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     // >1: pixel
00152     if(getRight() > 1)
00153         return Int32(getRight());
00154 
00155     // <=1: partial screen, use 1 less to not overlap other windows
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     // >1: pixel
00176     if(getTop() > 1)
00177         return Int32(getTop());
00178 
00179     // <=1: partial screen, use 1 less to not overlap other windows
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 /*-------------------------- your_category---------------------------------*/
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     GLint pl=getPixelLeft(), pr=getPixelRight(), pb=getPixelBottom(), 
00277           pt=getPixelTop();
00278     GLint pw=pr-pl+1,ph=pt-pb+1;
00279     bool full = isFullWindow();
00280 
00281     glViewport(pl, pb, pw, ph);
00282     glScissor(pl, pb, pw, ph);
00283 
00284     if(! full)
00285         glEnable(GL_SCISSOR_TEST);
00286     */
00287 
00288     action->setCamera    (getCamera    ().getCPtr());
00289     action->setBackground(getBackground().getCPtr());
00290     action->setViewport  (this                     );
00291     action->setTravMask  (getTravMask()            );
00292 
00293 //  getCamera()->setup(action, *this);
00294 //  getBackground()->clear(action, this);
00295 
00296 /*
00297 fprintf(stderr,"%p: node 0x%p startrender\n", Thread::getCurrent(), 
00298                 getRoot().getCPtr());
00299 */
00300     action->apply(getRoot());
00301 
00302     for(UInt16 i=0; i < getForegrounds().size(); i++)
00303         getForegrounds(i)->draw(action, this);
00304 
00305 /*
00306     if(! full)
00307         glDisable(GL_SCISSOR_TEST);
00308         */
00309 }
00310 
00311 /*------------------------------- dump ----------------------------------*/
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 /*                              cvs id's                                  */
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 

Generated on Thu Aug 25 04:12:01 2005 for OpenSG by  doxygen 1.4.3