GtePVWUpdater.cpp
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 #include <GTEnginePCH.h>
10 using namespace gte;
11 
13 {
14 }
15 
17 {
18  Set(nullptr, [](std::shared_ptr<Buffer> const&) {});
19 }
20 
21 PVWUpdater::PVWUpdater(std::shared_ptr<Camera> const& camera, BufferUpdater const& updater)
22 {
23  Set(camera, updater);
24 }
25 
26 void PVWUpdater::Set(std::shared_ptr<Camera> const& camera, BufferUpdater const& updater)
27 {
28  mCamera = camera;
29  mUpdater = updater;
30 }
31 
32 bool PVWUpdater::Subscribe(Matrix4x4<float> const& worldMatrix,
33  std::shared_ptr<ConstantBuffer> const& cbuffer,
34  std::string const& pvwMatrixName)
35 {
36  if (cbuffer && cbuffer->HasMember(pvwMatrixName))
37  {
38  if (mSubscribers.find(&worldMatrix) == mSubscribers.end())
39  {
40  mSubscribers.insert(std::make_pair(&worldMatrix,
41  std::make_pair(cbuffer, pvwMatrixName)));
42  return true;
43  }
44  }
45  return false;
46 }
47 
48 bool PVWUpdater::Unsubscribe(Matrix4x4<float> const& worldMatrix)
49 {
50  return mSubscribers.erase(&worldMatrix) > 0;
51 }
52 
54 {
55  mSubscribers.clear();
56 }
57 
59 {
60  // The function is called knowing that mCamera is not null.
61  Matrix4x4<float> pvMatrix = mCamera->GetProjectionViewMatrix();
62  for (auto& element : mSubscribers)
63  {
64  // Compute the new projection-view-world matrix. The matrix
65  // *element.first is the model-to-world matrix for the associated
66  // object.
67 #if defined(GTE_USE_MAT_VEC)
68  Matrix4x4<float> pvwMatrix = pvMatrix * (*element.first);
69 #else
70  Matrix4x4<float> pvwMatrix = (*element.first) * pvMatrix;
71 #endif
72  // Copy the source matrix into the system memory of the constant
73  // buffer.
74  element.second.first->SetMember(element.second.second, pvwMatrix);
75 
76  // Allow the caller to update GPU memory as desired.
77  mUpdater(element.second.first);
78  }
79 }
void Set(std::shared_ptr< Camera > const &camera, BufferUpdater const &updater)
std::function< void(std::shared_ptr< Buffer > const &)> BufferUpdater
Definition: GteBuffer.h:24
std::shared_ptr< Camera > mCamera
Definition: GtePVWUpdater.h:57
std::map< PVWKey, PVWValue > mSubscribers
Definition: GtePVWUpdater.h:62
BufferUpdater mUpdater
Definition: GtePVWUpdater.h:58
bool Subscribe(Matrix4x4< float > const &worldMatrix, std::shared_ptr< ConstantBuffer > const &cbuffer, std::string const &pvwMatrixName="pvwMatrix")
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
bool Unsubscribe(Matrix4x4< float > const &worldMatrix)
virtual ~PVWUpdater()


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