OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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_asynchronousTimeWarp = timeWarp["asynchronous"].asBool();
99  m_maxMSBeforeVsyncTimeWarp = timeWarp["maxMsBeforeVSync"].asFloat();
100  }
101 
102  // prediction
103  {
104  auto prediction = params["prediction"];
105  m_predictEnabled = prediction["enabled"].asBool();
106  m_predictStaticDelayMS = prediction["staticDelayMS"].asFloat();
107  m_predictLeftEyeDelayMS = prediction["leftEyeDelayMS"].asFloat();
108  m_predictRightEyeDelayMS = prediction["rightEyeDelayMS"].asFloat();
109  m_predictLocalTimeOverride = prediction["localTimeOverride"].asBool();
110  }
111  }
112 
113  inline void print() const
114  {
115  std::cout << "Direct mode: " << m_directMode << std::endl;
116  std::cout << "Direct mode display index: " << m_displayIndex << std::endl;
117  std::cout << "Number of buffers: " << m_numBuffers << std::endl;
118  std::cout << "Vertical sync: " << m_verticalSync << std::endl;
119  std::cout << "Vertical sync block rendering: " << m_verticalSyncBlockRendering << std::endl;
120  std::cout << "Window Title: " << m_windowTitle << std::endl;
121  std::cout << "Window full screen: " << m_windowFullScreen << std::endl;
122  std::cout << "Window X Position: " << m_windowXPosition << std::endl;
123  std::cout << "Window Y Position: " << m_windowYPosition << std::endl;
124  std::cout << "Display rotation: " << m_displayRotation << std::endl;
125  std::cout << "Bits per color: " << m_bitsPerColor << std::endl;
126  std::cout << "Prediction enabled: " << m_predictEnabled << std::endl;
127  std::cout << "Static delay (ms): " << m_predictStaticDelayMS << std::endl;
128  std::cout << "Left eye delay (ms): " << m_predictLeftEyeDelayMS << std::endl;
129  std::cout << "Right eye delay (ms): " << m_predictRightEyeDelayMS << std::endl;
130  std::cout << "Prediction local time override: " << m_predictLocalTimeOverride << std::endl;
131  std::cout << "Enable time warp: " << m_enableTimeWarp << std::endl;
132  std::cout << "Asynchronous time warp: " << m_asynchronousTimeWarp << std::endl;
133  std::cout << "Max ms before vsync time warp: " << m_maxMSBeforeVsyncTimeWarp << std::endl;
134  std::cout << "Render overfill factor: " << m_renderOverfillFactor << std::endl;
135  std::cout << "Render oversample factor: " << m_renderOversampleFactor << std::endl;
136  }
137 
139  inline bool getDirectMode() const
140  {
141  return m_directMode;
142  }
143 
144  inline uint32_t getDisplayIndex() const
145  {
146  return m_displayIndex;
147  }
148 
149  inline bool getDirectHighPriority() const
150  {
151  return m_directHighPriority;
152  }
153 
154  inline bool getEnableTimeWarp() const
155  {
156  return m_enableTimeWarp;
157  }
158 
159  inline bool getAsynchronousTimeWarp() const
160  {
161  return m_asynchronousTimeWarp;
162  }
163 
164  inline float getMaxMSBeforeVsyncTimeWarp() const
165  {
166  return m_maxMSBeforeVsyncTimeWarp;
167  }
168 
169  inline float getRenderOverfillFactor() const
170  {
171  return m_renderOverfillFactor;
172  }
173 
174  inline float getRenderOversampleFactor() const
175  {
176  return m_renderOversampleFactor;
177  }
178 
179  inline std::size_t getNumBuffers() const
180  {
181  return m_numBuffers;
182  }
183 
184  inline bool getVerticalSync() const
185  {
186  return m_verticalSync;
187  }
188 
189  inline bool getVerticalSyncBlockRendering() const
190  {
191  return m_verticalSyncBlockRendering;
192  }
193 
194  inline std::string getWindowTitle() const
195  {
196  return m_windowTitle;
197  }
198 
199  inline bool getWindowFullScreen() const
200  {
201  return m_windowFullScreen;
202  }
203 
204  inline int32_t getWindowXPosition() const
205  {
206  return m_windowXPosition;
207  }
208 
209  inline int32_t getWindowYPosition() const
210  {
211  return m_windowYPosition;
212  }
213 
214  inline uint32_t getDisplayRotation() const
215  {
216  return m_displayRotation;
217  }
218 
219  inline uint32_t getBitsPerColor() const
220  {
221  return m_bitsPerColor;
222  }
223 
224  inline bool getclientPredictionEnabled() const
225  {
226  return m_predictEnabled;
227  }
228 
229  inline float getStaticDelayMS() const
230  {
231  return m_predictStaticDelayMS;
232  }
233 
234  inline float getLeftEyeDelayMS() const
235  {
236  return m_predictLeftEyeDelayMS;
237  }
238 
239  inline float getRightEyeDelayMS() const
240  {
241  return m_predictRightEyeDelayMS;
242  }
243 
244  inline bool getclientPredictionLocalTimeOverride() const
245  {
246  return m_predictLocalTimeOverride;
247  }
248 
249  private:
250  bool m_directMode;
251  uint32_t m_displayIndex;
252  bool m_directHighPriority;
253  std::size_t m_numBuffers;
254  bool m_verticalSync;
255  bool m_verticalSyncBlockRendering;
256 
257  std::string m_windowTitle;
258  bool m_windowFullScreen;
259  int32_t m_windowXPosition;
260  int32_t m_windowYPosition;
261  uint32_t m_displayRotation;
262  uint32_t m_bitsPerColor;
263  bool m_predictEnabled;
264  float m_predictStaticDelayMS;
265  float m_predictLeftEyeDelayMS;
266  float m_predictRightEyeDelayMS;
267  bool m_predictLocalTimeOverride;
268 
269  bool m_enableTimeWarp;
270  bool m_asynchronousTimeWarp;
271  float m_maxMSBeforeVsyncTimeWarp;
272  float m_renderOverfillFactor;
273  float m_renderOversampleFactor;
274  };
275 
276  typedef std::shared_ptr<RenderManagerConfig> RenderManagerConfigPtr;
277 
279  public:
280  inline static RenderManagerConfigPtr createShared(OSVR_ClientContext ctx)
281  {
282  try {
283  auto const configString = ctx->getStringParameter("/renderManagerConfig");
284  RenderManagerConfigPtr cfg(new RenderManagerConfig(configString));
285  return cfg;
286  }
287  catch (std::exception const &e) {
288  std::cerr <<
289  "Couldn't create a render manager config internally! Exception: "
290  << e.what() << std::endl;
291  return RenderManagerConfigPtr{};
292  }
293  catch (...) {
294  std::cerr << "Couldn't create a render manager config internally! "
295  "Unknown exception!" << std::endl;
296  return RenderManagerConfigPtr{};
297  }
298  }
299  };
300 
301  } // namespace client
302 } // namespace osvr
303 
304 #endif // INCLUDED_RenderManagerConfig_h_GUID_C8DA5781_5B6C_454A_B4FF_1DB50CBE3479
Header containing wrappers for some common jsoncpp operations.
std::string getStringParameter(std::string const &path) const
Gets a string parameter value.
Header declaring opaque types used by Client and ClientKit.
Header to bring unique_ptr into the osvr namespace.
bool getDirectMode() const
Read the property information.
Automatically-generated export header - do not edit!