BGE: Allow access to original texture openGL Bind code/Id/Number

This patch adds a python method to get openGL bind code of material's texture according to the texture slot.

Example:
import bge

cont = bge.logic.getCurrentController()
own = cont.owner

bindId = own.meshes[0].materials[0].getTextureBindcode(0)
Test file: http://www.pasteall.org/blend/40679

This can be used to play with texture in openGL, for example, remove mipmap on the texture or play with all wrapping or filtering options.
And this can be used to learn openGL with Blender.

Reviewers: TwisterGE, kupoman, moguri, panzergame

Reviewed By: TwisterGE, kupoman, moguri, panzergame

Projects: #game_engine

Differential Revision: https://developer.blender.org/D1804
This commit is contained in:
Ulysse Martin 2016-02-18 11:56:25 +01:00 committed by Porteries Tristan
parent e24323ea40
commit 608ee3e073
3 changed files with 27 additions and 0 deletions

@ -89,6 +89,15 @@ base class --- :class:`PyObjectPlus`
:return: the material's shader
:rtype: :class:`BL_Shader`
.. method:: getTextureBindcode(textureslot)
Returns the material's texture OpenGL bind code/id/number/name.
:arg textureslot: Specifies the texture slot number
:type textureslot: integer
:return: the material's texture OpenGL bind code/id/number/name
:rtype: integer
.. attribute:: alpha
The material's alpha transparency.

@ -972,6 +972,7 @@ PyMethodDef KX_BlenderMaterial::Methods[] =
{
KX_PYMETHODTABLE( KX_BlenderMaterial, getShader ),
KX_PYMETHODTABLE( KX_BlenderMaterial, getMaterialIndex ),
KX_PYMETHODTABLE( KX_BlenderMaterial, getTextureBindcode ),
KX_PYMETHODTABLE( KX_BlenderMaterial, setBlending ),
{NULL,NULL} //Sentinel
};
@ -1325,4 +1326,20 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setBlending , "setBlending( bge.logic.sr
return NULL;
}
KX_PYMETHODDEF_DOC(KX_BlenderMaterial, getTextureBindcode, "getTextureBindcode(texslot)")
{
unsigned int texslot;
if (!PyArg_ParseTuple(args, "i:texslot", &texslot)) {
PyErr_SetString(PyExc_ValueError, "material.getTextureBindcode(texslot): KX_BlenderMaterial, expected an int.");
return NULL;
}
Image *ima = getImage(texslot);
if (ima) {
unsigned int *bindcode = ima->bindcode;
return PyLong_FromLong(*bindcode);
}
PyErr_SetString(PyExc_ValueError, "material.getTextureBindcode(texslot): KX_BlenderMaterial, invalid texture slot.");
return NULL;
}
#endif // WITH_PYTHON

@ -133,6 +133,7 @@ public:
KX_PYMETHOD_DOC(KX_BlenderMaterial, getMaterialIndex);
KX_PYMETHOD_DOC(KX_BlenderMaterial, getTexture);
KX_PYMETHOD_DOC(KX_BlenderMaterial, setTexture);
KX_PYMETHOD_DOC(KX_BlenderMaterial, getTextureBindcode);
KX_PYMETHOD_DOC(KX_BlenderMaterial, setBlending);
#endif /* WITH_PYTHON */