00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include "nvsg/nvsg.h"
00018 #include "nvsg/Camera.h"
00019
00020 namespace nvsg
00021 {
00022 class CullData;
00023
00025 class ViewState : public nvutil::RCObject
00026 , public nvutil::ISWMRSync
00027 {
00028 public:
00030
00031 NVSG_API static const ViewState * create();
00032
00034
00037 NVSG_API const ViewState * clone() const;
00038
00040
00041 NVSG_API size_t getAnimationFrame( void ) const;
00042
00044
00045 NVSG_API const Camera * getCamera( void ) const;
00046
00048
00049 NVSG_API bool isAnimating( void ) const;
00050
00052
00053 NVSG_API bool isStereo( void ) const;
00054
00056 NVSG_API void setAnimationFrame( size_t frame
00057 );
00058
00060 NVSG_API void setAnimation( bool state
00061 );
00062
00064 NVSG_API void setCamera( const Camera * pCamera
00065 );
00066
00068 NVSG_API void setStereo( bool state
00069 );
00070
00072 NVSG_API void clearCullTree( void ) const ;
00073
00075 NVSG_API const CullData * getCullTree( void ) const;
00076
00078 NVSG_API void setCullTree( const CullData *cullTree );
00079
00081
00087 NVSG_API bool waitToRead( size_t milliseconds = 0xFFFFFFFF
00088 ) const;
00089
00091
00093 NVSG_API void doneReading( void ) const;
00094
00096
00102 NVSG_API bool waitToWrite( size_t milliseconds = 0xFFFFFFFF
00103 ) const;
00104
00106
00108 NVSG_API void doneWriting( void ) const;
00109
00110 protected:
00112
00113 NVSG_API ViewState( void );
00114
00116
00118 NVSG_API ViewState( const ViewState& rhs );
00119
00121 NVSG_API virtual ~ViewState(void);
00122
00123 private:
00124
00125 ViewState& operator=(const ViewState&);
00126
00127 private:
00128 size_t m_animationFrame;
00129 const Camera * m_camera;
00130 bool m_stereoState;
00131
00132
00133 volatile bool m_animationState;
00134
00135 mutable const CullData * m_cullTree;
00136
00137 nvutil::SWMRSync m_lock;
00138 };
00139
00140
00141 inline size_t ViewState::getAnimationFrame( void ) const
00142 {
00143 return( m_animationFrame );
00144 }
00145
00146 inline bool ViewState::isAnimating( void ) const
00147 {
00148 return( m_animationState );
00149 }
00150
00151 inline const Camera * ViewState::getCamera( void ) const
00152 {
00153 return( m_camera );
00154 }
00155
00156 inline bool ViewState::isStereo( void ) const
00157 {
00158 return( m_stereoState );
00159 }
00160
00161 inline void ViewState::setAnimationFrame( size_t frame )
00162 {
00163 if ( m_animationFrame != frame )
00164 {
00165 m_animationFrame = frame;
00166 }
00167 }
00168
00169 inline void ViewState::setAnimation( bool state )
00170 {
00171 m_animationState = state;
00172 }
00173
00174 inline void ViewState::setCamera( const Camera * pCamera )
00175 {
00176 if ( m_camera != pCamera )
00177 {
00178 if ( m_camera )
00179 {
00180 m_camera->removeRef();
00181 }
00182 m_camera = pCamera;
00183 if ( m_camera )
00184 {
00185 m_camera->addRef();
00186 }
00187 }
00188 }
00189
00190 inline void ViewState::setStereo( bool state )
00191 {
00192 m_stereoState = state;
00193 }
00194
00195 inline const CullData * ViewState::getCullTree( void ) const
00196 {
00197 return( m_cullTree );
00198 }
00199
00200 inline void ViewState::setCullTree( const CullData *cullTree )
00201 {
00202 clearCullTree();
00203 m_cullTree = cullTree;
00204 }
00205
00206 inline bool ViewState::waitToRead( size_t milliseconds ) const
00207 {
00208 size_t status;
00209 return m_lock.waitToRead(milliseconds, status);
00210 }
00211
00212 inline void ViewState::doneReading( void ) const
00213 {
00214 m_lock.doneReading();
00215 }
00216
00217 inline bool ViewState::waitToWrite( size_t milliseconds ) const
00218 {
00219 size_t status;
00220 return m_lock.waitToWrite(milliseconds, status);
00221 }
00222
00223 inline void ViewState::doneWriting( void ) const
00224 {
00225 m_lock.doneWriting();
00226 }
00227 }