[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27425] branches/bmesh/blender/source/ blender/python/generic: turned BGL.c/.h -> bgl.c/.h
Joseph Eagar
joeedh at gmail.com
Thu Mar 11 20:33:00 CET 2010
Revision: 27425
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27425
Author: joeedh
Date: 2010-03-11 20:33:00 +0100 (Thu, 11 Mar 2010)
Log Message:
-----------
turned BGL.c/.h -> bgl.c/.h
Added Paths:
-----------
branches/bmesh/blender/source/blender/python/generic/bgl.c
branches/bmesh/blender/source/blender/python/generic/bgl.h
Removed Paths:
-------------
branches/bmesh/blender/source/blender/python/generic/BGL.c
branches/bmesh/blender/source/blender/python/generic/BGL.h
Deleted: branches/bmesh/blender/source/blender/python/generic/BGL.c
===================================================================
--- branches/bmesh/blender/source/blender/python/generic/BGL.c 2010-03-11 19:14:35 UTC (rev 27424)
+++ branches/bmesh/blender/source/blender/python/generic/BGL.c 2010-03-11 19:33:00 UTC (rev 27425)
@@ -1,1599 +0,0 @@
-/*
- * $Id: BGL.c 21218 2009-06-28 13:27:06Z campbellbarton $
- *
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * This is a new part of Blender.
- *
- * Contributor(s): Willian P. Germano
- *
- * ***** END GPL LICENSE BLOCK *****
-*/
-
-/* This file is the Blender.BGL part of opy_draw.c, from the old
- * bpython/intern dir, with minor changes to adapt it to the new Python
- * implementation. The BGL submodule "wraps" OpenGL functions and constants,
- * allowing script writers to make OpenGL calls in their Python scripts. */
-
-#include "BGL.h" /*This must come first */
-
-#include "MEM_guardedalloc.h"
-
-static int type_size( int type );
-static Buffer *make_buffer( int type, int ndimensions, int *dimensions );
-
-static char Method_Buffer_doc[] =
- "(type, dimensions, [template]) - Create a new Buffer object\n\n\
-(type) - The format to store data in\n\
-(dimensions) - An int or sequence specifying the dimensions of the buffer\n\
-[template] - A sequence of matching dimensions to the buffer to be created\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\
-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\
-created. If a sequence is passed for the dimensions the buffer\n\
-will have len(sequence) dimensions, where the size for each dimension\n\
-is determined by the value in the sequence at that index.\n\n\
-For example, passing [100, 100] will create a 2 dimensional\n\
-square buffer. Passing [16, 16, 32] will create a 3 dimensional\n\
-buffer which is twice as deep as it is wide or high.";
-
-static PyObject *Method_Buffer( PyObject * self, PyObject * args );
-
-/* Buffer sequence methods */
-
-static int Buffer_len( PyObject * self );
-static PyObject *Buffer_item( PyObject * self, int i );
-static PyObject *Buffer_slice( PyObject * self, int begin, int end );
-static int Buffer_ass_item( PyObject * self, int i, PyObject * v );
-static int Buffer_ass_slice( PyObject * self, int begin, int end,
- PyObject * seq );
-
-static PySequenceMethods Buffer_SeqMethods = {
- ( lenfunc ) Buffer_len, /*sq_length */
- ( binaryfunc ) 0, /*sq_concat */
- ( ssizeargfunc ) 0, /*sq_repeat */
- ( ssizeargfunc ) Buffer_item, /*sq_item */
- ( ssizessizeargfunc ) Buffer_slice, /*sq_slice */
- ( ssizeobjargproc ) Buffer_ass_item, /*sq_ass_item */
- ( ssizessizeobjargproc ) Buffer_ass_slice, /*sq_ass_slice */
-};
-
-static void Buffer_dealloc( PyObject * self );
-static PyObject *Buffer_tolist( PyObject * self );
-static PyObject *Buffer_dimensions( PyObject * self );
-static PyObject *Buffer_getattr( PyObject * self, char *name );
-static PyObject *Buffer_repr( PyObject * self );
-
-PyTypeObject buffer_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "buffer", /*tp_name */
- sizeof( Buffer ), /*tp_basicsize */
- 0, /*tp_itemsize */
- ( destructor ) Buffer_dealloc, /*tp_dealloc */
- ( printfunc ) 0, /*tp_print */
- ( getattrfunc ) Buffer_getattr, /*tp_getattr */
- ( setattrfunc ) 0, /*tp_setattr */
- 0, /*tp_compare */
- ( reprfunc ) Buffer_repr, /*tp_repr */
- 0, /*tp_as_number */
- &Buffer_SeqMethods, /*tp_as_sequence */
-};
-
-/* #ifndef __APPLE__ */
-
-#define BGL_Wrap(nargs, funcname, ret, arg_list) \
-static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
- arg_def##nargs arg_list; \
- ret_def_##ret; \
- if(!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\
- ret_set_##ret gl##funcname (arg_var##nargs arg_list);\
- ret_ret_##ret; \
-}
-
-#define BGLU_Wrap(nargs, funcname, ret, arg_list) \
-static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
- arg_def##nargs arg_list; \
- ret_def_##ret; \
- if(!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\
- ret_set_##ret glu##funcname (arg_var##nargs arg_list);\
- ret_ret_##ret; \
-}
-
-/* #endif */
-
-/********/
-static int type_size(int type)
-{
- switch (type) {
- case GL_BYTE:
- return sizeof(char);
- case GL_SHORT:
- return sizeof(short);
- case GL_INT:
- return sizeof(int);
- case GL_FLOAT:
- return sizeof(float);
- case GL_DOUBLE:
- return sizeof(double);
- }
- return -1;
-}
-
-static Buffer *make_buffer(int type, int ndimensions, int *dimensions)
-{
- Buffer *buffer;
- void *buf= NULL;
- int i, size, length;
-
- length= 1;
- for (i=0; i<ndimensions; i++)
- length*= dimensions[i];
-
- size= type_size(type);
-
- buf= MEM_mallocN(length*size, "Buffer buffer");
-
- buffer= (Buffer *) PyObject_NEW(Buffer, &buffer_Type);
- buffer->parent= NULL;
- buffer->ndimensions= ndimensions;
- buffer->dimensions= dimensions;
- buffer->type= type;
- buffer->buf.asvoid= buf;
-
- for (i= 0; i<length; i++) {
- if (type==GL_BYTE)
- buffer->buf.asbyte[i]= 0;
- else if (type==GL_SHORT)
- buffer->buf.asshort[i]= 0;
- else if (type==GL_INT)
- buffer->buf.asint[i]= 0;
- else if (type==GL_FLOAT)
- buffer->buf.asfloat[i]= 0.0f;
- else if (type==GL_DOUBLE)
- buffer->buf.asdouble[i]= 0.0;
- }
- return buffer;
-}
-
-static PyObject *Method_Buffer (PyObject *self, PyObject *args)
-{
- PyObject *length_ob= NULL, *template= NULL;
- Buffer *buffer;
-
- int i, type;
- int *dimensions = 0, ndimensions = 0;
-
- if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) {
- PyErr_SetString(PyExc_AttributeError, "expected an int and one or two PyObjects");
- return NULL;
- }
- if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT && type!=GL_DOUBLE) {
- PyErr_SetString(PyExc_AttributeError, "invalid first argument type, should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
- return NULL;
- }
-
- if (PyNumber_Check(length_ob)) {
- ndimensions= 1;
- dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
- dimensions[0]= PyLong_AsLong(length_ob);
- } else if (PySequence_Check(length_ob)) {
- ndimensions= PySequence_Length(length_ob);
- dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
- for (i=0; i<ndimensions; i++) {
- PyObject *ob= PySequence_GetItem(length_ob, i);
-
- if (!PyNumber_Check(ob)) dimensions[i]= 1;
- else dimensions[i]= PyLong_AsLong(ob);
- Py_DECREF(ob);
- }
- }
-
- buffer= make_buffer(type, ndimensions, dimensions);
- if (template && ndimensions) {
- if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], template)) {
- Py_DECREF(buffer);
- return NULL;
- }
- }
-
- return (PyObject *) buffer;
-}
-
-/*@ Buffer sequence methods */
-
-static int Buffer_len(PyObject *self)
-{
- Buffer *buf= (Buffer *) self;
- return buf->dimensions[0];
-}
-
-static PyObject *Buffer_item(PyObject *self, int i)
-{
- Buffer *buf= (Buffer *) self;
-
- if (i >= buf->dimensions[0]) {
- PyErr_SetString(PyExc_IndexError, "array index out of range");
- return NULL;
- }
-
- if (buf->ndimensions==1) {
- switch (buf->type) {
- case GL_BYTE: return Py_BuildValue("b", buf->buf.asbyte[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_FLOAT: return PyFloat_FromDouble(buf->buf.asfloat[i]);
- case GL_DOUBLE: return Py_BuildValue("d", buf->buf.asdouble[i]);
- }
- } else {
- Buffer *newbuf;
- int j, length, size;
-
- length= 1;
- for (j=1; j<buf->ndimensions; j++) {
- length*= buf->dimensions[j];
- }
- size= type_size(buf->type);
-
- newbuf= (Buffer *) PyObject_NEW(Buffer, &buffer_Type);
-
- Py_INCREF(self);
- newbuf->parent= self;
-
- newbuf->ndimensions= buf->ndimensions-1;
- newbuf->type= buf->type;
- newbuf->buf.asvoid= buf->buf.asbyte + i*length*size;
- newbuf->dimensions= MEM_mallocN(newbuf->ndimensions*sizeof(int),
- "Buffer dimensions");
- memcpy(newbuf->dimensions, buf->dimensions+1,
- newbuf->ndimensions*sizeof(int));
-
- return (PyObject *) newbuf;
- }
-
- return NULL;
-}
-
-static PyObject *Buffer_slice(PyObject *self, int begin, int end)
-{
- Buffer *buf= (Buffer *) self;
- PyObject *list;
- int count;
-
- if (begin<0) begin= 0;
- if (end>buf->dimensions[0])
- end= buf->dimensions[0];
- if (begin>end) begin= end;
-
- list= PyList_New(end-begin);
-
- for (count= begin; count<end; count++)
- PyList_SetItem(list, count-begin, Buffer_item(self, count));
-
- return list;
-}
-
-static int Buffer_ass_item(PyObject *self, int i, PyObject *v)
-{
- Buffer *buf= (Buffer *) self;
-
- if (i >= buf->dimensions[0]) {
- PyErr_SetString(PyExc_IndexError, "array assignment index out of range");
- return -1;
- }
-
- if (buf->ndimensions!=1) {
- PyObject *row= Buffer_item(self, i);
- int ret;
-
- if (!row) return -1;
- ret= Buffer_ass_slice(row, 0, buf->dimensions[1], v);
- Py_DECREF(row);
- return ret;
- }
-
- if (buf->type==GL_BYTE) {
- if (!PyArg_Parse(v, "b;Coordinates must be ints", &buf->buf.asbyte[i]))
- return -1;
- } else if (buf->type==GL_SHORT) {
- if (!PyArg_Parse(v, "h;Coordinates must be ints", &buf->buf.asshort[i]))
- return -1;
-
- } else if (buf->type==GL_INT) {
- if (!PyArg_Parse(v, "i;Coordinates must be ints", &buf->buf.asint[i]))
- return -1;
- } else if (buf->type==GL_FLOAT) {
- if (!PyArg_Parse(v, "f;Coordinates must be floats", &buf->buf.asfloat[i]))
- return -1;
- } else if (buf->type==GL_DOUBLE) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list