VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 00005 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 #ifndef vtkglBufferObject_h 00015 #define vtkglBufferObject_h 00016 00017 #include "vtkRenderingOpenGL2Module.h" 00018 #include "vtkStdString.h" // for std::string 00019 00020 namespace vtkgl { 00021 00029 class VTKRENDERINGOPENGL2_EXPORT BufferObject 00030 { 00031 public: 00032 enum ObjectType { 00033 ArrayBuffer, 00034 ElementArrayBuffer 00035 }; 00036 00037 BufferObject(ObjectType type = ArrayBuffer); 00038 ~BufferObject(); 00039 00041 ObjectType GetType() const; 00042 00044 int GetHandle() const; 00045 00047 bool IsReady() const { return Dirty == false; } 00048 00058 template <class T> 00059 bool Upload(const T &array, ObjectType type); 00060 00061 // non vector version 00062 template <class T> 00063 bool Upload(const T *array, size_t numElements, ObjectType type); 00064 00070 bool Bind(); 00071 00075 bool Release(); 00076 00077 00078 // Description: 00079 // Release any graphics resources that are being consumed by this class. 00080 void ReleaseGraphicsResources(); 00081 00085 std::string GetError() const { return Error; } 00086 00087 private: 00088 bool UploadInternal(const void *buffer, size_t size, ObjectType objectType); 00089 00090 struct Private; 00091 Private *d; 00092 00093 bool Dirty; 00094 std::string Error; 00095 }; 00096 00097 template <class T> 00098 inline bool BufferObject::Upload(const T &array, 00099 BufferObject::ObjectType objectType) 00100 { 00101 if (array.empty()) 00102 { 00103 this->Error = "Refusing to upload empty array."; 00104 return false; 00105 } 00106 return this->UploadInternal(&array[0], 00107 array.size() * sizeof(typename T::value_type), 00108 objectType); 00109 } 00110 00111 template <class T> 00112 inline bool BufferObject::Upload(const T *array, size_t numElements, 00113 BufferObject::ObjectType objectType) 00114 { 00115 if (!array) 00116 { 00117 this->Error = "Refusing to upload empty array."; 00118 return false; 00119 } 00120 return this->UploadInternal(array, 00121 numElements * sizeof(T), 00122 objectType); 00123 } 00124 00125 } 00126 00127 #endif 00128 00129 // VTK-HeaderTest-Exclude: vtkglBufferObject.h