source: trunk/src/gl/gl_vertex_buffer.cc @ 116

Last change on this file since 116 was 116, checked in by epyon, 12 years ago
  • support for indexed arrays
File size: 2.3 KB
RevLine 
[42]1// Copyright (C) 2012-2013 Kornel Kisielewicz
2// This file is part of NV Libraries.
3// For conditions of distribution and use, see copyright notice in nv.hh
4
5#include "nv/gl/gl_vertex_buffer.hh"
6
7#include "nv/lib/gl.hh"
8#include "nv/gl/gl_enum.hh"
9
10using namespace nv;
11
12gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, int size, void* data )
13        : vertex_buffer( hint, size ), m_name()
14{
[100]15        bind();
[42]16        glBufferData( GL_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) );
[100]17        unbind();
[42]18}
19
[100]20void gl_vertex_buffer::update( void* data, int offset, int size )
[99]21{
22        glBufferSubData( GL_ARRAY_BUFFER, offset, size, data );
23}
24
25
[42]26void gl_vertex_buffer::bind()
27{
28        glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );
29}
30
31void gl_vertex_buffer::unbind()
32{
33        glBindBuffer( GL_ARRAY_BUFFER, 0 );
34}
35
36bool gl_vertex_buffer::is_valid() const
37{
38        return m_name.is_valid();
39}
[44]40
41gl_index_buffer::gl_index_buffer( buffer_hint hint, int size, void* data )
42        : index_buffer( hint, size ), m_name()
43{
[100]44        bind();
[44]45        glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) );
[100]46        unbind();
[44]47}
48
[100]49void gl_index_buffer::update( void* data, int offset, int size )
[99]50{
51        glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, offset, size, data );
52}
53
[44]54void gl_index_buffer::bind()
55{
56        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
57}
58
59void gl_index_buffer::unbind()
60{
61        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
62}
63
64bool gl_index_buffer::is_valid() const
65{
66        return m_name.is_valid();
67}
68
69gl_vertex_array::gl_vertex_array()
70{
71
72}
73
74void gl_vertex_array::bind()
75{
76        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
77        {
78                int location                = i->first;
79                vertex_buffer_attribute* va = i->second;
80                vertex_buffer*           vb = va->get_buffer();
81                glEnableVertexAttribArray( location );
82                vb->bind();
83                glVertexAttribPointer(
84                        location,
85                        va->get_components(),
[70]86                        nv::datatype_to_gl_enum( va->get_datatype() ),
[44]87                        GL_FALSE,
88                        va->get_stride(),
89                        (void*)va->get_offset()
90                        );
91                vb->unbind();
92        }
93
[116]94        if ( m_index )
95        {
96                m_index->bind();
97        }
[44]98}
99
100void gl_vertex_array::unbind()
101{
[116]102        if ( m_index )
103        {
104                m_index->unbind();
105        }
106
[44]107        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
108        {
109                glDisableVertexAttribArray( i->first );
110        }
111}
Note: See TracBrowser for help on using the repository browser.