BGE Rasterizer Cleanup: Removing the Singletexture material mode. More conversion code will probably be needed.

This commit is contained in:
Mitchell Stokes 2013-11-04 19:21:50 +00:00
parent a35e9daaef
commit 0cec5c63da
15 changed files with 42 additions and 796 deletions

View File

@ -9783,6 +9783,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
{
Scene *scene;
for (scene = main->scene.first; scene; scene = scene->id.next) {
if (scene->gm.matmode == GAME_MAT_TEXFACE) {
scene->gm.matmode = GAME_MAT_MULTITEX;
}
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */

View File

@ -725,7 +725,7 @@ typedef struct GameData {
#define GAME_PLAYER_DESKTOP_RESOLUTION (1 << 1)
/* GameData.matmode */
#define GAME_MAT_TEXFACE 0
#define GAME_MAT_TEXFACE 0 /* deprecated */
#define GAME_MAT_MULTITEX 1
#define GAME_MAT_GLSL 2

View File

@ -3143,7 +3143,6 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
};
static EnumPropertyItem material_items[] = {
{GAME_MAT_TEXFACE, "SINGLETEXTURE", 0, "Singletexture", "Singletexture face materials"},
{GAME_MAT_MULTITEX, "MULTITEXTURE", 0, "Multitexture", "Multitexture materials"},
{GAME_MAT_GLSL, "GLSL", 0, "GLSL", "OpenGL shading language shaders"},
{0, NULL, 0, NULL, NULL}

View File

@ -470,7 +470,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
else if (gs.matmode == GAME_MAT_GLSL)
usemat = false;
if (usemat && (gs.matmode != GAME_MAT_TEXFACE))
if (usemat)
sceneconverter->SetMaterials(true);
if (useglslmat && (gs.matmode == GAME_MAT_GLSL))
sceneconverter->SetGLSLMaterials(true);

View File

@ -42,7 +42,6 @@
#include "KX_BlenderScalarInterpolator.h"
#include "RAS_IPolygonMaterial.h"
#include "KX_PolygonMaterial.h"
// Expressions
#include "ListValue.h"
@ -891,167 +890,33 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace
RAS_IPolyMaterial* polymat = converter->FindCachedPolyMaterial(scene, ma);
BL_Material* bl_mat = converter->FindCachedBlenderMaterial(scene, ma);
KX_BlenderMaterial* kx_blmat = NULL;
KX_PolygonMaterial* kx_polymat = NULL;
if (converter->GetMaterials()) {
/* do Blender Multitexture and Blender GLSL materials */
/* first is the BL_Material */
if (!bl_mat)
{
bl_mat = new BL_Material();
/* first is the BL_Material */
if (!bl_mat)
{
bl_mat = new BL_Material();
ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol,
converter->GetGLSLMaterials());
ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol,
converter->GetGLSLMaterials());
if (ma && (ma->mode & MA_FACETEXTURE) == 0)
converter->CacheBlenderMaterial(scene, ma, bl_mat);
}
const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat);
GetRGB(use_vcol, mface, mcol, ma, rgb);
GetUVs(bl_mat, layers, mface, tface, uvs);
/* then the KX_BlenderMaterial */
if (polymat == NULL)
{
kx_blmat = new KX_BlenderMaterial();
kx_blmat->Initialize(scene, bl_mat, (ma?&ma->game:NULL), lightlayer);
polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat);
if (ma && (ma->mode & MA_FACETEXTURE) == 0)
converter->CachePolyMaterial(scene, ma, polymat);
}
if (ma && (ma->mode & MA_FACETEXTURE) == 0)
converter->CacheBlenderMaterial(scene, ma, bl_mat);
}
else {
/* do Texture Face materials */
Image* bima = (tface)? (Image*)tface->tpage: NULL;
STR_String imastr = (tface)? (bima? (bima)->id.name : "" ) : "";
char alpha_blend=0;
short tile=0;
int tilexrep=4,tileyrep = 4;
/* set material properties - old TexFace */
if (ma) {
alpha_blend = ma->game.alpha_blend;
/* Commented out for now. If we ever get rid of
* "Texture Face/Singletexture" we can then think about it */
const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat);
GetRGB(use_vcol, mface, mcol, ma, rgb);
/* Texture Face mode ignores texture but requires "Face Textures to be True "*/
#if 0
if ((ma->mode &MA_FACETEXTURE)==0 && (ma->game.flag &GEMAT_TEXT)==0) {
bima = NULL;
imastr = "";
alpha_blend = GEMAT_SOLID;
}
else {
alpha_blend = ma->game.alpha_blend;
}
#endif
}
/* check for tface tex to fallback on */
else {
if (bima) {
/* see if depth of the image is 32 */
if (BKE_image_has_alpha(bima))
alpha_blend = GEMAT_ALPHA;
else
alpha_blend = GEMAT_SOLID;
}
else {
alpha_blend = GEMAT_SOLID;
}
}
GetUVs(bl_mat, layers, mface, tface, uvs);
if (bima) {
tilexrep = bima->xrep;
tileyrep = bima->yrep;
}
/* set UV properties */
if (tface) {
uvs[0][0].setValue(tface->uv[0]);
uvs[1][0].setValue(tface->uv[1]);
uvs[2][0].setValue(tface->uv[2]);
if (mface->v4)
uvs[3][0].setValue(tface->uv[3]);
tile = tface->tile;
}
else {
/* no texfaces */
tile = 0;
}
/* get vertex colors */
if (mcol) {
/* we have vertex colors */
rgb[0] = KX_Mcol2uint_new(mcol[0]);
rgb[1] = KX_Mcol2uint_new(mcol[1]);
rgb[2] = KX_Mcol2uint_new(mcol[2]);
if (mface->v4)
rgb[3] = KX_Mcol2uint_new(mcol[3]);
}
else {
/* no vertex colors, take from material, otherwise white */
unsigned int color = 0xFFFFFFFFL;
if (ma)
{
union
{
unsigned char cp[4];
unsigned int integer;
} col_converter;
col_converter.cp[3] = (unsigned char) (ma->r*255.0);
col_converter.cp[2] = (unsigned char) (ma->g*255.0);
col_converter.cp[1] = (unsigned char) (ma->b*255.0);
col_converter.cp[0] = (unsigned char) (ma->alpha*255.0);
color = col_converter.integer;
}
rgb[0] = KX_rgbaint2uint_new(color);
rgb[1] = KX_rgbaint2uint_new(color);
rgb[2] = KX_rgbaint2uint_new(color);
if (mface->v4)
rgb[3] = KX_rgbaint2uint_new(color);
}
// only zsort alpha + add
const bool alpha = ELEM3(alpha_blend, GEMAT_ALPHA, GEMAT_ADD, GEMAT_ALPHA_SORT);
const bool zsort = (alpha_blend == GEMAT_ALPHA_SORT);
const bool light = (ma)?(ma->mode & MA_SHLESS)==0:default_light_mode;
// don't need zort anymore, deal as if it it's alpha blend
if (alpha_blend == GEMAT_ALPHA_SORT) alpha_blend = GEMAT_ALPHA;
if (polymat == NULL)
{
kx_polymat = new KX_PolygonMaterial();
kx_polymat->Initialize(imastr, ma, (int)mface->mat_nr,
tile, tilexrep, tileyrep,
alpha_blend, alpha, zsort, light, lightlayer, tface, (unsigned int*)mcol);
polymat = static_cast<RAS_IPolyMaterial*>(kx_polymat);
if (ma) {
polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec;
polymat->m_shininess = (float)ma->har/4.0f; // 0 < ma->har <= 512
polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref);
}
else {
polymat->m_specular.setValue(0.0f,0.0f,0.0f);
polymat->m_shininess = 35.0;
}
/* then the KX_BlenderMaterial */
if (polymat == NULL)
{
kx_blmat = new KX_BlenderMaterial();
kx_blmat->Initialize(scene, bl_mat, (ma?&ma->game:NULL), lightlayer);
polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat);
if (ma && (ma->mode & MA_FACETEXTURE) == 0)
converter->CachePolyMaterial(scene, ma, polymat);
}
}
// see if a bucket was reused or a new one was created
@ -1061,8 +926,7 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace
if (bucketCreated) {
// this is needed to free up memory afterwards
converter->RegisterPolyMaterial(polymat);
if (converter->GetMaterials())
converter->RegisterBlenderMaterial(bl_mat);
converter->RegisterBlenderMaterial(bl_mat);
}
return bucket;

