vertex_format.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
00089 int m_index;
00090 int m_dimension;
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