Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update() member for vbo.ElementBuffer class. #11

Merged
merged 1 commit into from Sep 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions glamour/vbo.d
Expand Up @@ -21,6 +21,8 @@ interface IBuffer {
void bind(); ///
void unbind(); ///
void set_data(T)(const ref T data, GLenum hint = GL_STATIC_DRAW); ///
void update(T)(const T data, GLintptr offset); ///
void update(T)(const T ptr, size_t size, GLintptr offset); /// should the interface have this overload member? set_date() have no overload version.
}

/// Represents an OpenGL element buffer.
Expand Down Expand Up @@ -92,6 +94,20 @@ class ElementBuffer : IBuffer {
length = size;
this.hint = hint;
}

/// Updates the Buffer, using glBufferSubData.
void update(T)(const T data, GLintptr offset) if(isArray!T) {
checkgl!glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
checkgl!glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, data.length*(ElementType!T).sizeof, data.ptr);
checkgl!glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

/// ditto
void update(T)(const T ptr, size_t size, GLintptr offset) if(isPointer!T) {
checkgl!glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
checkgl!glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, ptr);
checkgl!glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}


Expand Down