View File

@ -46,7 +46,6 @@
#include "BL_Material.h"
#include "BL_ActionActuator.h"
#include "KX_BlenderMaterial.h"
#include "KX_PolygonMaterial.h"
#include "BL_System.h"
@ -1419,15 +1418,8 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie)
RAS_IPolyMaterial *mat= (*polymit).second;
Material *bmat= NULL;
/* Why do we need to check for RAS_BLENDERMAT if both are cast to a (PyObject *)? - Campbell */
if (mat->GetFlag() & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
bmat= bl_mat->GetBlenderMaterial();
} else {
KX_PolygonMaterial *kx_mat = static_cast<KX_PolygonMaterial*>(mat);
bmat= kx_mat->GetBlenderMaterial();
}
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
bmat= bl_mat->GetBlenderMaterial();
if (IS_TAGGED(bmat)) {
/* only remove from bucket */
@ -1444,15 +1436,8 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie)
RAS_IPolyMaterial *mat= (*polymit).second;
Material *bmat= NULL;
/* Why do we need to check for RAS_BLENDERMAT if both are cast to a (PyObject *)? - Campbell */
if (mat->GetFlag() & RAS_BLENDERMAT) {
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
bmat= bl_mat->GetBlenderMaterial();
} else {
KX_PolygonMaterial *kx_mat = static_cast<KX_PolygonMaterial*>(mat);
bmat= kx_mat->GetBlenderMaterial();
}
KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
bmat= bl_mat->GetBlenderMaterial();
if (bmat) {
//printf("FOUND MAT '%s' !!! ", ((ID*)bmat)->name+2);

View File

@ -703,7 +703,7 @@ bool GPG_Application::startEngine(void)
// if (always_use_expand_framing)
// sceneconverter->SetAlwaysUseExpandFraming(true);
if (m_blendermat && (m_globalSettings->matmode != GAME_MAT_TEXFACE))
if (m_blendermat)
m_sceneconverter->SetMaterials(true);
if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL))
m_sceneconverter->SetGLSLMaterials(true);

