GtePVWUpdater.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteCamera.h>
12 #include <map>
13 
14 namespace gte
15 {
16 
18 {
19 public:
20  // Construction and destruction.
21  virtual ~PVWUpdater();
22  PVWUpdater();
23  PVWUpdater(std::shared_ptr<Camera> const& camera, BufferUpdater const& updater);
24 
25  // Member access. The functions are for deferred construction after
26  // a default construction of a PVWUpdater.
27  void Set(std::shared_ptr<Camera> const& camera, BufferUpdater const& updater);
28  inline std::shared_ptr<Camera> const& GetCamera() const;
29  inline void SetUpdater(BufferUpdater const& updater);
30  inline BufferUpdater const& GetUpdater() const;
31 
32  // Update the constant buffer's projection-view-world matrix (pvw-matrix)
33  // when the camera's view or projection matrices change. The input
34  // 'pvwMatrixName' is the name specified in the shader program and is
35  // used in calls to ConstantBuffer::SetMember<Matrix4x4<float>>(...).
36  // If you modify the view or projection matrices directly through the
37  // Camera interface, you are responsible for calling UpdatePVWMatrices().
38  //
39  // The Subscribe function uses the address of 'worldMatrix' as a key
40  // to a std::map, so be careful to ensure that 'worldMatrix' persists
41  // until a call to an Unsubscribe function. The return value of Subscribe
42  // is 'true' as long as 'cbuffer' is not already subscribed and actually
43  // has a member named 'pvwMatrixName'. The return value of Unsubscribe is
44  // true if and only if the input matrix is currently subscribed.
45  bool Subscribe(Matrix4x4<float> const& worldMatrix,
46  std::shared_ptr<ConstantBuffer> const& cbuffer,
47  std::string const& pvwMatrixName = "pvwMatrix");
48  bool Unsubscribe(Matrix4x4<float> const& worldMatrix);
49  void UnsubscribeAll();
50 
51  // After any camera modifictions that change the projection or view
52  // matrices, call this function to update the constant buffers that
53  // are subscribed.
54  void Update();
55 
56 protected:
57  std::shared_ptr<Camera> mCamera;
59 
60  typedef Matrix4x4<float> const* PVWKey;
61  typedef std::pair<std::shared_ptr<ConstantBuffer>, std::string> PVWValue;
62  std::map<PVWKey, PVWValue> mSubscribers;
63 };
64 
65 
66 inline std::shared_ptr<Camera> const& PVWUpdater::GetCamera() const
67 {
68  return mCamera;
69 }
70 
71 inline void PVWUpdater::SetUpdater(BufferUpdater const& updater)
72 {
73  mUpdater = updater;
74 }
75 
77 {
78  return mUpdater;
79 }
80 
81 }
Matrix4x4< float > const * PVWKey
Definition: GtePVWUpdater.h:60
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
Definition: GteBuffer.h:24
BufferUpdater const & GetUpdater() const
Definition: GtePVWUpdater.h:76
std::shared_ptr< Camera > mCamera
Definition: GtePVWUpdater.h:57
std::map< PVWKey, PVWValue > mSubscribers
Definition: GtePVWUpdater.h:62
BufferUpdater mUpdater
Definition: GtePVWUpdater.h:58
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
std::shared_ptr< Camera > const & GetCamera() const
Definition: GtePVWUpdater.h:66
void SetUpdater(BufferUpdater const &updater)
Definition: GtePVWUpdater.h:71
std::pair< std::shared_ptr< ConstantBuffer >, std::string > PVWValue
Definition: GtePVWUpdater.h:61
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01