~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/gameengine/VideoTexture/Texture.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
-----------------------------------------------------------------------------
3
 
This source file is part of VideoTexture library
4
 
 
5
 
Copyright (c) 2007 The Zdeno Ash Miklas
6
 
 
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
10
 
version.
11
 
 
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.
15
 
 
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
 
-----------------------------------------------------------------------------
21
 
*/
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * Copyright (c) 2007 The Zdeno Ash Miklas
 
19
 *
 
20
 * This source file is part of VideoTexture library
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * ***** END GPL LICENSE BLOCK *****
 
25
 */
22
26
 
23
27
/** \file gameengine/VideoTexture/Texture.cpp
24
28
 *  \ingroup bgevideotex
26
30
 
27
31
// implementation
28
32
 
29
 
#include <PyObjectPlus.h>
 
33
#include "PyObjectPlus.h"
30
34
#include <structmember.h>
31
35
 
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>
39
 
 
40
 
#include <MEM_guardedalloc.h>
41
 
 
42
 
#include <KX_BlenderMaterial.h>
43
 
#include <BL_Texture.h>
 
36
#include "KX_GameObject.h"
 
37
#include "KX_Light.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"
 
44
 
 
45
#include "MEM_guardedalloc.h"
 
46
 
 
47
#include "KX_BlenderMaterial.h"
 
48
#include "BL_Texture.h"
44
49
 
45
50
#include "KX_KetsjiEngine.h"
46
51
#include "KX_PythonInit.h"
59
64
 
60
65
// Blender GameObject type
61
66
BlendType<KX_GameObject> gameObjectType ("KX_GameObject");
 
67
BlendType<KX_LightObject> lightObjectType ("KX_LightObject");
62
68
 
63
69
 
64
70
// load texture
105
111
        return NULL;
106
112
}
107
113
 
 
114
// get pointer to a lamp
 
115
static KX_LightObject *getLamp(PyObject *obj)
 
116
{
 
117
        // if object is available
 
118
        if (obj == NULL) return NULL;
 
119
 
 
120
        // returns NULL if obj is not a KX_LightObject
 
121
        return lightObjectType.checkType(obj);
 
122
}
 
123
 
108
124
 
109
125
// get material ID
110
 
short getMaterialID(PyObject * obj, const char *name)
 
126
short getMaterialID(PyObject *obj, const char *name)
111
127
{
112
128
        // search for material
113
129
        for (short matID = 0;; ++matID)
118
134
                if (mat == NULL) 
119
135
                        break;
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')
122
 
                {
 
137
                if (name[0] == 'I' && name[1] == 'M') {
123
138
                        // if texture name matches
124
139
                        if (strcmp(mat->GetTextureName().ReadPtr(), name) == 0)
125
140
                                return matID;
126
 
                } else 
127
 
                {
 
141
                }
 
142
                else {
128
143
                        // if material name matches
129
144
                        if (strcmp(mat->GetMaterialName().ReadPtr(), name) == 0)
130
145
                                return matID;
136
151
 
137
152
 
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)
140
155
{
141
156
        // allocate object
142
157
        Texture * self = reinterpret_cast<Texture*>(type->tp_alloc(type, 0));
156
171
 
157
172
 
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);
161
176
 
162
177
 
163
178
// Texture object deallocation
164
 
void Texture_dealloc (Texture * self)
 
179
static void Texture_dealloc(Texture *self)
165
180
{
166
181
        // release renderer
167
182
        Py_XDECREF(self->m_source);
168
183
        // close texture
169
 
        PyObject* ret = Texture_close(self);
 
184
        PyObject *ret = Texture_close(self);
170
185
        Py_DECREF(ret);
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);
175
190
}
176
191
 
177
192
 
179
194
ExpDesc MaterialNotAvailDesc (MaterialNotAvail, "Texture material is not available");
180
195
 
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)
183
198
{
184
199
        // parameters - game object with video texture
185
 
        PyObject * obj = NULL;
 
200
        PyObject *obj = NULL;
186
201
        // material ID
187
202
        short matID = 0;
188
203
        // texture ID
206
221
                {
207
222
                        // get pointer to texture image
208
223
                        RAS_IPolyMaterial * mat = getMaterial(obj, matID);
 
224
                        KX_LightObject * lamp = getLamp(obj);
209
225
                        if (mat != NULL)
210
226
                        {
211
227
                                // is it blender material or polygon material
227
243
                                        self->m_useMatTexture = false;
228
244
                                }
229
245
                        }
 
246
                        else if (lamp != NULL)
 
247
                        {
 
248
                                self->m_imgTexture = lamp->GetTextureImage(texID);
 
249
                                self->m_useMatTexture = false;
 
250
                        }
 
251
 
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
257
279
 
258
280
 
259
281
// close added texture
260
 
PyObject * Texture_close(Texture * self)
 
282
PyObject *Texture_close(Texture * self)
261
283
{
262
284
        // restore texture
263
285
        if (self->m_orgSaved)
280
302
 
281
303
 
282
304
// refresh texture
283
 
PyObject * Texture_refresh (Texture * self, PyObject * args)
 
305
static PyObject *Texture_refresh(Texture *self, PyObject *args)
284
306
{
285
307
        // get parameter - refresh source
286
 
        PyObject * param;
 
308
        PyObject *param;
287
309
        double ts = -1.0;
288
310
 
289
311
        if (!PyArg_ParseTuple(args, "O|d:refresh", &param, &ts) || !PyBool_Check(param))
372
394
}
373
395
 
374
396
// get OpenGL Bind Id
375
 
PyObject * Texture_getBindId (Texture * self, void * closure)
 
397
static PyObject *Texture_getBindId(Texture *self, void *closure)
376
398
{
377
399
        unsigned int id = self->m_actTex;
378
400
        return Py_BuildValue("h", id);
379
401
}
380
402
 
381
403
// get mipmap value
382
 
PyObject * Texture_getMipmap (Texture * self, void * closure)
 
404
static PyObject *Texture_getMipmap(Texture *self, void *closure)
383
405
{
384
406
        // return true if flag is set, otherwise false
385
407
        if (self->m_mipmap) Py_RETURN_TRUE;
387
409
}
388
410
 
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)
391
413
{
392
414
        // check parameter, report failure
393
415
        if (value == NULL || !PyBool_Check(value))
403
425
 
404
426
 
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)
407
429
{
408
430
        // if source exists
409
431
        if (self->m_source != NULL)
417
439
 
418
440
 
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)
421
443
{
422
444
        // check new value
423
445
        if (value == NULL || !pyImageTypes.in(Py_TYPE(value)))