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

Last change on this file since 121 was 121, checked in by epyon, 12 years ago
  • Nova builds with -Weverything/-Wall/-pedantic/etc on: on MSVC 2012 on GCC 4.6.3 on clang 3.2
  • ... without a single fucking warning.
File size: 2.5 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, size_t size, void* data )
13        : vertex_buffer( hint, size ), m_name()
14{
15        bind();
16        glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
17        unbind();
18}
19
20void gl_vertex_buffer::update( void* data, size_t offset, size_t size )
21{
22        glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)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, size_t size, void* data )
42        : index_buffer( hint, size ), m_name()
43{
44        bind();
45        glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
46        unbind();
47}
48
49void gl_index_buffer::update( void* data, size_t offset, size_t size )
50{
51        glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)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                uint32 location             = static_cast<uint32>( 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                        static_cast<GLint>( va->get_components() ),
86                        nv::datatype_to_gl_enum( va->get_datatype() ),
87                        GL_FALSE,
88                        static_cast<GLsizei>( va->get_stride() ),
89                        (void*)va->get_offset()
90                        );
91                vb->unbind();
92        }
93
94        if ( m_index )
95        {
96                m_index->bind();
97        }
98}
99
100void gl_vertex_array::unbind()
101{
102        if ( m_index )
103        {
104                m_index->unbind();
105        }
106
107        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
108        {
109                glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
110        }
111}
Note: See TracBrowser for help on using the repository browser.