attribute_bindings.cpp

Go to the documentation of this file.
00001 /*
00002     RenderStack  Support library for OpenGL 3+
00003     Copyright (C) 2010  Timo Suoranta
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00027 #include "renderstack/attribute_bindings.hpp"
00028 #include "renderstack/program.hpp"
00029 #include "renderstack/mesh.hpp"
00030 #include "renderstack/rs_gl.h"
00031 
00032 namespace renderstack {
00033 
00034 void attribute_mappings::bind_attributes(
00035     class attribute_bindings    &bindings,
00036     class program const         &program, 
00037     class mesh const            &mesh
00038 ) const
00039 {
00040     for(
00041         std::vector<std::tr1::shared_ptr<attribute_mapping> >::const_iterator i = m_mappings.begin();
00042         i != m_mappings.end();
00043         ++i
00044     )
00045     {
00046         class vertex_format const &vertex_format = mesh.vertex_buffer()->vertex_format();
00047 
00048         std::tr1::shared_ptr<attribute_mapping> mapping = *i;
00049 
00050         if(
00051             (program.has_attribute(mapping->name) == true) &&
00052             (vertex_format.has_attribute(mapping->usage, mapping->index) == true)
00053         )
00054         {
00055             class vertex_attribute const &vertex_attribute = vertex_format.attribute(mapping->usage, mapping->index);
00056 
00057             bindings.add(
00058                 program.attribute(mapping->name).gl_slot(),     /*  index       */ 
00059                 vertex_attribute.dimension(),                   /*  size        */ 
00060                 vertex_attribute.gl_type_code(),                /*  type        */ 
00061                 GL_FALSE,                                       /*  normalized  */ 
00062                 vertex_format.stride(),                         /*  stride      */ 
00063                 reinterpret_cast<const ::GLvoid *>(             /*  pointer     */ 
00064                     vertex_attribute.offset()
00065                 )
00066             );
00067         }
00068 
00069     }
00070 }
00071 
00072 }
00073 
00074 
Generated on Sun Apr 11 12:23:08 2010 for RenderStack by  doxygen 1.6.3