/usr/include/vtk-7.1/vtkShaderProgram.h is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | /*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkShaderProgram
* @brief a glsl shader program
*
* This class contains the vertex, fragment, geometry shaders that combine to make a shader program
*/
#ifndef vtkShaderProgram_h
#define vtkShaderProgram_h
#include "vtkRenderingOpenGL2Module.h" // for export macro
#include "vtkObject.h"
#include <string> // For member variables.
#include <map> // For member variables.
class vtkMatrix3x3;
class vtkMatrix4x4;
class vtkTransformFeedback;
class vtkShader;
class VertexArrayObject;
class vtkWindow;
/**
* @brief The ShaderProgram uses one or more Shader objects.
*
* This class creates a Vertex or Fragment shader, that can be attached to a
* ShaderProgram in order to render geometry etc.
*/
class VTKRENDERINGOPENGL2_EXPORT vtkShaderProgram : public vtkObject
{
public:
static vtkShaderProgram *New();
vtkTypeMacro(vtkShaderProgram, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
//@{
/**
* Get the vertex shader for this program
*/
vtkGetObjectMacro(VertexShader, vtkShader);
void SetVertexShader(vtkShader*);
//@}
//@{
/**
* Get the fragment shader for this program
*/
vtkGetObjectMacro(FragmentShader, vtkShader);
void SetFragmentShader(vtkShader*);
//@}
//@{
/**
* Get the geometry shader for this program
*/
vtkGetObjectMacro(GeometryShader, vtkShader);
void SetGeometryShader(vtkShader*);
//@}
//@{
/**
* Get/Set a TransformFeedbackCapture object on this shader program.
*/
vtkGetObjectMacro(TransformFeedback, vtkTransformFeedback);
void SetTransformFeedback(vtkTransformFeedback *tfc);
//@}
//@{
/**
* Set/Get flag for if this program is compiled
*/
vtkGetMacro(Compiled, bool);
vtkSetMacro(Compiled, bool);
vtkBooleanMacro(Compiled, bool);
//@}
/**
* Set/Get the md5 hash of this program
*/
std::string GetMD5Hash() const { return this->MD5Hash; }
void SetMD5Hash(const std::string &hash) { this->MD5Hash = hash; }
/** Options for attribute normalization. */
enum NormalizeOption {
/// The values range across the limits of the numeric type.
/// This option instructs the rendering engine to normalize them to
/// the range [0.0, 1.0] for unsigned types, and [-1.0, 1.0] for signed
/// types.
/// For example, unsigned char values will be mapped so that 0 = 0.0,
/// and 255 = 1.0.
/// The resulting floating point numbers will be passed into
/// the shader program.
Normalize,
/// The values should be used as-is. Do not perform any normalization.
NoNormalize
};
/**
* Check if the program is currently bound, or not.
* @return True if the program is bound, false otherwise.
*/
bool isBound() const { return this->Bound; }
/**
* release any graphics resources this class is using.
*/
void ReleaseGraphicsResources(vtkWindow *win);
/** Get the handle of the shader program. */
int GetHandle() const { return Handle; }
/** Get the error message (empty if none) for the shader program. */
std::string GetError() const { return Error; }
/**
* Enable the named attribute array. Return false if the attribute array is
* not contained in the linked shader program.
*/
bool EnableAttributeArray(const char *name);
/**
* Disable the named attribute array. Return false if the attribute array is
* not contained in the linked shader program.
*/
bool DisableAttributeArray(const char *name);
/**
* Use the named attribute array with the bound BufferObject.
* @param name of the attribute (as seen in the shader program).
* @param offset into the bound BufferObject.
* @param stride The stride of the element access (i.e. the size of each
* element in the currently bound BufferObject). 0 may be used to indicate
* tightly packed data.
* @param elementType Tag identifying the memory representation of the
* element.
* @param elementTupleSize The number of elements per vertex (e.g. a 3D
* position attribute would be 3).
* @param normalize Indicates the range used by the attribute data.
* See NormalizeOption for more information.
* @return false if the attribute array does not exist.
*/
bool UseAttributeArray(const char *name, int offset, size_t stride,
int elementType, int elementTupleSize,
NormalizeOption normalize);
/**
* Upload the supplied array of tightly packed values to the named attribute.
* BufferObject attributes should be preferred and this may be removed in
* future.
*
* @param name Attribute name
* @param array Container of data. See note.
* @param tupleSize The number of elements per vertex, e.g. a 3D coordinate
* array will have a tuple size of 3.
* @param normalize Indicates the range used by the attribute data.
* See NormalizeOption for more information.
*
* @note The T type must have tightly packed values of
* T::value_type accessible by reference via T::operator[].
* Additionally, the standard size() and empty() methods must be implemented.
* The std::vector classes is an example of such a container.
*/
template <class T>
bool SetAttributeArray(const char *name, const T &array,
int tupleSize, NormalizeOption normalize);
/** Set the @p name uniform value to int @p v. */
bool SetUniformi(const char *name, int v);
bool SetUniformf(const char *name, float v);
bool SetUniform2i(const char *name, const int v[2]);
bool SetUniform2f(const char *name, const float v[2]);
bool SetUniform3f(const char *name, const float v[3]);
bool SetUniform4f(const char *name, const float v[4]);
bool SetUniform3uc(const char *name, const unsigned char v[3]); // maybe remove
bool SetUniform4uc(const char *name, const unsigned char v[4]); // maybe remove
bool SetUniformMatrix(const char *name, vtkMatrix3x3 *v);
bool SetUniformMatrix(const char *name, vtkMatrix4x4 *v);
bool SetUniformMatrix3x3(const char *name, float *v);
bool SetUniformMatrix4x4(const char *name, float *v);
/** Set the @p name uniform array to @p f with @p count elements */
bool SetUniform1iv(const char *name, const int count, const int *f);
bool SetUniform1fv(const char *name, const int count, const float *f);
bool SetUniform2fv(const char *name, const int count, const float (*f)[2]);
bool SetUniform3fv(const char *name, const int count, const float (*f)[3]);
bool SetUniform4fv(const char *name, const int count, const float (*f)[4]);
bool SetUniformMatrix4x4v(const char *name, const int count, float *v);
// How many outputs does this program produce
// only valid for OpenGL 3.2 or later
vtkSetMacro(NumberOfOutputs,unsigned int);
/**
* perform in place string substitutions, indicate if a substitution was done
* this is useful for building up shader strings which typically involve
* lots of string substitutions. Return true if a substitution was done.
*/
static bool Substitute(
std::string &source,
const std::string &search,
const std::string &replace,
bool all = true);
/**
* methods to inquire as to what uniforms/attributes are used by
* this shader. This can save some compute time if the uniforms
* or attributes are expensive to compute
*/
bool IsUniformUsed(const char *);
/**
* Return true if the compiled and linked shader has an attribute matching @a
* name.
*/
bool IsAttributeUsed(const char *name);
// maps of std::string are super slow when calling find
// with a string literal or const char * as find
// forces construction/copy/destruction of a
// std::sting copy of the const char *
// In spite of the doubters this can really be a
// huge CPU hog.
struct cmp_str
{
bool operator()(const char *a, const char *b) const
{
return strcmp(a, b) < 0;
}
};
protected:
vtkShaderProgram();
~vtkShaderProgram();
/***************************************************************
* The following functions are only for use by the shader cache
* which is why they are protected and that class is a friend
* you need to use the shader cache to compile/link/bind your shader
* do not try to do it yourself as it will screw up the cache
***************************************************************/
friend class vtkOpenGLShaderCache;
/**
* Attach the supplied shader to this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool AttachShader(const vtkShader *shader);
/** Detach the supplied shader from this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool DetachShader(const vtkShader *shader);
/**
* Compile this shader program and attached shaders
*/
virtual int CompileShader();
/**
* Attempt to link the shader program.
* @return false on failure. Query error to get the reason.
* @note The shaders attached to the program must have been compiled.
*/
bool Link();
/**
* Bind the program in order to use it. If the program has not been linked
* then link() will be called.
*/
bool Bind();
/** Releases the shader program from the current context. */
void Release();
/************* end **************************************/
vtkShader *VertexShader;
vtkShader *FragmentShader;
vtkShader *GeometryShader;
vtkTransformFeedback *TransformFeedback;
// hash of the shader program
std::string MD5Hash;
bool SetAttributeArrayInternal(const char *name, void *buffer,
int type, int tupleSize,
NormalizeOption normalize);
int Handle;
int VertexShaderHandle;
int FragmentShaderHandle;
int GeometryShaderHandle;
bool Linked;
bool Bound;
bool Compiled;
// for glsl 1.5 or later, how many outputs
// does this shader create
// they will be bound in order to
// fragOutput0 fragOutput1 etc...
unsigned int NumberOfOutputs;
std::string Error;
// since we are using const char * arrays we have to
// free our memory :-)
void ClearMaps();
std::map<const char *, int, cmp_str> AttributeLocs;
std::map<const char *, int, cmp_str> UniformLocs;
friend class VertexArrayObject;
private:
int FindAttributeArray(const char *name);
int FindUniform(const char *name);
vtkShaderProgram(const vtkShaderProgram&) VTK_DELETE_FUNCTION;
void operator=(const vtkShaderProgram&) VTK_DELETE_FUNCTION;
};
#endif
|