Changeset 50


Ignore:
Timestamp:
05/28/13 22:29:08 (12 years ago)
Author:
epyon
Message:
  • error checking for attribute and uniform queries
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/interface/program.hh

    r41 r50  
    1515#include <unordered_map>
    1616#include <nv/logging.hh>
     17#include <nv/exception.hh>
    1718#include <nv/common.hh>
    1819#include <nv/string.hh>
     
    108109                                        i != m_uniform_map.end(); ++i ) delete i->second;
    109110                }
     111                attribute* try_get_attribute( const string& name ) const
     112                {
     113                        attribute_map::const_iterator i = m_attribute_map.find( name );
     114                        if ( i != m_attribute_map.end() )
     115                        {
     116                                return i->second;
     117                        }
     118                        return nullptr;
     119                }
     120
    110121                attribute* get_attribute( const string& name ) const
    111122                {
    112123                        attribute_map::const_iterator i = m_attribute_map.find( name );
    113124                        if ( i != m_attribute_map.end() )
     125                        {
     126                                return i->second;
     127                        }
     128                        NV_LOG( LOG_ERROR, "Attribute '" << name << "' not found in program!" );
     129                        throw runtime_error( "Attribute '"+name+"' not found!" );
     130                }
     131
     132                uniform_base* try_get_uniform( const string& name ) const
     133                {
     134                        uniform_map::const_iterator i = m_uniform_map.find( name );
     135                        if ( i != m_uniform_map.end() )
    114136                        {
    115137                                return i->second;
     
    125147                                return i->second;
    126148                        }
    127                         return nullptr;
     149                        NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
     150                        throw runtime_error( "Uniform '"+name+"' not found!" );
    128151                }
    129152
     
    133156                        uniform_base* base = get_uniform( name );
    134157                        // restore typechecking, but remember to accept int for float!
    135                         if ( base == nullptr /* || base->get_type() != type_to_enum<T>::type */ )
    136                         {
    137                                 NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
    138                                 return;
    139                         }
     158                        // if ( /* base->get_type() != type_to_enum<T>::type */ )
     159                        // {
     160                        //              NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
     161                        //              return;
     162                        // }
    140163                        ((uniform<T>*)( base ))->set_value( value );
    141164                }
  • trunk/tests/render_test/rl.cc

    r49 r50  
    186186        va = m_device->create_vertex_array();
    187187
    188         nv::attribute* a;
    189         a = p->get_attribute( "coords" ); if (a == nullptr) return false;
    190188        nv::vertex_buffer* vbcoords   = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), vertex );
    191         va->add_vertex_buffer( a->get_location(), vbcoords, nv::BYTE, 3 );
    192 
    193         a = p->get_attribute( "material" ); if (a == nullptr) return false;
     189        va->add_vertex_buffer( p->get_attribute( "coords" )->get_location(), vbcoords, nv::BYTE, 3 );
    194190        nv::vertex_buffer* vbmaterial = m_device->create_vertex_buffer( nv::STATIC_DRAW, count*sizeof(byte3), material );
    195         va->add_vertex_buffer( a->get_location(), vbmaterial, nv::BYTE, 3 );
     191        va->add_vertex_buffer( p->get_attribute( "material" )->get_location(), vbmaterial, nv::BYTE, 3 );
    196192
    197193        return true;
Note: See TracChangeset for help on using the changeset viewer.