svn merge ^/trunk/blender -r41226:41227 .
[blender.git] / source / gameengine / VideoTexture / Texture.cpp
index 3533cee0f7f85ac83986d6e056dcd06750b55029..eaf6002663b5695cedc5ef9550fc38afb46871f9 100644 (file)
@@ -1,4 +1,6 @@
-/* $Id$
+/** \file gameengine/VideoTexture/Texture.cpp
+ *  \ingroup bgevideotex
+ */
 -----------------------------------------------------------------------------
 This source file is part of VideoTexture library
 
@@ -50,7 +52,7 @@ http://www.gnu.org/copyleft/lesser.txt.
 
 // macro for exception handling and logging
 #define CATCH_EXCP catch (Exception & exp) \
-{ exp.report(); }
+{ exp.report(); return NULL; }
 
 
 // Blender GameObject type
@@ -162,11 +164,12 @@ void Texture_dealloc (Texture * self)
        // release renderer
        Py_XDECREF(self->m_source);
        // close texture
-       Texture_close(self);
+       PyObject* ret = Texture_close(self);
+       Py_DECREF(ret);
        // release scaled image buffer
        delete [] self->m_scaledImg;
        // release object
-       self->ob_type->tp_free((PyObject*)self);
+       ((PyObject *)self)->ob_type->tp_free((PyObject*)self);
 }
 
 
@@ -185,11 +188,12 @@ int Texture_init (Texture *self, PyObject *args, PyObject *kwds)
        // texture object with shared texture ID
        Texture * texObj = NULL;
 
-       static char *kwlist[] = {"gameObj", "materialID", "textureID", "textureObj", NULL};
+       static const char *kwlist[] = {"gameObj", "materialID", "textureID", "textureObj", NULL};
 
        // get parameters
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhO!", kwlist, &obj, &matID,
-               &texID, &TextureType, &texObj))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhO!",
+               const_cast<char**>(kwlist), &obj, &matID, &texID, &TextureType,
+               &texObj))
                return -1; 
 
        // if parameters are available
@@ -278,7 +282,9 @@ PyObject * Texture_refresh (Texture * self, PyObject * args)
 {
        // get parameter - refresh source
        PyObject * param;
-       if (!PyArg_ParseTuple(args, "O", &param) || !PyBool_Check(param))
+       double ts = -1.0;
+
+       if (!PyArg_ParseTuple(args, "O|d:refresh", &param, &ts) || !PyBool_Check(param))
        {
                // report error
                PyErr_SetString(PyExc_TypeError, "The value must be a bool");
@@ -314,7 +320,7 @@ PyObject * Texture_refresh (Texture * self, PyObject * args)
                                }
 
                                // get texture
-                               unsigned int * texture = self->m_source->m_image->getImage(self->m_actTex);
+                               unsigned int * texture = self->m_source->m_image->getImage(self->m_actTex, ts);
                                // if texture is available
                                if (texture != NULL)
                                {
@@ -353,6 +359,12 @@ PyObject * Texture_refresh (Texture * self, PyObject * args)
        Py_RETURN_NONE;
 }
 
+// get OpenGL Bind Id
+PyObject * Texture_getBindId (Texture * self, void * closure)
+{
+       unsigned int id = self->m_actTex;
+       return Py_BuildValue("h", id);
+}
 
 // get mipmap value
 PyObject * Texture_getMipmap (Texture * self, void * closure)
@@ -426,6 +438,7 @@ static PyGetSetDef textureGetSets[] =
 { 
        {(char*)"source", (getter)Texture_getSource, (setter)Texture_setSource, (char*)"source of texture", NULL},
        {(char*)"mipmap", (getter)Texture_getMipmap, (setter)Texture_setMipmap, (char*)"mipmap texture", NULL},
+       {(char*)"bindId", (getter)Texture_getBindId, NULL, (char*)"OpenGL Bind Name", NULL},
        {NULL}
 };
 
@@ -433,8 +446,7 @@ static PyGetSetDef textureGetSets[] =
 // class Texture declaration
 PyTypeObject TextureType =
 {
-       PyObject_HEAD_INIT(NULL)
-       0,                         /*ob_size*/
+       PyVarObject_HEAD_INIT(NULL, 0)
        "VideoTexture.Texture",   /*tp_name*/
        sizeof(Texture),           /*tp_basicsize*/
        0,                         /*tp_itemsize*/
@@ -452,7 +464,7 @@ PyTypeObject TextureType =
        0,                         /*tp_str*/
        0,                         /*tp_getattro*/
        0,                         /*tp_setattro*/
-       0,                         /*tp_as_buffer*/
+       &imageBufferProcs,         /*tp_as_buffer*/
        Py_TPFLAGS_DEFAULT,        /*tp_flags*/
        "Texture objects",       /* tp_doc */
        0,                             /* tp_traverse */