Class: SFML::VertexBuffer
- Inherits:
-
Object
- Object
- SFML::VertexBuffer
- Defined in:
- ext/graphics/vertex_buffer.c,
ext/graphics/vertex_buffer.c
Overview
Like VertexArray, but the vertex data lives in GPU memory rather than being re-uploaded on every draw -- more efficient for large, static or semi-static vertex sets.
Includes Drawable.
Instance Attribute Summary collapse
-
#primitive ⇒ Symbol
Returns the primitive type used to draw the vertices.
-
#usage ⇒ Symbol
Returns the buffer's usage hint.
Class Method Summary collapse
-
.available? ⇒ Boolean
Returns
trueif vertex buffers are supported.
Instance Method Summary collapse
-
#bind ⇒ self
Binds the buffer for drawing.
-
#copy ⇒ VertexBuffer
Returns a deep copy of the object.
-
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
-
#initialize(*args) ⇒ VertexBuffer
constructor
Creates a GPU-side vertex buffer holding
countvertices (default 0), interpreted asprimitive(default :points, see VertexArray#primitive), with the givenusagehint (one of :stream, :dynamic, :static; default :static). -
#native_handle ⇒ Integer
Returns the underlying OpenGL handle.
-
#swap(other) ⇒ self
Swaps the contents with
other. -
#update(*args) ⇒ Boolean
Uploads
vertices(an Array of Vertex, or of anything Vertex.new accepts) into the buffer starting atoffset(default 0). -
#update_from(other) ⇒ Boolean
Copies the contents of
other(a VertexBuffer of the same vertex count) into this buffer. -
#vertex_count ⇒ Integer
Returns the number of vertices stored.
Constructor Details
#new ⇒ VertexBuffer #new(count) ⇒ VertexBuffer #new(count, primitive) ⇒ VertexBuffer #new(count, primitive, usage) ⇒ VertexBuffer
Creates a GPU-side vertex buffer holding count vertices (default 0),
interpreted as primitive (default :points, see VertexArray#primitive),
with the given usage hint (one of :stream, :dynamic, :static; default
:static).
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'ext/graphics/vertex_buffer.c', line 88
static VALUE VertexBuffer_initialize(int argc, VALUE* argv, VALUE self) {
VALUE rb_count, rb_primitive, rb_usage;
size_t count = 0;
sfPrimitiveType primitive = sfPoints;
sfVertexBufferUsage usage = sfVertexBufferStatic;
sfVertexBuffer* buffer;
rb_scan_args(argc, argv, "03", &rb_count, &rb_primitive, &rb_usage);
if (!NIL_P(rb_count)) {
count = (size_t)NUM2SIZET(rb_count);
}
if (!NIL_P(rb_primitive)) {
primitive = primitive_type_from_rb(rb_primitive);
}
if (!NIL_P(rb_usage)) {
usage = usage_from_rb(rb_usage);
}
buffer = sfVertexBuffer_create(count, primitive, usage);
if (buffer == NULL) {
rb_raise(rb_eRuntimeError, "failed to create vertex buffer");
}
DATA_PTR(self) = buffer;
return self;
}
|
Instance Attribute Details
#primitive ⇒ Symbol
Returns the primitive type used to draw the vertices.
312 313 314 315 |
# File 'ext/graphics/vertex_buffer.c', line 312 static VALUE VertexBuffer_get_primitive_type(VALUE self) { return ID2SYM(rb_intern( primitive_type_name(sfVertexBuffer_getPrimitiveType(Get_VertexBuffer_Struct(self))))); } |
#usage ⇒ Symbol
Returns the buffer's usage hint.
312 313 314 |
# File 'ext/graphics/vertex_buffer.c', line 312 static VALUE VertexBuffer_get_usage(VALUE self) { return ID2SYM(rb_intern(usage_names[sfVertexBuffer_getUsage(Get_VertexBuffer_Struct(self))])); } |
Class Method Details
.available? ⇒ Boolean
Returns true if vertex buffers are supported.
285 286 287 |
# File 'ext/graphics/vertex_buffer.c', line 285 static VALUE VertexBuffer_is_available(VALUE klass) { return BOOL2RB(sfVertexBuffer_isAvailable()); } |
Instance Method Details
#bind ⇒ self
Binds the buffer for drawing.
273 274 275 276 |
# File 'ext/graphics/vertex_buffer.c', line 273 static VALUE VertexBuffer_bind(VALUE self) { sfVertexBuffer_bind(Get_VertexBuffer_Struct(self)); return self; } |
#copy ⇒ VertexBuffer
Returns a deep copy of the object.
126 127 128 129 |
# File 'ext/graphics/vertex_buffer.c', line 126 static VALUE VertexBuffer_copy(VALUE self) { return VertexBuffer_wrap(Get_Klass_VertexBuffer(), sfVertexBuffer_copy(Get_VertexBuffer_Struct(self))); } |
#draw(target, state) ⇒ nil
Part of the Drawable interface; call Target#draw instead of this directly.
299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'ext/graphics/vertex_buffer.c', line 299
static VALUE VertexBuffer_draw(VALUE self, VALUE rb_target, VALUE rb_state) {
TargetView view = Get_RenderTarget_View(rb_target);
if (!rb_obj_is_kind_of(rb_state, Get_Klass_RenderState())) {
raise_invalid_argument_class(Get_Klass_RenderState());
}
TARGET_DRAW(view, sfRenderWindow_drawVertexBuffer, sfRenderTexture_drawVertexBuffer,
Get_VertexBuffer_Struct(self), Get_RenderState_Struct(rb_state));
return Qnil;
}
|
#native_handle ⇒ Integer
Returns the underlying OpenGL handle.
263 264 265 |
# File 'ext/graphics/vertex_buffer.c', line 263 static VALUE VertexBuffer_get_native_handle(VALUE self) { return UINT2NUM(sfVertexBuffer_getNativeHandle(Get_VertexBuffer_Struct(self))); } |
#swap(other) ⇒ self
Swaps the contents with other.
202 203 204 205 206 207 208 209 210 |
# File 'ext/graphics/vertex_buffer.c', line 202
static VALUE VertexBuffer_swap(VALUE self, VALUE rb_other) {
if (!rb_obj_is_kind_of(rb_other, rb_cVertexBuffer)) {
raise_invalid_argument_class(rb_cVertexBuffer);
}
sfVertexBuffer_swap(Get_VertexBuffer_Struct(self), Get_VertexBuffer_Struct(rb_other));
return self;
}
|
#update(vertices) ⇒ Boolean #update(vertices, offset) ⇒ Boolean
Uploads vertices (an Array of Vertex, or of anything Vertex.new
accepts) into the buffer starting at offset (default 0). The buffer
must have enough room; use #resize (via .new) if not.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/graphics/vertex_buffer.c', line 151
static VALUE VertexBuffer_update(int argc, VALUE* argv, VALUE self) {
VALUE rb_vertices, rb_offset;
unsigned int offset = 0;
size_t count;
sfVertex* vertices;
bool result;
rb_scan_args(argc, argv, "11", &rb_vertices, &rb_offset);
if (!NIL_P(rb_offset)) {
offset = (unsigned int)NUM2UINT(rb_offset);
}
vertices = vertices_from_rb(rb_vertices, &count);
result =
sfVertexBuffer_update(Get_VertexBuffer_Struct(self), vertices, (unsigned int)count, offset);
xfree(vertices);
return BOOL2RB(result);
}
|
#update_from(other) ⇒ Boolean
Copies the contents of other (a VertexBuffer of the same vertex count)
into this buffer.
183 184 185 186 187 188 189 190 |
# File 'ext/graphics/vertex_buffer.c', line 183
static VALUE VertexBuffer_update_from(VALUE self, VALUE rb_other) {
if (!rb_obj_is_kind_of(rb_other, rb_cVertexBuffer)) {
raise_invalid_argument_class(rb_cVertexBuffer);
}
return BOOL2RB(sfVertexBuffer_updateFromVertexBuffer(Get_VertexBuffer_Struct(self),
Get_VertexBuffer_Struct(rb_other)));
}
|
#vertex_count ⇒ Integer
Returns the number of vertices stored.
137 138 139 |
# File 'ext/graphics/vertex_buffer.c', line 137 static VALUE VertexBuffer_get_vertex_count(VALUE self) { return SIZET2NUM(sfVertexBuffer_getVertexCount(Get_VertexBuffer_Struct(self))); } |