renderstack::mesh Class Reference

holds vertex buffer and a number of index buffers

#include <mesh.hpp>

Inherited by renderstack::dynamic_rectangle, renderstack::grid, and renderstack::shapes::polymesh.

Public Member Functions

 mesh (int draw_mode=GL_STATIC_DRAW)
virtual ~mesh ()
void begin (class program const &program, enum mesh_mode mode=mesh_mode_not_set)
void end ()
buffer *const vertex_buffer () const
buffervertex_buffer ()
bufferindex_buffer (enum mesh_mode mode)
bufferfind_or_create_index_buffer (enum mesh_mode mode, int gl_target, int gl_usage, int gl_index_type, int gl_mode)

Protected Member Functions

void use (enum mesh_mode mode)
void apply_attributes (class program const &program, bool enable)

Detailed Description

Definition at line 67 of file mesh.hpp.


Constructor & Destructor Documentation

renderstack::mesh::mesh ( int  draw_mode = GL_STATIC_DRAW  )  [inline]

Definition at line 70 of file mesh.hpp.

00071     :   m_enabled_attribute_bindings(NULL)
00072     {
00073         m_vertex_buffer.reset(
00074             new buffer(GL_ARRAY_BUFFER, draw_mode)
00075         );
00076     }

virtual renderstack::mesh::~mesh (  )  [inline, virtual]

Definition at line 77 of file mesh.hpp.

00078     {
00079     }


Member Function Documentation

void renderstack::mesh::begin ( class program const &  program,
enum mesh_mode  mode = mesh_mode_not_set 
)

Definition at line 111 of file mesh.cpp.

00115 {
00116     vertex_buffer()->use();
00117     if(mode == mesh_mode_not_set)
00118     {
00119         mode = program.mesh_mode();
00120     }
00121     index_buffer(mode)->use();
00122     apply_attributes(program, true);
00123 }

void renderstack::mesh::end (  ) 

Definition at line 125 of file mesh.cpp.

00126 {
00127     if(m_enabled_attribute_bindings != NULL)
00128     {
00129         m_enabled_attribute_bindings->apply(false);
00130         m_enabled_attribute_bindings = NULL;
00131     }
00132 }

buffer* const renderstack::mesh::vertex_buffer (  )  const [inline]

Definition at line 87 of file mesh.hpp.

00087 { return m_vertex_buffer.get(); } 

buffer* renderstack::mesh::vertex_buffer (  )  [inline]

Definition at line 88 of file mesh.hpp.

00088 { return m_vertex_buffer.get(); } 

buffer * renderstack::mesh::index_buffer ( enum mesh_mode  mode  ) 

Definition at line 32 of file mesh.cpp.

00033 {
00034     std::map<
00035         enum mesh_mode, 
00036         std::tr1::shared_ptr<buffer>
00037     >::const_iterator i = m_index_buffers.find(mode);
00038 
00039     if(i != m_index_buffers.end())
00040     {
00041         std::tr1::shared_ptr<buffer> buffer = (*i).second;
00042         return buffer.get();
00043     }
00044 
00045     throw index_buffer_not_found_exception(mode);
00046 }

buffer * renderstack::mesh::find_or_create_index_buffer ( enum mesh_mode  mode,
int  gl_target,
int  gl_usage,
int  gl_index_type,
int  gl_mode 
)

Definition at line 48 of file mesh.cpp.

00055 {
00056     std::map<
00057         enum mesh_mode, 
00058         std::tr1::shared_ptr<buffer>
00059     >::const_iterator i = m_index_buffers.find(mode);
00060 
00061     if(i != m_index_buffers.end())
00062     {
00063         std::tr1::shared_ptr<buffer> buffer = (*i).second;
00064         return buffer.get();
00065     }
00066 
00067     std::tr1::shared_ptr<buffer> b(
00068         new buffer(gl_target, gl_usage, gl_index_type, gl_mode)
00069     );
00070     m_index_buffers.insert(
00071         std::make_pair(
00072             mode, 
00073             b
00074         )
00075     );
00076     return b.get();
00077 }

void renderstack::mesh::use ( enum mesh_mode  mode  )  [protected]
void renderstack::mesh::apply_attributes ( class program const &  program,
bool  enable 
) [protected]

Definition at line 79 of file mesh.cpp.

00080 {
00081     int gl_program_object = program.gl_program_object();
00082 
00083     std::map<int, std::tr1::shared_ptr<attribute_bindings> >::const_iterator i = m_attribute_bindings.find(gl_program_object);
00084     if(i != m_attribute_bindings.end())
00085     {
00086         std::tr1::shared_ptr<attribute_bindings> bindings = (*i).second;
00087         bindings->apply(enable);
00088         m_enabled_attribute_bindings = bindings.get();
00089     }
00090     else
00091     {
00092         std::tr1::shared_ptr<attribute_bindings> bindings(
00093             new attribute_bindings()
00094         );
00095         m_attribute_bindings.insert(
00096             std::make_pair(
00097                 gl_program_object,
00098                 bindings
00099             )
00100         );
00101         program.attribute_mappings().bind_attributes(
00102             *bindings,
00103             program,
00104             *this
00105         );
00106         bindings->apply(enable);
00107         m_enabled_attribute_bindings = bindings.get();
00108     }
00109 }


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:11 2010 for RenderStack by  doxygen 1.6.3