add missing files after merging
[blender.git] / source / gameengine / Ketsji / KX_PolygonMaterial.cpp
index 5b4322ae4cdb91ddabca1a4c65f122a6f1a9090c..9d0597051ad1f0dca8c8613fb395cea8e500556f 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -14,7 +14,7 @@
  *
  * 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.
+ * 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.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+
+/** \file gameengine/Ketsji/KX_PolygonMaterial.cpp
+ *  \ingroup ketsji
+ */
+
+
+#include <stddef.h>
 
 #include "KX_PolygonMaterial.h"
 
@@ -51,6 +55,8 @@
 
 #include "KX_PyMath.h"
 
+#define KX_POLYGONMATERIAL_CAPSULE_ID "KX_POLYGONMATERIAL_PTR"
+
 KX_PolygonMaterial::KX_PolygonMaterial()
                : PyObjectPlus(),
                  RAS_IPolyMaterial(),
@@ -58,7 +64,9 @@ KX_PolygonMaterial::KX_PolygonMaterial()
        m_tface(NULL),
        m_mcol(NULL),
        m_material(NULL),
+#ifdef WITH_PYTHON
        m_pymaterial(NULL),
+#endif
        m_pass(0)
 {
 }
@@ -92,26 +100,37 @@ void KX_PolygonMaterial::Initialize(
        m_tface = tface;
        m_mcol = mcol;
        m_material = ma;
+#ifdef WITH_PYTHON
        m_pymaterial = 0;
+#endif
        m_pass = 0;
 }
 
 KX_PolygonMaterial::~KX_PolygonMaterial()
 {
+#ifdef WITH_PYTHON
        if (m_pymaterial)
        {
                Py_DECREF(m_pymaterial);
        }
+#endif // WITH_PYTHON
+}
+
+Image *KX_PolygonMaterial::GetBlenderImage() const
+{
+       return (m_tface) ? m_tface->tpage : NULL;
 }
 
 bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const 
 {
        bool dopass = false;
+
+#ifdef WITH_PYTHON
        if (m_pymaterial)
        {
-               PyObject *pyRasty = PyCObject_FromVoidPtr((void*)rasty, NULL);  /* new reference */
-               PyObject *pyCachingInfo = PyCObject_FromVoidPtr((void*) &cachingInfo, NULL); /* new reference */
-               PyObject *ret = PyObject_CallMethod(m_pymaterial, "activate", "(NNO)", pyRasty, pyCachingInfo, (PyObject*) this->m_proxy);
+               PyObject *pyRasty = PyCapsule_New((void*)rasty, KX_POLYGONMATERIAL_CAPSULE_ID, NULL);   /* new reference */
+               PyObject *pyCachingInfo = PyCapsule_New((void*) &cachingInfo, KX_POLYGONMATERIAL_CAPSULE_ID, NULL); /* new reference */
+               PyObject *ret = PyObject_CallMethod(m_pymaterial, (char *)"activate", (char *)"(NNO)", pyRasty, pyCachingInfo, (PyObject*) this->m_proxy);
                if (ret)
                {
                        bool value = PyLong_AsSsize_t(ret);
@@ -126,6 +145,7 @@ bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingI
                }
        }
        else
+#endif // WITH_PYTHON
        {
                switch (m_pass++)
                {
@@ -152,7 +172,7 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c
 
                cachingInfo = GetCachingInfo();
 
-               if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED))
+               if ((m_drawingmode & RAS_IRasterizer::KX_TEX)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED))
                {
                        Image *ima = (Image*)m_tface->tpage;
                        GPU_update_image_time(ima, rasty->GetTime());
@@ -196,6 +216,7 @@ void KX_PolygonMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
                RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
 }
 
+#ifdef WITH_PYTHON
 
 //----------------------------------------------------------------------------
 //Python