View File

@ -103,7 +103,6 @@ set(SRC
KX_OrientationInterpolator.cpp
KX_ParentActuator.cpp
KX_PolyProxy.cpp
KX_PolygonMaterial.cpp
KX_PositionInterpolator.cpp
KX_PyConstraintBinding.cpp
KX_PyMath.cpp
@ -186,7 +185,6 @@ set(SRC
KX_ParentActuator.h
KX_PhysicsEngineEnums.h
KX_PolyProxy.h
KX_PolygonMaterial.h
KX_PositionInterpolator.h
KX_PyConstraintBinding.h
KX_PyMath.h

View File

@ -39,7 +39,6 @@
#include "KX_VertexProxy.h"
#include "KX_PolyProxy.h"
#include "KX_PolygonMaterial.h"
#include "KX_BlenderMaterial.h"
#include "KX_PyMath.h"
@ -388,14 +387,8 @@ PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_
for (i=0; i<tot; mit++, i++) {
RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
if (polymat->GetFlag() & RAS_BLENDERMAT) {
KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat);
PyList_SET_ITEM(materials, i, mat->GetProxy());
}
else {
KX_PolygonMaterial *mat = static_cast<KX_PolygonMaterial *>(polymat);
PyList_SET_ITEM(materials, i, mat->GetProxy());
}
KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat);
PyList_SET_ITEM(materials, i, mat->GetProxy());
}
return materials;
}

