[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30958] branches/soc-2010-moguri-2/source/ gameengine/Ketsji: Some Python API work:

Mitchell Stokes mogurijin at gmail.com
Mon Aug 2 02:30:38 CEST 2010


Revision: 30958
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30958
Author:   moguri
Date:     2010-08-02 02:30:37 +0200 (Mon, 02 Aug 2010)

Log Message:
-----------
Some Python API work:
 * Added a Shader type
 * Added a Uniform Type
 * Shader has fragment, vertex, geometry and uniform Attributes
 * Uniform has ro name attribute (name is set in the constructor)

Modified Paths:
--------------
    branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonInitTypes.cpp

Added Paths:
-----------
    branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp
    branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h

Modified: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
===================================================================
--- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonInitTypes.cpp	2010-08-02 00:08:01 UTC (rev 30957)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonInitTypes.cpp	2010-08-02 00:30:37 UTC (rev 30958)
@@ -57,6 +57,7 @@
 #include "KX_PolyProxy.h"
 #include "KX_PolygonMaterial.h"
 #include "KX_PythonSeq.h"
+#include "KX_PythonShaders.h"
 #include "KX_SCA_AddObjectActuator.h"
 #include "KX_SCA_EndObjectActuator.h"
 #include "KX_SCA_ReplaceMeshActuator.h"
@@ -212,6 +213,8 @@
 		PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset);
 		PyType_Ready_Attr(dict, KX_Scene, init_getset);
 		PyType_Ready_Attr(dict, KX_SceneActuator, init_getset);
+		PyType_Ready_Attr(dict, KX_PythonShader, init_getset);
+		PyType_Ready_Attr(dict, KX_PythonUniform, init_getset);
 		PyType_Ready_Attr(dict, KX_SoundActuator, init_getset);
 		PyType_Ready_Attr(dict, KX_StateActuator, init_getset);
 		PyType_Ready_Attr(dict, KX_TouchSensor, init_getset);

Added: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp
===================================================================
--- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp	                        (rev 0)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp	2010-08-02 00:30:37 UTC (rev 30958)
@@ -0,0 +1,162 @@
+/**
+ * $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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * Init bge.shaders
+ */
+
+#ifndef DISABLE_PYTHON
+#include "KX_PythonInit.h"
+#include "PyObjectPlus.h"
+#include "KX_PythonShaders.h"
+#include "BL_BlenderShader.h"
+
+/**
+ * The Shader type
+ */
+
+KX_PythonShader::KX_PythonShader()
+	: PyObjectPlus(),
+	m_vert(""),
+	m_geom(""),
+	m_frag(""),
+	m_uniforms(NULL)
+{
+}
+
+KX_PythonShader::~KX_PythonShader()
+{
+	Py_XDECREF(m_uniforms);
+}
+
+PyObject *KX_PythonShader::py_shader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	KX_PythonShader* pyshader = new KX_PythonShader();
+	return pyshader->NewProxy(true);
+}
+
+PyTypeObject KX_PythonShader::Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"Shader",
+	sizeof(PyObjectPlus_Proxy),
+	0,
+	py_base_dealloc,
+	0,
+	0,
+	0,
+	0,
+	py_base_repr,
+	0,0,0,0,0,0,0,0,0,
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+	0,0,0,0,0,0,0,
+	Methods,
+	0,
+	0,
+	&PyObjectPlus::Type,
+	0,0,0,0,0,0,
+	py_shader_new
+};
+
+PyMethodDef KX_PythonShader::Methods[] = {
+	{NULL} //Sentinel
+};
+
+PyAttributeDef KX_PythonShader::Attributes[] = {
+	KX_PYATTRIBUTE_STRING_RW("vertex", 0, 64000, false, KX_PythonShader, m_vert),
+	KX_PYATTRIBUTE_STRING_RW("geometry", 0, 64000, false, KX_PythonShader, m_geom),
+	KX_PYATTRIBUTE_STRING_RW("fragment", 0, 64000, false, KX_PythonShader, m_frag),
+	KX_PYATTRIBUTE_RO_FUNCTION("uniforms", KX_PythonShader, pyattr_get_uniforms),
+	{NULL}	//Sentinel
+};
+
+PyObject* KX_PythonShader::pyattr_get_uniforms(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_PythonShader* self = static_cast<KX_PythonShader*>(self_v);
+
+	if (self->m_uniforms == NULL)
+		self->m_uniforms = PyList_New(0);
+
+	Py_INCREF(self->m_uniforms);
+	return self->m_uniforms;
+}
+
+
+/**
+ * The Uniform type
+ */
+
+KX_PythonUniform::KX_PythonUniform(char* name)
+	: PyObjectPlus()
+{
+	m_name = STR_String(name);
+}
+
+KX_PythonUniform::~KX_PythonUniform()
+{
+}
+
+PyObject *KX_PythonUniform::py_uniform_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+	char *name;
+
+	if (!PyArg_ParseTuple(args, "s:Uniform", &name))
+		return NULL;
+
+	KX_PythonUniform* pyuniform = new KX_PythonUniform(name);
+	return pyuniform->NewProxy(true);
+}
+
+PyTypeObject KX_PythonUniform::Type = {
+	PyVarObject_HEAD_INIT(NULL, 0)
+	"Uniform",
+	sizeof(PyObjectPlus_Proxy),
+	0,
+	py_base_dealloc,
+	0,
+	0,
+	0,
+	0,
+	py_base_repr,
+	0,0,0,0,0,0,0,0,0,
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+	0,0,0,0,0,0,0,
+	Methods,
+	0,
+	0,
+	&PyObjectPlus::Type,
+	0,0,0,0,0,0,
+	py_uniform_new
+};
+
+PyMethodDef KX_PythonUniform::Methods[] = {
+	{NULL} //Sentinel
+};
+
+PyAttributeDef KX_PythonUniform::Attributes[] = {
+	KX_PYATTRIBUTE_STRING_RO("name", KX_PythonUniform, m_name),
+	{NULL}	//Sentinel
+};
+#endif // ndef DISABLE_PYTHON
\ No newline at end of file

Added: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h
===================================================================
--- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h	                        (rev 0)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h	2010-08-02 00:30:37 UTC (rev 30958)
@@ -0,0 +1,69 @@
+/**
+ * $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) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * Init bge.shaders
+ */
+
+#ifndef __KX_PYSHADERS
+#define __KX_PYSHADERS
+#ifndef DISABLE_PYTHON
+
+#include "PyObjectPlus.h"
+
+class KX_PythonShader: public PyObjectPlus
+{
+	Py_Header;
+
+	STR_String m_vert, m_geom, m_frag;
+	PyObject* m_uniforms;
+
+public:
+	KX_PythonShader();
+	~KX_PythonShader();
+
+	static PyObject* py_shader_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+
+	static PyObject* pyattr_get_uniforms(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+};
+
+class KX_PythonUniform: public PyObjectPlus
+{
+	Py_Header;
+
+	STR_String m_name;
+	short type;
+	void *data;
+
+public:
+	KX_PythonUniform(char* name);
+	~KX_PythonUniform();
+
+	static PyObject* py_uniform_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
+};
+
+#endif //ndef DISABLE_PYTHON
+#endif // __KX_PYSHADERS
\ No newline at end of file





More information about the Bf-blender-cvs mailing list