Changeset 41 for trunk


Ignore:
Timestamp:
05/28/13 10:19:28 (12 years ago)
Author:
epyon
Message:
  • proper uniform binding implemented
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gl/gl_program.hh

    r37 r41  
    5454        protected:
    5555                bool validate();
     56                void update_uniforms();
    5657                void load_attributes();
    5758                void load_uniforms();
  • trunk/nv/interface/program.hh

    r33 r41  
    1414
    1515#include <unordered_map>
     16#include <nv/logging.hh>
    1617#include <nv/common.hh>
    1718#include <nv/string.hh>
     
    131132                {
    132133                        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 */ )
    134136                        {
    135                                 // signal error
     137                                NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
    136138                                return;
    137139                        }
    138                         uniform<T>( base )->set_value( value );
     140                        ((uniform<T>*)( base ))->set_value( value );
    139141                }
    140142        protected:
  • 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.