1 /* 2 * Copyright 2015 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 GrGLUniformHandler_DEFINED 9 #define GrGLUniformHandler_DEFINED 10 11 #include "glsl/GrGLSLUniformHandler.h" 12 13 #include "gl/GrGLProgramDataManager.h" 14 15 class GrGLCaps; 16 17 class GrGLUniformHandler : public GrGLSLUniformHandler { 18 public: 19 static const int kUniformsPerBlock = 8; 20 getUniformVariable(UniformHandle u)21 const GrShaderVar& getUniformVariable(UniformHandle u) const override { 22 return fUniforms[u.toIndex()].fVariable; 23 } 24 getUniformCStr(UniformHandle u)25 const char* getUniformCStr(UniformHandle u) const override { 26 return this->getUniformVariable(u).c_str(); 27 } 28 private: GrGLUniformHandler(GrGLSLProgramBuilder * program)29 explicit GrGLUniformHandler(GrGLSLProgramBuilder* program) 30 : INHERITED(program) 31 , fUniforms(kUniformsPerBlock) 32 , fSamplers(kUniformsPerBlock) 33 , fImageStorages(kUniformsPerBlock) {} 34 35 UniformHandle internalAddUniformArray(uint32_t visibility, 36 GrSLType type, 37 GrSLPrecision precision, 38 const char* name, 39 bool mangleName, 40 int arrayCount, 41 const char** outName) override; 42 43 SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision, 44 const char* name) override; 45 samplerVariable(SamplerHandle handle)46 const GrShaderVar& samplerVariable(SamplerHandle handle) const override { 47 return fSamplers[handle.toIndex()].fVariable; 48 } 49 50 ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType, GrImageStorageFormat, 51 GrSLMemoryModel, GrSLRestrict, GrIOType, 52 const char* name) override; 53 samplerSwizzle(SamplerHandle handle)54 GrSwizzle samplerSwizzle(SamplerHandle handle) const override { 55 return fSamplerSwizzles[handle.toIndex()]; 56 } 57 imageStorageVariable(ImageStorageHandle handle)58 const GrShaderVar& imageStorageVariable(ImageStorageHandle handle) const override { 59 return fImageStorages[handle.toIndex()].fVariable; 60 } 61 62 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; 63 64 // Manually set uniform locations for all our uniforms. 65 void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); 66 67 // Updates the loction of the Uniforms if we cannot bind uniform locations manually 68 void getUniformLocations(GrGLuint programID, const GrGLCaps& caps); 69 70 const GrGLGpu* glGpu() const; 71 72 typedef GrGLProgramDataManager::UniformInfo UniformInfo; 73 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; 74 75 UniformInfoArray fUniforms; 76 UniformInfoArray fSamplers; 77 SkTArray<GrSwizzle> fSamplerSwizzles; 78 UniformInfoArray fImageStorages; 79 80 friend class GrGLProgramBuilder; 81 82 typedef GrGLSLUniformHandler INHERITED; 83 }; 84 85 #endif 86