2
-----------------------------------------------------------------------------
3
This source file is part of VideoTexture library
5
Copyright (c) 2007 The Zdeno Ash Miklas
7
This program is free software; you can redistribute it and/or modify it under
8
the terms of the GNU Lesser General Public License as published by the Free Software
9
Foundation; either version 2 of the License, or (at your option) any later
12
This program is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License along with
17
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
19
http://www.gnu.org/copyleft/lesser.txt.
20
-----------------------------------------------------------------------------
2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Copyright (c) 2007 The Zdeno Ash Miklas
20
* This source file is part of VideoTexture library
24
* ***** END GPL LICENSE BLOCK *****
23
27
/** \file gameengine/VideoTexture/Texture.cpp
24
28
* \ingroup bgevideotex
29
#include <PyObjectPlus.h>
33
#include "PyObjectPlus.h"
30
34
#include <structmember.h>
32
#include <KX_GameObject.h>
33
#include <RAS_MeshObject.h>
34
#include <DNA_mesh_types.h>
35
#include <DNA_meshdata_types.h>
36
#include <DNA_image_types.h>
37
#include <IMB_imbuf_types.h>
38
#include <KX_PolygonMaterial.h>
40
#include <MEM_guardedalloc.h>
42
#include <KX_BlenderMaterial.h>
43
#include <BL_Texture.h>
36
#include "KX_GameObject.h"
38
#include "RAS_MeshObject.h"
39
#include "DNA_mesh_types.h"
40
#include "DNA_meshdata_types.h"
41
#include "DNA_image_types.h"
42
#include "IMB_imbuf_types.h"
43
#include "KX_PolygonMaterial.h"
45
#include "MEM_guardedalloc.h"
47
#include "KX_BlenderMaterial.h"
48
#include "BL_Texture.h"
45
50
#include "KX_KetsjiEngine.h"
46
51
#include "KX_PythonInit.h"
114
// get pointer to a lamp
115
static KX_LightObject *getLamp(PyObject *obj)
117
// if object is available
118
if (obj == NULL) return NULL;
120
// returns NULL if obj is not a KX_LightObject
121
return lightObjectType.checkType(obj);
109
125
// get material ID
110
short getMaterialID(PyObject * obj, const char *name)
126
short getMaterialID(PyObject *obj, const char *name)
112
128
// search for material
113
129
for (short matID = 0;; ++matID)
120
136
// name is a material name if it starts with MA and a UV texture name if it starts with IM
121
if (name[0] == 'I' && name[1] == 'M')
137
if (name[0] == 'I' && name[1] == 'M') {
123
138
// if texture name matches
124
139
if (strcmp(mat->GetTextureName().ReadPtr(), name) == 0)
128
143
// if material name matches
129
144
if (strcmp(mat->GetMaterialName().ReadPtr(), name) == 0)
138
153
// Texture object allocation
139
PyObject * Texture_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
154
static PyObject *Texture_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
141
156
// allocate object
142
157
Texture * self = reinterpret_cast<Texture*>(type->tp_alloc(type, 0));
158
173
// forward declaration
159
PyObject * Texture_close(Texture * self);
160
int Texture_setSource (Texture * self, PyObject * value, void * closure);
174
PyObject *Texture_close(Texture * self);
175
int Texture_setSource (Texture * self, PyObject *value, void *closure);
163
178
// Texture object deallocation
164
void Texture_dealloc (Texture * self)
179
static void Texture_dealloc(Texture *self)
166
181
// release renderer
167
182
Py_XDECREF(self->m_source);
169
PyObject* ret = Texture_close(self);
184
PyObject *ret = Texture_close(self);
171
186
// release scaled image buffer
172
187
delete [] self->m_scaledImg;
173
188
// release object
174
Py_TYPE((PyObject *)self)->tp_free((PyObject*)self);
189
Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
179
194
ExpDesc MaterialNotAvailDesc (MaterialNotAvail, "Texture material is not available");
181
196
// Texture object initialization
182
int Texture_init (Texture *self, PyObject *args, PyObject *kwds)
197
static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
184
199
// parameters - game object with video texture
185
PyObject * obj = NULL;
200
PyObject *obj = NULL;
227
243
self->m_useMatTexture = false;
246
else if (lamp != NULL)
248
self->m_imgTexture = lamp->GetTextureImage(texID);
249
self->m_useMatTexture = false;
230
252
// check if texture is available, if not, initialization failed
231
253
if (self->m_imgTexture == NULL && self->m_matTexture == NULL)
232
254
// throw exception if initialization failed
282
304
// refresh texture
283
PyObject * Texture_refresh (Texture * self, PyObject * args)
305
static PyObject *Texture_refresh(Texture *self, PyObject *args)
285
307
// get parameter - refresh source
287
309
double ts = -1.0;
289
311
if (!PyArg_ParseTuple(args, "O|d:refresh", ¶m, &ts) || !PyBool_Check(param))
374
396
// get OpenGL Bind Id
375
PyObject * Texture_getBindId (Texture * self, void * closure)
397
static PyObject *Texture_getBindId(Texture *self, void *closure)
377
399
unsigned int id = self->m_actTex;
378
400
return Py_BuildValue("h", id);
381
403
// get mipmap value
382
PyObject * Texture_getMipmap (Texture * self, void * closure)
404
static PyObject *Texture_getMipmap(Texture *self, void *closure)
384
406
// return true if flag is set, otherwise false
385
407
if (self->m_mipmap) Py_RETURN_TRUE;
389
411
// set mipmap value
390
int Texture_setMipmap (Texture * self, PyObject * value, void * closure)
412
static int Texture_setMipmap(Texture *self, PyObject *value, void *closure)
392
414
// check parameter, report failure
393
415
if (value == NULL || !PyBool_Check(value))
405
427
// get source object
406
PyObject * Texture_getSource (Texture * self, PyObject * value, void * closure)
428
static PyObject *Texture_getSource(Texture *self, PyObject *value, void *closure)
408
430
// if source exists
409
431
if (self->m_source != NULL)
419
441
// set source object
420
int Texture_setSource (Texture * self, PyObject * value, void * closure)
442
int Texture_setSource (Texture * self, PyObject *value, void *closure)
422
444
// check new value
423
445
if (value == NULL || !pyImageTypes.in(Py_TYPE(value)))