Ignore:
Timestamp:
05/12/14 16:52:16 (11 years ago)
Author:
epyon
Message:
  • camera class extension
  • additional built-in uniforms added
  • support for uniform arrays
  • BONEINDEX and BONEWEIGHT built in attributes added
  • i16vec's added to math
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/uniform.hh

    r232 r235  
    3232                bool is_dirty() const { return m_dirty; }
    3333                void clean() { m_dirty = false; }
     34                virtual ~uniform_base() {}
    3435        protected:
    3536                string   m_name;
     
    4748
    4849                uniform( const string& name, int location, int length )
    49                         : uniform_base( name, type_to_enum< T >::type, location, length ), m_value()
    50                 {}
     50                        : uniform_base( name, type_to_enum< T >::type, location, length ), m_value( nullptr )
     51                {
     52                        m_value = new T[ m_length ];
     53                }
    5154
    5255                void set_value( const T& value )
    5356                {
    54                         if ( value != m_value )
     57                        NV_ASSERT( m_length == 1, "set_value on array uniform!" );
     58                        if ( value != m_value[0] )
    5559                        {
    56                                 m_value = value;
     60                                m_value[0] = value;
    5761                                m_dirty = true;
    5862                        }
    5963                }
    6064
    61                 const T& get_value() { return m_value; }
     65                void set_value( const T* value, uint32 count )
     66                {
     67                        // TODO: memcmp?
     68                        std::copy( value, value + count, m_value );
     69                        m_dirty = true;
     70                }
     71
     72                const T* get_value() { return m_value; }
     73                virtual ~uniform()
     74                {
     75                        delete[] m_value;
     76                }
    6277        protected:
    63                 T m_value;
     78                T* m_value;
    6479        };
    6580
     
    145160        };
    146161
     162        class engine_uniform_m_model_inv : public engine_uniform< mat4 >
     163        {
     164        public:
     165                engine_uniform_m_model_inv( uniform_base* u ) : engine_uniform( u ) {}
     166                virtual void set( const context* , const scene_state* s ) { m_uniform->set_value( s->get_model_inv() ); }
     167        };
     168
    147169        class engine_uniform_m_modelview : public engine_uniform< mat4 >
    148170        {
     
    173195        };
    174196
     197        class engine_uniform_v_camera_position : public engine_uniform< vec3 >
     198        {
     199        public:
     200                engine_uniform_v_camera_position( uniform_base* u ) : engine_uniform( u ) {}
     201                virtual void set( const context* , const scene_state* s ) { m_uniform->set_value( s->get_camera().get_position() ); }
     202        };
     203
     204        class engine_uniform_v_camera_direction : public engine_uniform< vec3 >
     205        {
     206        public:
     207                engine_uniform_v_camera_direction( uniform_base* u ) : engine_uniform( u ) {}
     208                virtual void set( const context* , const scene_state* s ) { m_uniform->set_value( s->get_camera().get_direction() ); }
     209        };
     210
    175211        template< int VALUE >
    176212        class engine_link_uniform_int : public engine_link_uniform< int >
Note: See TracChangeset for help on using the changeset viewer.