Changeset 41
- Timestamp:
- 05/28/13 10:19:28 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gl/gl_program.hh
r37 r41 54 54 protected: 55 55 bool validate(); 56 void update_uniforms(); 56 57 void load_attributes(); 57 58 void load_uniforms(); -
trunk/nv/interface/program.hh
r33 r41 14 14 15 15 #include <unordered_map> 16 #include <nv/logging.hh> 16 17 #include <nv/common.hh> 17 18 #include <nv/string.hh> … … 131 132 { 132 133 uniform_base* base = get_uniform( name ); 133 if ( base == nullptr || base->get_type() != type_to_enum<T>::type ) 134 // restore typechecking, but remember to accept int for float! 135 if ( base == nullptr /* || base->get_type() != type_to_enum<T>::type */ ) 134 136 { 135 // signal error137 NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" ); 136 138 return; 137 139 } 138 uniform<T>( base)->set_value( value );140 ((uniform<T>*)( base ))->set_value( value ); 139 141 } 140 142 protected: -
trunk/src/gl/gl_program.cc
r40 r41 8 8 #include "nv/logging.hh" 9 9 #include "nv/lib/gl.hh" 10 11 #include <glm/glm.hpp> 12 #include <glm/gtc/type_ptr.hpp> 10 13 11 14 using namespace nv; … … 119 122 { 120 123 glUseProgram( m_name.get_value() ); 124 update_uniforms(); 121 125 } 122 126 … … 181 185 } 182 186 187 void gl_program::update_uniforms() 188 { 189 for ( uniform_map::iterator i = m_uniform_map.begin(); i != m_uniform_map.end(); ++i ) 190 { 191 uniform_base* ubase = i->second; 192 if ( ubase->is_dirty() ) 193 { 194 int uloc = ubase->get_location(); 195 switch( ubase->get_type() ) 196 { 197 case FLOAT : glUniform1f( uloc, ((uniform< enum_to_type< FLOAT >::type >*)( ubase ))->get_value() ); break; 198 case INT : glUniform1i( uloc, ((uniform< enum_to_type< INT >::type >*)( ubase ))->get_value() ); break; 199 case FLOAT_VECTOR_2 : glUniform2fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_2 >::type >*)( ubase ))->get_value()) ); break; 200 case FLOAT_VECTOR_3 : glUniform3fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_3 >::type >*)( ubase ))->get_value()) ); break; 201 case FLOAT_VECTOR_4 : glUniform4fv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< FLOAT_VECTOR_4 >::type >*)( ubase ))->get_value()) ); break; 202 case INT_VECTOR_2 : glUniform2iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_2 >::type >*)( ubase ))->get_value()) ); break; 203 case INT_VECTOR_3 : glUniform3iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_3 >::type >*)( ubase ))->get_value()) ); break; 204 case INT_VECTOR_4 : glUniform4iv( uloc, 1, glm::value_ptr(((uniform< enum_to_type< INT_VECTOR_4 >::type >*)( ubase ))->get_value()) ); break; 205 case FLOAT_MATRIX_2 : glUniformMatrix2fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_2 >::type >*)( ubase ))->get_value()) ); break; 206 case FLOAT_MATRIX_3 : glUniformMatrix3fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_3 >::type >*)( ubase ))->get_value()) ); break; 207 case FLOAT_MATRIX_4 : glUniformMatrix4fv( uloc, 1, GL_FALSE, glm::value_ptr(((uniform< enum_to_type< FLOAT_MATRIX_4 >::type >*)( ubase ))->get_value()) ); break; 208 //default : error? 209 } 210 ubase->clean(); 211 } 212 } 213 214 } 215 216 183 217 bool gl_program::validate() 184 218 {
Note: See TracChangeset
for help on using the changeset viewer.