rename bgl.Buffer attribute list to a method, to_list() as used for IDProps, also made repr function nicer.
This commit is contained in:
@@ -1379,14 +1379,15 @@ OpenGL}" and the online NeHe tutorials are two of the best resources.
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import Blender
|
import bgl
|
||||||
from Blender.BGL import *
|
|
||||||
xval, yval= 100, 40
|
xval, yval= 100, 40
|
||||||
# Get the scale of the view matrix
|
# Get the scale of the view matrix
|
||||||
viewMatrix = Buffer(GL_FLOAT, 16)
|
view_matrix = bgl.Buffer(bgl.GL_FLOAT, 16)
|
||||||
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix)
|
bgl.glGetFloatv(bgl.GL_MODELVIEW_MATRIX, view_matrix)
|
||||||
f = 1/viewMatrix[0]
|
f = 1.0 / view_matrix[0]
|
||||||
glRasterPos2f(xval*f, yval*f) # Instead of the usual glRasterPos2i(xval, yval)
|
|
||||||
|
# Instead of the usual glRasterPos2i(xval, yval)
|
||||||
|
bgl.glRasterPos2f(xval * f, yval * f)
|
||||||
|
|
||||||
|
|
||||||
.. function:: glReadBuffer(mode):
|
.. 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
|
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
|
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
|
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
|
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
|
parameter, while in other instances the user will want to create just a blank buffer
|
||||||
which will be zeroed by default.
|
which will be zeroed by default.
|
||||||
|
|
||||||
Example with Buffer::
|
.. code-block:: python
|
||||||
import Blender
|
|
||||||
from Blender import BGL
|
import bgl
|
||||||
myByteBuffer = BGL.Buffer(BGL.GL_BYTE, [32,32])
|
myByteBuffer = bgl.Buffer(bgl.GL_BYTE, [32, 32])
|
||||||
BGL.glGetPolygonStipple(myByteBuffer)
|
bgl.glGetPolygonStipple(myByteBuffer)
|
||||||
print myByteBuffer.dimensions
|
print(myByteBuffer.dimensions)
|
||||||
print myByteBuffer.list
|
print(myByteBuffer.to_list())
|
||||||
sliceBuffer = myByteBuffer[0:16]
|
sliceBuffer = myByteBuffer[0:16]
|
||||||
print sliceBuffer
|
print(sliceBuffer)
|
||||||
|
|
||||||
.. attribute:: list
|
|
||||||
|
|
||||||
The contents of the Buffer.
|
|
||||||
|
|
||||||
.. attribute:: dimensions
|
.. 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):
|
.. 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
|
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
|
are necessary. Buffers are zeroed by default unless a template is supplied, in
|
||||||
which case the buffer is initialized to the template.
|
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_tolist(PyObject *self, void *arg);
|
||||||
static PyObject *Buffer_dimensions(PyObject *self, void *arg);
|
static PyObject *Buffer_dimensions(PyObject *self, void *arg);
|
||||||
static PyObject *Buffer_repr(PyObject *self);
|
static PyObject *Buffer_repr(PyObject *self);
|
||||||
|
static PyMethodDef Buffer_methods[];
|
||||||
static PyGetSetDef Buffer_getseters[];
|
static PyGetSetDef Buffer_getseters[];
|
||||||
|
|
||||||
PyTypeObject BGL_bufferType = {
|
PyTypeObject BGL_bufferType = {
|
||||||
@@ -123,7 +124,7 @@ PyTypeObject BGL_bufferType = {
|
|||||||
NULL, /* getiterfunc tp_iter; */
|
NULL, /* getiterfunc tp_iter; */
|
||||||
NULL, /* iternextfunc tp_iternext; */
|
NULL, /* iternextfunc tp_iternext; */
|
||||||
/*** Attribute descriptor and subclassing stuff ***/
|
/*** Attribute descriptor and subclassing stuff ***/
|
||||||
NULL, /* struct PyMethodDef *tp_methods; */
|
Buffer_methods, /* struct PyMethodDef *tp_methods; */
|
||||||
NULL, /* struct PyMemberDef *tp_members; */
|
NULL, /* struct PyMemberDef *tp_members; */
|
||||||
Buffer_getseters, /* struct PyGetSetDef *tp_getset; */
|
Buffer_getseters, /* struct PyGetSetDef *tp_getset; */
|
||||||
NULL, /*tp_base*/
|
NULL, /*tp_base*/
|
||||||
@@ -459,7 +460,7 @@ static void Buffer_dealloc(PyObject *self)
|
|||||||
PyObject_DEL(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];
|
int i, len= ((Buffer *)self)->dimensions[0];
|
||||||
PyObject *list= PyList_New(len);
|
PyObject *list= PyList_New(len);
|
||||||
@@ -484,16 +485,33 @@ static PyObject *Buffer_dimensions(PyObject *self, void *UNUSED(arg))
|
|||||||
return list;
|
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[] = {
|
static PyGetSetDef Buffer_getseters[] = {
|
||||||
{(char *)"list", (getter)Buffer_tolist, NULL, NULL, NULL},
|
|
||||||
{(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL},
|
{(char *)"dimensions", (getter)Buffer_dimensions, NULL, NULL, NULL},
|
||||||
{NULL, NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyObject *Buffer_repr(PyObject *self)
|
static PyObject *Buffer_repr(PyObject *self)
|
||||||
{
|
{
|
||||||
PyObject *list= Buffer_tolist(self, NULL);
|
PyObject *list= Buffer_to_list(self);
|
||||||
PyObject *repr= PyObject_Repr(list);
|
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);
|
Py_DECREF(list);
|
||||||
|
|
||||||
return repr;
|
return repr;
|
||||||
|
Reference in New Issue
Block a user