View File

@ -36,7 +36,6 @@
#include "KX_MeshProxy.h"
#include "RAS_MeshObject.h"
#include "KX_BlenderMaterial.h"
#include "KX_PolygonMaterial.h"
#include "KX_PyMath.h"
@ -259,16 +258,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterial,
"getMaterial() : returns a material\n")
{
RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial();
if (polymat->GetFlag() & RAS_BLENDERMAT)
{
KX_BlenderMaterial* mat = static_cast<KX_BlenderMaterial*>(polymat);
return mat->GetProxy();
}
else
{
KX_PolygonMaterial* mat = static_cast<KX_PolygonMaterial*>(polymat);
return mat->GetProxy();
}
KX_BlenderMaterial* mat = static_cast<KX_BlenderMaterial*>(polymat);
return mat->GetProxy();
}
#endif // WITH_PYTHON

View File

@ -1,422 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file gameengine/Ketsji/KX_PolygonMaterial.cpp
* \ingroup ketsji
*/
#include <stddef.h>
#include "KX_PolygonMaterial.h"
#include "BKE_mesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_image_types.h"
#include "DNA_meshdata_types.h"
#include "IMB_imbuf_types.h"
#include "GPU_draw.h"
#include "MEM_guardedalloc.h"
#include "RAS_LightObject.h"
#include "RAS_MaterialBucket.h"
#include "KX_PyMath.h"
#define KX_POLYGONMATERIAL_CAPSULE_ID "KX_POLYGONMATERIAL_PTR"
KX_PolygonMaterial::KX_PolygonMaterial()
: PyObjectPlus(),
RAS_IPolyMaterial(),
m_material(NULL),
#ifdef WITH_PYTHON
m_pymaterial(NULL),
#endif
m_pass(0)
{
memset(&m_tface, 0, sizeof(m_tface));
memset(&m_mcol, 0, sizeof(m_mcol));
}
void KX_PolygonMaterial::Initialize(
const STR_String &texname,
Material* ma,
int materialindex,
int tile,
int tilexrep,
int tileyrep,
int alphablend,
bool alpha,
bool zsort,
bool light,
int lightlayer,
struct MTFace* tface,
unsigned int* mcol)
{
RAS_IPolyMaterial::Initialize(
texname,
ma?ma->id.name:"",
materialindex,
tile,
tilexrep,
tileyrep,
alphablend,
alpha,
zsort,
light,
(texname && texname != ""?true:false), /* if we have a texture we have image */
ma?&ma->game:NULL);
if (tface) {
m_tface = *tface;
}
else {
memset(&m_tface, 0, sizeof(m_tface));
}
if (mcol) {
m_mcol = *mcol;
}
else {
memset(&m_mcol, 0, sizeof(m_mcol));
}
m_material = ma;
#ifdef WITH_PYTHON
m_pymaterial = 0;
#endif
m_pass = 0;
}
KX_PolygonMaterial::~KX_PolygonMaterial()
{
#ifdef WITH_PYTHON
if (m_pymaterial)
{
Py_DECREF(m_pymaterial);
}
#endif // WITH_PYTHON
}
Image *KX_PolygonMaterial::GetBlenderImage() const
{
return m_tface.tpage;
}
bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
{
bool dopass = false;
#ifdef WITH_PYTHON
if (m_pymaterial)
{
PyObject *pyRasty = PyCapsule_New((void*)rasty, KX_POLYGONMATERIAL_CAPSULE_ID, NULL); /* new reference */
PyObject *pyCachingInfo = PyCapsule_New((void*) &cachingInfo, KX_POLYGONMATERIAL_CAPSULE_ID, NULL); /* new reference */
PyObject *ret = PyObject_CallMethod(m_pymaterial, (char *)"activate", (char *)"(NNO)", pyRasty, pyCachingInfo, (PyObject *) this->m_proxy);
if (ret)
{
bool value = PyLong_AsLong(ret);
Py_DECREF(ret);
dopass = value;
}
else
{
PyErr_Print();
PyErr_Clear();
PySys_SetObject("last_traceback", NULL);
}
}
else
#endif // WITH_PYTHON
{
switch (m_pass++)
{
case 0:
DefaultActivate(rasty, cachingInfo);
dopass = true;
break;
default:
m_pass = 0;
dopass = false;
break;
}
}
return dopass;
}
void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
{
if (GetCachingInfo() != cachingInfo)
{
if (!cachingInfo)
GPU_set_tpage(NULL, 0, 0);
cachingInfo = GetCachingInfo();
if ((m_drawingmode & RAS_IRasterizer::KX_TEX)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED))
{
Image *ima = m_tface.tpage;
GPU_update_image_time(ima, rasty->GetTime());
GPU_set_tpage(&m_tface, 1, m_alphablend);
}
else
GPU_set_tpage(NULL, 0, 0);
if (m_drawingmode & RAS_IRasterizer::KX_BACKCULL)
rasty->SetCullFace(true);
else
rasty->SetCullFace(false);
if ((m_drawingmode & RAS_IRasterizer::KX_LINES) ||
(rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
rasty->SetLines(true);
else
rasty->SetLines(false);
rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity);
rasty->SetShinyness(m_shininess);
rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0);
if (m_material)
rasty->SetPolygonOffset(-m_material->zoffs, 0.0);
}
//rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity);
//rasty->SetShinyness(m_shininess);
//rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0);
//if (m_material)
// rasty->SetPolygonOffset(-m_material->zoffs, 0.0);
}
void KX_PolygonMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
{
if (m_material) {
*rgba++ = (unsigned char) (m_material->r*255.0);
*rgba++ = (unsigned char) (m_material->g*255.0);
*rgba++ = (unsigned char) (m_material->b*255.0);
*rgba++ = (unsigned char) (m_material->alpha*255.0);
} else
RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
}
#ifdef WITH_PYTHON
//----------------------------------------------------------------------------
//Python
PyMethodDef KX_PolygonMaterial::Methods[] = {
KX_PYMETHODTABLE(KX_PolygonMaterial, setCustomMaterial),
KX_PYMETHODTABLE(KX_PolygonMaterial, updateTexture),
KX_PYMETHODTABLE(KX_PolygonMaterial, setTexture),
KX_PYMETHODTABLE(KX_PolygonMaterial, activate),
// KX_PYMETHODTABLE(KX_PolygonMaterial, setPerPixelLights),
{NULL,NULL} //Sentinel
};
PyAttributeDef KX_PolygonMaterial::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("texture", KX_PolygonMaterial, pyattr_get_texture),
KX_PYATTRIBUTE_RO_FUNCTION("material", KX_PolygonMaterial, pyattr_get_material), /* should probably be .name ? */
KX_PYATTRIBUTE_INT_RW("tile", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tile),
KX_PYATTRIBUTE_INT_RW("tilexrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tilexrep),
KX_PYATTRIBUTE_INT_RW("tileyrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tileyrep),
KX_PYATTRIBUTE_INT_RW("drawingmode", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_drawingmode),
//KX_PYATTRIBUTE_INT_RW("lightlayer", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_lightlayer),
KX_PYATTRIBUTE_BOOL_RW("transparent", KX_PolygonMaterial, m_alpha),
KX_PYATTRIBUTE_BOOL_RW("zsort", KX_PolygonMaterial, m_zsort),
KX_PYATTRIBUTE_FLOAT_RW("shininess", 0.0f, 1000.0f, KX_PolygonMaterial, m_shininess),
KX_PYATTRIBUTE_FLOAT_RW("specularity", 0.0f, 1000.0f, KX_PolygonMaterial, m_specularity),
KX_PYATTRIBUTE_RW_FUNCTION("diffuse", KX_PolygonMaterial, pyattr_get_diffuse, pyattr_set_diffuse),
KX_PYATTRIBUTE_RW_FUNCTION("specular",KX_PolygonMaterial, pyattr_get_specular, pyattr_set_specular),
KX_PYATTRIBUTE_RO_FUNCTION("tface", KX_PolygonMaterial, pyattr_get_tface), /* How the heck is this even useful??? - Campbell */
KX_PYATTRIBUTE_RO_FUNCTION("gl_texture", KX_PolygonMaterial, pyattr_get_gl_texture), /* could be called 'bindcode' */
{ NULL } //Sentinel
};
PyTypeObject KX_PolygonMaterial::Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"KX_PolygonMaterial",
sizeof(PyObjectPlus_Proxy),
0,
py_base_dealloc,
0,
0,
0,
0,
py_base_repr,
0,0,0,0,0,0,0,0,0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
0,0,0,0,0,0,0,
Methods,
0,
0,
&PyObjectPlus::Type,
0,0,0,0,0,0,
py_base_new
};
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)")
{
PyObject *material;
if (PyArg_ParseTuple(args, "O:setCustomMaterial", &material))
{
if (m_pymaterial) {
Py_DECREF(m_pymaterial);
}
m_pymaterial = material;
Py_INCREF(m_pymaterial);
Py_RETURN_NONE;
}
return NULL;
}
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rasty)")
{
PyObject *pyrasty, *pytface;
if (PyArg_ParseTuple(args, "O!O!:updateTexture", &PyCapsule_Type, &pytface, &PyCapsule_Type, &pyrasty))
{
MTFace *tface = (MTFace*) PyCapsule_GetPointer(pytface, KX_POLYGONMATERIAL_CAPSULE_ID);
RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCapsule_GetPointer(pyrasty, KX_POLYGONMATERIAL_CAPSULE_ID);
Image *ima = (Image*)tface->tpage;
GPU_update_image_time(ima, rasty->GetTime());
Py_RETURN_NONE;
}
return NULL;
}
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)")
{
PyObject *pytface;
if (PyArg_ParseTuple(args, "O!:setTexture", &PyCapsule_Type, &pytface))
{
MTFace *tface = (MTFace*) PyCapsule_GetPointer(pytface, KX_POLYGONMATERIAL_CAPSULE_ID);
GPU_set_tpage(tface, 1, m_alphablend);
Py_RETURN_NONE;
}
return NULL;
}
KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)")
{
PyObject *pyrasty, *pyCachingInfo;
if (PyArg_ParseTuple(args, "O!O!:activate", &PyCapsule_Type, &pyrasty, &PyCapsule_Type, &pyCachingInfo))
{
RAS_IRasterizer *rasty = static_cast<RAS_IRasterizer*>(PyCapsule_GetPointer(pyrasty, KX_POLYGONMATERIAL_CAPSULE_ID));
TCachingInfo *cachingInfo = static_cast<TCachingInfo*>(PyCapsule_GetPointer(pyCachingInfo, KX_POLYGONMATERIAL_CAPSULE_ID));
if (rasty && cachingInfo)
{
DefaultActivate(rasty, *cachingInfo);
Py_RETURN_NONE;
}
}
return NULL;
}
PyObject *KX_PolygonMaterial::pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
return PyUnicode_From_STR_String(self->m_texturename);
}
PyObject *KX_PolygonMaterial::pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
return PyUnicode_From_STR_String(self->m_materialname);
}
/* this does not seem useful */
PyObject *KX_PolygonMaterial::pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
return PyCapsule_New(&self->m_tface, KX_POLYGONMATERIAL_CAPSULE_ID, NULL);
}
PyObject *KX_PolygonMaterial::pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
int bindcode= 0;
if (self->m_tface.tpage)
bindcode= self->m_tface.tpage->bindcode;
return PyLong_FromLong(bindcode);
}
PyObject *KX_PolygonMaterial::pyattr_get_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
return PyObjectFrom(self->m_diffuse);
}
int KX_PolygonMaterial::pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
MT_Vector3 vec;
if (!PyVecTo(value, vec))
return PY_SET_ATTR_FAIL;
self->m_diffuse= vec;
return PY_SET_ATTR_SUCCESS;
}
PyObject *KX_PolygonMaterial::pyattr_get_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
return PyObjectFrom(self->m_specular);
}
int KX_PolygonMaterial::pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_PolygonMaterial* self = static_cast<KX_PolygonMaterial*>(self_v);
MT_Vector3 vec;
if (!PyVecTo(value, vec))
return PY_SET_ATTR_FAIL;
self->m_specular= vec;
return PY_SET_ATTR_SUCCESS;
}
#endif // WITH_PYTHON