@@ -227,7 +248,7 @@ PyAttributeDef KX_PolygonMaterial::Attributes[] = {
        KX_PYATTRIBUTE_FLOAT_RW("shininess", 0.0f, 1000.0f, KX_PolygonMaterial, m_shininess),
        KX_PYATTRIBUTE_FLOAT_RW("specularity", 0.0f, 1000.0f, KX_PolygonMaterial, m_specularity),
        
-       KX_PYATTRIBUTE_RW_FUNCTION("diffuse", KX_PolygonMaterial, pyattr_get_texture, pyattr_set_diffuse),
+       KX_PYATTRIBUTE_RW_FUNCTION("diffuse", KX_PolygonMaterial, pyattr_get_diffuse, pyattr_set_diffuse),
        KX_PYATTRIBUTE_RW_FUNCTION("specular",KX_PolygonMaterial, pyattr_get_specular, pyattr_set_specular),    
        
        KX_PYATTRIBUTE_RO_FUNCTION("tface",     KX_PolygonMaterial, pyattr_get_tface), /* How the heck is this even useful??? - Campbell */
@@ -278,10 +299,10 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(mat
 KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rasty)")
 {
        PyObject *pyrasty, *pytface;
-       if (PyArg_ParseTuple(args, "O!O!:updateTexture", &PyCObject_Type, &pytface, &PyCObject_Type, &pyrasty))
+       if (PyArg_ParseTuple(args, "O!O!:updateTexture", &PyCapsule_Type, &pytface, &PyCapsule_Type, &pyrasty))
        {
-               MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface);
-               RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCObject_AsVoidPtr(pyrasty);
+               MTFace *tface = (MTFace*) PyCapsule_GetPointer(pytface, KX_POLYGONMATERIAL_CAPSULE_ID);
+               RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCapsule_GetPointer(pyrasty, KX_POLYGONMATERIAL_CAPSULE_ID);
                Image *ima = (Image*)tface->tpage;
                GPU_update_image_time(ima, rasty->GetTime());
 
@@ -294,9 +315,9 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rast
 KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)")
 {
        PyObject *pytface;
-       if (PyArg_ParseTuple(args, "O!:setTexture", &PyCObject_Type, &pytface))
+       if (PyArg_ParseTuple(args, "O!:setTexture", &PyCapsule_Type, &pytface))
        {
-               MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface);
+               MTFace *tface = (MTFace*) PyCapsule_GetPointer(pytface, KX_POLYGONMATERIAL_CAPSULE_ID);
                GPU_set_tpage(tface, 1);
                Py_RETURN_NONE;
        }
@@ -307,10 +328,10 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)")
 KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)")
 {
        PyObject *pyrasty, *pyCachingInfo;
-       if (PyArg_ParseTuple(args, "O!O!:activate", &PyCObject_Type, &pyrasty, &PyCObject_Type, &pyCachingInfo))
+       if (PyArg_ParseTuple(args, "O!O!:activate", &PyCapsule_Type, &pyrasty, &PyCapsule_Type, &pyCachingInfo))
        {
-               RAS_IRasterizer *rasty = static_cast<RAS_IRasterizer*>(PyCObject_AsVoidPtr(pyrasty));
-               TCachingInfo *cachingInfo = static_cast<TCachingInfo*>(PyCObject_AsVoidPtr(pyCachingInfo));
+               RAS_IRasterizer *rasty = static_cast<RAS_IRasterizer*>(PyCapsule_GetPointer(pyrasty, KX_POLYGONMATERIAL_CAPSULE_ID));
+               TCachingInfo *cachingInfo = static_cast<TCachingInfo*>(PyCapsule_GetPointer(pyCachingInfo, KX_POLYGONMATERIAL_CAPSULE_ID));
                if (rasty && cachingInfo)
                {
                        DefaultActivate(rasty, *cachingInfo);
@@ -337,7 +358,7 @@ PyObject* KX_PolygonMaterial::pyattr_get_material(void *self_v, const KX_PYATTRI
 PyObject* KX_PolygonMaterial::pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        KX_PolygonMaterial* self= static_cast<KX_PolygonMaterial*>(self_v);
-       return PyCObject_FromVoidPtr(self->m_tface, NULL);
+       return PyCapsule_New(self->m_tface, KX_POLYGONMATERIAL_CAPSULE_ID, NULL);
 }
 
 PyObject* KX_PolygonMaterial::pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
@@ -386,3 +407,5 @@ int KX_PolygonMaterial::pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_D
        self->m_specular= vec;
        return PY_SET_ATTR_SUCCESS;
 }
+
+#endif // WITH_PYTHON