Skip to content

Commit 7b46737

Browse files
committed
Introduce and use an enum class with just the device types we actually can handle.
1 parent 134ae3e commit 7b46737

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

OsvrRenderingPlugin.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,17 @@ inline void dispatchEventToRenderer(UnityRendererType renderer,
168168
return;
169169
}
170170
switch (renderer.getDeviceTypeEnum()) {
171-
#if SUPPORT_OPENGL
172-
case kUnityGfxRendererOpenGL:
173-
DoEventGraphicsDeviceOpenGL(eventType);
174-
break;
175-
#endif
176171
#if SUPPORT_D3D11
177-
case kUnityGfxRendererD3D11:
172+
case OSVRSupportedRenderers::D3D11:
178173
DoEventGraphicsDeviceD3D11(eventType);
179174
break;
180175
#endif
176+
#if SUPPORT_OPENGL
177+
case OSVRSupportedRenderers::OpenGL:
178+
DoEventGraphicsDeviceOpenGL(eventType);
179+
break;
180+
#endif
181+
case OSVRSupportedRenderers::EmptyRenderer:
181182
default:
182183
break;
183184
}
@@ -323,15 +324,16 @@ OSVR_ReturnCode UNITY_INTERFACE_API ConstructRenderBuffers() {
323324
const int n = static_cast<int>(renderInfo.size());
324325
switch (s_deviceType.getDeviceTypeEnum()) {
325326
#if SUPPORT_D3D11
326-
case kUnityGfxRendererD3D11:
327+
case OSVRSupportedRenderers::D3D11:
327328
return applyRenderBufferConstructor(n, ConstructBuffersD3D11);
328329
break;
329330
#endif
330331
#if SUPPORT_OPENGL
331-
case kUnityGfxRendererOpenGL:
332+
case OSVRSupportedRenderers::OpenGL:
332333
return applyRenderBufferConstructor(n, ConstructBuffersOpenGL);
333334
break;
334335
#endif
336+
case OSVRSupportedRenderers::EmptyRenderer:
335337
default:
336338
DebugLog("Device type not supported.");
337339
return OSVR_RETURN_FAILURE;
@@ -610,7 +612,7 @@ inline void DoRender() {
610612

611613
switch (s_deviceType.getDeviceTypeEnum()) {
612614
#if SUPPORT_D3D11
613-
case kUnityGfxRendererD3D11: {
615+
case OSVRSupportedRenderers::D3D11: {
614616
// Render into each buffer using the specified information.
615617
for (int i = 0; i < n; ++i) {
616618
RenderViewD3D11(renderInfo[i],
@@ -631,7 +633,7 @@ inline void DoRender() {
631633
}
632634
#endif
633635
#if SUPPORT_OPENGL
634-
case kUnityGfxRendererOpenGL: {
636+
case OSVRSupportedRenderers::OpenGL: {
635637
// OpenGL
636638
//@todo OpenGL path is not working yet
637639
// Render into each buffer using the specified information.
@@ -649,6 +651,9 @@ inline void DoRender() {
649651
break;
650652
}
651653
#endif
654+
case OSVRSupportedRenderers::EmptyRenderer:
655+
default:
656+
break;
652657
}
653658
}
654659

@@ -700,7 +705,7 @@ inline void DoEventGraphicsDeviceD3D11(UnityGfxDeviceEventType eventType) {
700705
s_deviceType,
701706
"Should only be able to get in here with a valid device type.");
702707
BOOST_ASSERT_MSG(
703-
s_deviceType.getDeviceTypeEnum == kUnityGfxRendererD3D11,
708+
s_deviceType.getDeviceTypeEnum() == OSVRSupportedRenderers::D3D11,
704709
"Should only be able to get in here if using D3D11 device type.");
705710

706711
switch (eventType) {
@@ -738,7 +743,7 @@ inline void DoEventGraphicsDeviceOpenGL(UnityGfxDeviceEventType eventType) {
738743
s_deviceType,
739744
"Should only be able to get in here with a valid device type.");
740745
BOOST_ASSERT_MSG(
741-
s_deviceType.getDeviceTypeEnum == kUnityGfxRendererOpenGL,
746+
s_deviceType.getDeviceTypeEnum() == OSVRSupportedRenderers::OpenGL,
742747
"Should only be able to get in here if using OpenGL device type.");
743748

744749
switch (eventType) {

UnityRendererType.h

+20-9
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,42 @@
3434
// Standard includes
3535
// - none
3636

37+
/// An enum class that only contains the renderer types that we support. This
38+
/// avoids spurious "unhandled cases in switch" warnings".
39+
enum class OSVRSupportedRenderers {
40+
EmptyRenderer,
41+
#if SUPPORT_D3D11
42+
D3D11,
43+
#endif
44+
#if SUPPORT_OPENGL
45+
OpenGL,
46+
#endif
47+
};
48+
3749
/// Wrapper around UnityGfxRenderer that knows about our support capabilities.
3850
class UnityRendererType {
3951
public:
4052
explicit operator bool() const { return supported_; }
41-
UnityGfxRenderer getDeviceTypeEnum() const {
53+
OSVRSupportedRenderers getDeviceTypeEnum() const {
4254
BOOST_ASSERT_MSG(supported_, "Cannot get an unsupported renderer!");
4355
return renderer_;
4456
}
45-
UnityGfxRenderer getDeviceTypeEnumUnconditionally() const {
57+
OSVRSupportedRenderers getDeviceTypeEnumUnconditionally() const {
4658
return renderer_;
4759
}
4860
UnityRendererType &operator=(UnityGfxRenderer gfxRenderer) {
49-
BOOST_ASSERT_MSG(renderer_ == kUnityGfxRendererNull,
61+
BOOST_ASSERT_MSG(renderer_ == OSVRSupportedRenderers::EmptyRenderer,
5062
"Expect to only set renderer when it's null!");
5163
switch (gfxRenderer) {
5264
#if SUPPORT_OPENGL
5365
case kUnityGfxRendererOpenGL:
54-
renderer_ = gfxRenderer;
66+
renderer_ = OSVRSupportedRenderers::OpenGL;
5567
supported_ = true;
5668
break;
5769
#endif
5870
#if SUPPORT_D3D11
5971
case kUnityGfxRendererD3D11:
60-
renderer_ = gfxRenderer;
72+
renderer_ = OSVRSupportedRenderers::D3D11;
6173
supported_ = true;
6274
break;
6375
#endif
@@ -73,20 +85,19 @@ class UnityRendererType {
7385
case kUnityGfxRendererMetal:
7486
case kUnityGfxRendererD3D12:
7587
default:
76-
renderer_ = kUnityGfxRendererNull;
77-
supported_ = false;
88+
reset();
7889
break;
7990
}
8091
return *this;
8192
}
8293

8394
void reset() {
84-
renderer_ = kUnityGfxRendererNull;
95+
renderer_ = OSVRSupportedRenderers::EmptyRenderer;
8596
supported_ = false;
8697
}
8798

8899
private:
89-
UnityGfxRenderer renderer_ = kUnityGfxRendererNull;
100+
OSVRSupportedRenderers renderer_ = OSVRSupportedRenderers::EmptyRenderer;
90101
bool supported_ = false;
91102
};
92103

0 commit comments

Comments
 (0)