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 =========================================================================*/ 00020 #ifndef vtkShaderProgram_h 00021 #define vtkShaderProgram_h 00022 00023 #include "vtkRenderingOpenGL2Module.h" // for export macro 00024 #include "vtkObject.h" 00025 00026 #include <string> // For member variables. 00027 #include <map> // For member variables. 00028 00029 class vtkMatrix3x3; 00030 class vtkMatrix4x4; 00031 class vtkShader; 00032 class VertexArrayObject; 00033 class vtkWindow; 00034 00042 class VTKRENDERINGOPENGL2_EXPORT vtkShaderProgram : public vtkObject 00043 { 00044 public: 00045 static vtkShaderProgram *New(); 00046 vtkTypeMacro(vtkShaderProgram, vtkObject); 00047 void PrintSelf(ostream& os, vtkIndent indent); 00048 00050 00051 vtkGetObjectMacro(VertexShader, vtkShader); 00053 00055 00056 vtkGetObjectMacro(FragmentShader, vtkShader); 00058 00060 00061 vtkGetObjectMacro(GeometryShader, vtkShader); 00063 00065 00066 vtkGetMacro(Compiled, bool); 00067 vtkSetMacro(Compiled, bool); 00068 vtkBooleanMacro(Compiled, bool); 00070 00072 00073 std::string GetMD5Hash() const { return this->MD5Hash; } 00074 void SetMD5Hash(const std::string &hash) { this->MD5Hash = hash; } 00076 00077 00079 enum NormalizeOption { 00088 Normalize, 00090 NoNormalize 00091 }; 00092 00093 00098 bool isBound() const { return this->Bound; } 00099 00101 void ReleaseGraphicsResources(vtkWindow *win); 00102 00104 int GetHandle() const { return Handle; } 00105 00107 std::string GetError() const { return Error; } 00108 00113 bool EnableAttributeArray(const char *name); 00114 00119 bool DisableAttributeArray(const char *name); 00120 00136 bool UseAttributeArray(const char *name, int offset, size_t stride, 00137 int elementType, int elementTupleSize, 00138 NormalizeOption normalize); 00139 00157 template <class T> 00158 bool SetAttributeArray(const char *name, const T &array, 00159 int tupleSize, NormalizeOption normalize); 00160 00162 bool SetUniformi(const char *name, int v); 00163 bool SetUniformf(const char *name, float v); 00164 bool SetUniform2i(const char *name, const int v[2]); 00165 bool SetUniform2f(const char *name, const float v[2]); 00166 bool SetUniform3f(const char *name, const float v[3]); 00167 bool SetUniform4f(const char *name, const float v[4]); 00168 bool SetUniform3uc(const char *name, const unsigned char v[3]); // maybe remove 00169 bool SetUniform4uc(const char *name, const unsigned char v[4]); // maybe remove 00170 bool SetUniformMatrix(const char *name, vtkMatrix3x3 *v); 00171 bool SetUniformMatrix(const char *name, vtkMatrix4x4 *v); 00172 bool SetUniformMatrix3x3(const char *name, float *v); 00173 bool SetUniformMatrix4x4(const char *name, float *v); 00174 00176 bool SetUniform1iv(const char *name, const int count, const int *f); 00177 bool SetUniform1fv(const char *name, const int count, const float *f); 00178 bool SetUniform2fv(const char *name, const int count, const float (*f)[2]); 00179 bool SetUniform3fv(const char *name, const int count, const float (*f)[3]); 00180 bool SetUniform4fv(const char *name, const int count, const float (*f)[4]); 00181 00182 protected: 00183 vtkShaderProgram(); 00184 ~vtkShaderProgram(); 00185 00186 /*************************************************************** 00187 * The following functions are only for use by the shader cache 00188 * which is why they are protected and that class is a friend 00189 * you need to use the shader cache to compile/link/bind your shader 00190 * do not try to do it yourself as it will screw up the cache 00191 ***************************************************************/ 00192 friend class vtkOpenGLShaderCache; 00193 00200 bool AttachShader(const vtkShader *shader); 00201 00207 bool DetachShader(const vtkShader *shader); 00208 00210 virtual int CompileShader(); 00211 00217 bool Link(); 00218 00223 bool Bind(); 00224 00226 void Release(); 00227 00228 /************* end **************************************/ 00229 00230 vtkShader *VertexShader; 00231 vtkShader *FragmentShader; 00232 vtkShader *GeometryShader; 00233 00234 // hash of the shader program 00235 std::string MD5Hash; 00236 00237 bool SetAttributeArrayInternal(const char *name, void *buffer, 00238 int type, int tupleSize, 00239 NormalizeOption normalize); 00240 int Handle; 00241 int VertexShaderHandle; 00242 int FragmentShaderHandle; 00243 00244 bool Linked; 00245 bool Bound; 00246 bool Compiled; 00247 00248 std::string Error; 00249 00250 std::map<std::string, int> Attributes; 00251 00252 friend class VertexArrayObject; 00253 00254 private: 00255 int FindAttributeArray(const char *name); 00256 int FindUniform(const char *name); 00257 00258 vtkShaderProgram(const vtkShaderProgram&); // Not implemented. 00259 void operator=(const vtkShaderProgram&); // Not implemented. 00260 }; 00261 00262 00263 #endif