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/FilterSource.h | |
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/FilterSource.h')
-rw-r--r-- | source/gameengine/VideoTexture/FilterSource.h | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h index a4900e8c148..0e0a3e8d1b9 100644 --- a/source/gameengine/VideoTexture/FilterSource.h +++ b/source/gameengine/VideoTexture/FilterSource.h @@ -31,7 +31,6 @@ http://www.gnu.org/copyleft/lesser.txt. #include "FilterBase.h" - /// class for RGB24 conversion class FilterRGB24 : public FilterBase { @@ -97,6 +96,65 @@ protected: { VT_RGBA(val,src[2],src[1],src[0],0xFF); return val; } }; +/// class for Z_buffer conversion +class FilterZZZA : public FilterBase +{ +public: + /// constructor + FilterZZZA (void) {} + /// destructor + virtual ~FilterZZZA (void) {} + + /// get source pixel size + virtual unsigned int getPixelSize (void) { return 1; } + +protected: + /// filter pixel, source float buffer + virtual unsigned int filter (float * src, short x, short y, + short * size, unsigned int pixSize, unsigned int val) + { + // calculate gray value + // convert float to unsigned char + unsigned int depth = int(src[0] * 255); + // return depth scale value + VT_R(val) = depth; + VT_G(val) = depth; + VT_B(val) = depth; + VT_A(val) = 0xFF; + + return val; + } +}; + + +/// class for Z_buffer conversion +class FilterDEPTH : public FilterBase +{ +public: + /// constructor + FilterDEPTH (void) {} + /// destructor + virtual ~FilterDEPTH (void) {} + + /// get source pixel size + virtual unsigned int getPixelSize (void) { return 1; } + +protected: + /// filter pixel, source float buffer + virtual unsigned int filter (float * src, short x, short y, + short * size, unsigned int pixSize, unsigned int val) + { + // Copy the float value straight away + // The user can retrieve the original float value by using + // 'F' mode in BGL buffer + memcpy(&val, src, sizeof (unsigned int)); + return val; + } +}; + + + + /// class for YV12 conversion class FilterYV12 : public FilterBase { |