Merged changes in the trunk up to revision 40096.

Conflicts resolved:
source/blender/makesrna/intern/rna_scene.c
source/blender/python/intern/CMakeLists.txt

Note for branch builders: Enabling Blender Player may cause linker errors.
This commit is contained in:
2011-09-10 13:36:27 +00:00
420 changed files with 39931 additions and 15902 deletions

View File

@@ -5,7 +5,7 @@
Import ('env')
incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes'
incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager'
incs += ' ../imbuf ../blenloader ../gpu ../render/extern/include ../windowmanager'
incs += ' ../freestyle/intern/python'
incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include'
incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']

View File

@@ -344,7 +344,7 @@ void bpy_text_clear_modules(int clear_all)
/* looping over the dict */
PyObject *key, *value;
int pos= 0;
Py_ssize_t pos= 0;
/* new list */
PyObject *list;
@@ -374,7 +374,7 @@ void bpy_text_clear_modules(int clear_all)
}
/* remove all our modules */
for(pos=0; pos < PyList_Size(list); pos++) {
for(pos=0; pos < PyList_GET_SIZE(list); pos++) {
/* PyObject_Print(key, stderr, 0); */
key= PyList_GET_ITEM(list, pos);
PyDict_DelItem(modules, key);

View File

@@ -209,6 +209,10 @@ PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
}
/* returns the exception string as a new PyUnicode object, depends on external traceback module */
#if 0
/* this version uses traceback module but somehow fails on UI errors */
PyObject *PyC_ExceptionBuffer(void)
{
PyObject *traceback_mod= NULL;
@@ -236,6 +240,78 @@ error_cleanup:
return ret;
}
#else /* verbose, non-threadsafe version */
PyObject *PyC_ExceptionBuffer(void)
{
PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */
PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */
PyObject *string_io = NULL;
PyObject *string_io_buf = NULL;
PyObject *string_io_mod= NULL;
PyObject *string_io_getvalue= NULL;
PyObject *error_type, *error_value, *error_traceback;
if (!PyErr_Occurred())
return NULL;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
/* import io
* string_io = io.StringIO()
*/
if(! (string_io_mod= PyImport_ImportModule("io")) ) {
goto error_cleanup;
}
else if (! (string_io = PyObject_CallMethod(string_io_mod, (char *)"StringIO", NULL))) {
goto error_cleanup;
}
else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
goto error_cleanup;
}
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
Py_INCREF(stderr_backup);
PySys_SetObject("stdout", string_io); // both of these are free'd when restoring
PySys_SetObject("stderr", string_io);
PyErr_Restore(error_type, error_value, error_traceback);
PyErr_Print(); /* print the error */
PyErr_Clear();
string_io_buf = PyObject_CallObject(string_io_getvalue, NULL);
PySys_SetObject("stdout", stdout_backup);
PySys_SetObject("stderr", stderr_backup);
Py_DECREF(stdout_backup); /* now sys owns the ref again */
Py_DECREF(stderr_backup);
Py_DECREF(string_io_mod);
Py_DECREF(string_io_getvalue);
Py_DECREF(string_io); /* free the original reference */
PyErr_Clear();
return string_io_buf;
error_cleanup:
/* could not import the module so print the error and close */
Py_XDECREF(string_io_mod);
Py_XDECREF(string_io);
PyErr_Restore(error_type, error_value, error_traceback);
PyErr_Print(); /* print the error */
PyErr_Clear();
return NULL;
}
#endif
/* string conversion, escape non-unicode chars, coerce must be set to NULL */
const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)

View File

@@ -32,6 +32,7 @@ set(INC
../../makesdna
../../makesrna
../../windowmanager
../../gpu
../../freestyle/intern/python
../../../../intern/guardedalloc
)
@@ -41,6 +42,7 @@ set(INC_SYS
)
set(SRC
gpu.c
bpy.c
bpy_app.c
bpy_app_handlers.c
@@ -59,6 +61,7 @@ set(SRC
bpy_util.c
stubs.c
gpu.h
bpy.h
bpy_app.h
bpy_app_handlers.h

View File

@@ -76,6 +76,13 @@ int bpy_pydriver_create_dict(void)
Py_DECREF(mod);
}
/* add noise to global namespace */
mod= PyImport_ImportModuleLevel((char *)"noise", NULL, NULL, NULL, 0);
if (mod) {
PyDict_SetItemString(bpy_pydriver_Dict, "noise", mod);
Py_DECREF(mod);
}
return 0;
}

View File

@@ -40,6 +40,7 @@
#include "RNA_types.h"
#include "bpy.h"
#include "gpu.h"
#include "bpy_rna.h"
#include "bpy_util.h"
#include "bpy_traceback.h"
@@ -181,6 +182,7 @@ static struct _inittab bpy_internal_modules[]= {
#ifdef WITH_AUDASPACE
{(char *)"aud", AUD_initPython},
#endif
{(char *)"gpu", GPU_initPython},
{NULL, NULL}
};

View File

@@ -4608,7 +4608,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
#ifdef DEBUG_STRING_FREE
// if(PyList_Size(string_free_ls)) printf("%.200s.%.200s(): has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_Size(string_free_ls));
// if(PyList_GET_SIZE(string_free_ls)) printf("%.200s.%.200s(): has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_GET_SIZE(string_free_ls));
Py_DECREF(string_free_ls);
#undef DEBUG_STRING_FREE
#endif
@@ -5443,7 +5443,7 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
if(bpy_types==NULL) {
PyErr_Print();
PyErr_Clear();
fprintf(stderr, "pyrna_srna_ExternalType: failed to find 'bpy_types' module\n");
fprintf(stderr, "%s: failed to find 'bpy_types' module\n", __func__);
return NULL;
}
bpy_types_dict= PyModule_GetDict(bpy_types); // borrow
@@ -5457,18 +5457,18 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
PyObject *base_compare= pyrna_srna_PyBase(srna);
//PyObject *slots= PyObject_GetAttrString(newclass, "__slots__"); // cant do this because it gets superclasses values!
//PyObject *bases= PyObject_GetAttrString(newclass, "__bases__"); // can do this but faster not to.
PyObject *bases= ((PyTypeObject *)newclass)->tp_bases;
PyObject *slots= PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__);
PyObject *tp_bases= ((PyTypeObject *)newclass)->tp_bases;
PyObject *tp_slots= PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__);
if(slots==NULL) {
fprintf(stderr, "pyrna_srna_ExternalType: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", idname);
if(tp_slots==NULL) {
fprintf(stderr, "%s: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", __func__, idname);
newclass= NULL;
}
else if(PyTuple_GET_SIZE(bases)) {
PyObject *base= PyTuple_GET_ITEM(bases, 0);
else if(PyTuple_GET_SIZE(tp_bases)) {
PyObject *base= PyTuple_GET_ITEM(tp_bases, 0);
if(base_compare != base) {
fprintf(stderr, "pyrna_srna_ExternalType: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", idname);
fprintf(stderr, "%s: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", __func__, idname);
PyC_ObSpit("Expected! ", base_compare);
newclass= NULL;
}
@@ -5538,7 +5538,7 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
}
else {
/* this should not happen */
printf("Error registering '%s'\n", idname);
printf("%s: error registering '%s'\n", __func__, idname);
PyErr_Print();
PyErr_Clear();
}
@@ -5581,7 +5581,7 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
Py_DECREF(tp); /* srna owns, cant hold a ref */
}
else {
fprintf(stderr, "Could not make type\n");
fprintf(stderr, "%s: could not make type\n", __func__);
pyrna= (BPy_StructRNA *) PyObject_GC_New(BPy_StructRNA, &pyrna_struct_Type);
#ifdef USE_WEAKREFS
pyrna->in_weakreflist= NULL;
@@ -6231,10 +6231,10 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
#endif
py_class= RNA_struct_py_type_get(ptr->type);
/* rare case. can happen when registering subclasses */
if(py_class==NULL) {
fprintf(stderr, "bpy_class_call(): unable to get python class for rna struct '%.200s'\n", RNA_struct_identifier(ptr->type));
fprintf(stderr, "%s: unable to get python class for rna struct '%.200s'\n",
__func__, RNA_struct_identifier(ptr->type));
return -1;
}

View File

@@ -0,0 +1,289 @@
/*
* $Id$
*
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Benoit Bolsee.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/intern/gpu.c
* \ingroup pythonintern
*/
/* python redefines */
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#include <Python.h>
#include "GPU_material.h"
#include "DNA_scene_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "DNA_lamp_types.h"
#include "DNA_object_types.h"
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "RNA_access.h"
#include "bpy_rna.h"
#define PY_MODULE_ADD_CONSTANT(module, name) PyModule_AddIntConstant(module, #name, name)
PyDoc_STRVAR(M_gpu_doc,
"This module provides access to the GLSL shader.");
static struct PyModuleDef gpumodule = {
PyModuleDef_HEAD_INIT,
"gpu", /* name of module */
M_gpu_doc, /* module documentation */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
NULL, NULL, NULL, NULL, NULL
};
PyMODINIT_FUNC
PyInit_gpu(void)
{
PyObject* m;
m = PyModule_Create(&gpumodule);
if(m == NULL)
return NULL;
// device constants
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWMAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_MAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWIMAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_IMAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_COLOR);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNVEC);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCO);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNIMAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNPERSMAT);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNENERGY);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCOL);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DBUFFER);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DIMAGE);
PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DSHADOW);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1I);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_2F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_3F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_9F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_16F);
PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4UB);
PY_MODULE_ADD_CONSTANT(m, CD_MTFACE);
PY_MODULE_ADD_CONSTANT(m, CD_ORCO);
PY_MODULE_ADD_CONSTANT(m, CD_TANGENT);
PY_MODULE_ADD_CONSTANT(m, CD_MCOL);
return m;
}
#define PY_DICT_ADD_STRING(d,s,f) \
val = PyUnicode_FromString(s->f); \
PyDict_SetItemString(d, #f, val); \
Py_DECREF(val)
#define PY_DICT_ADD_LONG(d,s,f) \
val = PyLong_FromLong(s->f); \
PyDict_SetItemString(d, #f, val); \
Py_DECREF(val)
#define PY_DICT_ADD_ID(d,s,f) \
RNA_id_pointer_create((struct ID*)s->f, &tptr); \
val = pyrna_struct_CreatePyObject(&tptr); \
PyDict_SetItemString(d, #f, val); \
Py_DECREF(val)
#define PY_OBJ_ADD_ID(d,s,f) \
val = PyUnicode_FromString(&s->f->id.name[2]); \
PyObject_SetAttrString(d, #f, val); \
Py_DECREF(val)
#define PY_OBJ_ADD_LONG(d,s,f) \
val = PyLong_FromLong(s->f); \
PyObject_SetAttrString(d, #f, val); \
Py_DECREF(val)
#define PY_OBJ_ADD_STRING(d,s,f) \
val = PyUnicode_FromString(s->f); \
PyObject_SetAttrString(d, #f, val); \
Py_DECREF(val)
static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObject *kwds)
{
PyObject* pyscene;
PyObject* pymat;
PyObject* as_pointer;
PyObject* pointer;
PyObject* result;
PyObject* dict;
PyObject* val;
PyObject* seq;
int i;
Scene *scene;
PointerRNA tptr;
Material *material;
GPUShaderExport *shader;
GPUInputUniform *uniform;
GPUInputAttribute *attribute;
static const char *kwlist[] = {"scene", "material", NULL};
if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO:export_shader", (char**)(kwlist), &pyscene, &pymat))
return NULL;
if (!strcmp(Py_TYPE(pyscene)->tp_name, "Scene") &&
(as_pointer = PyObject_GetAttrString(pyscene, "as_pointer")) != NULL &&
PyCallable_Check(as_pointer)) {
// must be a scene object
pointer = PyObject_CallObject(as_pointer, NULL);
if (!pointer) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;
}
scene = (Scene*)PyLong_AsVoidPtr(pointer);
Py_DECREF(pointer);
if (!scene) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;
}
} else {
PyErr_SetString(PyExc_TypeError, "gpu.export_shader() first argument should be of Scene type");
return NULL;
}
if (!strcmp(Py_TYPE(pymat)->tp_name, "Material") &&
(as_pointer = PyObject_GetAttrString(pymat, "as_pointer")) != NULL &&
PyCallable_Check(as_pointer)) {
// must be a material object
pointer = PyObject_CallObject(as_pointer, NULL);
if (!pointer) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;
}
material = (Material*)PyLong_AsVoidPtr(pointer);
Py_DECREF(pointer);
if (!material) {
PyErr_SetString(PyExc_SystemError, "scene.as_pointer() failed");
return NULL;
}
} else {
PyErr_SetString(PyExc_TypeError, "gpu.export_shader() second argument should be of Material type");
return NULL;
}
// we can call our internal function at last:
shader = GPU_shader_export(scene, material);
if (!shader) {
PyErr_SetString(PyExc_RuntimeError, "cannot export shader");
return NULL;
}
// build a dictionary
result = PyDict_New();
if (shader->fragment) {
PY_DICT_ADD_STRING(result,shader,fragment);
}
if (shader->vertex) {
PY_DICT_ADD_STRING(result,shader,vertex);
}
seq = PyList_New(BLI_countlist(&shader->uniforms));
for (i=0, uniform=shader->uniforms.first; uniform; uniform=uniform->next, i++) {
dict = PyDict_New();
PY_DICT_ADD_STRING(dict,uniform,varname);
PY_DICT_ADD_LONG(dict,uniform,datatype);
PY_DICT_ADD_LONG(dict,uniform,type);
if (uniform->lamp) {
PY_DICT_ADD_ID(dict,uniform,lamp);
}
if (uniform->image) {
PY_DICT_ADD_ID(dict,uniform,image);
}
if (uniform->type == GPU_DYNAMIC_SAMPLER_2DBUFFER ||
uniform->type == GPU_DYNAMIC_SAMPLER_2DIMAGE ||
uniform->type == GPU_DYNAMIC_SAMPLER_2DSHADOW) {
PY_DICT_ADD_LONG(dict,uniform,texnumber);
}
if (uniform->texpixels) {
val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize);
PyDict_SetItemString(dict, "texpixels", val);
Py_DECREF(val);
PY_DICT_ADD_LONG(dict,uniform,texsize);
}
PyList_SET_ITEM(seq, i, dict);
}
PyDict_SetItemString(result, "uniforms", seq);
Py_DECREF(seq);
seq = PyList_New(BLI_countlist(&shader->attributes));
for (i=0, attribute=shader->attributes.first; attribute; attribute=attribute->next, i++) {
dict = PyDict_New();
PY_DICT_ADD_STRING(dict,attribute,varname);
PY_DICT_ADD_LONG(dict,attribute,datatype);
PY_DICT_ADD_LONG(dict,attribute,type);
PY_DICT_ADD_LONG(dict,attribute,number);
if (attribute->name) {
if (attribute->name[0] != 0) {
PY_DICT_ADD_STRING(dict,attribute,name);
} else {
val = PyLong_FromLong(0);
PyDict_SetItemString(dict, "name", val);
Py_DECREF(val);
}
}
PyList_SET_ITEM(seq, i, dict);
}
PyDict_SetItemString(result, "attributes", seq);
Py_DECREF(seq);
GPU_free_shader_export(shader);
return result;
}
static PyMethodDef meth_export_shader[] = {{ "export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS,
"export_shader(scene,material)\n\n"
"Returns the GLSL shader that produces the visual effect of material in scene.\n\n"
":return: Dictionary defining the shader, uniforms and attributes.\n"
":rtype: Dict"}};
PyObject* GPU_initPython(void)
{
PyObject* module = PyInit_gpu();
PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));
PyDict_SetItemString(PyImport_GetModuleDict(), "gpu", module);
return module;
}

