OSVR-Core
RenderManagerConfig.h
Go to the documentation of this file.
1 
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 #ifndef INCLUDED_RenderManagerConfig_h_GUID_C8DA5781_5B6C_454A_B4FF_1DB50CBE3479
27 #define INCLUDED_RenderManagerConfig_h_GUID_C8DA5781_5B6C_454A_B4FF_1DB50CBE3479
28 
29 // Internal Includes
30 #include <osvr/Client/Export.h>
31 #include <osvr/Util/UniquePtr.h>
35 
36 // Library/third-party includes
37 #include <json/value.h>
38 #include <json/reader.h>
39 
40 // Standard includes
41 #include <string>
42 #include <iostream>
43 #include <exception>
44 #include <vector>
45 #include <stdexcept>
46 
47 namespace osvr {
48  namespace client {
49 
51  public:
52 
53  inline RenderManagerConfig(const std::string &renderManagerConfig)
54  {
55  parse(renderManagerConfig);
56  }
57 
58  inline RenderManagerConfig() {}
59 
60  inline void parse(const std::string &renderManagerConfig)
61  {
62  Json::Reader reader;
63  Json::Value root;
64  if (!reader.parse(renderManagerConfig, root, false)) {
65  throw std::runtime_error("RenderManagerConfig::parse - failed to parse render manager config string. Invalid JSON value?");
66  }
67 
68  auto &params = root["renderManagerConfig"];
69  m_directMode = params["directModeEnabled"].asBool();
70  m_displayIndex = params["directDisplayIndex"].asUInt();
71  m_directHighPriority = params["directHighPriorityEnabled"].asBool();
72  m_numBuffers = params["numBuffers"].asUInt();
73  m_verticalSync = params["verticalSyncEnabled"].asBool();
74  m_verticalSyncBlockRendering = params["verticalSyncBlockRenderingEnabled"].asBool();
75  m_renderOverfillFactor = params["renderOverfillFactor"].asFloat();
76  m_renderOversampleFactor = params.get("renderOversampleFactor", 1).asFloat();
77 
78  // window
79  {
80  auto &window = params["window"];
81  m_windowTitle = window["title"].asString();
82  m_windowFullScreen = window["fullScreenEnabled"].asBool();
83  m_windowXPosition = window["xPosition"].asInt();
84  m_windowYPosition = window["yPosition"].asInt();
85  }
86 
87  // display
88  {
89  auto display = params["display"];
90  m_displayRotation = display["rotation"].asUInt();
91  m_bitsPerColor = display["bitsPerColor"].asUInt();
92  }
93 
94  // time warp
95  {
96  auto &timeWarp = params["timeWarp"];
97  m_enableTimeWarp = timeWarp["enabled"].asBool();
98  m_justInTimeWarp = timeWarp["justInTime"].asBool();
99  m_asynchronousTimeWarp = timeWarp["asynchronous"].asBool();
100  m_maxMSBeforeVsyncTimeWarp = timeWarp["maxMsBeforeVSync"].asFloat();
101  }
102 
103  // prediction
104  {
105  auto prediction = params["prediction"];
106  m_predictEnabled = prediction["enabled"].asBool();
107  m_predictStaticDelayMS = prediction["staticDelayMS"].asFloat();
108  m_predictLeftEyeDelayMS = prediction["leftEyeDelayMS"].asFloat();
109  m_predictRightEyeDelayMS = prediction["rightEyeDelayMS"].asFloat();
110  m_predictLocalTimeOverride = prediction["localTimeOverride"].asBool();
111  }
112  }
113 
114  inline void print() const
115  {
116  std::cout << "Direct mode: " << m_directMode << std::endl;
117  std::cout << "Direct mode display index: " << m_displayIndex << std::endl;
118  std::cout << "Number of buffers: " << m_numBuffers << std::endl;
119  std::cout << "Vertical sync: " << m_verticalSync << std::endl;
120  std::cout << "Vertical sync block rendering: " << m_verticalSyncBlockRendering << std::endl;
121  std::cout << "Window Title: " << m_windowTitle << std::endl;
122  std::cout << "Window full screen: " << m_windowFullScreen << std::endl;
123  std::cout << "Window X Position: " << m_windowXPosition << std::endl;
124  std::cout << "Window Y Position: " << m_windowYPosition << std::endl;
125  std::cout << "Display rotation: " << m_displayRotation << std::endl;
126  std::cout << "Bits per color: " << m_bitsPerColor << std::endl;
127  std::cout << "Prediction enabled: " << m_predictEnabled << std::endl;
128  std::cout << "Static delay (ms): " << m_predictStaticDelayMS << std::endl;
129  std::cout << "Left eye delay (ms): " << m_predictLeftEyeDelayMS << std::endl;
130  std::cout << "Right eye delay (ms): " << m_predictRightEyeDelayMS << std::endl;
131  std::cout << "Prediction local time override: " << m_predictLocalTimeOverride << std::endl;
132  std::cout << "Enable time warp: " << m_enableTimeWarp << std::endl;
133  std::cout << "Asynchronous time warp: " << m_asynchronousTimeWarp << std::endl;
134  std::cout << "Max ms before vsync time warp: " << m_maxMSBeforeVsyncTimeWarp << std::endl;
135  std::cout << "Render overfill factor: " << m_renderOverfillFactor << std::endl;
136  std::cout << "Render oversample factor: " << m_renderOversampleFactor << std::endl;
137  }
138 
140  inline bool getDirectMode() const
141  {
142  return m_directMode;
143  }
144 
145  inline uint32_t getDisplayIndex() const
146  {
147  return m_displayIndex;
148  }
149 
150  inline bool getDirectHighPriority() const
151  {
152  return m_directHighPriority;
153  }
154 
155  inline bool getEnableTimeWarp() const
156  {
157  return m_enableTimeWarp;
158  }
159 
160  inline bool getAsynchronousTimeWarp() const
161  {
162  return m_asynchronousTimeWarp;
163  }
164 
165  inline bool getJustInTimeWarp() const
166  {
167  return m_justInTimeWarp;
168  }
169 
170  inline float getMaxMSBeforeVsyncTimeWarp() const
171  {
172  return m_maxMSBeforeVsyncTimeWarp;
173  }
174 
175  inline float getRenderOverfillFactor() const
176  {
177  return m_renderOverfillFactor;
178  }
179 
180  inline float getRenderOversampleFactor() const
181  {
182  return m_renderOversampleFactor;
183  }
184 
185  inline std::size_t getNumBuffers() const
186  {
187  return m_numBuffers;
188  }
189 
190  inline bool getVerticalSync() const
191  {
192  return m_verticalSync;
193  }
194 
195  inline bool getVerticalSyncBlockRendering() const
196  {
197  return m_verticalSyncBlockRendering;
198  }
199 
200  inline std::string getWindowTitle() const
201  {
202  return m_windowTitle;
203  }
204 
205  inline bool getWindowFullScreen() const
206  {
207  return m_windowFullScreen;
208  }
209 
210  inline int32_t getWindowXPosition() const
211  {
212  return m_windowXPosition;
213  }
214 
215  inline int32_t getWindowYPosition() const
216  {
217  return m_windowYPosition;
218  }
219 
220  inline uint32_t getDisplayRotation() const
221  {
222  return m_displayRotation;
223  }
224 
225  inline uint32_t getBitsPerColor() const
226  {
227  return m_bitsPerColor;
228  }
229 
230  inline bool getclientPredictionEnabled() const
231  {
232  return m_predictEnabled;
233  }
234 
235  inline float getStaticDelayMS() const
236  {
237  return m_predictStaticDelayMS;
238  }
239 
240  inline float getLeftEyeDelayMS() const
241  {
242  return m_predictLeftEyeDelayMS;
243  }
244 
245  inline float getRightEyeDelayMS() const
246  {
247  return m_predictRightEyeDelayMS;
248  }
249 
250  inline bool getclientPredictionLocalTimeOverride() const
251  {
252  return m_predictLocalTimeOverride;
253  }
254 
255  private:
256  bool m_directMode;
257  uint32_t m_displayIndex;
258  bool m_directHighPriority;
259  std::size_t m_numBuffers;
260  bool m_verticalSync;
261  bool m_verticalSyncBlockRendering;
262 
263  std::string m_windowTitle;
264  bool m_windowFullScreen;
265  int32_t m_windowXPosition;
266  int32_t m_windowYPosition;
267  uint32_t m_displayRotation;
268  uint32_t m_bitsPerColor;
269  bool m_predictEnabled;
270  float m_predictStaticDelayMS;
271  float m_predictLeftEyeDelayMS;
272  float m_predictRightEyeDelayMS;
273  bool m_predictLocalTimeOverride;
274 
275  bool m_enableTimeWarp;
276  bool m_justInTimeWarp;
277  bool m_asynchronousTimeWarp;
278  float m_maxMSBeforeVsyncTimeWarp;
279  float m_renderOverfillFactor;
280  float m_renderOversampleFactor;
281  };
282 
283  typedef std::shared_ptr<RenderManagerConfig> RenderManagerConfigPtr;
284 
286  public:
287  inline static RenderManagerConfigPtr createShared(OSVR_ClientContext ctx)
288  {
289  try {
290  auto const configString = ctx->getStringParameter("/renderManagerConfig");
291  RenderManagerConfigPtr cfg(new RenderManagerConfig(configString));
292  return cfg;
293  }
294  catch (std::exception const &e) {
295  std::cerr <<
296  "Couldn't create a render manager config internally! Exception: "
297  << e.what() << std::endl;
298  return RenderManagerConfigPtr{};
299  }
300  catch (...) {
301  std::cerr << "Couldn't create a render manager config internally! "
302  "Unknown exception!" << std::endl;
303  return RenderManagerConfigPtr{};
304  }
305  }
306  };
307 
308  } // namespace client
309 } // namespace osvr
310 
311 #endif // INCLUDED_RenderManagerConfig_h_GUID_C8DA5781_5B6C_454A_B4FF_1DB50CBE3479
Header containing wrappers for some common jsoncpp operations.
Definition: RenderManagerConfig.h:50
bool getDirectMode() const
Read the property information.
Definition: RenderManagerConfig.h:140
Header declaring opaque types used by Client and ClientKit.
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header to bring unique_ptr into the osvr namespace.
Definition: RenderManagerConfig.h:285
Definition: ClientContext.h:50
OSVR_COMMON_EXPORT std::string getStringParameter(std::string const &path) const
Gets a string parameter value.
Definition: ClientContext.cpp:131