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

Last change on this file since 108 was 100, checked in by epyon, 12 years ago
  • vertex_buffer - assign changed to update, needs bind
  • gfx/cached_buffer - initial implementation with buffer_slice proxies
File size: 2.2 KB
Line 
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{
15        bind();
16        glBufferData( GL_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) );
17        unbind();
18}
19
20void gl_vertex_buffer::update( void* data, int offset, int size )
21{
22        glBufferSubData( GL_ARRAY_BUFFER, offset, size, data );
23}
24
25
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}
40
41gl_index_buffer::gl_index_buffer( buffer_hint hint, int size, void* data )
42        : index_buffer( hint, size ), m_name()
43{
44        bind();
45        glBufferData( GL_ELEMENT_ARRAY_BUFFER, m_size, data, buffer_hint_to_enum( m_hint ) );
46        unbind();
47}
48
49void gl_index_buffer::update( void* data, int offset, int size )
50{
51        glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, offset, size, data );
52}
53
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(),
86                        nv::datatype_to_gl_enum( va->get_datatype() ),
87                        GL_FALSE,
88                        va->get_stride(),
89                        (void*)va->get_offset()
90                        );
91                vb->unbind();
92        }
93
94}
95
96void gl_vertex_array::unbind()
97{
98        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
99        {
100                glDisableVertexAttribArray( i->first );
101        }
102}
Note: See TracBrowser for help on using the repository browser.