forked from bartvdbraak/blender
rename bgl.Buffer attribute list to a method, to_list() as used for IDProps, also made repr function nicer.
This commit is contained in:
parent
aef6f15b49
commit
0a46f9a737
@ -1379,14 +1379,15 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import Blender
|
||||
from Blender.BGL import *
|
||||
import bgl
|
||||
xval, yval= 100, 40
|
||||
# Get the scale of the view matrix
|
||||
viewMatrix = Buffer(GL_FLOAT, 16)
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix)
|
||||
f = 1/viewMatrix[0]
|
||||
glRasterPos2f(xval*f, yval*f) # Instead of the usual glRasterPos2i(xval, yval)
|
||||
view_matrix = bgl.Buffer(bgl.GL_FLOAT, 16)
|
||||
bgl.glGetFloatv(bgl.GL_MODELVIEW_MATRIX, view_matrix)
|
||||
f = 1.0 / view_matrix[0]
|
||||
|
||||
# Instead of the usual glRasterPos2i(xval, yval)
|
||||
bgl.glRasterPos2f(xval * f, yval * f)
|
||||
|
||||
|
||||
.. function:: glReadBuffer(mode):
|
||||
@ -1839,32 +1840,32 @@ class Buffer:
|
||||
The Buffer object is simply a block of memory that is delineated and initialized by the
|
||||
user. Many OpenGL functions return data to a C-style pointer, however, because this
|
||||
is not possible in python the Buffer object can be used to this end. Wherever pointer
|
||||
notation is used in the OpenGL functions the Buffer object can be used in it's BGL
|
||||
notation is used in the OpenGL functions the Buffer object can be used in it's bgl
|
||||
wrapper. In some instances the Buffer object will need to be initialized with the template
|
||||
parameter, while in other instances the user will want to create just a blank buffer
|
||||
which will be zeroed by default.
|
||||
|
||||
Example with Buffer::
|
||||
import Blender
|
||||
from Blender import BGL
|
||||
myByteBuffer = BGL.Buffer(BGL.GL_BYTE, [32,32])
|
||||
BGL.glGetPolygonStipple(myByteBuffer)
|
||||
print myByteBuffer.dimensions
|
||||
print myByteBuffer.list
|
||||
.. code-block:: python
|
||||
|
||||
import bgl
|
||||
myByteBuffer = bgl.Buffer(bgl.GL_BYTE, [32, 32])
|
||||
bgl.glGetPolygonStipple(myByteBuffer)
|
||||
print(myByteBuffer.dimensions)
|
||||
print(myByteBuffer.to_list())
|
||||
sliceBuffer = myByteBuffer[0:16]
|
||||
print sliceBuffer
|
||||
|
||||
.. attribute:: list
|
||||
|
||||
The contents of the Buffer.
|
||||
print(sliceBuffer)
|
||||
|
||||
.. attribute:: dimensions
|
||||
|
||||
The size of the Buffer.
|
||||
The number of dimensions of the Buffer.
|
||||
|
||||
.. method:: to_list()
|
||||
|
||||
The contents of the Buffer as a python list.
|
||||
|
||||
.. method:: __init__(type, dimensions, template = None):
|
||||
|
||||
This will create a new Buffer object for use with other BGL OpenGL commands.
|
||||
This will create a new Buffer object for use with other bgl OpenGL commands.
|
||||
Only the type of argument to store in the buffer and the dimensions of the buffer
|
||||
are necessary. Buffers are zeroed by default unless a template is supplied, in
|
||||
which case the buffer is initialized to the template.
|
||||
|
@ -72,6 +72,7 @@ static void Buffer_dealloc(PyObject *self);
|
||||
static PyObject *Buffer_tolist(PyObject *self, void *arg);
|
||||
static PyObject *Buffer_dimensions(PyObject *self, void *arg);
|
||||
static PyObject *Buffer_repr(PyObject *self);
|
||||
static PyMethodDef Buffer_methods[];
|
||||
static PyGetSetDef Buffer_getseters[];
|
||||
|
||||
PyTypeObject BGL_bufferType = {
|
||||
@ -123,7 +124,7 @@ PyTypeObject BGL_bufferType = {
|
||||
NULL, /* getiterfunc tp_iter; */
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
NULL, /* struct PyMethodDef *tp_methods; */
|
||||
Buffer_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
Buffer_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /*tp_base*/
|
||||
@ -459,7 +460,7 @@ static void Buffer_dealloc(PyObject *self)
|
||||
PyObject_DEL(self);
|
||||
}
|
||||
|
||||
static PyObject *Buffer_tolist(PyObject *self, void *UNUSED(arg))
|
||||
static PyObject *Buffer_to_list(PyObject *self)
|
||||
{
|
||||
int i, len= ((Buffer *)self)->dimensions[0];
|
||||
PyObject *list= PyList_New(len);
|
||||
@ -484,18 +485,35 @@ static PyObject *Buffer_dimensions(PyObject *self, void *UNUSED(arg))
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyMethodDef Buffer_methods[] = {
|
||||
{"to_list", (PyCFunction)Buffer_to_list, METH_NOARGS,
|
||||
"return the buffer as a list"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static PyGetSetDef Buffer_getseters[] = {
|
||||
{(char *)"list", (getter)Buffer_tolist, NULL, NULL, NULL},
|
||||
{(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL},
|
||||
{NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
static PyObject *Buffer_repr(PyObject *self)
|
||||
{
|
||||
PyObject *list= Buffer_tolist(self, NULL);
|
||||
PyObject *repr= PyObject_Repr(list);
|
||||
PyObject *list= Buffer_to_list(self);
|
||||
PyObject *repr;
|
||||
const char *typestr= "UNKNOWN";
|
||||
Buffer *buffer= (Buffer *)self;
|
||||
|
||||
switch(buffer->type) {
|
||||
case GL_BYTE: typestr= "GL_BYTE"; break;
|
||||
case GL_SHORT: typestr= "GL_SHORT"; break;
|
||||
case GL_INT: typestr= "GL_BYTE"; break;
|
||||
case GL_FLOAT: typestr= "GL_FLOAT"; break;
|
||||
case GL_DOUBLE: typestr= "GL_DOUBLE"; break;
|
||||
}
|
||||
|
||||
repr= PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
|
||||
Py_DECREF(list);
|
||||
|
||||
|
||||
return repr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user