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 "src/gpu/glsl/GrGLSLUniformHandler.h" 12 13 #include "src/gpu/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 34 UniformHandle internalAddUniformArray(uint32_t visibility, 35 GrSLType type, 36 const char* name, 37 bool mangleName, 38 int arrayCount, 39 const char** outName) override; 40 41 SamplerHandle addSampler(const GrTexture*, const GrSamplerState&, const GrSwizzle&, 42 const char* name, const GrShaderCaps*) override; 43 samplerVariable(SamplerHandle handle)44 const char* samplerVariable(SamplerHandle handle) const override { 45 return fSamplers[handle.toIndex()].fVariable.c_str(); 46 } 47 samplerSwizzle(SamplerHandle handle)48 GrSwizzle samplerSwizzle(SamplerHandle handle) const override { 49 return fSamplerSwizzles[handle.toIndex()]; 50 } 51 52 void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; 53 54 // Manually set uniform locations for all our uniforms. 55 void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); 56 57 // Updates the loction of the Uniforms if we cannot bind uniform locations manually 58 void getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force); 59 60 const GrGLGpu* glGpu() const; 61 62 typedef GrGLProgramDataManager::UniformInfo UniformInfo; 63 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; 64 65 UniformInfoArray fUniforms; 66 UniformInfoArray fSamplers; 67 SkTArray<GrSwizzle> fSamplerSwizzles; 68 69 friend class GrGLProgramBuilder; 70 71 typedef GrGLSLUniformHandler INHERITED; 72 }; 73 74 #endif 75