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
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
[121]12gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, size_t size, void* data )
[42]13        : vertex_buffer( hint, size ), m_name()
14{
[100]15        bind();
[121]16        glBufferData( GL_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
[100]17        unbind();
[42]18}
19
[121]20void gl_vertex_buffer::update( void* data, size_t offset, size_t size )
[99]21{
[121]22        glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
[99]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
[121]41gl_index_buffer::gl_index_buffer( buffer_hint hint, size_t size, void* data )
[44]42        : index_buffer( hint, size ), m_name()
43{
[100]44        bind();
[121]45        glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
[100]46        unbind();
[44]47}
48
[121]49void gl_index_buffer::update( void* data, size_t offset, size_t size )
[99]50{
[121]51        glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
[99]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        {
[121]78                uint32 location             = static_cast<uint32>( i->first );
[44]79                vertex_buffer_attribute* va = i->second;
80                vertex_buffer*           vb = va->get_buffer();
81                glEnableVertexAttribArray( location );
82                vb->bind();
83                glVertexAttribPointer(
84                        location,
[121]85                        static_cast<GLint>( va->get_components() ),
[70]86                        nv::datatype_to_gl_enum( va->get_datatype() ),
[44]87                        GL_FALSE,
[121]88                        static_cast<GLsizei>( va->get_stride() ),
[44]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        {
[121]109                glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
[44]110        }
111}
Note: See TracBrowser for help on using the repository browser.