Showing the changes to libraries/render-utils/src/DebugDeferredBuffer.cpp (1 of 9 files). Show all
Unified · Split
| @@ -0,0 +1,72 @@ | ||
| 1 | +// | |
| 2 | +// DebugDeferredBuffer.cpp | |
| 3 | +// libraries/render-utils/src | |
| 4 | +// | |
| 5 | +// Created by Clement on 12/3/15. | |
| 6 | +// Copyright 2015 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include "DebugDeferredBuffer.h" | |
| 13 | + | |
| 14 | +#include <gpu/Batch.h> | |
| 15 | +#include <gpu/Context.h> | |
| 16 | +#include <render/Scene.h> | |
| 17 | +#include <ViewFrustum.h> | |
| 18 | + | |
| 19 | +#include "GeometryCache.h" | |
| 20 | + | |
| 21 | +#include "debug_deferred_buffer_vert.h" | |
| 22 | +#include "debug_deferred_buffer_frag.h" | |
| 23 | + | |
| 24 | +using namespace render; | |
| 25 | + | |
| 26 | +const gpu::PipelinePointer& DebugDeferredBuffer::getPipeline() { | |
| 27 | + if (!_pipeline) { | |
| 28 | + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex({ debug_deferred_buffer_vert })); | |
| 29 | + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel({ debug_deferred_buffer_frag })); | |
| 30 | + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); | |
| 31 | + | |
| 32 | + | |
| 33 | + gpu::Shader::BindingSet slotBindings; | |
| 34 | + gpu::Shader::makeProgram(*program, slotBindings); | |
| 35 | + | |
| 36 | + auto state = std::make_shared<gpu::State>(); | |
| 37 | + | |
| 38 | + state->setDepthTest(false, false, gpu::LESS_EQUAL); | |
| 39 | + | |
| 40 | + // Blend on transparent | |
| 41 | + state->setBlendFunction(true, | |
| 42 | + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); | |
| 43 | + | |
| 44 | + // Good to go add the brand new pipeline | |
| 45 | + _pipeline.reset(gpu::Pipeline::create(program, state)); | |
| 46 | + } | |
| 47 | + return _pipeline; | |
| 48 | +} | |
| 49 | + | |
| 50 | + | |
| 51 | +void DebugDeferredBuffer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { | |
| 52 | + assert(renderContext->args); | |
| 53 | + assert(renderContext->args->_viewFrustum); | |
| 54 | + RenderArgs* args = renderContext->args; | |
| 55 | + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { | |
| 56 | + | |
| 57 | + glm::mat4 projMat; | |
| 58 | + Transform viewMat; | |
| 59 | + args->_viewFrustum->evalProjectionMatrix(projMat); | |
| 60 | + args->_viewFrustum->evalViewTransform(viewMat); | |
| 61 | + batch.setProjectionTransform(projMat); | |
| 62 | + batch.setViewTransform(viewMat); | |
| 63 | + batch.setModelTransform(Transform()); | |
| 64 | + | |
| 65 | + batch.setPipeline(getPipeline()); | |
| 66 | + | |
| 67 | + glm::vec4 color(0.0f, 0.0f, 1.0f, 1.0f); | |
| 68 | + glm::vec2 bottomLeft(0.0f, -1.0f); | |
| 69 | + glm::vec2 topRight(1.0f, 1.0f); | |
| 70 | + DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, color); | |
| 71 | + }); | |
| 72 | +} | |