OLD | NEW |
1 /* | 1 /* |
2 ----------------------------------------------------------------------------- | 2 ----------------------------------------------------------------------------- |
3 This source file is part of VideoTexture library | 3 This source file is part of VideoTexture library |
4 | 4 |
5 Copyright (c) 2007 The Zdeno Ash Miklas | 5 Copyright (c) 2007 The Zdeno Ash Miklas |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify it under | 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 Soft
ware | 8 the terms of the GNU Lesser General Public License as published by the Free Soft
ware |
9 Foundation; either version 2 of the License, or (at your option) any later | 9 Foundation; either version 2 of the License, or (at your option) any later |
10 version. | 10 version. |
(...skipping 12 matching lines...) Expand all Loading... |
23 /** \file gameengine/VideoTexture/Texture.cpp | 23 /** \file gameengine/VideoTexture/Texture.cpp |
24 * \ingroup bgevideotex | 24 * \ingroup bgevideotex |
25 */ | 25 */ |
26 | 26 |
27 // implementation | 27 // implementation |
28 | 28 |
29 #include <PyObjectPlus.h> | 29 #include <PyObjectPlus.h> |
30 #include <structmember.h> | 30 #include <structmember.h> |
31 | 31 |
32 #include <KX_GameObject.h> | 32 #include <KX_GameObject.h> |
| 33 #include <KX_Light.h> |
33 #include <RAS_MeshObject.h> | 34 #include <RAS_MeshObject.h> |
34 #include <DNA_mesh_types.h> | 35 #include <DNA_mesh_types.h> |
35 #include <DNA_meshdata_types.h> | 36 #include <DNA_meshdata_types.h> |
36 #include <DNA_image_types.h> | 37 #include <DNA_image_types.h> |
37 #include <IMB_imbuf_types.h> | 38 #include <IMB_imbuf_types.h> |
38 #include <KX_PolygonMaterial.h> | 39 #include <KX_PolygonMaterial.h> |
39 | 40 |
40 #include <MEM_guardedalloc.h> | 41 #include <MEM_guardedalloc.h> |
41 | 42 |
42 #include <KX_BlenderMaterial.h> | 43 #include <KX_BlenderMaterial.h> |
43 #include <BL_Texture.h> | 44 #include <BL_Texture.h> |
44 | 45 |
45 #include "KX_KetsjiEngine.h" | 46 #include "KX_KetsjiEngine.h" |
46 #include "KX_PythonInit.h" | 47 #include "KX_PythonInit.h" |
47 #include "Texture.h" | 48 #include "Texture.h" |
48 #include "ImageBase.h" | 49 #include "ImageBase.h" |
49 #include "Exception.h" | 50 #include "Exception.h" |
50 | 51 |
51 #include <memory.h> | 52 #include <memory.h> |
52 #include "GL/glew.h" | 53 #include "GL/glew.h" |
53 | 54 |
54 | 55 |
55 // macro for exception handling and logging | 56 // macro for exception handling and logging |
56 #define CATCH_EXCP catch (Exception & exp) \ | 57 #define CATCH_EXCP catch (Exception & exp) \ |
57 { exp.report(); return NULL; } | 58 { exp.report(); return NULL; } |
58 | 59 |
59 | 60 |
60 // Blender GameObject type | 61 // Blender GameObject type |
61 BlendType<KX_GameObject> gameObjectType ("KX_GameObject"); | 62 BlendType<KX_GameObject> gameObjectType ("KX_GameObject"); |
| 63 BlendType<KX_LightObject> lightObjectType ("KX_LightObject"); |
62 | 64 |
63 | 65 |
64 // load texture | 66 // load texture |
65 void loadTexture (unsigned int texId, unsigned int * texture, short * size, | 67 void loadTexture (unsigned int texId, unsigned int * texture, short * size, |
66 bool mipmap) | 68 bool mipmap) |
67 { | 69 { |
68 // load texture for rendering | 70 // load texture for rendering |
69 glBindTexture(GL_TEXTURE_2D, texId); | 71 glBindTexture(GL_TEXTURE_2D, texId); |
70 if (mipmap) | 72 if (mipmap) |
71 { | 73 { |
(...skipping 26 matching lines...) Expand all Loading... |
98 RAS_MeshMaterial *meshMat = mesh->GetMeshMaterial(matID)
; | 100 RAS_MeshMaterial *meshMat = mesh->GetMeshMaterial(matID)
; |
99 if (meshMat != NULL && meshMat->m_bucket != NULL) | 101 if (meshMat != NULL && meshMat->m_bucket != NULL) |
100 // return pointer to polygon or blender material | 102 // return pointer to polygon or blender material |
101 return meshMat->m_bucket->GetPolyMaterial(); | 103 return meshMat->m_bucket->GetPolyMaterial(); |
102 } | 104 } |
103 } | 105 } |
104 // otherwise material was not found | 106 // otherwise material was not found |
105 return NULL; | 107 return NULL; |
106 } | 108 } |
107 | 109 |
| 110 // get pointer to a lamp |
| 111 KX_LightObject * getLamp(PyObject *obj) |
| 112 { |
| 113 // if object is available |
| 114 if (obj == NULL) return NULL; |
| 115 |
| 116 // returns NULL if obj is not a KX_LightObject |
| 117 return lightObjectType.checkType(obj); |
| 118 } |
| 119 |
108 | 120 |
109 // get material ID | 121 // get material ID |
110 short getMaterialID(PyObject * obj, const char *name) | 122 short getMaterialID(PyObject * obj, const char *name) |
111 { | 123 { |
112 // search for material | 124 // search for material |
113 for (short matID = 0;; ++matID) | 125 for (short matID = 0;; ++matID) |
114 { | 126 { |
115 // get material | 127 // get material |
116 RAS_IPolyMaterial * mat = getMaterial(obj, matID); | 128 RAS_IPolyMaterial * mat = getMaterial(obj, matID); |
117 // if material is not available, report that no material was fou
nd | 129 // if material is not available, report that no material was fou
nd |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return -1;· | 211 return -1;· |
200 | 212 |
201 // if parameters are available | 213 // if parameters are available |
202 if (obj != NULL) | 214 if (obj != NULL) |
203 { | 215 { |
204 // process polygon material or blender material | 216 // process polygon material or blender material |
205 try | 217 try |
206 { | 218 { |
207 // get pointer to texture image | 219 // get pointer to texture image |
208 RAS_IPolyMaterial * mat = getMaterial(obj, matID); | 220 RAS_IPolyMaterial * mat = getMaterial(obj, matID); |
| 221 KX_LightObject * lamp = getLamp(obj); |
209 if (mat != NULL) | 222 if (mat != NULL) |
210 { | 223 { |
211 // is it blender material or polygon material | 224 // is it blender material or polygon material |
212 if (mat->GetFlag() & RAS_BLENDERGLSL)· | 225 if (mat->GetFlag() & RAS_BLENDERGLSL)· |
213 { | 226 { |
214 self->m_imgTexture = static_cast<KX_Blen
derMaterial*>(mat)->getImage(texID); | 227 self->m_imgTexture = static_cast<KX_Blen
derMaterial*>(mat)->getImage(texID); |
215 self->m_useMatTexture = false; | 228 self->m_useMatTexture = false; |
216 } else if (mat->GetFlag() & RAS_BLENDERMAT) | 229 } else if (mat->GetFlag() & RAS_BLENDERMAT) |
217 { | 230 { |
218 // get blender material texture | 231 // get blender material texture |
219 self->m_matTexture = static_cast<KX_Blen
derMaterial*>(mat)->getTex(texID); | 232 self->m_matTexture = static_cast<KX_Blen
derMaterial*>(mat)->getTex(texID); |
220 self->m_useMatTexture = true; | 233 self->m_useMatTexture = true; |
221 } | 234 } |
222 else | 235 else |
223 { | 236 { |
224 // get texture pointer from polygon mate
rial | 237 // get texture pointer from polygon mate
rial |
225 MTFace * tface = static_cast<KX_PolygonM
aterial*>(mat)->GetMTFace(); | 238 MTFace * tface = static_cast<KX_PolygonM
aterial*>(mat)->GetMTFace(); |
226 self->m_imgTexture = (Image*)tface->tpag
e; | 239 self->m_imgTexture = (Image*)tface->tpag
e; |
227 self->m_useMatTexture = false; | 240 self->m_useMatTexture = false; |
228 } | 241 } |
229 } | 242 } |
| 243 else if (lamp != NULL) |
| 244 { |
| 245 self->m_imgTexture = lamp->GetTextureImage(texID
); |
| 246 self->m_useMatTexture = false; |
| 247 } |
| 248 |
230 // check if texture is available, if not, initialization
failed | 249 // check if texture is available, if not, initialization
failed |
231 if (self->m_imgTexture == NULL && self->m_matTexture ==
NULL) | 250 if (self->m_imgTexture == NULL && self->m_matTexture ==
NULL) |
232 // throw exception if initialization failed | 251 // throw exception if initialization failed |
233 THRWEXCP(MaterialNotAvail, S_OK); | 252 THRWEXCP(MaterialNotAvail, S_OK); |
234 | 253 |
235 // if texture object is provided | 254 // if texture object is provided |
236 if (texObj != NULL) | 255 if (texObj != NULL) |
237 { | 256 { |
238 // copy texture code | 257 // copy texture code |
239 self->m_actTex = texObj->m_actTex; | 258 self->m_actTex = texObj->m_actTex; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 textureGetSets, /* tp_getset */ | 509 textureGetSets, /* tp_getset */ |
491 0, /* tp_base */ | 510 0, /* tp_base */ |
492 0, /* tp_dict */ | 511 0, /* tp_dict */ |
493 0, /* tp_descr_get */ | 512 0, /* tp_descr_get */ |
494 0, /* tp_descr_set */ | 513 0, /* tp_descr_set */ |
495 0, /* tp_dictoffset */ | 514 0, /* tp_dictoffset */ |
496 (initproc)Texture_init, /* tp_init */ | 515 (initproc)Texture_init, /* tp_init */ |
497 0, /* tp_alloc */ | 516 0, /* tp_alloc */ |
498 Texture_new, /* tp_new */ | 517 Texture_new, /* tp_new */ |
499 }; | 518 }; |
OLD | NEW |