OsgRenderTarget.h
Go to the documentation of this file.
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 
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 
67  OsgRenderTarget(int width, int height, double scale = 1.0,
68  int colorCount = 0, bool useDepth = false);
71 
74  void getSize(int* width, int* height) const override;
75 
77  int getColorTargetCount() const override;
78 
82  std::shared_ptr<Texture> getColorTarget(int index) const override;
83 
87  std::shared_ptr<OsgTexture> getColorTargetOsg(int index) const;
88 
91  bool doesUseDepthTarget() const override;
92 
95  std::shared_ptr<Texture> getDepthTarget() const override;
96 
99  std::shared_ptr<OsgTexture> getDepthTargetOsg() const;
100 
101 private:
102 
104  enum TargetTypes {
107  };
108 
110  int m_width;
111 
113  int m_height;
114 
117 
119  std::vector<std::shared_ptr<TextureType>> m_textures;
120 
124  int setColorTargetCount(int count);
125 
128  void useDepthTarget(bool val);
129 
132  void setupTexture(int type);
133 };
134 
140 
141 }; // Graphics
142 }; // SurgSim
143 
145 
146 #endif
SurgSim::Graphics::OsgRenderTarget::setupTexture
void setupTexture(int type)
Sets up the texture with a given target type (depth or color w/ index).
Definition: OsgRenderTarget-inl.h:148
SurgSim::Graphics::OsgRenderTarget::TextureType
T TextureType
The internal type of the texture, not exposed in the public interface.
Definition: OsgRenderTarget.h:57
SurgSim::Graphics::OsgRenderTarget::m_width
int m_width
The width of this RenderTarget.
Definition: OsgRenderTarget.h:110
SurgSim::Graphics::OsgRenderTarget::TARGETTYPE_DEPTH
Definition: OsgRenderTarget.h:105
SurgSim::Graphics::OsgRenderTarget2d
OsgRenderTarget< OsgTexture2d > OsgRenderTarget2d
Definition: OsgRenderTarget.h:137
SurgSim::Graphics::RenderTarget
RenderTarget is an abstraction of the target buffers that a Camera should use to render it's scene va...
Definition: RenderTarget.h:33
SurgSim::Graphics::OsgRenderTarget::~OsgRenderTarget
~OsgRenderTarget()
Destructor.
Definition: OsgRenderTarget-inl.h:55
SurgSim::Graphics::OsgRenderTarget::getDepthTargetOsg
std::shared_ptr< OsgTexture > getDepthTargetOsg() const
Accessor for the depth target as an OsgTexture.
Definition: OsgRenderTarget-inl.h:142
SurgSim::Graphics::OsgAbstractRenderTarget::getColorTargetOsg
virtual std::shared_ptr< OsgTexture > getColorTargetOsg(int index) const =0
Accessor for the color target as an OsgTexture.
SurgSim::Graphics::OsgRenderTarget::m_height
int m_height
The height of this RenderTarget.
Definition: OsgRenderTarget.h:113
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
OsgTexture2d.h
OsgTexture.h
SurgSim::Graphics::OsgRenderTarget::setColorTargetCount
int setColorTargetCount(int count)
Sets color target count.
Definition: OsgRenderTarget-inl.h:67
SurgSim::Graphics::OsgRenderTarget::TargetTypes
TargetTypes
Values that represent TargetTypes.
Definition: OsgRenderTarget.h:104
SurgSim::Graphics::OsgRenderTarget::getSize
void getSize(int *width, int *height) const override
Gets a size.
Definition: OsgRenderTarget-inl.h:60
SurgSim::Graphics::OsgRenderTarget::m_textures
std::vector< std::shared_ptr< TextureType > > m_textures
The textures that are being used as target, size of this is 16 (ColorTargets) + 1 (Depth).
Definition: OsgRenderTarget.h:119
SurgSim::Graphics::OsgRenderTarget::getColorTarget
std::shared_ptr< Texture > getColorTarget(int index) const override
Generic accessor for a specific color target texture.
Definition: OsgRenderTarget-inl.h:91
OsgTextureRectangle.h
SurgSim::Graphics::OsgRenderTarget::OsgRenderTarget
OsgRenderTarget()
Default constructor.
Definition: OsgRenderTarget-inl.h:29
SurgSim::Graphics::OsgAbstractRenderTarget::getDepthTargetOsg
virtual std::shared_ptr< OsgTexture > getDepthTargetOsg() const =0
Accessor for the depth target as an OsgTexture.
SurgSim::Graphics::OsgRenderTargetRectangle
OsgRenderTarget< OsgTextureRectangle > OsgRenderTargetRectangle
Definition: OsgRenderTarget.h:138
SurgSim::Graphics::OsgRenderTarget::getColorTargetOsg
std::shared_ptr< OsgTexture > getColorTargetOsg(int index) const
Accessor for the color target as an OsgTexture.
Definition: OsgRenderTarget-inl.h:104
SurgSim::Graphics::OsgRenderTarget::getColorTargetCount
int getColorTargetCount() const override
Definition: OsgRenderTarget-inl.h:85
SurgSim::Graphics::OsgRenderTarget::TARGETTYPE_COLORBASE
Definition: OsgRenderTarget.h:106
SurgSim::Graphics::OsgRenderTarget::getDepthTarget
std::shared_ptr< Texture > getDepthTarget() const override
Generic accessor for the depth Target.
Definition: OsgRenderTarget-inl.h:136
SurgSim::Graphics::OsgRenderTarget::m_colorTargetCount
int m_colorTargetCount
Number of color targets.
Definition: OsgRenderTarget.h:116
OsgRenderTarget-inl.h
SurgSim::Graphics::OsgAbstractRenderTarget
Osg abstract render target, this hides the type of the actual osg texture and lets us use OsgRenderTa...
Definition: OsgRenderTarget.h:37
SurgSim::Graphics::OsgRenderTarget
Specific implementation of the render target class.
Definition: OsgRenderTarget.h:52
SurgSim::Graphics::OsgRenderTarget::useDepthTarget
void useDepthTarget(bool val)
Use depth target.
Definition: OsgRenderTarget-inl.h:117
SurgSim::Graphics::OsgRenderTarget::doesUseDepthTarget
bool doesUseDepthTarget() const override
Determines if RenderTarget does use a depth target.
Definition: OsgRenderTarget-inl.h:130
RenderTarget.h