Ignore:
Timestamp:
05/28/13 10:19:28 (12 years ago)
Author:
epyon
Message:
  • proper uniform binding implemented
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_program.cc

    r40 r41  
    88#include "nv/logging.hh"
    99#include "nv/lib/gl.hh"
     10
     11#include <glm/glm.hpp>
     12#include <glm/gtc/type_ptr.hpp>
    1013
    1114using namespace nv;
     
    119122{
    120123        glUseProgram( m_name.get_value() );
     124        update_uniforms();
    121125}
    122126
     
    181185}
    182186
     187void 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
    183217bool gl_program::validate()
    184218{
Note: See TracChangeset for help on using the changeset viewer.