1 /*---------------------------------------------------------------------------*\
5 * Copyright(C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
51 #include "OSGFieldContainer.h"
52 #include "OSGAction.h"
54 #include "OSGRenderActionBase.h"
56 #include "OSGDrawEnv.h"
58 #include "OSGBackground.h"
59 #include "OSGViewarea.h"
60 #include "OSGWindow.h"
61 #include "OSGCamera.h"
62 #include "OSGForeground.h"
63 #include "OSGFrameBufferObject.h"
65 #include "OSGTraversalValidator.h"
69 // Documentation for this class is emited in the
70 // OSGViewareaBase.cpp file.
71 // To modify it, please change the .fcd file (OSGViewarea.fcd) and
72 // regenerate the base file.
74 /***************************************************************************\
76 \***************************************************************************/
78 /*-------------------------------------------------------------------------*\
80 \*-------------------------------------------------------------------------*/
82 void Viewarea::initMethod(InitPhase ePhase
)
84 Inherited::initMethod(ePhase
);
87 void Viewarea::onCreate (const Viewarea
*source
)
89 Inherited::onCreate(source
);
92 void Viewarea::onCreateAspect(const Viewarea
*createAspect
,
93 const Viewarea
*source
)
95 Inherited::onCreateAspect(createAspect
, source
);
97 // Don't add the prototype instances to the list
98 if(GlobalSystemState
!= Running
)
101 _pTravValidator
= new TraversalValidator
;
104 void Viewarea::onDestroy(UInt32 uiContainerId
)
106 Inherited::onDestroy(uiContainerId
);
109 void Viewarea::onDestroyAspect(UInt32 uiContainerId
,
112 delete _pTravValidator
;
114 _pTravValidator
= NULL
;
116 Inherited::onDestroyAspect(uiContainerId
, uiAspect
);
119 /***************************************************************************\
121 \***************************************************************************/
123 /*------------- constructors & destructors --------------------------------*/
125 Viewarea::Viewarea(void) :
127 _pTravValidator (NULL
)
132 Viewarea::Viewarea(const Viewarea
&source
) :
134 _pTravValidator (NULL
)
139 Viewarea::~Viewarea(void)
143 void Viewarea::changed(ConstFieldMaskArg whichField
,
147 Inherited::changed(whichField
, origin
, details
);
150 void Viewarea::computePixelSizes(Window
*pWin
,
152 UInt32
&uiPixelWidth
,
153 UInt32
&uiPixelHeight
)
162 uiPixelWidth
= this->getRight() - this->getLeft () + 1;
163 uiPixelHeight
= this->getTop () - this->getBottom() + 1;
168 if(this->getLeft() > 1.f
)
169 iPixelLeft
= Int32(this->getLeft());
171 iPixelLeft
= Int32(pWin
->getWidth() * this->getLeft());
173 if(this->getRight() > 1.f
)
174 iPixelRight
= Int32(this->getRight());
176 iPixelRight
= Int32(pWin
->getWidth() * this->getRight()) - 1;
179 if(this->getBottom() > 1.f
)
180 iPixelBottom
= Int32(this->getBottom());
182 iPixelBottom
= Int32(pWin
->getHeight() * this->getBottom());
184 if(this->getTop() > 1.f
)
185 iPixelTop
= Int32(this->getTop());
187 iPixelTop
= Int32(pWin
->getHeight() * this->getTop()) - 1;
189 uiPixelWidth
= iPixelRight
- iPixelLeft
+ 1;
190 uiPixelHeight
= iPixelTop
- iPixelBottom
+ 1;
194 /*---------------------------- properties ---------------------------------*/
196 void Viewarea::render(RenderActionBase
*action
)
199 _pTravValidator
->incEventCounter();
201 if(getTravMask() == 0x0000 || getEnabled() == false)
204 if(getCamera() == NULL
)
206 SWARNING
<< "Viewarea::render: no Camera, can not render!" << std::endl
;
209 if(getBackground() == NULL
)
211 SWARNING
<< "Viewarea::render: no Background, can not render!" << std::endl
;
214 if(getRoot() == NULL
)
216 SWARNING
<< "Viewarea::render: no root, can not render!" << std::endl
;
220 #if 0 // Have to check GV
224 action
->setCamera (getCamera ());
225 action
->setBackground(getBackground());
226 action
->setViewarea (this );
227 action
->setTravMask (getTravMask() );
229 action
->apply(getRoot());
231 Window
*pWin
= action
->getWindow();
233 if((pWin
->getDrawMode() & Window::PartitionDrawMask
) ==
234 Window::SequentialPartitionDraw
)
238 oEnv
.setWindow(action
->getWindow());
241 getCamera()->getProjection (m
,
244 getCamera()->getProjectionTranslation(t
,
247 oEnv
.setupProjection(m
, t
);
249 getCamera()->getViewing(m
,
252 oEnv
.setupViewing(m
);
254 oEnv
.setTileFullSize(getCamera()->tileGetFullSize());
255 oEnv
.setTileRegion (getCamera()->tileGetRegion ());
257 oEnv
.setViewareaDimension(getPixelLeft (),
263 oEnv
.setDrawerId (action
->getDrawerId ());
264 oEnv
.setDrawableId(action
->getDrawableId());
266 for(UInt16 i
= 0; i
< getMFForegrounds()->size(); i
++)
268 Foreground
*pForeground
= getForegrounds(i
);
269 FrameBufferObject
*pTarget
= this->getTarget();
273 pTarget
->activate(&oEnv
);
276 pForeground
->draw(&oEnv
);
280 pTarget
->deactivate(&oEnv
);
286 if(_pForegroundTask
== NULL
)
289 new ViewareaDrawTask(this, ViewareaDrawTask::Foregrounds
);
292 pWin
->queueTaskFromDrawer(_pForegroundTask
);
295 #if 0 // Have to check GV
301 bool Viewarea::isPassive(void)
306 FrameBufferObject
*Viewarea::getTarget(void)
311 /*------------------------------- dump ----------------------------------*/
313 void Viewarea::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
314 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
316 SLOG
<< "Dump Viewarea NI" << std::endl
;
318 fprintf(stderr
, "%p\n",
319 static_cast<const void *>(this));