2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrGLProgramDataManager_DEFINED
9 #define GrGLProgramDataManager_DEFINED
11 #include "gl/GrGLShaderVar.h"
12 #include "gl/GrGLSL.h"
13 #include "GrAllocator.h"
20 class GrGLShaderBuilder;
22 /** Manages the resources used by a shader program.
23 * The resources are objects the program uses to communicate with the
26 class GrGLProgramDataManager : public SkRefCnt {
28 // Opaque handle to a uniform
31 /** Creates a reference to an unifrom of a GrGLShaderBuilder.
32 * The ref can be used to set the uniform with corresponding the GrGLProgramDataManager.*/
33 static UniformHandle CreateFromUniformIndex(int i);
35 bool isValid() const { return -1 != fValue; }
37 bool operator==(const UniformHandle& other) const { return other.fValue == fValue; }
44 UniformHandle(int value)
49 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; }
50 int toShaderBuilderIndex() const { return toProgramDataIndex(); }
53 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex().
54 friend class GrGLShaderBuilder; // For accessing toShaderBuilderIndex().
57 GrGLProgramDataManager(GrGpuGL*, GrGLProgram*, const GrGLShaderBuilder&);
59 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
60 * array of uniforms. arrayCount must be <= the array count of the uniform.
62 void setSampler(UniformHandle, GrGLint texUnit) const;
63 void set1f(UniformHandle, GrGLfloat v0) const;
64 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
65 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const;
66 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
67 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const;
68 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
69 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const;
70 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
71 // matrices are column-major, the first three upload a single matrix, the latter three upload
72 // arrayCount matrices into a uniform array.
73 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const;
74 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const;
75 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
76 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
78 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
79 void setSkMatrix(UniformHandle, const SkMatrix&) const;
95 SkTArray<Uniform, true> fUniforms;
98 typedef SkRefCnt INHERITED;