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 #ifndef _OSGDRAWENV_H_
40 #define _OSGDRAWENV_H_
46 #include "OSGBaseTypes.h"
47 #include "OSGSystemDef.h"
48 #include "OSGMatrix.h"
50 #include "OSGStatCollector.h"
51 #include "OSGContainerForwards.h"
53 #include <boost/function.hpp>
57 class RenderActionBase
;
59 class RenderPartition
;
64 /*! \ingroup GrpSystemRenderingBackendBase
65 \ingroup GrpLibOSGSystem
67 \brief Old OpenGL State Uniforms so this can be passed to the shader.
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;
82 /*---------------------------------------------------------------------*/
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;
98 /*---------------------------------------------------------------------*/
99 /*! \name Constructors */
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 );
112 /*---------------------------------------------------------------------*/
113 /*! \name Constructors */
119 /*---------------------------------------------------------------------*/
120 /*! \name Destructor */
123 virtual ~OpenGLState(void);
127 /*========================= PROTECTED ===============================*/
131 /*---------------------------------------------------------------------*/
135 #ifdef OSG_OGL_COREONLY
136 Matrix _mModelViewProjection
;
137 Matrix _mNormalMatrix
;
142 UInt8 _uiTransformFeedback
;
145 /*========================== 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 =================================*/
165 /*---------------------------------------------------------------------*/
169 typedef RenderFunctor DrawFunctor
;
172 /*---------------------------------------------------------------------*/
176 OpenGLState _openGLState
;
179 /*---------------------------------------------------------------------*/
180 /*! \name Statistic */
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
,
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
);
211 /*---------------------------------------------------------------------*/
215 const Matrix
&getCameraProjection (void ) const;
216 const Matrix
&getCameraProjectionTrans(void ) const;
217 const Matrix
&getCameraDecoration (void ) const;
219 const Matrix
&getCameraViewing (void ) const;
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;
237 /*---------------------------------------------------------------------*/
241 void setStatCollector(StatCollector
*pStatCollector
);
242 StatCollector
*getStatCollector(void );
245 /*---------------------------------------------------------------------*/
249 const Matrix
&getVPCameraFullProjection (void ) const;
250 const Matrix
&getVPCameraProjection (void ) const;
251 const Matrix
&getVPCameraProjectionTrans(void ) const;
253 const Matrix
&getVPCameraViewing (void ) const;
256 const Matrix
&getVPCameraToWorld (void ) const;
258 const Matrix
&getVPWorldToScreen (void ) const;
261 /*---------------------------------------------------------------------*/
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 );
275 /*---------------------------------------------------------------------*/
276 /*! \name Constructors */
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);
290 /*---------------------------------------------------------------------*/
291 /*! \name Constructors */
294 void clearState(void);
296 void activateState (State
*pNewState
,
297 StateOverride
*pNewStateOverride
);
299 void deactivateState(void);
302 /*---------------------------------------------------------------------*/
303 /*! \name Constructors */
306 void setViewportDimension(Int32 iPixelLeft
,
312 void calcViewportDimension(Real32 rLeft
,
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;
331 /*---------------------------------------------------------------------*/
332 /*! \name Constructors */
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;
344 /*---------------------------------------------------------------------*/
345 /*! \name Constructors */
348 Int32
getDrawerId (void ) const;
349 void setDrawerId (Int32 iId
);
351 Int32
getDrawableId(void ) const;
352 void setDrawableId(Int32 iId
);
355 /*---------------------------------------------------------------------*/
356 /*! \name Constructors */
359 void setLightState(UInt32 uiState
);
360 UInt32
getLightState(void );
363 /*---------------------------------------------------------------------*/
364 /*! \name Constructors */
367 template<class ValuePtr
>
368 ValuePtr
getData(Int32 iSlotId
) const;
371 /*---------------------------------------------------------------------*/
372 /*! \name Constructors */
378 /*---------------------------------------------------------------------*/
379 /*! \name Destructor */
382 virtual ~DrawEnv(void);
385 /*========================= PROTECTED ===============================*/
389 /*---------------------------------------------------------------------*/
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
;
419 Vec2u _uiTileFullSize
;
427 UInt32 _uiLightState
;
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
;
445 GLenum _eTargetBufferFormat
;
446 UInt32 _uiRequiredOGLFeature
;
449 /*---------------------------------------------------------------------*/
450 /*! \name Destructor */
453 void activate (State
*pState
);
454 void activate (State
*pState
,
455 StateOverride
*pOverride
);
457 void changeTo (State
*pState
,
460 void changeTo (State
*pState
,
462 StateOverride
*oldOverride
);
464 void changeTo (State
*pState
,
465 StateOverride
*pOverride
,
468 void changeTo (State
*pState
,
469 StateOverride
*pOverride
,
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
);
486 /*---------------------------------------------------------------------*/
487 /*! \name Destructor */
490 void setAction(RenderAction
*pAction
);
491 RenderAction
*getAction(void ) const;
493 template<class Action
, class Result
>
494 static Result
doGetData(Action
*pA
, UInt32 iSlotId
);
497 /*========================== 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
);
511 #include "OSGDrawEnv.inl"
513 #endif /* _OSGDRAWENV_H_ */