diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2013-07-30 02:31:32 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2013-07-30 02:31:32 +0400 |
commit | 29f8dfd37a2fbf4190e551bef0b04ff1ae1fd7b6 (patch) | |
tree | af50623534adee419cecbbf6e0d8dd789409d266 /source/gameengine/Ketsji/KX_PythonInit.cpp | |
parent | 2840edba840382f0957c4963c3613c7836ac5979 (diff) |
BGE: Adding vsync control. Users can enable vsync, disable vsync, or use adaptive vsync via UI options in the render properties, or by using the new Python method bge.render.setVsync(). Win32 and X11 support are done via EXT_swap_control. Support for using EXT_swap_control on OS X still needs to be added to Ghost.
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7845c113643..e595f24a662 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1372,6 +1372,29 @@ static PyObject *gPyGetMipmapping(PyObject *) return PyLong_FromLong(gp_Rasterizer->GetMipmapping()); } +static PyObject *gPySetVsync(PyObject *, PyObject *args) +{ + int interval; + + if (!PyArg_ParseTuple(args, "i:setVsync", &interval)) + return NULL; + + if (interval < VSYNC_OFF || interval > VSYNC_ADAPTIVE) { + PyErr_SetString(PyExc_ValueError, "Rasterizer.setVsync(value): value must be VSYNC_OFF, VSYNC_ON, or VSYNC_ADAPTIVE"); + return NULL; + } + + if (interval == VSYNC_ADAPTIVE) + interval = -1; + gp_Canvas->SetSwapInterval(interval); + Py_RETURN_NONE; +} + +static PyObject *gPyGetVsync(PyObject *) +{ + return PyLong_FromLong(gp_Canvas->GetSwapInterval()); +} + static struct PyMethodDef rasterizer_methods[] = { {"getWindowWidth",(PyCFunction) gPyGetWindowWidth, METH_VARARGS, "getWindowWidth doc"}, @@ -1417,6 +1440,8 @@ static struct PyMethodDef rasterizer_methods[] = { {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""}, {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""}, {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""}, + {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""}, + {"getVsync", (PyCFunction) gPyGetVsync, METH_NOARGS, ""}, { NULL, (PyCFunction) NULL, 0, NULL } }; @@ -2189,6 +2214,11 @@ PyObject *initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NEAREST, RAS_IRasterizer::RAS_MIPMAP_NEAREST); KX_MACRO_addTypesToDict(d, RAS_MIPMAP_LINEAR, RAS_IRasterizer::RAS_MIPMAP_LINEAR); + /* for get/setVsync */ + KX_MACRO_addTypesToDict(d, VSYNC_OFF, VSYNC_OFF); + KX_MACRO_addTypesToDict(d, VSYNC_ON, VSYNC_ON); + KX_MACRO_addTypesToDict(d, VSYNC_ADAPTIVE, VSYNC_ADAPTIVE); + // XXXX Add constants here // Check for errors |