AGX Dynamics  2.37.3.2
RenderTarget.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are 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 
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 AGXOSG_EXPORT
osg::ref_ptr< osg::Camera > m_camera
Definition: RenderTarget.h:185
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
osg::ref_ptr< CameraSynchronizeCallback > m_cameraSynchronizeCallback
Definition: RenderTarget.h:186
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
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
ImageCaptureBaseRef m_imageCapture
Definition: RenderTarget.h:184
TextureFormat
Specifies target texture format.
Definition: RenderTarget.h:53
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::Object is a refcounted object with a name.
Definition: Object.h:58