Revision: 31361 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31361 Author: moguri Date: 2010-08-16 03:39:37 +0200 (Mon, 16 Aug 2010)
Log Message: ----------- Uniforms created during runtime can now be used to affect shaders. Modified Paths: -------------- branches/soc-2010-moguri-2/source/gameengine/Ketsji/BL_BlenderShader.cpp 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/BL_BlenderShader.cpp =================================================================== --- branches/soc-2010-moguri-2/source/gameengine/Ketsji/BL_BlenderShader.cpp 2010-08-16 00:56:29 UTC (rev 31360) +++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/BL_BlenderShader.cpp 2010-08-16 01:39:37 UTC (rev 31361) @@ -8,6 +8,8 @@ #include "BKE_main.h" #include "BKE_material.h" +#include "BLI_listbase.h" + #include "BL_BlenderShader.h" #include "BL_Material.h" @@ -69,10 +71,14 @@ } } - // Skip this uniform if we didn't find it + // If we didn't find the copy, it means the uniform wasn't an original (probably made with Python), + // so go ahead and get rid of it if(!copy) { + // We just remove here, and let the PythonUniform handle freeing cu = cu->next; + BLI_remlink(&mMat->csi.uniforms, cu->prev); + continue; } Modified: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp =================================================================== --- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp 2010-08-16 00:56:29 UTC (rev 31360) +++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp 2010-08-16 01:39:37 UTC (rev 31361) @@ -36,6 +36,7 @@ #include "KX_BlenderMaterial.h" #include "BL_BlenderShader.h" #include "DNA_material_types.h" +#include "BLI_listbase.h" /** * The Shader type @@ -189,6 +190,7 @@ KX_PythonUniform *uniform = static_cast<KX_PythonUniform*>BGE_PROXY_REF(value); + BLI_addhead(&m_mat->GetBlenderMaterial()->csi.uniforms, uniform->GetCustomUniform()); m_uniforms.push_back(uniform); Py_RETURN_NONE; @@ -203,8 +205,8 @@ m_name(name), m_type(type), m_size(size), - m_data(NULL), - m_cu(NULL) + m_cu(NULL), + m_owns_cu(true) { m_cu = (CustomUniform*)malloc(sizeof(CustomUniform)); m_cu->next = m_cu->prev = NULL; @@ -213,13 +215,35 @@ m_cu->type = type; m_cu->size = size; - m_cu->data =NULL; + switch (m_cu->type) + { + case MA_UNF_FLOAT: + *(float*)&m_cu->data = 0.f; + break; + case MA_UNF_VEC2: + case MA_UNF_VEC3: + case MA_UNF_VEC4: + m_cu->data = calloc(m_size, sizeof(float)); + break; + case MA_UNF_INT: + *(int*)&m_cu->data = 0; + break; + case MA_UNF_IVEC2: + case MA_UNF_IVEC3: + case MA_UNF_IVEC4: + m_cu->data = calloc(m_size, sizeof(int)); + default: + m_cu->data = NULL; + } + m_data = m_cu->data; + } KX_PythonUniform::KX_PythonUniform(CustomUniform *cu) : PyObjectPlus(), - m_cu(cu) + m_cu(cu), + m_owns_cu(false) { m_name = cu->name; m_type = cu->type; @@ -230,7 +254,8 @@ KX_PythonUniform::~KX_PythonUniform() { - // Empty + if (m_owns_cu) + free(m_cu); } PyObject *KX_PythonUniform::py_uniform_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Modified: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h =================================================================== --- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h 2010-08-16 00:56:29 UTC (rev 31360) +++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h 2010-08-16 01:39:37 UTC (rev 31361) @@ -40,6 +40,7 @@ { Py_Header; +private: STR_String m_vert, m_geom, m_frag; class KX_BlenderMaterial *m_mat; UniformList m_uniforms; @@ -68,12 +69,14 @@ { Py_Header; +private: STR_String m_name; short m_type; int m_size; void *m_data; struct CustomUniform *m_cu; + bool m_owns_cu; // This is so uniforms created in Python can clean up after themselves public: KX_PythonUniform(char* name, short type, int size); @@ -81,6 +84,7 @@ ~KX_PythonUniform(); STR_String& GetName() {return m_name;} + struct CustomUniform *GetCustomUniform() {return m_cu;} virtual PyObject* py_repr(void) { _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs