fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / Base / OSGViewarea.cpp
blob735ba2512ba46b931144bffa7930121978328c74
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright(C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGL.h"
50 #include "OSGField.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"
67 OSG_USING_NAMESPACE
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 /***************************************************************************\
75 * Class methods *
76 \***************************************************************************/
78 /*-------------------------------------------------------------------------*\
79 - public -
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)
99 return;
101 _pTravValidator = new TraversalValidator;
104 void Viewarea::onDestroy(UInt32 uiContainerId)
106 Inherited::onDestroy(uiContainerId);
109 void Viewarea::onDestroyAspect(UInt32 uiContainerId,
110 UInt32 uiAspect )
112 delete _pTravValidator;
114 _pTravValidator = NULL;
116 Inherited::onDestroyAspect(uiContainerId, uiAspect);
119 /***************************************************************************\
120 * Instance methods *
121 \***************************************************************************/
123 /*------------- constructors & destructors --------------------------------*/
125 Viewarea::Viewarea(void) :
126 Inherited ( ),
127 _pTravValidator (NULL)
132 Viewarea::Viewarea(const Viewarea &source) :
133 Inherited (source),
134 _pTravValidator (NULL )
139 Viewarea::~Viewarea(void)
143 void Viewarea::changed(ConstFieldMaskArg whichField,
144 UInt32 origin,
145 BitVector details)
147 Inherited::changed(whichField, origin, details);
150 void Viewarea::computePixelSizes(Window *pWin,
152 UInt32 &uiPixelWidth,
153 UInt32 &uiPixelHeight)
155 Int32 iPixelLeft;
156 Int32 iPixelRight;
157 Int32 iPixelTop;
158 Int32 iPixelBottom;
160 if(pWin == NULL)
162 uiPixelWidth = this->getRight() - this->getLeft () + 1;
163 uiPixelHeight = this->getTop () - this->getBottom() + 1;
165 return;
168 if(this->getLeft() > 1.f)
169 iPixelLeft = Int32(this->getLeft());
170 else
171 iPixelLeft = Int32(pWin->getWidth() * this->getLeft());
173 if(this->getRight() > 1.f)
174 iPixelRight = Int32(this->getRight());
175 else
176 iPixelRight = Int32(pWin->getWidth() * this->getRight()) - 1;
179 if(this->getBottom() > 1.f)
180 iPixelBottom = Int32(this->getBottom());
181 else
182 iPixelBottom = Int32(pWin->getHeight() * this->getBottom());
184 if(this->getTop() > 1.f)
185 iPixelTop = Int32(this->getTop());
186 else
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)
198 #if 0
199 _pTravValidator->incEventCounter();
201 if(getTravMask() == 0x0000 || getEnabled() == false)
202 return;
204 if(getCamera() == NULL)
206 SWARNING << "Viewarea::render: no Camera, can not render!" << std::endl;
207 return;
209 if(getBackground() == NULL)
211 SWARNING << "Viewarea::render: no Background, can not render!" << std::endl;
212 return;
214 if(getRoot() == NULL)
216 SWARNING << "Viewarea::render: no root, can not render!" << std::endl;
217 return;
220 #if 0 // Have to check GV
221 activate();
222 #endif
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)
236 DrawEnv oEnv;
238 oEnv.setWindow(action->getWindow());
240 Matrix m, t;
241 getCamera()->getProjection (m,
242 getPixelWidth (),
243 getPixelHeight());
244 getCamera()->getProjectionTranslation(t,
245 getPixelWidth (),
246 getPixelHeight());
247 oEnv.setupProjection(m, t);
249 getCamera()->getViewing(m,
250 getPixelWidth (),
251 getPixelHeight());
252 oEnv.setupViewing(m);
254 oEnv.setTileFullSize(getCamera()->tileGetFullSize());
255 oEnv.setTileRegion (getCamera()->tileGetRegion ());
257 oEnv.setViewareaDimension(getPixelLeft (),
258 getPixelBottom(),
259 getPixelRight (),
260 getPixelTop (),
261 isFullWindow ());
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();
271 if(pTarget != NULL)
273 pTarget->activate(&oEnv);
276 pForeground->draw(&oEnv);
278 if(pTarget != NULL)
280 pTarget->deactivate(&oEnv);
284 else
286 if(_pForegroundTask == NULL)
288 _pForegroundTask =
289 new ViewareaDrawTask(this, ViewareaDrawTask::Foregrounds);
292 pWin->queueTaskFromDrawer(_pForegroundTask);
295 #if 0 // Have to check GV
296 deactivate();
297 #endif
298 #endif
301 bool Viewarea::isPassive(void)
303 return false;
306 FrameBufferObject *Viewarea::getTarget(void)
308 return NULL;
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));