View File

@@ -0,0 +1,41 @@
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This shader 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. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This shader 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 shader; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2005 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Benoit Bolsee.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/intern/gpu.h
* \ingroup pythonintern
*/
/**
* Initalizes the gpu Python module.
*/
PyObject* GPU_initPython(void);

View File

@@ -983,7 +983,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
{
int len, i;
Py_ssize_t len, i;
PyObject *list_item, *item_1, *item_2;
boxPack *box;
@@ -995,14 +995,14 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
return -1;
}
len= PyList_Size(value);
len= PyList_GET_SIZE(value);
(*boxarray)= MEM_mallocN(len*sizeof(boxPack), "boxPack box");
for(i= 0; i < len; i++) {
list_item= PyList_GET_ITEM(value, i);
if(!PyList_Check(list_item) || PyList_Size(list_item) < 4) {
if(!PyList_Check(list_item) || PyList_GET_SIZE(list_item) < 4) {
MEM_freeN(*boxarray);
PyErr_SetString(PyExc_TypeError,
"can only pack a list of [x, y, w, h]");
@@ -1034,11 +1034,11 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray)
{
int len, i;
Py_ssize_t len, i;
PyObject *list_item;
boxPack *box;
len= PyList_Size(value);
len= PyList_GET_SIZE(value);
for(i= 0; i < len; i++) {
box= (*boxarray)+i;
@@ -1062,7 +1062,7 @@ PyDoc_STRVAR(M_Geometry_box_pack_2d_doc,
static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist)
{
float tot_width= 0.0f, tot_height= 0.0f;
int len;
Py_ssize_t len;
PyObject *ret;