diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2011-08-31 09:51:51 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2011-08-31 09:51:51 +0400 |
commit | f63d049adc268bc71ac87c2b781e2f44f60da1f5 (patch) | |
tree | 59c19b08cf004d27485a89769662c115fd0c146c | |
parent | 471c005137540dd4c348c2f8e93146c0dff37a3f (diff) |
BGE: Adding two new functions to bge.render to allow users to change the anisotropic filtering level used by textures:
* setAnisotropicFiltering(level)
* getAnisotropicFiltering()
5 files changed, 59 insertions, 0 deletions
diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst index 10514049a8a..eeb50a833ff 100644 --- a/doc/python_api/rst/bge.render.rst +++ b/doc/python_api/rst/bge.render.rst @@ -215,7 +215,19 @@ Functions :type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures) :rtype: boolean +.. function:: setAnisotropicFiltering(level) + Set the anisotropic filtering level for textures. + + :arg level: The new anisotropic filtering level to use + :type level: integer (must be one of 1, 2, 4, 8, 16) + +.. function:: getAnisotropicFiltering() + + Get the anisotropic filtering level used for textures. + + :rtype: integer (one of 1, 2, 4, 8, 16) + .. function:: drawLine(fromVec,toVec,color) Draw a line in the 3D scene. diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 06db84feb23..8557ebab0a9 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1208,6 +1208,28 @@ static PyObject* gPyGetMaterialType(PyObject*) return PyLong_FromSsize_t(flag); } +static PyObject* gPySetAnisotropicFiltering(PyObject*, PyObject* args) +{ + short level; + + if (!PyArg_ParseTuple(args, "h:setAnisotropicFiltering", &level)) + return NULL; + + if (level != 1 && level != 2 && level != 4 && level != 8 && level != 16) { + PyErr_SetString(PyExc_ValueError, "Rasterizer.setAnisotropicFiltering(level): Expected value of 1, 2, 4, 8, or 16 for value"); + return NULL; + } + + gp_Rasterizer->SetAnisotropicFiltering(level); + + Py_RETURN_NONE; +} + +static PyObject* gPyGetAnisotropicFiltering(PyObject*, PyObject* args) +{ + return PyLong_FromLong(gp_Rasterizer->GetAnisotropicFiltering()); +} + static PyObject* gPyDrawLine(PyObject*, PyObject* args) { PyObject* ob_from; @@ -1272,6 +1294,10 @@ static struct PyMethodDef rasterizer_methods[] = { METH_VARARGS, "set the state of a GLSL material setting"}, {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting, METH_VARARGS, "get the state of a GLSL material setting"}, + {"setAnisotropicFiltering", (PyCFunction) gPySetAnisotropicFiltering, + METH_VARARGS, "set the anisotropic filtering level (must be one of 1, 2, 4, 8, 16)"}, + {"getAnisotropicFiltering", (PyCFunction) gPyGetAnisotropicFiltering, + METH_VARARGS, "get the anisotropic filtering level"}, {"drawLine", (PyCFunction) gPyDrawLine, METH_VARARGS, "draw a line on the screen"}, { NULL, (PyCFunction) NULL, 0, NULL } diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 305e2bca756..c46ebf742a0 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -417,6 +417,9 @@ public: virtual void SetBlendingMode(int blendmode)=0; virtual void SetFrontFace(bool ccw)=0; + + virtual void SetAnisotropicFiltering(short level)=0; + virtual short GetAnisotropicFiltering()=0; #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 23e0a50ed6f..50d034a5a5a 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -99,12 +99,16 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) hinterlace_mask[i] = (i&1)*0xFFFFFFFF; } hinterlace_mask[32] = 0; + + m_prevafvalue = GPU_get_anisotropic(); } RAS_OpenGLRasterizer::~RAS_OpenGLRasterizer() { + // Restore the previous AF value + GPU_set_anisotropic(m_prevafvalue); } bool RAS_OpenGLRasterizer::Init() @@ -1204,3 +1208,12 @@ void RAS_OpenGLRasterizer::SetFrontFace(bool ccw) m_last_frontface = ccw; } +void RAS_OpenGLRasterizer::SetAnisotropicFiltering(short level) +{ + GPU_set_anisotropic((float)level); +} + +short RAS_OpenGLRasterizer::GetAnisotropicFiltering() +{ + return (short)GPU_get_anisotropic(); +} diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 54fab906049..61568df91eb 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -94,6 +94,8 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer bool m_setfocallength; int m_noOfScanlines; + short m_prevafvalue; + //motion blur int m_motionblur; float m_motionblurvalue; @@ -294,6 +296,9 @@ public: virtual void SetBlendingMode(int blendmode); virtual void SetFrontFace(bool ccw); + virtual void SetAnisotropicFiltering(short level); + virtual short GetAnisotropicFiltering(); + #ifdef WITH_CXX_GUARDEDALLOC public: |