1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGLProgramDataManager_DEFINED 9 #define GrGLProgramDataManager_DEFINED 10 11 #include "GrAllocator.h" 12 #include "GrShaderVar.h" 13 #include "gl/GrGLTypes.h" 14 #include "glsl/GrGLSLProgramDataManager.h" 15 16 #include "SkTArray.h" 17 18 class GrGLGpu; 19 class SkMatrix; 20 class GrGLProgram; 21 22 /** Manages the resources used by a shader program. 23 * The resources are objects the program uses to communicate with the 24 * application code. 25 */ 26 class GrGLProgramDataManager : public GrGLSLProgramDataManager { 27 public: 28 struct UniformInfo { 29 GrShaderVar fVariable; 30 uint32_t fVisibility; 31 GrGLint fLocation; 32 }; 33 34 struct VaryingInfo { 35 GrShaderVar fVariable; 36 GrGLint fLocation; 37 }; 38 39 // This uses an allocator rather than array so that the GrShaderVars don't move in memory 40 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their 41 // name strings. Otherwise, we'd have to hand out copies. 42 typedef GrTAllocator<UniformInfo> UniformInfoArray; 43 typedef GrTAllocator<VaryingInfo> VaryingInfoArray; 44 45 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, 46 const VaryingInfoArray&); 47 48 void setSamplerUniforms(const UniformInfoArray& samplers, int startUnit) const; 49 50 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an 51 * array of uniforms. arrayCount must be <= the array count of the uniform. 52 */ 53 void set1i(UniformHandle, int32_t) const override; 54 void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 55 void set1f(UniformHandle, float v0) const override; 56 void set1fv(UniformHandle, int arrayCount, const float v[]) const override; 57 void set2i(UniformHandle, int32_t, int32_t) const override; 58 void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 59 void set2f(UniformHandle, float, float) const override; 60 void set2fv(UniformHandle, int arrayCount, const float v[]) const override; 61 void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; 62 void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 63 void set3f(UniformHandle, float, float, float) const override; 64 void set3fv(UniformHandle, int arrayCount, const float v[]) const override; 65 void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override; 66 void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 67 void set4f(UniformHandle, float, float, float, float) const override; 68 void set4fv(UniformHandle, int arrayCount, const float v[]) const override; 69 // matrices are column-major, the first three upload a single matrix, the latter three upload 70 // arrayCount matrices into a uniform array. 71 void setMatrix2f(UniformHandle, const float matrix[]) const override; 72 void setMatrix3f(UniformHandle, const float matrix[]) const override; 73 void setMatrix4f(UniformHandle, const float matrix[]) const override; 74 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; 75 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; 76 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; 77 78 // for nvpr only 79 void setPathFragmentInputTransform(VaryingHandle u, int components, 80 const SkMatrix& matrix) const override; 81 82 private: 83 enum { 84 kUnusedUniform = -1, 85 }; 86 87 struct Uniform { 88 GrGLint fLocation; 89 #ifdef SK_DEBUG 90 GrSLType fType; 91 int fArrayCount; 92 #endif 93 }; 94 95 enum { 96 kUnusedPathProcVarying = -1, 97 }; 98 struct PathProcVarying { 99 GrGLint fLocation; 100 SkDEBUGCODE( 101 GrSLType fType; 102 int fArrayCount; 103 ); 104 }; 105 106 template<int N> inline void setMatrices(UniformHandle, int arrayCount, 107 const float matrices[]) const; 108 109 SkTArray<Uniform, true> fUniforms; 110 SkTArray<PathProcVarying, true> fPathProcVaryings; 111 GrGLGpu* fGpu; 112 GrGLuint fProgramID; 113 114 typedef GrGLSLProgramDataManager INHERITED; 115 }; 116 117 #endif 118