BGE: Allow access to original texture openGL Bind code/Id/Number
authorUlysse Martin <you.le@live.fr>
Thu, 18 Feb 2016 10:56:25 +0000 (11:56 +0100)
committerPorteries Tristan <republicthunderbolt9@gmail.com>
Thu, 18 Feb 2016 11:05:53 +0000 (12:05 +0100)
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

doc/python_api/rst/bge_types/bge.types.KX_BlenderMaterial.rst
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.h

index 17f54031ec30235a6298754122206983701203d2..ece2a65af719be1f38d0bff8c70e5ff595aa6e23 100644 (file)
@@ -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.
index 1d185d52dc8c623cc533a26c09d56f8f307d73ff..476fbd29b8b96b5fcb2ec84d1ba2d9c6275c61d3 100644 (file)
@@ -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
index df089cb7f99ede5c7155168d26cad6594a0bbaa9..a3d10c0a89d5b0abc0015f84cb878ea8a629d8cf 100644 (file)
@@ -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 */