Class: Gl::Buffer
- Inherits:
-
Object
- Object
- Gl::Buffer
- Defined in:
- ext/opengl/gl_buffer.c
Class Method Summary collapse
Instance Method Summary collapse
- #addr ⇒ Object
- #length ⇒ Object
- #read(*args) ⇒ Object
- #target ⇒ Object
- #unmap ⇒ Object
- #write(*args) ⇒ Object
Class Method Details
.map(*args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/opengl/gl_buffer.c', line 39
VALUE
rb_gl_buffer_s_map(int argc, VALUE *argv, VALUE klass)
{
VALUE _target;
VALUE _access;
VALUE obj;
struct buffer *buf;
DECL_GL_FUNC_PTR(GLvoid *,glMapBuffer,(GLenum,GLenum));
rb_scan_args(argc, argv, "21", &_target, &_access, &obj);
if(NIL_P(obj)){
obj = g_default_glimpl;
} else if(!rb_obj_is_kind_of(obj, rb_cGlimpl)){
rb_raise(rb_eArgError, "wrong argument type %s (expected kind of Gl::Implementation)", rb_obj_classname(obj));
}
buf = ALLOC(struct buffer);
LOAD_GL_FUNC(glMapBuffer, "1.5");
buf->target = RUBY2GLENUM(_target);
buf->len = 0;
buf->glimpl = obj;
buf->ptr = fptr_glMapBuffer(buf->target, RUBY2GLENUM(_access));
if (buf->ptr == NULL) {
xfree(buf);
CHECK_GLERROR_FROM("glMapBuffer");
}
return TypedData_Wrap_Struct(klass, &buffer_type, buf);
}
|
Instance Method Details
#addr ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'ext/opengl/gl_buffer.c', line 72
static VALUE
rb_gl_buffer_addr(VALUE self) {
struct buffer *buf;
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
return SIZET2NUM((size_t)buf->ptr);
}
|
#length ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'ext/opengl/gl_buffer.c', line 81
static VALUE
rb_gl_buffer_length(VALUE self) {
struct buffer *buf;
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
return RETCONV_GLsizeiptr(buf->len);
}
|
#read(*args) ⇒ Object
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 |
# File 'ext/opengl/gl_buffer.c', line 90
static VALUE
rb_gl_buffer_read(int argc, VALUE *argv, VALUE self) {
struct buffer *buf;
VALUE _length, _offset;
GLsizeiptr offset, length;
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
rb_scan_args(argc, argv, "02", &_length, &_offset);
if (buf->len == 0 && NIL_P(_length))
rb_raise(rb_eArgError, "length must be provided for unbounded buffer");
length = NUM2SIZET(_length);
if (NIL_P(_offset)) {
offset = 0;
} else {
offset = NUM2SIZET(_offset);
}
if (buf->len != 0 && length + offset > buf->len)
rb_raise(rb_eArgError, "read to %lu past end of buffer %lu",
(unsigned long)(length + offset), (unsigned long)buf->len);
return rb_str_new((char *)buf->ptr + offset, length);
}
|
#target ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'ext/opengl/gl_buffer.c', line 118
static VALUE
rb_gl_buffer_target(VALUE self) {
struct buffer *buf;
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
return RETCONV_GLenum(buf->target);
}
|
#unmap ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'ext/opengl/gl_buffer.c', line 127
static VALUE
rb_gl_buffer_unmap(VALUE self) {
struct buffer *buf;
VALUE obj;
DECL_GL_FUNC_PTR(GLboolean,glUnmapBuffer,(GLenum));
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
obj = buf->glimpl;
LOAD_GL_FUNC(glUnmapBuffer, "1.5");
if (!buf->ptr)
return self;
fptr_glUnmapBuffer(buf->target);
CHECK_GLERROR_FROM("glUnmapBuffer");
buf->ptr = NULL;
buf->len = 0;
buf->target = 0;
return self;
}
|
#write(*args) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'ext/opengl/gl_buffer.c', line 152
static VALUE
rb_gl_buffer_write(int argc, VALUE *argv, VALUE self) {
struct buffer *buf;
VALUE _data, _offset;
GLsizeiptr offset;
long length;
TypedData_Get_Struct(self, struct buffer, &buffer_type, buf);
if (!buf->ptr)
rb_raise(rb_eArgError, "write to unmapped buffer");
rb_scan_args(argc, argv, "11", &_data, &_offset);
if (NIL_P(_data))
rb_raise(rb_eArgError, "cannot write nil to buffer");
_data = rb_String(_data);
length = RSTRING_LEN(_data);
if (NIL_P(_offset)) {
offset = 0;
} else {
offset = NUM2SIZET(_offset);
}
if (buf->len != 0 && length + offset > buf->len)
rb_raise(rb_eArgError, "write to %lu past end of buffer %lu",
(unsigned long)(length + offset), (unsigned long)buf->len);
memcpy((char *)buf->ptr + offset, RSTRING_PTR(_data), RSTRING_LEN(_data));
return self;
}
|