View File

@ -1,156 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file KX_PolygonMaterial.h
* \ingroup ketsji
*/
#ifndef __KX_POLYGONMATERIAL_H__
#define __KX_POLYGONMATERIAL_H__
#include "PyObjectPlus.h"
#include "RAS_MaterialBucket.h"
#include "RAS_IRasterizer.h"
#include "DNA_ID.h"
#include "DNA_meshdata_types.h"
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
struct MTFace;
struct Material;
struct MTex;
struct Image;
/**
* Material class.
*
* This holds the shader, textures and python methods for setting the render state before
* rendering.
*/
class KX_PolygonMaterial : public PyObjectPlus, public RAS_IPolyMaterial
{
Py_Header
private:
/** Blender texture face structure. */
mutable MTFace m_tface;
mutable unsigned int m_mcol;
Material* m_material;
#ifdef WITH_PYTHON
PyObject* m_pymaterial;
#endif
mutable int m_pass;
public:
KX_PolygonMaterial();
void Initialize(const STR_String &texname,
Material* ma,
int materialindex,
int tile,
int tilexrep,
int tileyrep,
int alphablend,
bool alpha,
bool zsort,
bool light,
int lightlayer,
struct MTFace* tface,
unsigned int* mcol);
virtual ~KX_PolygonMaterial();
/**
* Returns the caching information for this material,
* This can be used to speed up the rasterizing process.
* \return The caching information.
*/
virtual TCachingInfo GetCachingInfo(void) const
{
return (void*) this;
}
/**
* Activates the material in the (OpenGL) rasterizer.
* On entry, the cachingInfo contains info about the last activated material.
* On exit, the cachingInfo should contain updated info about this material.
* \param rasty The rasterizer in which the material should be active.
* \param cachingInfo The information about the material used to speed up rasterizing.
*/
void DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const;
virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const;
Material *GetBlenderMaterial() const
{
return m_material;
}
Image *GetBlenderImage() const;
/**
* Returns the Blender texture face structure that is used for this material.
* \return The material's texture face.
*/
MTFace* GetMTFace() const
{
return &m_tface;
}
unsigned int* GetMCol() const
{
return &m_mcol;
}
virtual void GetMaterialRGBAColor(unsigned char *rgba) const;
#ifdef WITH_PYTHON
KX_PYMETHOD_DOC(KX_PolygonMaterial, updateTexture);
KX_PYMETHOD_DOC(KX_PolygonMaterial, setTexture);
KX_PYMETHOD_DOC(KX_PolygonMaterial, activate);
KX_PYMETHOD_DOC(KX_PolygonMaterial, setCustomMaterial);
KX_PYMETHOD_DOC(KX_PolygonMaterial, loadProgram);
virtual PyObject *py_repr(void) { return PyUnicode_FromString(m_material ? ((ID *)m_material)->name+2 : ""); }
static PyObject* pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_diffuse(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_specular(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
#endif
};
#endif /* __KX_POLYGONMATERIAL_H__ */

View File

@ -1226,7 +1226,6 @@ static PyObject *gPyGetGLSLMaterialSetting(PyObject *,
return PyLong_FromLong(enabled);
}
#define KX_TEXFACE_MATERIAL 0
#define KX_BLENDER_MULTITEX_MATERIAL 1
#define KX_BLENDER_GLSL_MATERIAL 2
@ -1244,8 +1243,6 @@ static PyObject *gPySetMaterialType(PyObject *,
gs->matmode= GAME_MAT_GLSL;
else if (type == KX_BLENDER_MULTITEX_MATERIAL)
gs->matmode= GAME_MAT_MULTITEX;
else if (type == KX_TEXFACE_MATERIAL)
gs->matmode= GAME_MAT_TEXFACE;
else {
PyErr_SetString(PyExc_ValueError, "Rasterizer.setMaterialType(int): material type is not known");
return NULL;
@ -1261,10 +1258,8 @@ static PyObject *gPyGetMaterialType(PyObject *)
if (gs->matmode == GAME_MAT_GLSL)
flag = KX_BLENDER_GLSL_MATERIAL;
else if (gs->matmode == GAME_MAT_MULTITEX)
flag = KX_BLENDER_MULTITEX_MATERIAL;
else
flag = KX_TEXFACE_MATERIAL;
flag = KX_BLENDER_MULTITEX_MATERIAL;
return PyLong_FromLong(flag);
}
@ -2209,7 +2204,6 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
Py_DECREF(ErrorObject);
/* needed for get/setMaterialType */
KX_MACRO_addTypesToDict(d, KX_TEXFACE_MATERIAL, KX_TEXFACE_MATERIAL);
KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL);
KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL);

View File

@ -57,7 +57,6 @@
#include "KX_ObjectActuator.h"
#include "KX_ParentActuator.h"
#include "KX_PolyProxy.h"
#include "KX_PolygonMaterial.h"
#include "KX_PythonSeq.h"
#include "KX_SCA_AddObjectActuator.h"
#include "KX_SCA_EndObjectActuator.h"
@ -211,7 +210,6 @@ void initPyTypes(void)
PyType_Ready_Attr(dict, KX_ObjectActuator, init_getset);
PyType_Ready_Attr(dict, KX_ParentActuator, init_getset);
PyType_Ready_Attr(dict, KX_PolyProxy, init_getset);
PyType_Ready_Attr(dict, KX_PolygonMaterial, init_getset);
PyType_Ready_Attr(dict, KX_RadarSensor, init_getset);
PyType_Ready_Attr(dict, KX_RaySensor, init_getset);
PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator, init_getset);

View File

@ -40,7 +40,6 @@
#include "DNA_meshdata_types.h"
#include "DNA_image_types.h"
#include "IMB_imbuf_types.h"
#include "KX_PolygonMaterial.h"
#include "MEM_guardedalloc.h"
@ -229,19 +228,12 @@ static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
{
self->m_imgTexture = static_cast<KX_BlenderMaterial*>(mat)->getImage(texID);
self->m_useMatTexture = false;
} else if (mat->GetFlag() & RAS_BLENDERMAT)
} else
{
// get blender material texture
self->m_matTexture = static_cast<KX_BlenderMaterial*>(mat)->getTex(texID);
self->m_useMatTexture = true;
}
else
{
// get texture pointer from polygon material
MTFace * tface = static_cast<KX_PolygonMaterial*>(mat)->GetMTFace();
self->m_imgTexture = (Image*)tface->tpage;
self->m_useMatTexture = false;
}
}
else if (lamp != NULL)
{