Showing the changes to libraries/render-utils/src/DebugDeferredBuffer.cpp (1 of 3 files). Show all
Unified · Split
| @@ -11,6 +11,8 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | #include "DebugDeferredBuffer.h" |
| 13 | 13 | |
| 14 | +#include <QString> | |
| 15 | + | |
| 14 | 16 | #include <gpu/Batch.h> |
| 15 | 17 | #include <gpu/Context.h> |
| 16 | 18 | #include <render/Scene.h> |
| @@ -24,8 +26,16 @@ · 7 unmodified lines | ||
| 24 | 26 | |
| 25 | 27 | using namespace render; |
| 26 | 28 | |
| 27 | −static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; | |
| 28 | −static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES {{ | |
| 29 | +enum Slots { | |
| 30 | + Diffuse = 0, | |
| 31 | + Normal, | |
| 32 | + Specular, | |
| 33 | + Depth, | |
| 34 | + Lighting, | |
| 35 | + | |
| 36 | + NUM_SLOTS | |
| 37 | +}; | |
| 38 | +static const std::array<std::string, Slots::NUM_SLOTS> SLOT_NAMES {{ | |
| 29 | 39 | "diffuseMap", |
| 30 | 40 | "normalMap", |
| 31 | 41 | "specularMap", |
| @@ -33,14 +43,50 @@ static const std::array<std::string, DebugDeferredBuffer::NUM_SLOTS> SLOT_NAMES · 1 unmodified line | ||
| 33 | 43 | "lightingMap" |
| 34 | 44 | }}; |
| 35 | 45 | |
| 36 | −std::string getCode(int slot) { | |
| 37 | − return std::string("return texture(").append(SLOT_NAMES[slot]).append(", uv);"); | |
| 46 | +static const std::string PLACEHOLDER { "DEBUG_PLACEHOLDER" }; | |
| 47 | + | |
| 48 | +std::string DebugDeferredBuffer::getCode(Modes mode) { | |
| 49 | + switch (mode) { | |
| 50 | + case DiffuseMode: { | |
| 51 | + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; | |
| 52 | + return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); | |
| 53 | + } | |
| 54 | + case AlphaMode: { | |
| 55 | + QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; | |
| 56 | + return code.arg(SLOT_NAMES[Diffuse].c_str()).toStdString(); | |
| 57 | + } | |
| 58 | + case SpecularMode: { | |
| 59 | + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; | |
| 60 | + return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); | |
| 61 | + } | |
| 62 | + case RoughnessMode: { | |
| 63 | + QString code = "return vec4(vec3(texture(%1, uv).a), 1.0);"; | |
| 64 | + return code.arg(SLOT_NAMES[Specular].c_str()).toStdString(); | |
| 65 | + } | |
| 66 | + case NormalMode: { | |
| 67 | + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; | |
| 68 | + return code.arg(SLOT_NAMES[Normal].c_str()).toStdString(); | |
| 69 | + } | |
| 70 | + case DepthMode: { | |
| 71 | + QString code = "return vec4(vec3(texture(%1, uv).x), 1.0);"; | |
| 72 | + return code.arg(SLOT_NAMES[Depth].c_str()).toStdString(); | |
| 73 | + } | |
| 74 | + case LightingMode: { | |
| 75 | + QString code = "return vec4(texture(%1, uv).xyz, 1.0);"; | |
| 76 | + return code.arg(SLOT_NAMES[Lighting].c_str()).toStdString(); | |
| 77 | + } | |
| 78 | + case CustomMode: | |
| 79 | + return std::string("return vec4(1.0);"); | |
| 80 | + case NUM_MODES: | |
| 81 | + Q_UNIMPLEMENTED(); | |
| 82 | + return std::string("return vec4(1.0);"); | |
| 83 | + } | |
| 38 | 84 | } |
| 39 | 85 | |
| 40 | −const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { | |
| 41 | − if (!_pipelines[slot]) { | |
| 86 | +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(Modes mode) { | |
| 87 | + if (!_pipelines[mode]) { | |
| 42 | 88 | std::string fragmentShader = debug_deferred_buffer_frag; |
| 43 | − fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(slot)); | |
| 89 | + fragmentShader.replace(fragmentShader.find(PLACEHOLDER), PLACEHOLDER.size(), getCode(mode)); | |
| 44 | 90 | |
| 45 | 91 | auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); |
| 46 | 92 | auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShader)); |
| @@ -53,9 +99,9 @@ const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline(int slot) { · 6 unmodified lines | ||
| 53 | 99 | gpu::Shader::makeProgram(*program, slotBindings); |
| 54 | 100 | |
| 55 | 101 | // Good to go add the brand new pipeline |
| 56 | − _pipelines[slot] = gpu::Pipeline::create(program, std::make_shared<gpu::State>()); | |
| 102 | + _pipelines[mode] = gpu::Pipeline::create(program, std::make_shared<gpu::State>()); | |
| 57 | 103 | } |
| 58 | − return _pipelines[slot]; | |
| 104 | + return _pipelines[mode]; | |
| 59 | 105 | } |
| 60 | 106 | |
| 61 | 107 | |
| @@ -76,7 +122,7 @@ void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const Ren · 14 unmodified lines | ||
| 76 | 122 | batch.setViewTransform(viewMat); |
| 77 | 123 | batch.setModelTransform(Transform()); |
| 78 | 124 | |
| 79 | − batch.setPipeline(getPipeline((DebugDeferredBufferSlot)(renderContext->_drawDebugDeferredBuffer - 1))); | |
| 125 | + batch.setPipeline(getPipeline(Modes(renderContext->_drawDebugDeferredBuffer - 1))); | |
| 80 | 126 | |
| 81 | 127 | batch.setResourceTexture(Diffuse, framebufferCache->getDeferredColorTexture()); |
| 82 | 128 | batch.setResourceTexture(Normal, framebufferCache->getDeferredNormalTexture()); |