Commit 9e847557 authored by Jan Möbius's avatar Jan Möbius

Depth buffer rendering. Not working for snapshots yet

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10435 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bf69cec8
......@@ -155,6 +155,9 @@ void Core::applyOptions(){
// Picking Debugger
PluginFunctions::viewerProperties(i).renderPicking( OpenFlipperSettings().value("Core/Debug/Picking/RenderPicking",false).toBool() , target );
// Depth Debugger
PluginFunctions::viewerProperties(i).renderDepthImage( OpenFlipperSettings().value("Core/Debug/Picking/RenderDepthImage",false).toBool() );
}
//hideToolbox
......
......@@ -129,6 +129,7 @@
* <b>Rendering debugger Settings<b>\n
* * Core/Debug/Picking/RenderPicking Enable picking rendering (bool)\n
* * Core/Debug/Picking/RenderPickingMode The Mode used for picking rendering(QString) \n
* * Core/Debug/Picking/RenderDepthImage Renders the depth buffer as a grayscale image (bool) \n
* \n
* Anaglyph stereo mode settings:\n
*/
......
......@@ -66,6 +66,7 @@ namespace Viewer {
CCWFront_(true),
backgroundColor_(0.0f,0.0f,0.0f,1.0f),
renderPicking_(false),
renderDepthImage_(false),
pickRendererMode_(ACG::SceneGraph::PICK_ANYTHING),
locked_(0),
backFaceCulling_(false),
......
......@@ -256,11 +256,23 @@ namespace Viewer {
void renderPicking(bool _renderPicking, ACG::SceneGraph::PickTarget _mode) {
pickRendererMode_ = _mode ; renderPicking_ = _renderPicking; emit updated();
}
/** Render depth image or color image
*/
bool renderDepthImage(){ return renderDepthImage_; };
/** Render depth image or color image
*/
void renderDepthImage(bool _depth){ renderDepthImage_ = _depth; emit updated(); };
private:
/** This variable controls if the scene is rendered in normal or in picking mode
*/
bool renderPicking_;
/** This variable controls if the depth image is rendered instead of the color image
*/
bool renderDepthImage_;
/** If rendering is in picking mode, this variable controls which picking targets
* will be rendered. ( see renderPicking_ , renderPicking(bool _renderPicking, PickRendererMode _mode) ,
......
......@@ -147,6 +147,10 @@ glViewer::glViewer( QGraphicsScene* _scene,
cursorPositionValid_(false),
pProgram_(0),
philipsStereoInitialized_(false),
colorTextureBufferWidth_(0),
colorTextureBufferHeight_(0),
depthStencilTextureBufferWidth_(0),
depthStencilTextureBufferHeight_(0),
pickCache_(0),
updatePickCache_(true),
pickCacheSupported_(true),
......@@ -723,6 +727,83 @@ void glViewer::drawScene_mono()
glEnable(GL_LIGHTING);
glEnable(GL_BLEND);
}
// Render depth?
// If so, we take our depth buffer and draw it as our scene image
if ( properties_.renderDepthImage() ) {
// ======================================================================================================
// Adjust buffer to correct size
// ======================================================================================================
updateDepthStencilTextureBuffer();
// ======================================================================================================
// Get current viewport size
// ======================================================================================================
int vp_l, vp_b, vp_w, vp_h;
glstate_->get_viewport (vp_l, vp_b, vp_w, vp_h);
// ======================================================================================================
// Bind depth Stencil texture
// ======================================================================================================
pDepthStencilTexture_.enable();
pDepthStencilTexture_.bind();
// ======================================================================================================
// Copy depth component of rendered image to texture
// ======================================================================================================
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, 0, 0, vp_w , vp_h, 0);
// ======================================================================================================
// Render plain textured
// ======================================================================================================
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_DEPTH_TEST);
// ======================================================================================================
// Setup orthogonal projection
// ======================================================================================================
glstate_->push_projection_matrix();
glstate_->push_modelview_matrix();
glstate_->reset_projection();
glstate_->reset_modelview();
glstate_->ortho(0, vp_w, 0, vp_h, 0, 1);
// ======================================================================================================
// Clear rendering buffer
// ======================================================================================================
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// ======================================================================================================
// Render a simple quad (rest is done by the texture)
// ======================================================================================================
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2i(0, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex2i(vp_w, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex2i(vp_w, vp_h);
glTexCoord2f(0.0f, 1.0f);
glVertex2i(0, vp_h);
glEnd();
// Disable depth stencil buffer
pDepthStencilTexture_.disable();
// ======================================================================================================
// Reset projection and modelview
// ======================================================================================================
glstate_->pop_projection_matrix();
glstate_->pop_modelview_matrix();
}
}
if (cursorPainter_ && cursorPainter_->enabled () && cursorPositionValid_)
......@@ -2127,6 +2208,7 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha, bo
format.setSamples(samples);
QGLFramebufferObject fb( w, h, format);
if ( fb.isValid() ){
fb.bind();
......
......@@ -490,29 +490,9 @@ private:
void drawScene();
// helper called by drawScene().
void drawScene_mono();
// helper called by drawScene() when stereo viewing is active.
void drawScene_stereo();
// helper called by drawScene_stereo() when opengl stereo viewing is active.
void drawScene_glStereo();
// helper called by drawScene_stereo() when anaglyph stereo viewing is active.
void drawScene_anaglyphStereo();
// helper called by drawScene_stereo() when custom anaglyph stereo viewing is active.
void drawScene_customAnaglyphStereo();
// helper called to initialize/update custom anaglyph stereo
void updateCustomAnaglyphStereo();
// helper called to cleanup custom anaglyph stereo
void finiCustomAnaglyphStereo();
// Draws the scene for a philips stereo display ( Header, left color image, right depth map )
void drawScenePhilipsStereo();
// Updates the scene for a philips stereo display
void updateScenePhilipsStereo();
//-------------------------------------------------------------- protected data
protected:
......@@ -659,9 +639,37 @@ private:
/// enable/disable stereo mode
virtual void setStereoMode(bool _b);
private:
/// helper called by drawScene() when stereo viewing is active.
void drawScene_stereo();
/// helper called by drawScene_stereo() when opengl stereo viewing is active.
void drawScene_glStereo();
/// helper called by drawScene_stereo() when anaglyph stereo viewing is active.
void drawScene_anaglyphStereo();
/// helper called by drawScene_stereo() when custom anaglyph stereo viewing is active.
void drawScene_customAnaglyphStereo();
/// helper called to initialize/update custom anaglyph stereo
void updateCustomAnaglyphStereo();
/// helper called to cleanup custom anaglyph stereo
void finiCustomAnaglyphStereo();
/// Draws the scene for a philips stereo display ( Header, left color image, right depth map )
void drawScenePhilipsStereo();
/// Updates the scene for a philips stereo display
void updateScenePhilipsStereo();
private:
// stereo stuff
/// Stereo enabled?
bool stereo_;
// custom anaglyph stuff
......@@ -671,16 +679,41 @@ private:
GLuint agProgram_;
bool customAnaglyphSupported_;
// Philips stereo mode stuff
int pTexWidth_;
int pTexHeight_;
ACG::Texture2D pColorTexture_;
ACG::Texture2D pDepthStencilTexture_;
GLSL::PtrProgram pProgram_;
bool philipsStereoInitialized_;
/** @} */
//===========================================================================
/** @name Buffers
* @{ */
//===========================================================================
private:
/// Updates the Color Texture Buffer to the current size and initializes it if necessary
void updateColorTextureBuffer();
/// Updates the DepthStencil Texture Buffer to the current size and initializes it if necessary
void updateDepthStencilTextureBuffer();
/// color texture buffer
ACG::Texture2D pColorTexture_;
/// depthStencil texture buffer
ACG::Texture2D pDepthStencilTexture_;
/// Current width of the color texture buffer
int colorTextureBufferWidth_;
/// Current height of the color texture buffer
int colorTextureBufferHeight_;
/// Current width of the depthStencil texture buffer
int depthStencilTextureBufferWidth_;
/// Current height of the depthStencil texture buffer
int depthStencilTextureBufferHeight_;
//===========================================================================
/** @name Key handling
......
......@@ -395,6 +395,107 @@ void glViewer::drawScenePhilipsStereo() {
//-----------------------------------------------------------------------------
void
glViewer::updateColorTextureBuffer() {
int vp_l, vp_b, vp_w, vp_h;
glstate_->get_viewport (vp_l, vp_b, vp_w, vp_h);
// Does color texture exist?
if (!pColorTexture_.is_valid()) {
// ======================================================================================================
// creating a color texture
// ======================================================================================================
pColorTexture_.enable();
pColorTexture_.bind();
GLenum texTarget = GL_TEXTURE_2D;
GLenum texInternalFormat = GL_RGBA;
GLenum texFormat = GL_RGBA;
GLenum texType = GL_UNSIGNED_BYTE;
GLenum texFilterMode = GL_NEAREST;
glTexImage2D(texTarget, 0, texInternalFormat, vp_w, vp_h, 0, texFormat, texType, NULL);
glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(texTarget, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
if(!pColorTexture_.is_valid()) {
philipsStereoInitialized_ = false;
}
}
// Resize target textures
if (glstate_->viewport_width() != colorTextureBufferWidth_ || glstate_->viewport_height() != colorTextureBufferHeight_) {
// Color texture
pColorTexture_.bind();
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, glstate_->viewport_width(), glstate_->viewport_height(), 0,
GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
colorTextureBufferWidth_ = glstate_->viewport_width();
colorTextureBufferHeight_ = glstate_->viewport_height();
}
}
//-----------------------------------------------------------------------------
void
glViewer::updateDepthStencilTextureBuffer() {
int vp_l, vp_b, vp_w, vp_h;
glstate_->get_viewport (vp_l, vp_b, vp_w, vp_h);
// Does depth stencil texture exist?
if (!pDepthStencilTexture_.is_valid()) {
// ======================================================================================================
// creating an 24-bit depth + 8-bit stencil texture
// ======================================================================================================
pDepthStencilTexture_.enable();
pDepthStencilTexture_.bind();
GLenum texTarget = GL_TEXTURE_2D;
GLenum texInternalFormat = GL_DEPTH24_STENCIL8_EXT;
GLenum texFormat = GL_DEPTH_STENCIL_EXT;
GLenum texType = GL_UNSIGNED_INT_24_8_EXT;
GLenum texFilterMode = GL_NEAREST;
glTexImage2D(texTarget, 0, texInternalFormat, vp_w, vp_h, 0, texFormat, texType, NULL);
glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(texTarget, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
if(!pDepthStencilTexture_.is_valid()) {
philipsStereoInitialized_ = false;
}
}
// Resize target texture
if (glstate_->viewport_width() != depthStencilTextureBufferWidth_ || glstate_->viewport_height() != depthStencilTextureBufferHeight_) {
// Depth stencil texture
pDepthStencilTexture_.bind();
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, glstate_->viewport_width(), glstate_->viewport_height(), 0,
GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
depthStencilTextureBufferWidth_ = glstate_->viewport_width();
depthStencilTextureBufferHeight_ = glstate_->viewport_height();
}
}
//-----------------------------------------------------------------------------
void
glViewer::updateScenePhilipsStereo()
{
......@@ -428,77 +529,9 @@ glViewer::updateScenePhilipsStereo()
pProgram_->link();
}
// Does color texture exist?
if (!pColorTexture_.is_valid()) {
// ======================================================================================================
// creating a color texture
// ======================================================================================================
pColorTexture_.enable();
pColorTexture_.bind();
GLenum texTarget = GL_TEXTURE_2D;
GLenum texInternalFormat = GL_RGBA;
GLenum texFormat = GL_RGBA;
GLenum texType = GL_UNSIGNED_BYTE;
GLenum texFilterMode = GL_NEAREST;
glTexImage2D(texTarget, 0, texInternalFormat, vp_w, vp_h, 0, texFormat, texType, NULL);
glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(texTarget, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
if(!pColorTexture_.is_valid()) {
philipsStereoInitialized_ = false;
}
}
// Does depth stencil texture exist?
if (!pDepthStencilTexture_.is_valid()) {
// ======================================================================================================
// creating an 24-bit depth + 8-bit stencil texture
// ======================================================================================================
pDepthStencilTexture_.enable();
pDepthStencilTexture_.bind();
GLenum texTarget = GL_TEXTURE_2D;
GLenum texInternalFormat = GL_DEPTH24_STENCIL8_EXT;
GLenum texFormat = GL_DEPTH_STENCIL_EXT;
GLenum texType = GL_UNSIGNED_INT_24_8_EXT;
GLenum texFilterMode = GL_NEAREST;
glTexImage2D(texTarget, 0, texInternalFormat, vp_w, vp_h, 0, texFormat, texType, NULL);
glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(texTarget, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
if(!pDepthStencilTexture_.is_valid()) {
philipsStereoInitialized_ = false;
}
}
// Resize target textures
if (glstate_->viewport_width() != pTexWidth_ ||
glstate_->viewport_height() != pTexHeight_) {
// Color texture
pColorTexture_.bind();
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, glstate_->viewport_width(), glstate_->viewport_height(), 0,
GL_RGB, GL_UNSIGNED_BYTE, 0);
// Depth stencil texture
pDepthStencilTexture_.bind();
glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, glstate_->viewport_width(), glstate_->viewport_height(), 0,
GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, 0);
pTexWidth_ = glstate_->viewport_width();
pTexHeight_ = glstate_->viewport_height();
}
updateColorTextureBuffer();
updateDepthStencilTextureBuffer();
philipsStereoInitialized_ = true;
}
......
......@@ -350,6 +350,7 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());
renderPicking->setChecked( OpenFlipperSettings().value("Core/Debug/Picking/RenderPicking",false).toBool() );
renderDepth->setChecked( OpenFlipperSettings().value("Core/Debug/Picking/RenderDepthImage",false).toBool() );
int itemIndex = pickingRenderMode->findText( OpenFlipperSettings().value("Core/Debug/Picking/RenderPickingMode",QString("PICK_ANYTHING")).toString() );
if ( itemIndex != -1 )
pickingRenderMode->setCurrentIndex(itemIndex);
......@@ -682,6 +683,8 @@ void OptionsWidget::slotApply() {
OpenFlipperSettings().setValue("Core/Debug/Picking/RenderPicking",renderPicking->isChecked() );
OpenFlipperSettings().setValue("Core/Debug/Picking/RenderPickingMode",pickingRenderMode->currentText() );
OpenFlipperSettings().setValue("Core/Debug/Picking/RenderDepthImage",renderDepth->isChecked() );
//viewer defaults
for (int i=0; i < PluginFunctions::viewers(); i++){
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>778</width>
<height>932</height>
<height>964</height>
</rect>
</property>
<property name="windowTitle">
......@@ -23,7 +23,7 @@
<string/>
</property>
<property name="currentIndex">
<number>2</number>
<number>7</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
......@@ -371,7 +371,7 @@
<x>30</x>
<y>30</y>
<width>541</width>
<height>61</height>
<height>62</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_5">
......@@ -1848,6 +1848,22 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="renderDepth">
<property name="toolTip">
<string>Renders the depth buffer as a grayscale image</string>
</property>
<property name="statusTip">
<string>Renders the depth buffer as a grayscale image</string>
</property>
<property name="whatsThis">
<string>Renders the depth buffer as a grayscale image</string>
</property>
<property name="text">
<string>Render Depth Image</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment