VividRenderer.hpp 4.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*=============================================================================

  vlVivid is part of NifTK: A software platform for medical image computing.

  Copyright (c) University College London (UCL). All rights reserved.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.

  See NifTK license for details.

=============================================================================*/
Michele Bosi's avatar
Michele Bosi committed
14

15 16
#ifndef VividRenderer_INCLUDE_ONCE
#define VividRenderer_INCLUDE_ONCE
Michele Bosi's avatar
Michele Bosi committed
17

Michele Bosi's avatar
Michele Bosi committed
18
#include <vlVivid/link_config.hpp>
Michele Bosi's avatar
Michele Bosi committed
19
#include <vlGraphics/Renderer.hpp>
Michele Bosi's avatar
Michele Bosi committed
20
#include <vlGraphics/Geometry.hpp>
21
#include <vlGraphics/Effect.hpp>
22
#include <vlGraphics/GLSL.hpp>
23
#include <vlVolume/SlicedVolume.hpp>
Michele Bosi's avatar
Michele Bosi committed
24 25 26

namespace vl
{
27 28
  class VividRendering;

Michele Bosi's avatar
Michele Bosi committed
29 30 31
  /**
   * Implements a depth peeling rendering to be used by vl::VividRendering.
   */
Michele Bosi's avatar
Michele Bosi committed
32
  class VLVIVID_EXPORT VividRenderer: public Renderer
Michele Bosi's avatar
Michele Bosi committed
33
  {
34
    VL_INSTRUMENT_CLASS(vl::VividRenderer, Renderer)
Michele Bosi's avatar
Michele Bosi committed
35

Michele Bosi's avatar
Michele Bosi committed
36
  public:
Michele Bosi's avatar
Michele Bosi committed
37
    // --- Renderer Implementation ---
38
    VividRenderer(VividRendering* vivid_rendering);
39
    virtual ~VividRenderer();
40

Michele Bosi's avatar
Michele Bosi committed
41 42 43
    //! Maximum number of passes to do if UseQueryObject is disabled (default is 4).
    void setDetphPeelingPasses(int n) { mDepthPeelingPasses = n; VL_CHECK(mDepthPeelingPasses >= 1 && mDepthPeelingPasses <= 100); }
    int depthPeelingPasses() const { return mDepthPeelingPasses; }
Michele Bosi's avatar
Michele Bosi committed
44

Michele Bosi's avatar
Michele Bosi committed
45
    //! When enabled will use as many passes as needed to create a 100% correct rendering (disabled by default).
Michele Bosi's avatar
Michele Bosi committed
46 47 48
    void setUseQueryObject(bool use) { mUseQueryObject = use; }
    bool useQueryObject() const { return mUseQueryObject;  }

Michele Bosi's avatar
Michele Bosi committed
49
    //! Internal. Returns the depth texture used to access the depth buffer from the volume shader.
50 51
    Texture* depthFBOTex() { return mDepthFBOTex.get(); }
    const Texture* depthFBOTex() const { return mDepthFBOTex.get(); }
Michele Bosi's avatar
Michele Bosi committed
52

Michele Bosi's avatar
Michele Bosi committed
53
    //! Internal. The background TextureSampler that contains the vl::Texture used to render the background
54 55 56
    TextureSampler* backgroundTexSampler() { return mBackgroundTexSampler.get(); }
    const TextureSampler* backgroundTexSampler() const { return mBackgroundTexSampler.get(); }

Michele Bosi's avatar
Michele Bosi committed
57
  protected:
Michele Bosi's avatar
Michele Bosi committed
58 59 60 61 62
    int passCounter() const { return mPassCounter; }
    void initShaders();
    bool shadersReady() const;

    const RenderQueue* render(const RenderQueue* in_render_queue, Camera* camera, real frame_clock);
63
    int renderQueue(const RenderQueue* in_render_queue, vl::GLSLProgram* cur_glsl, Camera* camera, real frame_clock, bool depth_peeling_on=true, bool outline_on = false);
64
    void renderBackgroundImage( Camera* camera );
65
    void render2DOutlines( const RenderQueue* in_render_queue, Camera* camera, real frame_clock );
66 67
    // Used to render volumes, text and all Actors that we want to render using the standard VL rendering
    void renderStandard( const RenderQueue* in_render_queue, Camera* camera, real frame_clock );
Michele Bosi's avatar
Michele Bosi committed
68 69

    void lazyInitialize();
70 71
    void deleteGLBuffers();
    void initGLBuffers();
Michele Bosi's avatar
Michele Bosi committed
72
    void drawFullScreenQuad();
Michele Bosi's avatar
Michele Bosi committed
73 74
    void bindTexture(vl::GLSLProgram* glsl, GLenum target, std::string texname, GLuint texid, int texunit);
    void renderFrontToBackPeeling(const RenderQueue* render_queue, Camera* camera, real frame_clock);
Michele Bosi's avatar
Michele Bosi committed
75
    void renderControl(const RenderQueue* render_queue, Camera* camera, real frame_clock);
76
    void renderStencil(Camera* camera);
Michele Bosi's avatar
Michele Bosi committed
77 78

  protected:
Michele Bosi's avatar
Michele Bosi committed
79
    ivec2 mImageSize;
Michele Bosi's avatar
Michele Bosi committed
80

81
    vl::ref<vl::GLSLProgram> mShaderOutline2D;
82
    // vl::ref<vl::GLSLProgram> mShaderOutline3D;
83

84
    vl::ref<vl::GLSLProgram> mShaderFrontInit_S;
85
    // vl::ref<vl::GLSLProgram> mShaderFrontPeel_S;
Michele Bosi's avatar
Michele Bosi committed
86 87 88 89 90 91 92 93 94 95 96
    vl::ref<vl::GLSLProgram> mShaderFrontInit;
    vl::ref<vl::GLSLProgram> mShaderFrontPeel;
    vl::ref<vl::GLSLProgram> mShaderFrontBlend;
    vl::ref<vl::GLSLProgram> mShaderFrontFinal;

    GLuint mFrontFboId[2];
    GLuint mFrontDepthTexId[2];
    GLuint mFrontColorTexId[2];
    GLuint mFrontColorBlenderTexId;
    GLuint mFrontColorBlenderFboId;

97
    GLuint mStencilFBO;
Michele Bosi's avatar
Michele Bosi committed
98
    ref<Texture> mStencilTexture;
99

100
    GLuint mDepthFBO;
101
    ref<Texture> mDepthFBOTex;
102

103 104
    ref<TextureSampler> mBackgroundTexSampler;

Michele Bosi's avatar
Michele Bosi committed
105
    int mPassCounter;
Michele Bosi's avatar
Michele Bosi committed
106
    int mDepthPeelingPasses;
Michele Bosi's avatar
Michele Bosi committed
107
    bool mUseQueryObject;
Michele Bosi's avatar
Michele Bosi committed
108 109
    GLuint mQueryID;

110
    ref<Geometry> mFullScreenQuad;
111
    ref<Geometry> mBackgroundQuad;
112

113
    VividRendering* mVividRendering;
Michele Bosi's avatar
Michele Bosi committed
114 115 116 117 118
  };
  //------------------------------------------------------------------------------
}

#endif