mesh.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 MESH_HPP
00028 #define MESH_HPP
00029 
00030 #include "renderstack/rs.h"
00031 #include "renderstack/buffer.hpp"
00032 #include "renderstack/attribute_bindings.hpp"
00033 #include <memory>
00034 #include <map>
00035 #include <exception>
00036 
00037 namespace renderstack {
00038 
00039 enum mesh_mode
00040 {
00041     mesh_mode_not_set = 0,
00042     mesh_mode_polygon_fill,
00043     mesh_mode_edge_lines,
00044     mesh_mode_corner_points,
00045     mesh_mode_corner_normals,
00046     mesh_mode_polygon_centroids,
00047     mesh_mode_count
00048 };
00049 
00050 class program;
00051 
00052 class index_buffer_not_found_exception
00053 :   public std::exception
00054 {
00055 public:
00056     index_buffer_not_found_exception(enum mesh_mode mode)
00057     :   m_mesh_mode(mode)
00058     {
00059     }
00060     enum mesh_mode mesh_mode() const { return m_mesh_mode; }
00061 
00062 private:
00063     enum mesh_mode m_mesh_mode;
00064 };
00065 
00067 class mesh
00068 {
00069 public:
00070     mesh(int draw_mode = GL_STATIC_DRAW)
00071     :   m_enabled_attribute_bindings(NULL)
00072     {
00073         m_vertex_buffer.reset(
00074             new buffer(GL_ARRAY_BUFFER, draw_mode)
00075         );
00076     }
00077     virtual ~mesh()
00078     {
00079     }
00080 
00081     void begin(
00082         class program const &program, 
00083         enum mesh_mode      mode = mesh_mode_not_set
00084     );
00085     void end();
00086 
00087     buffer  * const vertex_buffer  () const { return m_vertex_buffer.get(); } 
00088     buffer  *vertex_buffer  (){ return m_vertex_buffer.get(); } 
00089     buffer  *index_buffer   (enum mesh_mode mode);
00090     buffer  *find_or_create_index_buffer(
00091         enum mesh_mode  mode,
00092         int             gl_target, 
00093         int             gl_usage, 
00094         int             gl_index_type, 
00095         int             gl_mode
00096     );
00097 
00098 protected:
00099     void use(enum mesh_mode mode);
00100     void apply_attributes(class program const &program, bool enable);
00101 
00102 private:
00103     std::tr1::shared_ptr<buffer>                                m_vertex_buffer;
00104     std::map<enum mesh_mode, std::tr1::shared_ptr<buffer> >     m_index_buffers;
00105     std::map<int, std::tr1::shared_ptr<attribute_bindings> >    m_attribute_bindings;
00106     attribute_bindings                                          *m_enabled_attribute_bindings;
00107 };
00108 
00109 }
00110 
00111 #endif
00112 
Generated on Sun Apr 11 12:23:08 2010 for RenderStack by  doxygen 1.6.3