Changeset 235 for trunk/src


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/src/gl/gl_program.cc

    r232 r235  
    106106        if (!fragment_shader.compile( fragment_program )) { return false; }
    107107
    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");
    113115
    114116        glAttachShader( m_name.get_value(), fragment_shader.get_id() );
     
    181183
    182184                string name( name_buffer, size_t(uni_nlen) );
    183 
     185               
    184186                // skip built-ins
    185187                if ( name.substr(0,3) == "gl_" ) continue;
     
    187189                int uni_loc = glGetUniformLocation( m_name.get_value(), name.c_str() );
    188190                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
    189199                m_uniform_map[ name ] = create_uniform( utype, name, uni_loc, uni_len );
    190200        }
     
    204214                        switch( ubase->get_type() )
    205215                        {
    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;
    217227                        default : break; // error?
    218228                        }
Note: See TracChangeset for help on using the changeset viewer.