AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderTarget.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, is copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxOSG/export.h>
20 #include <agxOSG/ImageCapture.h>
21 #include <agx/Object.h>
22 #include <agx/Vec2.h>
23 
24 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
25 #include <osg/Node>
26 #include <osg/Geometry>
27 #include <osg/Texture2D>
28 #include <osg/Image>
29 #include <osg/Camera>
30 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
31 
32 namespace agxOSG
33 {
36 
41  {
42  public:
43 
44 
47  {
48  COLOR_BUFFER=osg::Camera::COLOR_BUFFER,
49  DEPTH_BUFFER=osg::Camera::DEPTH_BUFFER
50  };
51 
54  {
55  RGBA=GL_RGBA,
56  RGB = GL_RGB,
57  DEPTH_COMPONENT= GL_DEPTH_COMPONENT
58  };
59 
61  {
62  DO_NOT_COMPUTE_NEAR_FAR=osg::Camera::DO_NOT_COMPUTE_NEAR_FAR,
63  COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES=osg::Camera::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES,
64  COMPUTE_NEAR_FAR_USING_PRIMITIVES=osg::Camera::COMPUTE_NEAR_FAR_USING_PRIMITIVES,
65  COMPUTE_NEAR_USING_PRIMITIVES=osg::Camera::COMPUTE_NEAR_USING_PRIMITIVES
66  };
67 
73  RenderTarget(agx::UInt width, agx::UInt height);
74 
79  void setReferenceCamera(const osg::Camera* referenceCamera);
80 
85  void setImageCapture(agxOSG::ImageCaptureBase *imageCapture);
86 
90  agxOSG::ImageCaptureBase* getImageCapture();
91 
97  void setSize(agx::UInt width, agx::UInt height);
98 
103  void setSize(agx::Vec2u size);
104 
106  agx::Vec2u getSize() const;
107 
111  osg::Camera* getCamera();
112 
117  void addPreRenderCallback(osg::Camera::DrawCallback* callback);
118 
125  void setViewMatrixAsLookAt(const agx::Vec3& eye, const agx::Vec3& center, const agx::Vec3& up);
126 
134  void setProjectionMatrixAsPerspective(double fovy, double aspectRatio, double zNear, double zFar);
135 
142  void setProjectionMatrixAsOrtho(double left, double right, double bottom, double top, double zNear, double zFar);
143 
147  void setComputeNearFarMode(agxOSG::RenderTarget::ComputeNearFarMode mode);
148 
154  agx::Vec2 calculateScreenCoords(agx::Vec3& worldPos);
155 
156 
157  protected:
158  virtual ~RenderTarget();
159 
160  private:
161  class CameraSynchronizeCallback;
162 
163  protected:
167  osg::ref_ptr<osg::Camera> m_camera;
168  osg::ref_ptr<CameraSynchronizeCallback> m_cameraSynchronizeCallback;
169  };
170 
171 
173  class RenderTarget::CameraSynchronizeCallback : public osg::Camera::DrawCallback
174  {
175  public:
176  CameraSynchronizeCallback(const osg::Camera *reference, osg::Camera *target);
177  virtual ~CameraSynchronizeCallback();
178 
179  virtual void operator () (osg::RenderInfo& /* renderInfo */) const;
180  using osg::Camera::DrawCallback::operator();
181 
182  void addNestedCallback(osg::Camera::DrawCallback *child);
183 
184  private:
185  osg::ref_ptr<const osg::Camera> m_reference;
186  osg::ref_ptr<osg::Camera> m_target;
188  };
190 }
#define AGXOSG_EXPORT
osg::ref_ptr< osg::Camera > m_camera
Definition: RenderTarget.h:167
AGX_DECLARE_VECTOR_TYPES(ClipPlane)
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
osg::ref_ptr< CameraSynchronizeCallback > m_cameraSynchronizeCallback
Definition: RenderTarget.h:168
Render target is used for rendering camera content to a buffer, either a DEPTH or COLOR target...
Definition: RenderTarget.h:40
Templated vector class.
Definition: Vector.h:52
uint32_t UInt
Definition: Integer.h:34
BufferComponent
Specifies which type of buffer to render.
Definition: RenderTarget.h:46
#define GL_RGB
Definition: gl.h:3658
ImageCaptureBaseRef m_imageCapture
Definition: RenderTarget.h:166
TextureFormat
Specifies target texture format.
Definition: RenderTarget.h:53
#define GL_DEPTH_COMPONENT
Definition: gl.h:1056
#define GL_RGBA
Definition: gl.h:3699
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100
agx::Object is a refcounted object with a name.
Definition: Object.h:59