source: nanovis/trunk/graphics/VertexBuffer.cpp @ 4897

Last change on this file since 4897 was 3465, checked in by ldelgass, 11 years ago

Rename R2 library to nv::graphics and nv::util.

  • Property svn:eol-style set to native
File size: 985 bytes
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 */
5#include <memory.h>
6#include <stdlib.h>
7
8#include <GL/glew.h>
9#include <GL/gl.h>
10
11#include "VertexBuffer.h"
12
13using namespace nv::graphics;
14
15VertexBuffer::VertexBuffer(int type, int vertexCount,
16                           int byteSize, void *data, bool copy) :
17    _graphicObjectID(0),
18    _byteSize(byteSize),
19    _vertexCount(vertexCount)
20{
21    if (copy) {
22        _data = (void*) malloc(byteSize);
23    } else {
24        _data = data;
25    }
26
27    glGenBuffers(1, &_graphicObjectID);
28    glBindBuffer(GL_ARRAY_BUFFER, _graphicObjectID);
29    glBufferData(GL_ARRAY_BUFFER,
30                 _byteSize,
31                 data,
32                 GL_STATIC_DRAW);
33    glBindBuffer(GL_ARRAY_BUFFER, 0);
34}
35
36VertexBuffer::~VertexBuffer()
37{
38    if (_graphicObjectID != 0) {
39        glDeleteBuffers(1, &_graphicObjectID);
40    }
41    if (_data) {
42        free(_data);
43    }
44}
Note: See TracBrowser for help on using the repository browser.