Add suffix Mode to DebugMode enum to avoid collision

This commit is contained in:
Zach Pomerantz 2016-01-26 19:11:59 -08:00
parent e770d7b679
commit 49c1285837
2 changed files with 32 additions and 29 deletions

View file

@ -30,15 +30,15 @@ using namespace render;
void DebugDeferredBufferConfig::setMode(int newMode) { void DebugDeferredBufferConfig::setMode(int newMode) {
if (newMode == mode) { if (newMode == mode) {
return; return;
} else if (newMode > (int)DebugDeferredBuffer::Custom || newMode < 0) { } else if (newMode > DebugDeferredBuffer::CustomMode || newMode < 0) {
mode = (int)DebugDeferredBuffer::Custom; mode = DebugDeferredBuffer::CustomMode;
} else { } else {
mode = newMode; mode = newMode;
} }
emit dirty(); emit dirty();
} }
enum Slots { enum Slot {
Diffuse = 0, Diffuse = 0,
Normal, Normal,
Specular, Specular,
@ -50,6 +50,8 @@ enum Slots {
AmbientOcclusionBlurred AmbientOcclusionBlurred
}; };
static const std::string DEFAULT_DIFFUSE_SHADER { static const std::string DEFAULT_DIFFUSE_SHADER {
"vec4 getFragmentColor() {" "vec4 getFragmentColor() {"
" return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);" " return vec4(pow(texture(diffuseMap, uv).xyz, vec3(1.0 / 2.2)), 1.0);"
@ -142,27 +144,27 @@ DebugDeferredBuffer::DebugDeferredBuffer() {
std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string customFile) { std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string customFile) {
switch (mode) { switch (mode) {
case Diffuse: case DiffuseMode:
return DEFAULT_DIFFUSE_SHADER; return DEFAULT_DIFFUSE_SHADER;
case Specular: case SpecularMode:
return DEFAULT_SPECULAR_SHADER; return DEFAULT_SPECULAR_SHADER;
case Roughness: case RoughnessMode:
return DEFAULT_ROUGHNESS_SHADER; return DEFAULT_ROUGHNESS_SHADER;
case Normal: case NormalMode:
return DEFAULT_NORMAL_SHADER; return DEFAULT_NORMAL_SHADER;
case Depth: case DepthMode:
return DEFAULT_DEPTH_SHADER; return DEFAULT_DEPTH_SHADER;
case Lighting: case LightingMode:
return DEFAULT_LIGHTING_SHADER; return DEFAULT_LIGHTING_SHADER;
case Shadow: case ShadowMode:
return DEFAULT_SHADOW_SHADER; return DEFAULT_SHADOW_SHADER;
case PyramidDepth: case PyramidDepthMode:
return DEFAULT_PYRAMID_DEPTH_SHADER; return DEFAULT_PYRAMID_DEPTH_SHADER;
case AmbientOcclusion: case AmbientOcclusionMode:
return DEFAULT_AMBIENT_OCCLUSION_SHADER; return DEFAULT_AMBIENT_OCCLUSION_SHADER;
case AmbientOcclusionBlurred: case AmbientOcclusionBlurredMode:
return DEFAULT_AMBIENT_OCCLUSION_BLURRED_SHADER; return DEFAULT_AMBIENT_OCCLUSION_BLURRED_SHADER;
case Custom: case CustomMode:
return getFileContent(customFile, DEFAULT_CUSTOM_SHADER); return getFileContent(customFile, DEFAULT_CUSTOM_SHADER);
} }
Q_UNREACHABLE(); Q_UNREACHABLE();
@ -170,7 +172,7 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
} }
bool DebugDeferredBuffer::pipelineNeedsUpdate(Mode mode, std::string customFile) const { bool DebugDeferredBuffer::pipelineNeedsUpdate(Mode mode, std::string customFile) const {
if (mode != Custom) { if (mode != CustomMode) {
return !_pipelines[mode]; return !_pipelines[mode];
} }
@ -218,14 +220,14 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Mode mode, std::str
auto pipeline = gpu::Pipeline::create(program, std::make_shared<gpu::State>()); auto pipeline = gpu::Pipeline::create(program, std::make_shared<gpu::State>());
// Good to go add the brand new pipeline // Good to go add the brand new pipeline
if (mode != Custom) { if (mode != CustomMode) {
_pipelines[mode] = pipeline; _pipelines[mode] = pipeline;
} else { } else {
_customPipelines[customFile].pipeline = pipeline; _customPipelines[customFile].pipeline = pipeline;
} }
} }
if (mode != Custom) { if (mode != CustomMode) {
return _pipelines[mode]; return _pipelines[mode];
} else { } else {
return _customPipelines[customFile].pipeline; return _customPipelines[customFile].pipeline;

View file

@ -46,17 +46,18 @@ protected:
friend class DebugDeferredBufferConfig; friend class DebugDeferredBufferConfig;
enum Mode : uint8_t { enum Mode : uint8_t {
Diffuse = 0, // Use Mode suffix to avoid collisions
Specular, DiffuseMode = 0,
Roughness, SpecularMode,
Normal, RoughnessMode,
Depth, NormalMode,
Lighting, DepthMode,
Shadow, LightingMode,
PyramidDepth, ShadowMode,
AmbientOcclusion, PyramidDepthMode,
AmbientOcclusionBlurred, AmbientOcclusionMode,
Custom // Needs to stay last AmbientOcclusionBlurredMode,
CustomMode // Needs to stay last
}; };
private: private:
@ -67,7 +68,7 @@ private:
gpu::PipelinePointer pipeline; gpu::PipelinePointer pipeline;
mutable QFileInfo info; mutable QFileInfo info;
}; };
using StandardPipelines = std::array<gpu::PipelinePointer, Custom>; using StandardPipelines = std::array<gpu::PipelinePointer, CustomMode>;
using CustomPipelines = std::unordered_map<std::string, CustomPipeline>; using CustomPipelines = std::unordered_map<std::string, CustomPipeline>;
bool pipelineNeedsUpdate(Mode mode, std::string customFile = std::string()) const; bool pipelineNeedsUpdate(Mode mode, std::string customFile = std::string()) const;