- add support for Python Buffer()s of type DOUBLE

This commit is contained in:
Daniel Dunbar 2005-10-02 17:09:11 +00:00
parent 173a4791b2
commit cdb8700ddc
2 changed files with 13 additions and 3 deletions

@ -52,7 +52,7 @@ static char Method_Buffer_doc[] =
[template] - A sequence of matching dimensions to the buffer to be created\n\ [template] - A sequence of matching dimensions to the buffer to be created\n\
which will be used to initialize the Buffer.\n\n\ which will be used to initialize the Buffer.\n\n\
If a template is not passed in all fields will be initialized to 0.\n\n\ If a template is not passed in all fields will be initialized to 0.\n\n\
The type should be one of GL_BYTE, GL_SHORT, GL_INT, or GL_FLOAT.\n\ The type should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE.\n\
If the dimensions are specified as an int a linear buffer will be\n\ If the dimensions are specified as an int a linear buffer will be\n\
created. If a sequence is passed for the dimensions the buffer\n\ created. If a sequence is passed for the dimensions the buffer\n\
will have len(sequence) dimensions, where the size for each dimension\n\ will have len(sequence) dimensions, where the size for each dimension\n\
@ -140,6 +140,8 @@ static int type_size(int type)
return sizeof(int); return sizeof(int);
case GL_FLOAT: case GL_FLOAT:
return sizeof(float); return sizeof(float);
case GL_DOUBLE:
return sizeof(double);
} }
return -1; return -1;
} }
@ -173,7 +175,9 @@ static Buffer *make_buffer(int type, int ndimensions, int *dimensions)
else if (type==GL_INT) else if (type==GL_INT)
buffer->buf.asint[i]= 0; buffer->buf.asint[i]= 0;
else if (type==GL_FLOAT) else if (type==GL_FLOAT)
buffer->buf.asfloat[i]= 0.0; buffer->buf.asfloat[i]= 0.0f;
else if (type==GL_DOUBLE)
buffer->buf.asdouble[i]= 0.0;
} }
return buffer; return buffer;
} }
@ -190,7 +194,7 @@ static PyObject *Method_Buffer (PyObject *self, PyObject *args)
return EXPP_ReturnPyObjError(PyExc_AttributeError, return EXPP_ReturnPyObjError(PyExc_AttributeError,
"expected an int and one or two PyObjects"); "expected an int and one or two PyObjects");
if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT) { if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT && type!=GL_DOUBLE) {
PyErr_SetString(PyExc_AttributeError, "type"); PyErr_SetString(PyExc_AttributeError, "type");
return NULL; return NULL;
} }
@ -245,6 +249,7 @@ static PyObject *Buffer_item(PyObject *self, int i)
case GL_SHORT: return Py_BuildValue("h", buf->buf.asshort[i]); case GL_SHORT: return Py_BuildValue("h", buf->buf.asshort[i]);
case GL_INT: return Py_BuildValue("i", buf->buf.asint[i]); case GL_INT: return Py_BuildValue("i", buf->buf.asint[i]);
case GL_FLOAT: return Py_BuildValue("f", buf->buf.asfloat[i]); case GL_FLOAT: return Py_BuildValue("f", buf->buf.asfloat[i]);
case GL_DOUBLE: return Py_BuildValue("d", buf->buf.asdouble[i]);
} }
} else { } else {
Buffer *newbuf; Buffer *newbuf;
@ -326,6 +331,9 @@ static int Buffer_ass_item(PyObject *self, int i, PyObject *v)
} else if (buf->type==GL_FLOAT) { } else if (buf->type==GL_FLOAT) {
if (!PyArg_Parse(v, "f;Coordinates must be floats", &buf->buf.asfloat[i])) if (!PyArg_Parse(v, "f;Coordinates must be floats", &buf->buf.asfloat[i]))
return -1; return -1;
} else if (buf->type==GL_DOUBLE) {
if (!PyArg_Parse(v, "d;Coordinates must be floats", &buf->buf.asdouble[i]))
return -1;
} }
return 0; return 0;
} }
@ -1445,6 +1453,7 @@ PyObject *BGL_Init(void)
EXPP_ADDCONST(GL_INT); EXPP_ADDCONST(GL_INT);
EXPP_ADDCONST(GL_UNSIGNED_INT); EXPP_ADDCONST(GL_UNSIGNED_INT);
EXPP_ADDCONST(GL_FLOAT); EXPP_ADDCONST(GL_FLOAT);
EXPP_ADDCONST(GL_DOUBLE);
EXPP_ADDCONST(GL_2_BYTES); EXPP_ADDCONST(GL_2_BYTES);
EXPP_ADDCONST(GL_3_BYTES); EXPP_ADDCONST(GL_3_BYTES);
EXPP_ADDCONST(GL_4_BYTES); EXPP_ADDCONST(GL_4_BYTES);

@ -63,6 +63,7 @@ typedef struct _Buffer {
short *asshort; short *asshort;
int *asint; int *asint;
float *asfloat; float *asfloat;
double *asdouble;
void *asvoid; void *asvoid;
} buf; } buf;