vertex_format.hpp

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 #ifndef VERTEX_FORMAT_HPP
00028 #define VERTEX_FORMAT_HPP
00029 
00030 #include "renderstack/rs.h"
00031 
00032 #include <exception>
00033 #include <vector>
00034 
00035 namespace renderstack {
00036 
00037 enum vertex_attribute_usage
00038 {
00039     vertex_attribute_usage_none,
00040     vertex_attribute_usage_position,
00041     vertex_attribute_usage_normal,
00042     vertex_attribute_usage_tangent,
00043     vertex_attribute_usage_bitangent,
00044     vertex_attribute_usage_color,
00045     vertex_attribute_usage_weights,
00046     vertex_attribute_usage_matrix_indices,
00047     vertex_attribute_usage_texcoord,
00048     vertex_attribute_usage_id
00049 };
00050 
00051 class vertex_attribute_not_found_exception 
00052 :   public std::exception
00053 {
00054 public:
00055     vertex_attribute_not_found_exception(
00056         vertex_attribute_usage  usage, 
00057         int                     index
00058     )
00059     :   m_usage(usage)
00060     ,   m_index(index)
00061     {
00062     }
00063 
00064     vertex_attribute_usage  usage(){ return m_usage; }
00065     int                     index(){ return m_index; }
00066 
00067 private:
00068     vertex_attribute_usage  m_usage;
00069     int                     m_index;
00070 };
00071 
00073 class vertex_attribute
00074 {
00075 public:
00076     vertex_attribute(vertex_attribute_usage usage, int gl_type_code, int index, int dimension);
00077 
00078     vertex_attribute_usage  usage       () const;
00079     int                     gl_type_code() const;
00080     int                     index       () const;
00081     int                     dimension   () const;
00082     int                     offset      () const;
00083 
00084     void                    set_offset(int offset);
00085 
00086 private:
00087     vertex_attribute_usage  m_usage;
00088     int                     m_gl_type_code;   /*  GL_FLOAT  */ 
00089     int                     m_index;          /*  texcoord0, texcoord1  */ 
00090     int                     m_dimension;      /*  normal is 3, texcoord typically 2  */ 
00091     int                     m_offset;
00092 };
00093 
00094 
00096 class vertex_format
00097 {
00098 public:
00099     vertex_format();
00100     ~vertex_format();
00101 
00102     void append(vertex_attribute &attribute);
00103 
00104     bool has_attribute(vertex_attribute_usage usage, int index = 0) const;
00105     vertex_attribute const &attribute(vertex_attribute_usage usage, int index = 0) const;
00106 
00107     int stride() const;
00108 
00109 private:
00110     std::vector<vertex_attribute>   m_attributes;
00111     int                             m_stride;
00112 };
00113 
00114 int gl_size_of_type(int type_code);
00115 
00116 }
00117 
00118 #endif
00119 
Generated on Sun Apr 11 12:23:09 2010 for RenderStack by  doxygen 1.6.3