vtkVertexBufferObject.h
Go to the documentation of this file.
00001   /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkPixelBufferObject.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 // .NAME vtkVertexBufferObject - abstracts an OpenGL vertex buffer object.
00016 // .SECTION Description
00017 // Provides low-level access to GPU memory. Used to pass raw data to GPU. 
00018 // The data is uploaded into a vertex buffer.
00019 // .SECTION See Also
00020 // OpenGL Vertex Buffer Object Extension Spec (ARB_vertex_buffer_object):
00021 // http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
00022 // .SECTION Caveats
00023 // Since most GPUs don't support double format all double data is converted to
00024 // float and then uploaded.
00025 // DON'T PLAY WITH IT YET.
00026 
00027 #ifndef __vtkVertexBufferObject_h
00028 #define __vtkVertexBufferObject_h
00029 
00030 #include <vector>
00031 
00032 #include "vtkObject.h"
00033 #include "vtkWeakPointer.h"
00034 
00035 #include "vtkgl.h" // Needed for gl data types exposed in API
00036 #include <pcl/pcl_macros.h>
00037 
00038 class vtkCellArray;
00039 class vtkDataArray;
00040 class vtkObject;
00041 class vtkPoints;
00042 class vtkUnsignedCharArray;
00043 class vtkOpenGLExtensionManager;
00044 class vtkRenderWindow;
00045 
00046 class PCL_EXPORTS vtkVertexBufferObject : public vtkObject
00047 {
00048 public:
00049   
00050   static vtkVertexBufferObject* New();
00051   vtkTypeMacro(vtkVertexBufferObject, vtkObject);
00052   void PrintSelf(ostream& os, vtkIndent indent);
00053 
00054   // Description:
00055   // Get/Set the context. Context must be a vtkOpenGLRenderWindow.
00056   // This does not increase the reference count of the
00057   // context to avoid reference loops.
00058   // SetContext() may raise an error is the OpenGL context does not support the
00059   // required OpenGL extensions.
00060   void SetContext(vtkRenderWindow* context);
00061   vtkRenderWindow* GetContext();
00062 
00063   //BTX
00064   // Usage values.
00065   enum 
00066   {
00067     StreamDraw=0,
00068     StreamRead,
00069     StreamCopy,
00070     StaticDraw,
00071     StaticRead,
00072     StaticCopy,
00073     DynamicDraw,
00074     DynamicRead,
00075     DynamicCopy,
00076     NumberOfUsages
00077   };
00078   //ETX
00079   
00080   // Description:
00081   // Usage is a performance hint.
00082   // Valid values are:
00083   // - StreamDraw specified once by A, used few times S
00084   // - StreamRead specified once by R, queried a few times by A
00085   // - StreamCopy specified once by R, used a few times S
00086   // - StaticDraw specified once by A, used many times S
00087   // - StaticRead specificed once by R, queried many times by A
00088   // - StaticCopy specified once by R, used many times S
00089   // - DynamicDraw respecified repeatedly by A, used many times S
00090   // - DynamicRead respecified repeatedly by R, queried many times by A
00091   // - DynamicCopy respecified repeatedly by R, used many times S
00092   // A: the application
00093   // S: as the source for GL drawing and image specification commands.
00094   // R: reading data from the GL
00095   // Initial value is StaticDraw, as in OpenGL spec.
00096   vtkGetMacro(Usage, int);
00097   vtkSetMacro(Usage, int);
00098   
00099   int GetAttributeIndex();
00100   void SetUserDefinedAttribute(int index, bool normalized=false, int stride=0);
00101   void ResetUserDefinedAttribute();
00102 
00103   void SetAttributeNormalized(bool normalized);
00104 
00105   // Description:
00106   // Set point data
00107   bool Upload(vtkPoints *points);
00108 
00109   // Description:
00110   // Set indice data
00111   bool Upload(vtkCellArray *verts);
00112 
00113   // Description:
00114   // Set indice data
00115   bool Upload(unsigned int *indices, unsigned int count);
00116 
00117   // Description:
00118   // Set color data
00119   bool Upload(vtkUnsignedCharArray *colors);
00120 
00121   // Description:
00122   // Set color data
00123   bool Upload(vtkDataArray *array);
00124   bool Upload(vtkDataArray *array, int attributeType, int arrayType);
00125   bool UploadNormals(vtkDataArray *normals);
00126   bool UploadColors(vtkDataArray *colors);
00127 
00128 
00129   // Description:
00130   // Get the size of the data loaded into the GPU. Size is in the number of
00131   // elements of the uploaded Type.
00132   vtkGetMacro(Size, unsigned int);
00133 
00134   // Description:
00135   // Get the size of the data loaded into the GPU. Size is in the number of
00136   // elements of the uploaded Type.
00137   vtkGetMacro(Count, unsigned int);
00138 
00139   // Description:
00140   // Get the openGL buffer handle.
00141   vtkGetMacro(Handle, unsigned int);
00142 
00143   // Description:
00144   // Inactivate the buffer.
00145   void UnBind();
00146 
00147   // Description:
00148   // Make the buffer active.
00149   void Bind();
00150 
00151   // Description:
00152   // Allocate the memory. size is in number of bytes. type is a VTK type.
00153 //  void Allocate(unsigned int size, int type);
00154   
00155 //BTX
00156 
00157   // Description:
00158   // Release the memory allocated without destroying the PBO handle.
00159   void ReleaseMemory();
00160 
00161   // Description:
00162   // Returns if the context supports the required extensions.
00163   static bool IsSupported(vtkRenderWindow* renWin);
00164 
00165 //ETX
00166 //BTX
00167 protected:
00168   vtkVertexBufferObject();
00169   ~vtkVertexBufferObject();
00170 
00171   // Description:
00172   // Loads all required OpenGL extensions. Must be called every time a new
00173   // context is set.
00174   bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
00175 
00176   // Description:
00177   // Create the pixel buffer object.
00178   void CreateBuffer();
00179 
00180   // Description:
00181   // Destroys the pixel buffer object.
00182   void DestroyBuffer();
00183 
00184   // Description:
00185   // Uploads data to buffer object
00186   bool Upload(GLvoid* data);
00187 
00188   // Description:
00189   // Get the openGL buffer handle.
00190   vtkGetMacro(ArrayType, unsigned int);
00191 
00192   int Usage;
00193   unsigned int Size;
00194   unsigned int Count;
00195   unsigned int Handle;
00196   unsigned int ArrayType;
00197   unsigned int BufferTarget;
00198 
00199   int AttributeIndex;
00200   int AttributeSize;
00201   int AttributeType;
00202   int AttributeNormalized;
00203   int AttributeStride;
00204 
00205   vtkWeakPointer<vtkRenderWindow> Context;
00206 
00207 
00208 private:
00209   vtkVertexBufferObject(const vtkVertexBufferObject&); // Not implemented.
00210   void operator=(const vtkVertexBufferObject&); // Not implemented.
00211 
00212   // Helper to get data type sizes when passing to opengl
00213   int GetDataTypeSize(int type);
00214   //ETX
00215 };
00216 
00217 #endif
00218 
00219 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:38:43