AGX Dynamics  2.35.0.1
RenderTarget.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
74 
79  void setReferenceCamera(const osg::Camera* referenceCamera);
80 
86 
91 
97  void setSize(agx::UInt width, agx::UInt height);
98 
103  void setSize(agx::Vec2u size);
104 
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 
148 
155 
169  void setCameraCullMask(int cullMask);
170 
172  int getCameraCullMask() const;
173 
174 
175  protected:
176  virtual ~RenderTarget();
177 
178  private:
179  class CameraSynchronizeCallback;
180 
181  protected:
185  osg::ref_ptr<osg::Camera> m_camera;
186  osg::ref_ptr<CameraSynchronizeCallback> m_cameraSynchronizeCallback;
187  };
188 
189 
191  class RenderTarget::CameraSynchronizeCallback : public osg::Camera::DrawCallback
192  {
193  public:
194  CameraSynchronizeCallback(const osg::Camera *reference, osg::Camera *target);
195  virtual ~CameraSynchronizeCallback();
196 
197  virtual void operator () (osg::RenderInfo& /* renderInfo */) const;
198  using osg::Camera::DrawCallback::operator();
199 
200  void addNestedCallback(osg::Camera::DrawCallback *child);
201 
202  private:
203  osg::ref_ptr<const osg::Camera> m_reference;
204  osg::ref_ptr<osg::Camera> m_target;
206  };
208 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Render target is used for rendering camera content to a buffer, either a DEPTH or COLOR target.
Definition: RenderTarget.h:41
osg::Camera * getCamera()
TextureFormat
Specifies target texture format.
Definition: RenderTarget.h:54
BufferComponent
Specifies which type of buffer to render.
Definition: RenderTarget.h:47
void setProjectionMatrixAsOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
Update the orthographic projection matrix given the arguments.
agxOSG::ImageCaptureBase * getImageCapture()
void setSize(agx::UInt width, agx::UInt height)
Update the size of the render target buffer size.
osg::ref_ptr< CameraSynchronizeCallback > m_cameraSynchronizeCallback
Definition: RenderTarget.h:186
ImageCaptureBaseRef m_imageCapture
Definition: RenderTarget.h:184
agx::Vec2 calculateScreenCoords(agx::Vec3 &worldPos)
Transform the position into screen coordinates using the camera associated to this RenderTarget.
void setImageCapture(agxOSG::ImageCaptureBase *imageCapture)
By attaching an ImageCaptureBase you can automatically store the image data to disk given a specific ...
void setComputeNearFarMode(agxOSG::RenderTarget::ComputeNearFarMode mode)
Specifies whether the near far should be automatically updated or not.
void setViewMatrixAsLookAt(const agx::Vec3 &eye, const agx::Vec3 &center, const agx::Vec3 &up)
Update the view matrix given the arguments.
osg::ref_ptr< osg::Camera > m_camera
Definition: RenderTarget.h:185
void setReferenceCamera(const osg::Camera *referenceCamera)
By using a reference camera, the render target camera will get the same view/projection/viewpoint as ...
void addPreRenderCallback(osg::Camera::DrawCallback *callback)
Add a pre-render callback to this RenderTarget.
void setProjectionMatrixAsPerspective(double fovy, double aspectRatio, double zNear, double zFar)
Update the perspective projection matrix given the arguments.
int getCameraCullMask() const
RenderTarget(agx::UInt width, agx::UInt height)
Constructor.
agx::Vec2u getSize() const
void setSize(agx::Vec2u size)
Update the size of the render target buffer size.
void setCameraCullMask(int cullMask)
agx::Object is a refcounted object with a name.
Definition: Object.h:60
Templated vector class.
Definition: agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
uint32_t UInt
Definition: Integer.h:34