VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtSwapChain.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2024 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
13 
15 #include <osg/StateSet>
16 #include <osg/Geometry>
17 #include <osg/Texture2D>
18 
19 #include <vector>
20 #include <map>
21 
22 namespace makVrv
23 {
24  class DtDe;
25  class DtGlProgram;
26 
28  {
32  NONE
33  };
34 
38  {
39  private:
41  DtSwapChain();
42 
44  DtSwapChain(const DtSwapChain& orig);
45 
47  DtSwapChain& operator=(const DtSwapChain&);
48 
49  public:
52 
54  virtual ~DtSwapChain();
55 
57  virtual bool initalise(unsigned int width, unsigned int height, unsigned int layers, DtSwapChainTextureType type, DtGlImageType format);
58 
60  virtual bool addFormat(DtSwapChainTextureType type, DtGlImageType format);
61 
63  virtual void acquireTextures() = 0;
64 
66  unsigned int getAcquiredIndex(DtSwapChainTextureType type) const;
67 
69  virtual unsigned int getTexture(DtSwapChainTextureType type, int index) const = 0;
70 
72  virtual void releaseTextures() = 0;
73 
75  bool isInitialized() const;
76 
78  unsigned int length() const;
79 
81  DtSwapChainTextureType type(unsigned int index) const;
82 
84  DtGlImageType format(unsigned int index) const;
85 
87  DtGlImageType format(DtSwapChainTextureType type) const;
88 
90  unsigned int width() const;
91 
93  unsigned int height() const;
94 
96  unsigned int layers() const;
97 
99  vrvVirtualReality::DtEye eye() const;
100 
102  GLuint getFbo(unsigned int index) const;
103 
105  virtual void copyTextures(osg::RenderInfo& renderInfo, unsigned int srcColorId, unsigned int srcDepthId, unsigned int srcStencilId, bool copySrcAlpha = false, bool srcIsArray = true, int mode = 0) const;
106 
109  virtual void blitTextureToScreen(int swidth, int sheight, bool showleftEye, int overrideIndex = -1);
110 
112  virtual void blendSwapChains(osg::RenderInfo& renderInfo, DtSwapChain* base, DtSwapChain* overlay) const;
113 
114  protected:
115 
118  virtual bool initaliseFbos() const;
119 
121  virtual bool initCopyProgram(bool copyDepth, bool copyStencil, bool copySrcAlpha, bool srcIsArray) const;
122 
124  virtual bool initBlendProgram() const;
125 
126  protected:
127 
128  // !\brief have the textue swap chains been initalised
130 
131  // !\brief the eye this swapchain represents
133 
135  mutable unsigned int myLength;
136 
138  std::vector<DtSwapChainTextureType> myTextureTypes;
139 
141  std::vector<DtGlImageType> myFormats;
142 
144  mutable unsigned int myWidth;
145 
147  mutable unsigned int myHeight;
148 
150  mutable unsigned int myLayers;
151 
153  mutable std::map<DtSwapChainTextureType, unsigned int> mySwapChainIndexes;
154 
156  mutable std::vector<GLuint> myFbos;
157 
160 
163 
166 
168  mutable unsigned int myCopyQuadVbo;
169 
171  mutable unsigned int myLastStencilTexId;
172 
174  mutable unsigned int mySrcStencilTexId;
175 
178 
180  };
181 
183 
184  class DT_DLL_VRVVR DtExternalTextureAttribute : public osg::Texture2D
185  {
186  public:
188  : osg::Texture2D()
189  , myTextureId(0)
190  {
191  }
192 
193  virtual osg::Object* cloneType() const
194  {
195  return new DtExternalTextureAttribute();
196  }
197  virtual osg::Object* clone(const osg::CopyOp& copyop) const
198  {
199  return new DtExternalTextureAttribute();// (*this, copyop);
200  }
201  virtual int compare(const StateAttribute& sa) const
202  {
203  COMPARE_StateAttribute_Types(DtExternalTextureAttribute, sa)
204  rhs;
205  return 0;
206  }
207 
208  virtual void apply(osg::State& state) const
209  {
210  if (myTextureId)
211  {
212  glBindTexture(GL_TEXTURE_2D, myTextureId);
213  }
214  }
215 
217  };
218 
219  class DT_DLL_VRVVR DtSwapChainPreviewDrawable : public osg::Geometry
220  {
221  public:
224 
226  virtual ~DtSwapChainPreviewDrawable();
227 
228  virtual void drawImplementation(osg::RenderInfo& info) const;
229  virtual void releaseGLObjects(osg::State* state/* =0 */) const;
230 
231  virtual void setSwapChain(DtSwapChain* swapchain);
232 
233  virtual void setOverlayTexture(osg::Texture2D* overlay);
234  virtual void setSceneTextureOffset(osg::Vec2 uvOffset);
235 
236  protected:
237 
238  virtual void initGlObjects() const;
239 
240  protected:
241 
244 
246 
249 
250  mutable std::map<vrvVirtualReality::DtEye, osg::ref_ptr<DtExternalTextureAttribute>> myLayerTextures;
252 
253  };
254 }
osg::ref_ptr< osg::StateSet > myStateSet
Definition: DtSwapChain.h:251
virtual void apply(osg::State &state) const
Definition: DtSwapChain.h:208
osg::ref_ptr< osg::StateSet > myCopyStateSet
state set to encapsulate state changes when doing swapchain fill
Definition: DtSwapChain.h:165
std::map< vrvVirtualReality::DtEye, osg::ref_ptr< DtExternalTextureAttribute > > myLayerTextures
Definition: DtSwapChain.h:250
virtual int compare(const StateAttribute &sa) const
Definition: DtSwapChain.h:201
DtGlProgram * myCopyProgram
shader to copy sources texture into swapchain
Definition: DtSwapChain.h:159
Contains DLL export macros.
std::vector< DtGlImageType > myFormats
the format of the texture swap chain
Definition: DtSwapChain.h:141
int myCurrentSwapChainIndex
Definition: DtSwapChain.h:248
Definition: DtSwapChain.h:31
Definition: DtSwapChain.h:219
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:18
unsigned int myLastStencilTexId
the current source depth texture id, tracked so we can recreate stencil view if it changes ...
Definition: DtSwapChain.h:171
DtGlProgram * myBlendProgram
shader to blend two swapchains into one (scene and overlay)
Definition: DtSwapChain.h:177
A convenience class to represent an OpenGL Shader Program.
Definition: DtGlProgram.h:66
A driver that manages virtual reality HMD and input devices.
Definition: DtVirtualRealityDriver.h:54
std::vector< DtSwapChainTextureType > myTextureTypes
the type of the texture swap chain
Definition: DtSwapChain.h:138
#define DT_DLL_VRVVR
Definition: vrvVirtualReality.h:19
DtEye
A virtual reality eye.
Definition: vrvVirtualReality.h:37
int myLastCopyProgramConfig
the bit mask for the last complied version of the copy program
Definition: DtSwapChain.h:162
DtVirtualRealityDriver & myDriver
Definition: DtSwapChain.h:243
DtSwapChain * mySwapChain
Definition: DtSwapChain.h:247
Definition: DtTemplatedModelInstanceCreator.h:28
Base implementation of a texture swapchain.
Definition: DtSwapChain.h:37
DtGlImageType
Definition: DtGlImageType.h:15
unsigned int myCopyQuadVbo
vbo for draw command used for swapchain fill
Definition: DtSwapChain.h:168
std::map< DtSwapChainTextureType, unsigned int > mySwapChainIndexes
active swapchain index for each format
Definition: DtSwapChain.h:153
unsigned int myWidth
the pixel width of the texture swap chain
Definition: DtSwapChain.h:144
DtDe & myDe
Definition: DtSwapChain.h:242
unsigned int mySrcStencilTexId
the current depth textures stencil view texture id
Definition: DtSwapChain.h:174
Definition: DtSwapChain.h:29
Definition: DtSwapChain.h:30
virtual osg::Object * cloneType() const
Definition: DtSwapChain.h:193
DtExternalTextureAttribute()
Definition: DtSwapChain.h:187
DT_DLL_VRVCORE double length(const makVrv::DtCoordinateSystem &, const std::vector< DtVector > &vertices)
Returns the total distance of a segmented line defined by the provided vector of vertices. Coordinates are in local database coordinates. The coordinate system is used to convert between the local database coordinates and geocentric. All distance is in 2D – the Z value is ignored.
const char int mode
Definition: ioapi.h:38
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Definition: DtSwapChain.h:197
unsigned int myLength
the length/number of textures in the swapchain
Definition: DtSwapChain.h:135
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
unsigned int myHeight
the pixel height of the texture swap chain
Definition: DtSwapChain.h:147
enum representing an OpenGL image type
unsigned int myLayers
the number of layers in the textures i.e. array layers
Definition: DtSwapChain.h:150
vrvVirtualReality::DtEye myEye
Definition: DtSwapChain.h:132
DtDe & myDe
Definition: DtSwapChain.h:179
DtSwapChainTextureType
Definition: DtSwapChain.h:27
bool myUseBlitMode
Definition: DtSwapChain.h:245
std::vector< GLuint > myFbos
fbo for swapchain copy operations
Definition: DtSwapChain.h:156
bool myIsInitialized
Definition: DtSwapChain.h:129
Definition: DtSwapChain.h:184
GLuint myTextureId
Definition: DtSwapChain.h:216

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)