diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2012-10-21 02:28:44 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2012-10-21 02:28:44 +0400 |
commit | 4213eca5fc3b5f2c2b23945e9462b38e13f843c4 (patch) | |
tree | 8f296c8e6847423ec0ded76e04a38efb44543d5c /source/gameengine/VideoTexture/ImageBase.cpp | |
parent | 7deb8d8a26a63a338b845eae3617111316e015f9 (diff) |
BGE VideoTexture: add depth buffer access to ImageViewport and ImageRender.
2 new attributes to ImageViewport and ImageRender object:
depth: set to True to retrieve the depth buffer as an array of float
(not suitable for texture source).
zbuff: set to True to retrieve the depth buffer as a grey scale pixel array
(suitable for texture source).
A new mode 'F' is added to VideoTexture.imageToArray() to allow returning the image
buffer as a one dimensional array of float. This mode should only be used to retrieve
the depth buffer of ImageViewport and ImageRender objects.
Example:
viewport = VideoTexture.ImageViewport()
viewport.depth = True
depth = VideoTexture.imageToArray(viewport,'F')
# show depth of bottom left pixel
# 1.0 = infinite, 0.0 = on near clip plane.
print(depth[0])
Diffstat (limited to 'source/gameengine/VideoTexture/ImageBase.cpp')
-rw-r--r-- | source/gameengine/VideoTexture/ImageBase.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index 2de49795681..de54d8e8940 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -49,6 +49,8 @@ extern "C" { // constructor ImageBase::ImageBase (bool staticSrc) : m_image(NULL), m_imgSize(0), m_avail(false), m_scale(false), m_scaleChange(false), m_flip(false), +m_zbuff(false), +m_depth(false), m_staticSources(staticSrc), m_pyfilter(NULL) { m_size[0] = m_size[1] = 0; @@ -402,6 +404,18 @@ PyObject *Image_getImage (PyImage *self, char * mode) { buffer = BGL_MakeBuffer( GL_BYTE, 1, &dimensions, image); } + else if (!strcasecmp(mode, "F")) + { + // this mode returns the image as an array of float. + // This makes sense ONLY for the depth buffer: + // source = VideoTexture.ImageViewport() + // source.depth = True + // depth = VideoTexture.imageToArray(source, 'F') + + // adapt dimension from byte to float + dimensions /= sizeof(float); + buffer = BGL_MakeBuffer( GL_FLOAT, 1, &dimensions, image); + } else { int i, c, ncolor, pixels; @@ -532,6 +546,52 @@ int Image_setFlip (PyImage *self, PyObject *value, void *closure) return 0; } +// get zbuff +PyObject * Image_getZbuff (PyImage * self, void * closure) +{ + if (self->m_image != NULL && self->m_image->getZbuff()) Py_RETURN_TRUE; + else Py_RETURN_FALSE; +} + +// set zbuff +int Image_setZbuff (PyImage * self, PyObject * value, void * closure) +{ + // check parameter, report failure + if (value == NULL || !PyBool_Check(value)) + { + PyErr_SetString(PyExc_TypeError, "The value must be a bool"); + return -1; + } + // set scale + if (self->m_image != NULL) self->m_image->setZbuff(value == Py_True); + // success + return 0; +} + +// get depth +PyObject * Image_getDepth (PyImage * self, void * closure) +{ + if (self->m_image != NULL && self->m_image->getDepth()) Py_RETURN_TRUE; + else Py_RETURN_FALSE; +} + +// set depth +int Image_setDepth (PyImage * self, PyObject * value, void * closure) +{ + // check parameter, report failure + if (value == NULL || !PyBool_Check(value)) + { + PyErr_SetString(PyExc_TypeError, "The value must be a bool"); + return -1; + } + // set scale + if (self->m_image != NULL) self->m_image->setDepth(value == Py_True); + // success + return 0; +} + + + // get filter source object PyObject *Image_getSource (PyImage *self, PyObject *args) |