1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 6 All rights reserved. 7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 8 9 This software is distributed WITHOUT ANY WARRANTY; without even 10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 PURPOSE. See the above copyright notice for more information. 12 13 =========================================================================*/ 14 // .NAME vtkOpenGLPolyDataMapper - PolyDataMapper using OpenGL to render. 15 // .SECTION Description 16 // PolyDataMapper that uses a OpenGL to do the actual rendering. 17 18 #ifndef vtkOpenGLPolyDataMapper_h 19 #define vtkOpenGLPolyDataMapper_h 20 21 #include "vtkRenderingOpenGL2Module.h" // For export macro 22 #include "vtkPolyDataMapper.h" 23 #include "vtkglVBOHelper.h" // used for ivars 24 25 class vtkOpenGLTexture; 26 class vtkMatrix4x4; 27 class vtkMatrix3x3; 28 29 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMapper 30 { 31 public: 32 static vtkOpenGLPolyDataMapper* New(); 33 vtkTypeMacro(vtkOpenGLPolyDataMapper, vtkPolyDataMapper) 34 void PrintSelf(ostream& os, vtkIndent indent); 35 36 // Description: 37 // Implemented by sub classes. Actual rendering is done here. 38 virtual void RenderPiece(vtkRenderer *ren, vtkActor *act); 39 40 // Description: 41 // Implemented by sub classes. Actual rendering is done here. 42 virtual void RenderPieceStart(vtkRenderer *ren, vtkActor *act); 43 virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act); 44 virtual void RenderPieceFinish(vtkRenderer *ren, vtkActor *act); 45 virtual void RenderEdges(vtkRenderer *ren, vtkActor *act); 46 47 // Description: 48 // Release any graphics resources that are being consumed by this mapper. 49 // The parameter window could be used to determine which graphic 50 // resources to release. 51 void ReleaseGraphicsResources(vtkWindow *); 52 53 vtkGetMacro(PopulateSelectionSettings,int); SetPopulateSelectionSettings(int v)54 void SetPopulateSelectionSettings(int v) { this->PopulateSelectionSettings = v; }; 55 56 // Description: 57 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 58 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS 59 // Used by vtkHardwareSelector to determine if the prop supports hardware 60 // selection. GetSupportsSelection()61 virtual bool GetSupportsSelection() { return true; } 62 63 // Description: 64 // Returns if the mapper does not expect to have translucent geometry. This 65 // may happen when using ScalarMode is set to not map scalars i.e. render the 66 // scalar array directly as colors and the scalar array has opacity i.e. alpha 67 // component. Note that even if this method returns true, an actor may treat 68 // the geometry as translucent since a constant translucency is set on the 69 // property, for example. 70 // Overridden to use the actual data and ScalarMode to determine if we have 71 // opaque geometry. 72 virtual bool GetIsOpaque(); 73 74 // used by RenderPiece and functions it calls to reduce 75 // calls to get the input and allow for rendering of 76 // other polydata (not the input) 77 vtkPolyData *CurrentInput; 78 79 // Description: 80 // Props may provide a mapping from picked value to actual value 81 // This is useful for hardware based pickers where 82 // there is a mapping between the color in the buffer 83 // and the actual pick value 84 virtual vtkIdType GetConvertedPickValue(vtkIdType idIn, int fieldassociation, vtkActor *act); 85 86 protected: 87 vtkOpenGLPolyDataMapper(); 88 ~vtkOpenGLPolyDataMapper(); 89 90 // Description: 91 // Called in GetBounds(). When this method is called, the consider the input 92 // to be updated depending on whether this->Static is set or not. This method 93 // simply obtains the bounds from the data-object and returns it. 94 virtual void ComputeBounds(); 95 96 // Description: 97 // Make sure an appropriate shader is defined, compiled and bound. This method 98 // orchistrates the process, much of the work is done in other methods 99 virtual void UpdateShader(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 100 101 // Description: 102 // Does the shader source need to be recomputed 103 virtual bool GetNeedToRebuildShader(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 104 105 // Description: 106 // Build the shader source code, called by UpdateShader 107 virtual void BuildShader(std::string &VertexCode, 108 std::string &fragmentCode, 109 std::string &geometryCode, 110 int lightComplexity, 111 vtkRenderer *ren, vtkActor *act); 112 113 // Description: 114 // Create the basic shaders before replacement 115 virtual void GetShaderTemplate(std::string &VertexCode, 116 std::string &fragmentCode, 117 std::string &geometryCode, 118 int lightComplexity, 119 vtkRenderer *ren, vtkActor *act); 120 121 // Description: 122 // Perform string replacments on the shader templates 123 virtual void ReplaceShaderValues(std::string &VertexCode, 124 std::string &fragmentCode, 125 std::string &geometryCode, 126 int lightComplexity, 127 vtkRenderer *ren, vtkActor *act); 128 129 // Description: 130 // Perform string replacments on the shader templates, called from 131 // ReplaceShaderValues 132 virtual void ReplaceShaderColorMaterialValues(std::string &VertexCode, 133 std::string &fragmentCode, 134 std::string &geometryCode, 135 int lightComplexity, 136 vtkRenderer *ren, vtkActor *act); 137 138 // Description: 139 // Set the shader parameteres related to the mapper/input data, called by UpdateShader 140 virtual void SetMapperShaderParameters(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 141 142 // Description: 143 // Set the shader parameteres related to lighting, called by UpdateShader 144 virtual void SetLightingShaderParameters(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 145 146 // Description: 147 // Set the shader parameteres related to the Camera, called by UpdateShader 148 virtual void SetCameraShaderParameters(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 149 150 // Description: 151 // Set the shader parameteres related to the property, called by UpdateShader 152 virtual void SetPropertyShaderParameters(vtkgl::CellBO &cellBO, vtkRenderer *ren, vtkActor *act); 153 154 // Description: 155 // Update the VBO/IBO to be current 156 virtual void UpdateBufferObjects(vtkRenderer *ren, vtkActor *act); 157 158 // Description: 159 // Does the VBO/IBO need to be rebuilt 160 virtual bool GetNeedToRebuildBufferObjects(vtkRenderer *ren, vtkActor *act); 161 162 // Description: 163 // Build the VBO/IBO, called by UpdateBufferObjects 164 virtual void BuildBufferObjects(vtkRenderer *ren, vtkActor *act); 165 166 // The VBO and its layout. 167 vtkgl::BufferObject VBO; 168 vtkgl::VBOLayout Layout; 169 170 // Structures for the various cell types we render. 171 vtkgl::CellBO Points; 172 vtkgl::CellBO Lines; 173 vtkgl::CellBO Tris; 174 vtkgl::CellBO TriStrips; 175 vtkgl::CellBO TrisEdges; 176 vtkgl::CellBO TriStripsEdges; 177 vtkgl::CellBO *LastBoundBO; 178 bool DrawingEdges; 179 180 // values we use to determine if we need to rebuild 181 int LastLightComplexity; 182 vtkTimeStamp LightComplexityChanged; 183 184 bool LastSelectionState; 185 vtkTimeStamp SelectionStateChanged; 186 187 int LastDepthPeeling; 188 vtkTimeStamp DepthPeelingChanged; 189 190 bool UsingScalarColoring; 191 vtkTimeStamp VBOBuildTime; // When was the OpenGL VBO updated? 192 vtkOpenGLTexture* InternalColorTexture; 193 194 int PopulateSelectionSettings; 195 int pickingAttributeIDOffset; 196 197 vtkMatrix4x4 *TempMatrix4; 198 vtkMatrix3x3 *TempMatrix3; 199 200 // this vector can be used while building 201 // the shader program to record specific variables 202 // that are being used by the program. This is 203 // useful later on when setting uniforms. At 204 // that point IsShaderVariableUsed can be called 205 // to see if the uniform should be set or not. 206 std::vector<std::string> ShaderVariablesUsed; 207 208 // used to see if the shader building code indicated that 209 // a specific variable is being used. Only some variables 210 // are currently populated. 211 bool IsShaderVariableUsed(const char *); 212 213 private: 214 vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&); // Not implemented. 215 void operator=(const vtkOpenGLPolyDataMapper&); // Not implemented. 216 }; 217 218 #endif 219