Changeset 235
- Timestamp:
- 05/12/14 16:52:16 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/interface/camera.hh
r232 r235 25 25 void set_lookat( const vec3& eye, const vec3& focus, const vec3& up ) 26 26 { 27 m_view = glm::lookAt( eye, focus, up ); 27 m_view = glm::lookAt( eye, focus, up ); 28 m_position = eye; 29 m_direction = glm::normalize( focus - eye ); 28 30 } 29 31 … … 40 42 return m_view; 41 43 } 44 const vec3& get_position() const 45 { 46 return m_position; 47 } 48 const vec3& get_direction() const 49 { 50 return m_direction; 51 } 42 52 private: 43 53 bool m_dirty; 54 vec3 m_position; 55 vec3 m_direction; 44 56 mat4 m_projection; 45 57 mat4 m_view; … … 62 74 63 75 mat4 get_view_inv() const { return glm::inverse( get_view() ); } 76 mat4 get_model_inv() const { return glm::inverse( get_model() ); } 64 77 mat3 get_normal() const { return glm::transpose(glm::inverse(glm::mat3( get_modelview() ) ) ); } 65 78 protected: -
trunk/nv/interface/program.hh
r232 r235 27 27 enum slot 28 28 { 29 POSITION = 0, 30 TEXCOORD = 1, 31 NORMAL = 2, 32 COLOR = 3, 33 TANGENT = 4, 29 POSITION = 0, 30 TEXCOORD = 1, 31 NORMAL = 2, 32 TANGENT = 3, 33 BONEINDEX = 4, 34 BONEWEIGHT = 5, 35 COLOR = 6, 34 36 }; 35 37 … … 95 97 } 96 98 97 attribute* get_attribute( const string& name ) const99 int try_get_attribute_location( const string& name ) const 98 100 { 99 101 attribute_map::const_iterator i = m_attribute_map.find( name ); 100 102 if ( i != m_attribute_map.end() ) 101 103 { 104 return i->second->get_location(); 105 } 106 return -1; 107 } 108 109 attribute* get_attribute( const string& name ) const 110 { 111 attribute_map::const_iterator i = m_attribute_map.find( name ); 112 if ( i != m_attribute_map.end() ) 113 { 102 114 return i->second; 103 115 } … … 128 140 129 141 template < typename T > 142 void set_uniform_array( const string& name, const T* value, uint32 count ) 143 { 144 uniform_base* base = get_uniform( name ); 145 // restore typechecking, but remember to accept int for float! 146 // if ( /* base->get_type() != type_to_enum<T>::type */ ) 147 // { 148 // NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" ); 149 // return; 150 // } 151 // TODO: nicer check 152 NV_ASSERT( count <= base->get_length(), "LENGTH CHECK FAIL" ); 153 ((uniform<T>*)( base ))->set_value( value, count ); 154 } 155 156 template < typename T > 157 void set_uniform_array( const string& name, const std::vector<T>& value ) 158 { 159 uniform_base* base = get_uniform( name ); 160 // restore typechecking, but remember to accept int for float! 161 // if ( /* base->get_type() != type_to_enum<T>::type */ ) 162 // { 163 // NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" ); 164 // return; 165 // } 166 // TODO: nicer check 167 NV_ASSERT( (int)value.size() <= base->get_length(), "LENGTH CHECK FAIL" ); 168 ((uniform<T>*)( base ))->set_value( value.data(), value.size() ); 169 } 170 171 template < typename T > 172 void set_opt_uniform_array( const string& name, const T* value, uint32 count ) 173 { 174 uniform_base* base = get_uniform( name ); 175 if (!base) return; 176 // restore typechecking, but remember to accept int for float! 177 // if ( /* base->get_type() != type_to_enum<T>::type */ ) 178 // { 179 // NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" ); 180 // return; 181 // } 182 // TODO: nicer check 183 NV_ASSERT( (int)count <= base->get_length(), "LENGTH CHECK FAIL" ); 184 ((uniform<T>*)( base ))->set_value( value, count ); 185 } 186 187 template < typename T > 188 void set_opt_uniform_array( const string& name, const std::vector<T>& value ) 189 { 190 uniform_base* base = try_get_uniform( name ); 191 if (!base) return; 192 // restore typechecking, but remember to accept int for float! 193 // if ( /* base->get_type() != type_to_enum<T>::type */ ) 194 // { 195 // NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" ); 196 // return; 197 // } 198 // TODO: nicer check 199 NV_ASSERT( (int)value.size() <= base->get_length(), "LENGTH CHECK FAIL" ); 200 ((uniform<T>*)( base ))->set_value( value.data(), value.size() ); 201 } 202 203 204 template < typename T > 130 205 void set_uniform( const string& name, const T& value ) 131 206 { 132 uniform_base* base = get_uniform( name );207 uniform_base* base = try_get_uniform( name ); 133 208 // restore typechecking, but remember to accept int for float! 134 209 // if ( /* base->get_type() != type_to_enum<T>::type */ ) … … 209 284 factory_map[ "nv_m_view" ] = new engine_uniform_factory< engine_uniform_m_view >(); 210 285 factory_map[ "nv_m_view_inv" ] = new engine_uniform_factory< engine_uniform_m_view_inv >(); 211 factory_map[ "nv_m_view" ] = new engine_uniform_factory< engine_uniform_m_view >();212 286 factory_map[ "nv_m_model" ] = new engine_uniform_factory< engine_uniform_m_model >(); 287 factory_map[ "nv_m_model_inv" ] = new engine_uniform_factory< engine_uniform_m_model_inv >(); 213 288 factory_map[ "nv_m_modelview" ] = new engine_uniform_factory< engine_uniform_m_modelview >(); 214 289 factory_map[ "nv_m_projection" ] = new engine_uniform_factory< engine_uniform_m_projection >(); 215 290 factory_map[ "nv_m_normal" ] = new engine_uniform_factory< engine_uniform_m_normal >(); 216 291 factory_map[ "nv_m_mvp" ] = new engine_uniform_factory< engine_uniform_m_mvp >(); 292 factory_map[ "nv_v_camera_position" ] = new engine_uniform_factory< engine_uniform_v_camera_position >(); 293 factory_map[ "nv_v_camera_direction" ] = new engine_uniform_factory< engine_uniform_v_camera_direction >(); 217 294 218 295 engine_link_uniform_factory_map& factory_link_map = get_link_uniform_factory(); -
trunk/nv/interface/uniform.hh
r232 r235 32 32 bool is_dirty() const { return m_dirty; } 33 33 void clean() { m_dirty = false; } 34 virtual ~uniform_base() {} 34 35 protected: 35 36 string m_name; … … 47 48 48 49 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 } 51 54 52 55 void set_value( const T& value ) 53 56 { 54 if ( value != m_value ) 57 NV_ASSERT( m_length == 1, "set_value on array uniform!" ); 58 if ( value != m_value[0] ) 55 59 { 56 m_value = value;60 m_value[0] = value; 57 61 m_dirty = true; 58 62 } 59 63 } 60 64 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 } 62 77 protected: 63 T m_value;78 T* m_value; 64 79 }; 65 80 … … 145 160 }; 146 161 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 147 169 class engine_uniform_m_modelview : public engine_uniform< mat4 > 148 170 { … … 173 195 }; 174 196 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 175 211 template< int VALUE > 176 212 class engine_link_uniform_int : public engine_link_uniform< int > -
trunk/nv/math.hh
r229 r235 27 27 typedef glm::detail::tvec3<sint8> i8vec3; 28 28 typedef glm::detail::tvec4<sint8> i8vec4; 29 30 typedef glm::detail::tvec2<sint16> i16vec2; 31 typedef glm::detail::tvec3<sint16> i16vec3; 32 typedef glm::detail::tvec4<sint16> i16vec4; 29 33 30 34 typedef glm::vec2 vec2; -
trunk/src/gl/gl_program.cc
r232 r235 106 106 if (!fragment_shader.compile( fragment_program )) { return false; } 107 107 108 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::POSITION ), "nv_position" ); 109 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TEXCOORD ), "nv_texcoord" ); 110 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::NORMAL ), "nv_normal" ); 111 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::COLOR ), "nv_color" ); 112 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TANGENT ), "nv_tangent" ); 108 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::POSITION ), "nv_position" ); 109 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TEXCOORD ), "nv_texcoord" ); 110 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::NORMAL ), "nv_normal" ); 111 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::COLOR ), "nv_color" ); 112 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::TANGENT ), "nv_tangent" ); 113 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEINDEX ), "nv_boneindex" ); 114 glBindAttribLocation( m_name.get_value(), static_cast<GLuint>( slot::BONEWEIGHT ), "nv_boneweight"); 113 115 114 116 glAttachShader( m_name.get_value(), fragment_shader.get_id() ); … … 181 183 182 184 string name( name_buffer, size_t(uni_nlen) ); 183 185 184 186 // skip built-ins 185 187 if ( name.substr(0,3) == "gl_" ) continue; … … 187 189 int uni_loc = glGetUniformLocation( m_name.get_value(), name.c_str() ); 188 190 datatype utype = gl_enum_to_datatype( uni_type ); 191 192 // check for array 193 string::size_type arrchar = name.find('['); 194 if ( arrchar != string::npos ) 195 { 196 name = name.substr( 0, arrchar ); 197 } 198 189 199 m_uniform_map[ name ] = create_uniform( utype, name, uni_loc, uni_len ); 190 200 } … … 204 214 switch( ubase->get_type() ) 205 215 { 206 case FLOAT : glUniform1f ( uloc, ((uniform< enum_to_type< FLOAT >::type >*)( ubase ))->get_value() ); break;207 case INT : glUniform1i ( uloc, ((uniform< enum_to_type< INT >::type >*)( ubase ))->get_value() ); break;208 case FLOAT_VECTOR_2 : glUniform2fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_2 >::type >*)( ubase ))->get_value())); break;209 case FLOAT_VECTOR_3 : glUniform3fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_3 >::type >*)( ubase ))->get_value())); break;210 case FLOAT_VECTOR_4 : glUniform4fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_4 >::type >*)( ubase ))->get_value())); break;211 case INT_VECTOR_2 : glUniform2iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_2 >::type >*)( ubase ))->get_value())); break;212 case INT_VECTOR_3 : glUniform3iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_3 >::type >*)( ubase ))->get_value())); break;213 case INT_VECTOR_4 : glUniform4iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_4 >::type >*)( ubase ))->get_value())); break;214 case FLOAT_MATRIX_2 : glUniformMatrix2fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_2 >::type >*)( ubase ))->get_value())); break;215 case FLOAT_MATRIX_3 : glUniformMatrix3fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_3 >::type >*)( ubase ))->get_value())); break;216 case FLOAT_MATRIX_4 : glUniformMatrix4fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_4 >::type >*)( ubase ))->get_value())); break;216 case FLOAT : glUniform1fv( uloc, ubase->get_length(), ((uniform< enum_to_type< FLOAT >::type >*)( ubase ))->get_value() ); break; 217 case INT : glUniform1iv( uloc, ubase->get_length(), ((uniform< enum_to_type< INT >::type >*)( ubase ))->get_value() ); break; 218 case FLOAT_VECTOR_2 : glUniform2fv( uloc, ubase->get_length(), (GLfloat*)((uniform< enum_to_type< FLOAT_VECTOR_2 >::type >*)( ubase ))->get_value()); break; 219 case FLOAT_VECTOR_3 : glUniform3fv( uloc, ubase->get_length(), (GLfloat*)((uniform< enum_to_type< FLOAT_VECTOR_3 >::type >*)( ubase ))->get_value()); break; 220 case FLOAT_VECTOR_4 : glUniform4fv( uloc, ubase->get_length(), (GLfloat*)((uniform< enum_to_type< FLOAT_VECTOR_4 >::type >*)( ubase ))->get_value()); break; 221 case INT_VECTOR_2 : glUniform2iv( uloc, ubase->get_length(), (GLint*)((uniform< enum_to_type< INT_VECTOR_2 >::type >*)( ubase ))->get_value()); break; 222 case INT_VECTOR_3 : glUniform3iv( uloc, ubase->get_length(), (GLint*)((uniform< enum_to_type< INT_VECTOR_3 >::type >*)( ubase ))->get_value()); break; 223 case INT_VECTOR_4 : glUniform4iv( uloc, ubase->get_length(), (GLint*)((uniform< enum_to_type< INT_VECTOR_4 >::type >*)( ubase ))->get_value()); break; 224 case FLOAT_MATRIX_2 : glUniformMatrix2fv( uloc, ubase->get_length(), GL_FALSE, (GLfloat*)((uniform< enum_to_type< FLOAT_MATRIX_2 >::type >*)( ubase ))->get_value()); break; 225 case FLOAT_MATRIX_3 : glUniformMatrix3fv( uloc, ubase->get_length(), GL_FALSE, (GLfloat*)((uniform< enum_to_type< FLOAT_MATRIX_3 >::type >*)( ubase ))->get_value()); break; 226 case FLOAT_MATRIX_4 : glUniformMatrix4fv( uloc, ubase->get_length(), GL_FALSE, (GLfloat*)((uniform< enum_to_type< FLOAT_MATRIX_4 >::type >*)( ubase ))->get_value()); break; 217 227 default : break; // error? 218 228 }
Note: See TracChangeset
for help on using the changeset viewer.