fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / RenderingBackend / OSGDrawEnv.h
blob004fbe5a0b2d41cb540a1abe075eaa501f160c6b
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 #ifndef _OSGDRAWENV_H_
40 #define _OSGDRAWENV_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGBaseTypes.h"
47 #include "OSGSystemDef.h"
48 #include "OSGMatrix.h"
49 #include "OSGGLEXT.h"
50 #include "OSGStatCollector.h"
51 #include "OSGContainerForwards.h"
53 #include <boost/function.hpp>
55 OSG_BEGIN_NAMESPACE
57 class RenderActionBase;
58 class RenderAction;
59 class RenderPartition;
60 class Window;
61 class State;
62 class StateOverride;
64 /*! \ingroup GrpSystemRenderingBackendBase
65 \ingroup GrpLibOSGSystem
67 \brief Old OpenGL State Uniforms so this can be passed to the shader.
70 class OpenGLState
72 /*========================== PUBLIC =================================*/
74 static const UInt8 TransformFeedbackModeMask = 0x0F;
75 static const UInt8 TransformFeedbackActiveMask = 0xF0;
77 static const UInt8 TransformFeedbackActive = 0x80;
78 static const UInt8 TransformFeedbackPaused = 0x40;
80 public:
82 /*---------------------------------------------------------------------*/
83 /*! \name Types */
84 /*! \{ */
86 void setModelView (const Matrix &matrix);
87 const Matrix &getModelView ( void ) const;
89 void setProjection (const Matrix &matrix);
90 const Matrix &getProjection ( void ) const;
92 #ifdef OSG_OGL_COREONLY
93 const Matrix &getModelViewProjection( void ) const;
94 const Matrix &getNormalMatrix ( void ) const;
95 #endif
97 /*! \} */
98 /*---------------------------------------------------------------------*/
99 /*! \name Constructors */
100 /*! \{ */
102 void setTransformFeedbackActive (UInt8 uiMode);
103 void setTransformFeedbackInactive(void );
105 void pauseTransformFeedback (void );
106 void resumeTransformFeedback (void );
108 bool isTransformFeedbackActive (void );
109 bool isTransformFeedbackPaused (void );
111 /*! \} */
112 /*---------------------------------------------------------------------*/
113 /*! \name Constructors */
114 /*! \{ */
116 OpenGLState(void);
118 /*! \} */
119 /*---------------------------------------------------------------------*/
120 /*! \name Destructor */
121 /*! \{ */
123 virtual ~OpenGLState(void);
125 /*! \} */
126 /*! \} */
127 /*========================= PROTECTED ===============================*/
129 protected:
131 /*---------------------------------------------------------------------*/
132 /*! \name Member */
133 /*! \{ */
135 #ifdef OSG_OGL_COREONLY
136 Matrix _mModelViewProjection;
137 Matrix _mNormalMatrix;
138 #endif
139 Matrix _mProjection;
140 Matrix _mModelView;
142 UInt8 _uiTransformFeedback;
144 /*! \} */
145 /*========================== PRIVATE ================================*/
147 private:
149 /*! \brief prohibit default function (move to 'public' if needed) */
150 OpenGLState(const OpenGLState &source);
151 /*! \brief prohibit default function (move to 'public' if needed) */
152 void operator =(const OpenGLState &source);
155 /*! \ingroup GrpSystemRenderingBackendBase
156 \ingroup GrpLibOSGSystem
159 class OSG_SYSTEM_DLLMAPPING DrawEnv
161 /*========================== PUBLIC =================================*/
163 public:
165 /*---------------------------------------------------------------------*/
166 /*! \name Types */
167 /*! \{ */
169 typedef RenderFunctor DrawFunctor;
171 /*! \} */
172 /*---------------------------------------------------------------------*/
173 /*! \name Vars */
174 /*! \{ */
176 OpenGLState _openGLState;
178 /*! \} */
179 /*---------------------------------------------------------------------*/
180 /*! \name Statistic */
181 /*! \{ */
183 void setWindow ( Window *pWindow );
184 void setSGNode ( Node *pSGNode );
186 void setupProjection (const Matrix &projection,
187 const Matrix &translation );
188 void setupViewing (const Matrix &matrix );
189 void setObjectToWorld (const Matrix &matrix );
191 void setCameraNear (const Real32 &camNear );
192 void setCameraFar (const Real32 &camFar );
194 void setActiveTexTarget ( UInt32 uiSlot,
195 GLenum uiTarget );
197 void setActiveShader ( UInt32 uiActiveShader);
198 UInt32 getActiveShader ( void );
200 void setActiveFBO ( UInt32 uiActiveFBO );
201 UInt32 getActiveFBO ( void );
203 void setTargetBufferFormat( GLenum eBufferFormat );
204 GLenum getTargetBufferFormat( void );
206 UInt32 getRequiredOGLFeature( void );
207 void addRequiredOGLFeature( UInt32 uiFeatureMask );
208 void subRequiredOGLFeature( UInt32 uiFeatureMask );
210 /*! \} */
211 /*---------------------------------------------------------------------*/
212 /*! \name Access */
213 /*! \{ */
215 const Matrix &getCameraProjection (void ) const;
216 const Matrix &getCameraProjectionTrans(void ) const;
217 const Matrix &getCameraDecoration (void ) const;
219 const Matrix &getCameraViewing (void ) const;
221 //CamViewing^-1
222 const Matrix &getCameraToWorld (void ) const;
224 const Matrix &getObjectToWorld (void ) const;
226 const Matrix &getWorldToScreen (void ) const;
228 Real32 getCameraNear (void ) const;
229 Real32 getCameraFar (void ) const;
231 Window *getWindow (void ) const;
232 Node *getSGNode (void ) const;
234 GLenum getActiveTexTarget (UInt32 uiSlot) const;
236 /*! \} */
237 /*---------------------------------------------------------------------*/
238 /*! \name Access */
239 /*! \{ */
241 void setStatCollector(StatCollector *pStatCollector);
242 StatCollector *getStatCollector(void );
244 /*! \} */
245 /*---------------------------------------------------------------------*/
246 /*! \name Access */
247 /*! \{ */
249 const Matrix &getVPCameraFullProjection (void ) const;
250 const Matrix &getVPCameraProjection (void ) const;
251 const Matrix &getVPCameraProjectionTrans(void ) const;
253 const Matrix &getVPCameraViewing (void ) const;
255 //VPCamViewing^-1
256 const Matrix &getVPCameraToWorld (void ) const;
258 const Matrix &getVPWorldToScreen (void ) const;
260 /*! \} */
261 /*---------------------------------------------------------------------*/
262 /*! \name Access */
263 /*! \{ */
265 void setVPCameraMatrices (const Matrix &mFullprojection,
266 const Matrix &mProjection,
267 const Matrix &mProjectionTrans,
268 const Matrix &mViewing,
269 const Matrix &mToWorld,
270 const Matrix &mWorldToScreen );
272 void initVPMatricesFromCamera(void );
274 /*! \} */
275 /*---------------------------------------------------------------------*/
276 /*! \name Constructors */
277 /*! \{ */
280 UInt32 getNumStateChanges (void) const;
281 UInt32 getNumChunkChanges (void) const;
282 UInt32 getNumShaderChanges (void) const;
283 UInt32 getNumShaderParamChanges(void) const;
285 void incNumChunkChanges (void);
286 void incNumShaderChanges (void);
287 void incNumShaderParamChanges(void);
289 /*! \} */
290 /*---------------------------------------------------------------------*/
291 /*! \name Constructors */
292 /*! \{ */
294 void clearState(void);
296 void activateState (State *pNewState,
297 StateOverride *pNewStateOverride);
299 void deactivateState(void);
301 /*! \} */
302 /*---------------------------------------------------------------------*/
303 /*! \name Constructors */
304 /*! \{ */
306 void setViewportDimension(Int32 iPixelLeft,
307 Int32 iPixelBottom,
308 Int32 iPixelRight,
309 Int32 iPixelTop,
310 bool bFull );
312 void calcViewportDimension(Real32 rLeft,
313 Real32 rBottom,
314 Real32 rRight,
315 Real32 rTop,
317 UInt16 iTargetWidth,
318 UInt16 iTargetHeight);
321 Int32 getPixelLeft (void ) const;
322 Int32 getPixelRight (void ) const;
323 Int32 getPixelBottom (void ) const;
324 Int32 getPixelTop (void ) const;
326 Int32 getPixelWidth (void ) const;
327 Int32 getPixelHeight (void ) const;
328 bool getFull (void ) const;
330 /*! \} */
331 /*---------------------------------------------------------------------*/
332 /*! \name Constructors */
333 /*! \{ */
335 void setTileFullSize (const Vec2u &uiTileFullSize);
336 void setTileRegion (const Vec4f &vTileRegion );
338 const Vec2u &getTileFullSize (void ) const;
339 const Vec4f &getTileRegion (void ) const;
341 Matrix calcTileDecorationMatrix(void ) const;
343 /*! \} */
344 /*---------------------------------------------------------------------*/
345 /*! \name Constructors */
346 /*! \{ */
348 Int32 getDrawerId (void ) const;
349 void setDrawerId (Int32 iId);
351 Int32 getDrawableId(void ) const;
352 void setDrawableId(Int32 iId);
354 /*! \} */
355 /*---------------------------------------------------------------------*/
356 /*! \name Constructors */
357 /*! \{ */
359 void setLightState(UInt32 uiState);
360 UInt32 getLightState(void );
362 /*! \} */
363 /*---------------------------------------------------------------------*/
364 /*! \name Constructors */
365 /*! \{ */
367 template<class ValuePtr>
368 ValuePtr getData(Int32 iSlotId) const;
370 /*! \} */
371 /*---------------------------------------------------------------------*/
372 /*! \name Constructors */
373 /*! \{ */
375 DrawEnv(void);
377 /*! \} */
378 /*---------------------------------------------------------------------*/
379 /*! \name Destructor */
380 /*! \{ */
382 virtual ~DrawEnv(void);
384 /*! \} */
385 /*========================= PROTECTED ===============================*/
387 protected:
389 /*---------------------------------------------------------------------*/
390 /*! \name Member */
391 /*! \{ */
393 RenderAction *_pRenderAction;
395 Matrix _cameraProjection;
396 Matrix _cameraProjectionTrans;
397 Matrix _cameraViewing;
398 Matrix _cameraToWorld;
399 Matrix _cameraDecoration;
401 Matrix _objectToWorld;
402 Matrix _worldToScreen;
404 Matrix _vpCameraFullProjection;
405 Matrix _vpCameraProjection;
406 Matrix _vpCameraProjectionTrans;
407 Matrix _vpCameraViewing;
408 Matrix _vpCameraToWorld;
409 Matrix _vpWorldToScreen;
411 Real32 _cameraNear;
412 Real32 _cameraFar;
414 Int32 _iPixelLeft;
415 Int32 _iPixelRight;
416 Int32 _iPixelBottom;
417 Int32 _iPixelTop;
419 Vec2u _uiTileFullSize;
420 Vec4f _vTileRegion;
422 bool _bFull;
424 Int32 _iDrawerId;
425 Int32 _iDrawableId;
427 UInt32 _uiLightState;
429 Window *_pWindow;
430 Node *_pSGNode;
432 State *_pActiveState;
433 StateOverride *_pActiveStateOverride;
435 UInt32 _uiNumStateChanges;
436 UInt32 _uiNumChunkChanges;
437 UInt32 _uiNumShaderChanges;
438 UInt32 _uiNumShaderParamChanges;
440 StatCollector *_pStatCollector;
442 GLenum _aActiveTexTargets[osgMaxTexImages];
443 UInt32 _uiActiveShader;
444 UInt32 _uiActiveFBO;
445 GLenum _eTargetBufferFormat;
446 UInt32 _uiRequiredOGLFeature;
448 /*! \} */
449 /*---------------------------------------------------------------------*/
450 /*! \name Destructor */
451 /*! \{ */
453 void activate (State *pState );
454 void activate (State *pState,
455 StateOverride *pOverride );
457 void changeTo (State *pState,
458 State *old );
460 void changeTo (State *pState,
461 State *old,
462 StateOverride *oldOverride);
464 void changeTo (State *pState,
465 StateOverride *pOverride,
466 State *old);
468 void changeTo (State *pState,
469 StateOverride *pOverride,
470 State *old,
471 StateOverride *oldOverride );
473 void deactivate(State *pState);
474 void deactivate(State *pState,
475 StateOverride *pOverride );
477 void update (State *pState);
478 void update (State *pState,
479 StateOverride *pOverride );
480 void updateChunk(State *pState);
481 void updateChunk(State *pState,
482 StateOverride *pOverride);
485 /*! \} */
486 /*---------------------------------------------------------------------*/
487 /*! \name Destructor */
488 /*! \{ */
490 void setAction(RenderAction *pAction);
491 RenderAction *getAction(void ) const;
493 template<class Action, class Result>
494 static Result doGetData(Action *pA, UInt32 iSlotId);
496 /*! \} */
497 /*========================== PRIVATE ================================*/
499 private:
501 friend class RenderPartition;
503 /*! \brief prohibit default function (move to 'public' if needed) */
504 DrawEnv(const DrawEnv &source);
505 /*! \brief prohibit default function (move to 'public' if needed) */
506 void operator =(const DrawEnv &source);
509 OSG_END_NAMESPACE
511 #include "OSGDrawEnv.inl"
513 #endif /* _OSGDRAWENV_H_ */