buffer.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 BUFFER_HPP
00028 #define BUFFER_HPP
00029 
00030 #include "renderstack/rs.h"
00031 #include "renderstack/vertex_format.hpp"
00032 #include <exception>
00033 #include <vector>
00034 
00035 namespace renderstack {
00036 
00037 class vec2;
00038 class vec3;
00039 class vec4;
00040 
00041 class index_out_of_range_exception
00042 :   public std::exception
00043 {
00044 };
00045 
00046 class invalid_buffer_stride_exception
00047 :   public std::exception
00048 {
00049 };
00050 
00051 class invalid_buffer_gl_target_exception
00052 :   public std::exception
00053 {
00054 public:
00055     invalid_buffer_gl_target_exception(int gl_target)
00056     :   m_gl_target(gl_target)
00057     {
00058     }
00059 
00060     int gl_target() const { return m_gl_target; }
00061 
00062 private:
00063     int m_gl_target;
00064 };
00065 
00067 class buffer
00068 {
00069 public:
00070     buffer(int gl_target, int gl_usage);
00071     buffer(int gl_target, int gl_usage, int gl_index_type, int gl_mode);
00072     ~buffer();
00073 
00074 public:
00075     void                        use             () const;
00076     class vertex_format         &vertex_format  () { return m_vertex_format; }
00077     class vertex_format const   &vertex_format  () const { return m_vertex_format; }
00078     int                         count           () const { return m_count; }
00079     int                         gl_target       () const { return m_gl_target; }
00080     int                         gl_usage        () const { return m_gl_usage; }
00081     unsigned int                gl_buffer_object() const { return m_gl_buffer_object; }
00082     int                         gl_index_type   () const { return m_gl_index_type; }
00083     int                         gl_mode         () const { return m_gl_mode; }
00084 
00085 public:
00086     void begin_edit     ();
00087     void end_edit       (uint32 end_index);
00088 
00089     void set_index      (uint32 index);
00090     void put_float      (vertex_attribute const &attribute, float x);
00091     void put_vec2       (vertex_attribute const &attribute, vec2 const &v);
00092     void put_vec2       (vertex_attribute const &attribute, float x, float y);
00093     void put_vec3       (vertex_attribute const &attribute, vec3 const &v);
00094     void put_vec3       (vertex_attribute const &attribute, float x, float y, float z);
00095     void put_vec4       (vertex_attribute const &attribute, vec4 const &v);
00096     void put_vec4       (vertex_attribute const &attribute, float x, float y, float z, float w);
00097     void put_uint16     (vertex_attribute const &attribute, uint16 x);
00098     void put_uint32     (vertex_attribute const &attribute, uint32 x);
00099     void put_position   (vec3 const &v, int index = 0);
00100     void put_position   (float x, float y, float z, int index = 0);
00101     void put_normal     (vec3 const &v, int index = 0);
00102     void put_normal     (float x, float y, float z, int index = 0);
00103     void put_texcoord   (vec2 const &v, int index = 0);
00104     void put_texcoord   (float s, float t, int index = 0);
00105 
00106     void put_index      (uint32 index_location, uint32 index);
00107     void point          (uint32 index0);
00108     void line           (uint32 index0, uint32 index1);
00109     void triangle       (uint32 index0, uint32 index1, uint32 index2);
00110     void quad           (uint32 index0, uint32 index1, uint32 index2, uint32 index3);
00111 
00112 private:
00113     class vertex_format m_vertex_format;
00114     int                 m_count;
00115     unsigned long       m_size;
00116     int                 m_gl_target;
00117     int                 m_gl_usage;
00118     unsigned int        m_gl_buffer_object;
00119     int                 m_gl_index_type;
00120     int                 m_gl_mode;
00121 
00122     std::vector<unsigned char>  m_data;
00123     uint32                      m_current_index;
00124     int                         m_stride;
00125 
00126 };
00127 
00128 }
00129 
00130 #endif
00131 
Generated on Sun Apr 11 12:23:08 2010 for RenderStack by  doxygen 1.6.3