~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_Light.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: KX_Light.cpp 20828 2009-06-12 12:56:12Z campbellbarton $
 
2
 * $Id: KX_Light.cpp 33442 2010-12-03 12:30:59Z campbellbarton $
3
3
 * ***** BEGIN GPL LICENSE BLOCK *****
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software Foundation,
17
 
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
 *
19
19
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20
20
 * All rights reserved.
26
26
 * ***** END GPL LICENSE BLOCK *****
27
27
 */
28
28
 
29
 
#ifdef HAVE_CONFIG_H
30
 
#include <config.h>
31
 
#endif
32
 
 
33
 
#ifdef WIN32
34
 
 
 
29
#if defined(WIN32) && !defined(FREE_WINDOWS)
35
30
#pragma warning (disable : 4786)
36
31
#endif
37
32
 
51
46
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
52
47
                                                           class RAS_IRenderTools* rendertools,
53
48
                                                           const RAS_LightObject&       lightobj,
54
 
                                                           bool glsl,
55
 
                                                           PyTypeObject* T
56
 
                                                           )
57
 
 :
58
 
        KX_GameObject(sgReplicationInfo,callbacks,T),
59
 
                m_rendertools(rendertools)
 
49
                                                           bool glsl)
 
50
        : KX_GameObject(sgReplicationInfo,callbacks),
 
51
          m_rendertools(rendertools)
60
52
{
61
53
        m_lightobj = lightobj;
62
54
        m_lightobj.m_scene = sgReplicationInfo;
73
65
 
74
66
        if((lamp = GetGPULamp())) {
75
67
                float obmat[4][4] = {{0}};
76
 
                GPU_lamp_update(lamp, 0, obmat);
 
68
                GPU_lamp_update(lamp, 0, 0, obmat);
77
69
        }
78
70
 
79
71
        m_rendertools->RemoveLight(&m_lightobj);
188
180
        if(m_glsl)
189
181
                return GPU_lamp_from_blender(m_blenderscene, GetBlenderObject(), GetBlenderGroupObject());
190
182
        else
191
 
                return false;
 
183
                return NULL;
192
184
}
193
185
 
194
186
void KX_LightObject::Update()
206
198
                        for(int j=0; j<4; j++, dobmat++)
207
199
                                obmat[i][j] = (float)*dobmat;
208
200
 
209
 
                GPU_lamp_update(lamp, m_lightobj.m_layer, obmat);
 
201
                GPU_lamp_update(lamp, m_lightobj.m_layer, 0, obmat);
210
202
                GPU_lamp_update_colors(lamp, m_lightobj.m_red, m_lightobj.m_green, 
211
203
                        m_lightobj.m_blue, m_lightobj.m_energy);
212
204
        }
267
259
        GPU_lamp_shadow_buffer_unbind(lamp);
268
260
}
269
261
 
 
262
#ifdef WITH_PYTHON
270
263
/* ------------------------------------------------------------------------- */
271
264
/* Python Integration Hooks                                                                      */
272
265
/* ------------------------------------------------------------------------- */
273
266
 
274
 
PyObject* KX_LightObject::py_getattro_dict() {
275
 
        py_getattro_dict_up(KX_GameObject);
276
 
}
277
 
 
278
 
 
279
267
PyTypeObject KX_LightObject::Type = {
280
 
#if (PY_VERSION_HEX >= 0x02060000)
281
268
        PyVarObject_HEAD_INIT(NULL, 0)
282
 
#else
283
 
        /* python 2.5 and below */
284
 
        PyObject_HEAD_INIT( NULL )  /* required py macro */
285
 
        0,                          /* ob_size */
286
 
#endif
287
 
                "KX_LightObject",
288
 
                sizeof(PyObjectPlus_Proxy),
289
 
                0,
290
 
                py_base_dealloc,
291
 
                0,
292
 
                0,
293
 
                0,
294
 
                0,
295
 
                py_base_repr,
296
 
                0,
297
 
                &KX_GameObject::Sequence,
298
 
                &KX_GameObject::Mapping,
299
 
                0,0,0,
300
 
                py_base_getattro,
301
 
                py_base_setattro,
302
 
                0,
303
 
                Py_TPFLAGS_DEFAULT,
304
 
                0,0,0,0,0,0,0,
305
 
                Methods
306
 
};
307
 
 
308
 
PyParentObject KX_LightObject::Parents[] = {
309
 
        &KX_LightObject::Type,
 
269
        "KX_LightObject",
 
270
        sizeof(PyObjectPlus_Proxy),
 
271
        0,
 
272
        py_base_dealloc,
 
273
        0,
 
274
        0,
 
275
        0,
 
276
        0,
 
277
        py_base_repr,
 
278
        0,
 
279
        &KX_GameObject::Sequence,
 
280
        &KX_GameObject::Mapping,
 
281
        0,0,0,
 
282
        NULL,
 
283
        NULL,
 
284
        0,
 
285
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
 
286
        0,0,0,0,0,0,0,
 
287
        Methods,
 
288
        0,
 
289
        0,
310
290
        &KX_GameObject::Type,
311
 
                &SCA_IObject::Type,
312
 
                &CValue::Type,
313
 
                NULL
 
291
        0,0,0,0,0,0,
 
292
        py_base_new
314
293
};
315
294
 
316
295
PyMethodDef KX_LightObject::Methods[] = {
322
301
        KX_PYATTRIBUTE_FLOAT_RW("energy", 0, 10, KX_LightObject, m_lightobj.m_energy),
323
302
        KX_PYATTRIBUTE_FLOAT_RW("distance", 0.01, 5000, KX_LightObject, m_lightobj.m_distance),
324
303
        KX_PYATTRIBUTE_RW_FUNCTION("color", KX_LightObject, pyattr_get_color, pyattr_set_color),
325
 
        KX_PYATTRIBUTE_RW_FUNCTION("colour", KX_LightObject, pyattr_get_color, pyattr_set_color),
326
304
        KX_PYATTRIBUTE_FLOAT_RW("lin_attenuation", 0, 1, KX_LightObject, m_lightobj.m_att1),
327
305
        KX_PYATTRIBUTE_FLOAT_RW("quad_attenuation", 0, 1, KX_LightObject, m_lightobj.m_att2),
328
306
        KX_PYATTRIBUTE_FLOAT_RW("spotsize", 1, 180, KX_LightObject, m_lightobj.m_spotsize),
361
339
 
362
340
        const char* type = attrdef->m_name;
363
341
 
364
 
        if(strcmp(type, "SPOT")) {
365
 
                retvalue = PyInt_FromLong(RAS_LightObject::LIGHT_SPOT);
366
 
        } else if (strcmp(type, "SUN")) {
367
 
                retvalue = PyInt_FromLong(RAS_LightObject::LIGHT_SUN);
368
 
        } else if (strcmp(type, "NORMAL")) {
369
 
                retvalue = PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL);
 
342
        if(!strcmp(type, "SPOT")) {
 
343
                retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_SPOT);
 
344
        } else if (!strcmp(type, "SUN")) {
 
345
                retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_SUN);
 
346
        } else if (!strcmp(type, "NORMAL")) {
 
347
                retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_NORMAL);
370
348
        }
 
349
    else {
 
350
        /* should never happen */
 
351
        PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type");
 
352
        retvalue = NULL;
 
353
    }
371
354
 
372
355
        return retvalue;
373
356
}
375
358
PyObject* KX_LightObject::pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef)
376
359
{
377
360
        KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
378
 
        return PyInt_FromLong(self->m_lightobj.m_type);
 
361
        return PyLong_FromSsize_t(self->m_lightobj.m_type);
379
362
}
380
363
 
381
364
int KX_LightObject::pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value)
382
365
{
383
366
        KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
384
 
        int val = PyInt_AsLong(value);
 
367
        int val = PyLong_AsSsize_t(value);
385
368
        if((val==-1 && PyErr_Occurred()) || val<0 || val>2) {
386
369
                PyErr_SetString(PyExc_ValueError, "light.type= val: KX_LightObject, expected an int between 0 and 2");
387
370
                return PY_SET_ATTR_FAIL;
401
384
 
402
385
        return PY_SET_ATTR_SUCCESS;
403
386
}
404
 
 
405
 
 
406
 
PyObject* KX_LightObject::py_getattro(PyObject *attr)
407
 
{
408
 
        py_getattro_up(KX_GameObject);
409
 
}
410
 
 
411
 
int KX_LightObject::py_setattro(PyObject *attr, PyObject *value)
412
 
{
413
 
        py_setattro_up(KX_GameObject);
414
 
}
 
387
#endif // WITH_PYTHON