opensurgsim
OsgRenderTarget.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_OSGRENDERTARGET_H
17 #define SURGSIM_GRAPHICS_OSGRENDERTARGET_H
18 
19 #include <memory>
20 #include <unordered_map>
21 
22 #include "SurgSim/Graphics/RenderTarget.h"
23 #include "SurgSim/Graphics/OsgTexture.h"
24 #include "SurgSim/Graphics/OsgTexture2d.h"
25 #include "SurgSim/Graphics/OsgTextureRectangle.h"
26 
27 #include <osg/FrameBufferObject>
28 
29 namespace SurgSim
30 {
31 namespace Graphics
32 {
33 
34 
38 {
42  virtual std::shared_ptr<OsgTexture> getColorTargetOsg(int index) const = 0;
43 
46  virtual std::shared_ptr<OsgTexture> getDepthTargetOsg() const = 0;
47 };
48 
51 template <class T>
53 {
54 public:
55 
57  typedef T TextureType;
58 
61 
68  OsgRenderTarget(int width, int height, double scale = 1.0,
69  int colorCount = 0, bool useDepth = false, bool useFloat = false);
71  ~OsgRenderTarget();
72 
75  void getSize(int* width, int* height) const override;
76 
78  int getColorTargetCount() const override;
79 
83  std::shared_ptr<Texture> getColorTarget(int index) const override;
84 
88  std::shared_ptr<OsgTexture> getColorTargetOsg(int index) const;
89 
92  bool doesUseDepthTarget() const override;
93 
96  std::shared_ptr<Texture> getDepthTarget() const override;
97 
100  std::shared_ptr<OsgTexture> getDepthTargetOsg() const;
101 
102 private:
103 
105  enum TargetTypes {
106  TARGETTYPE_DEPTH = 0,
107  TARGETTYPE_COLORBASE = 1
108  };
109 
111  int m_width;
112 
114  int m_height;
115 
117  int m_colorTargetCount;
118 
120  std::vector<std::shared_ptr<TextureType>> m_textures;
121 
126  int setColorTargetCount(int count, bool floatColor);
127 
130  void useDepthTarget(bool val);
131 
135  void setupTexture(int type, bool floatColor);
136 };
137 
143 
144 }; // Graphics
145 }; // SurgSim
146 
147 #include "SurgSim/Graphics/OsgRenderTarget-inl.h"
148 
149 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual void getSize(int *width, int *height) const =0
Gets a size.
Osg abstract render target, this hides the type of the actual osg texture and lets us use OsgRenderTa...
Definition: OsgRenderTarget.h:37
RenderTarget is an abstraction of the target buffers that a Camera should use to render it&#39;s scene va...
Definition: RenderTarget.h:33
virtual std::shared_ptr< Texture > getColorTarget(int index) const =0
Gets the indicated texture that is used as a target.
Specific implementation of the render target class.
Definition: OsgRenderTarget.h:52
T TextureType
The internal type of the texture, not exposed in the public interface.
Definition: OsgRenderTarget.h:57
virtual bool doesUseDepthTarget() const =0
Check wether this draws into a depth texture.
virtual int getColorTargetCount() const =0
Returns the number of textures that this RenderTarget uses to draw into.
virtual std::shared_ptr< Texture > getDepthTarget() const =0
Returns the texture that is used for the depth map drawing.