Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DistortionRendering.hh
1 #ifndef __DISTORTIONRENDERING_HH__
2 #define __DISTORTIONRENDERING_HH__
3 
4 #include <bias_config.h>
5 
6 #ifndef BIAS_HAVE_OPENGL
7 # error You need BIAS with USE_OpenGL Please recompile BIAS.
8 #endif // BUILD_GLviewer
9 
10 #include <Gui/biasgl.h>
11 #include <Base/Debug/Debug.hh>
12 #include <GLviewer/Scenes/SceneBase.hh>
13 
14 #if defined(BIAS_HAVE_GLEW)
15 
16 #define BIAS_HAVE_CLASS_DISTORTIONRENDERING
17 
18 //#include "GPU/GPUCG/ShaderCgF3img.h"
19 
20 #include <Geometry/ProjectionParametersPerspective.hh>
21 
22 #include <OpenGLFramework/Base/glfTexture2D.hh>
23 #include <OpenGLFramework/Base/glfFramebufferObject.hh>
24 #include <OpenGLFramework/Base/glfShaderProgram.hh>
25 #include <OpenGLFramework/Base/glfBatch.hh>
26 #include <OpenGLFramework/Base/glfViewport.hh>
27 #include <OpenGLFramework/Base/glfDepthBufferMode.hh>
28 #include <OpenGLFramework/Base/glfRenderTarget.hh>
29 
30 #include <OpenGLFramework/Passive/glfPassiveRenderTarget.hh>
31 #include <OpenGLFramework/Passive/glfPassiveDepthBufferMode.hh>
32 
33 namespace BIAS {
34 
35  /** @brief Utility class for distortion rendering used by GLProjection
36  @warning This class can only be used if
37  BIAS_HAVE_CLASS_DISTORTIONRENDERING is defined.
38  @ingroup g_glviewer
39  @author jkollmann */
40  class BIASGLviewer_EXPORT DistortionRendering : public BIAS::Debug
41  {
42  public:
44 
46 
47  int Init(BIAS::ProjectionParametersPerspective* projParams);
48 
49  void Reset();
50 
51 
52  inline void SetClearColor(double r, double g, double b) {
53  ClearColor_.Set((float)r, (float)g, (float)b, 0.0f);
54  }
55 
56  inline void SetClearColor(const BIAS::Vector4<float>& cc){
57  ClearColor_ = cc;
58  }
59 
60  // optional interfaces that works without SceneBase.
61  int BeginRendering(BIAS::ProjectionParametersPerspective* projParams,
62  bool useStencil = false);
63 
64  int EndRendering(BIAS::glfRenderTarget* renderTarget);
65 
66  void Bind();
67 
68  int DrawScenes(std::vector<SceneBase*>& scenes,
69  bool& FirstRenderingPassFinished,
70  bool& informScenesOfChange,
72  BIAS::glfRenderTarget* renderTarget,
73  bool useStencil = false);
74 
75 
76  private:
77  /* moved this here (former global function) because
78  of linker errors
79  -> multiple defined symbols in OpenGLFramework
80  */
81  // void SetQuadDataTexture(float* data);
82 
83  BIAS::glfFramebufferObject DistortionRenderingFBO_;
84 
85  // Texture holding texturecoordinates into undistorted image
86  // accessed while generating distorted image
87  BIAS::glfTexture2D distortionMap_;
88 
89  BIAS::Vector4<float> ClearColor_;
90 
91  bool loadDistortionShaders_;
92  bool DistortionShadersInitialized_;
93 
94  BIAS::glfShader PerspectiveDistortionFragmentShader_;
95  BIAS::glfShaderProgram distortionProgram_;
96 
97  // color texture for undistorted image
98  BIAS::glfTexture2D NotDistortedColorTexture_;
99 
100  // depth texture for undistorted image
101  BIAS::glfTexture2D NotDistortedDepthTexture_;
102 
103  bool UseStencilBuffer_;
104 
105  //rendering the z-buffer here
106  //DepthbufferAttachment NotDistortedDepthBuffer_;
107 
108  unsigned int NotDistortedImageWidth_, NotDistortedImageHeight_;
109 
110  // holding the viewport for the current distortion rendering
111  // is set in InitDistortionShaders_().
112  BIAS::Vector4<GLint> lastUsedGLViewport_;
113 
114  BIAS::glfViewport undistortedViewport_;
115  BIAS::glfViewport targetViewport_;
116  BIAS::glfBatch distortionBatch_;
117  BIAS::glfVertexBuffer vertices_;
118  BIAS::glfElementBuffer elements_;
119  BIAS::glfPassiveRenderTarget globalRenderTarget_;
120  BIAS::glfPassiveDepthBufferMode globalDepthBufferMode_;
121  BIAS::glfDepthBufferMode depthTest_;
122 
123  void SetupPrimitiveRendering_();
124 
125  void SetQuadDataTexture_(float* data);
126 
128  DistortionRendering& operator=(const DistortionRendering& d) { return (*this); };
129 
130  };
131 
132 
133 }
134 
135 #endif
136 #endif // __DISTORTIONRENDERING_HH__
An element buffer contains vertex indices that form primitives.
Defines the usage of the depth buffer.
A 2D texture.
Definition: glfTexture2D.hh:40
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
This class allows to use the currently set RenderTarget in the global opengl state! ...
A vertex buffer contains an array of vertices that can be used for rendering.
void SetClearColor(double r, double g, double b)
A batch represents a single Draw call including all parameters (render states).
Definition: glfBatch.hh:48
A shader program composed of several shaders.
A GLSL vertex shader or fragment shader, which must be linked in a shader program.
Definition: glfShader.hh:39
Utility class for distortion rendering used by GLProjection.
This class allows to use the currently set viewport in the global opengl state!
class for setting viewports
Definition: glfViewport.hh:37
Interface for render targets.
void SetClearColor(const BIAS::Vector4< float > &cc)