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

Last change on this file since 191 was 191, checked in by epyon, 12 years ago
  • formats - md3_animation works!
File size: 2.6 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
[153]12gl_vertex_buffer::gl_vertex_buffer( buffer_hint hint, size_t size, const 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
[153]20void gl_vertex_buffer::update( const void* data, size_t offset, size_t size )
[99]21{
[191]22        // IMPORTANT - THIS DOES NOT BIND, SHOULD IT?
[121]23        glBufferSubData( GL_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
[99]24}
25
26
[42]27void gl_vertex_buffer::bind()
28{
29        glBindBuffer( GL_ARRAY_BUFFER, m_name.get_value() );
30}
31
32void gl_vertex_buffer::unbind()
33{
34        glBindBuffer( GL_ARRAY_BUFFER, 0 );
35}
36
37bool gl_vertex_buffer::is_valid() const
38{
39        return m_name.is_valid();
40}
[44]41
[153]42gl_index_buffer::gl_index_buffer( buffer_hint hint, size_t size, const void* data )
[44]43        : index_buffer( hint, size ), m_name()
44{
[100]45        bind();
[121]46        glBufferData( GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)m_size, data, buffer_hint_to_enum( m_hint ) );
[100]47        unbind();
[44]48}
49
[153]50void gl_index_buffer::update( const void* data, size_t offset, size_t size )
[99]51{
[121]52        glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, (GLintptr)offset, (GLsizeiptr)size, data );
[99]53}
54
[44]55void gl_index_buffer::bind()
56{
57        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_name.get_value() );
58}
59
60void gl_index_buffer::unbind()
61{
62        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
63}
64
65bool gl_index_buffer::is_valid() const
66{
67        return m_name.is_valid();
68}
69
70gl_vertex_array::gl_vertex_array()
71{
72
73}
74
75void gl_vertex_array::bind()
76{
77        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
78        {
[121]79                uint32 location             = static_cast<uint32>( i->first );
[44]80                vertex_buffer_attribute* va = i->second;
81                vertex_buffer*           vb = va->get_buffer();
82                glEnableVertexAttribArray( location );
83                vb->bind();
84                glVertexAttribPointer(
85                        location,
[121]86                        static_cast<GLint>( va->get_components() ),
[70]87                        nv::datatype_to_gl_enum( va->get_datatype() ),
[44]88                        GL_FALSE,
[121]89                        static_cast<GLsizei>( va->get_stride() ),
[44]90                        (void*)va->get_offset()
91                        );
92                vb->unbind();
93        }
94
[116]95        if ( m_index )
96        {
97                m_index->bind();
98        }
[44]99}
100
101void gl_vertex_array::unbind()
102{
[116]103        if ( m_index )
104        {
105                m_index->unbind();
106        }
107
[44]108        for ( vertex_buffer_attribute_map::iterator i = m_map.begin();  i != m_map.end(); ++i )
109        {
[121]110                glDisableVertexAttribArray( static_cast<uint32>( i->first ) );
[44]111        }
112}
Note: See TracBrowser for help on using the repository browser.