Home | History | Annotate | Download | only in gl
      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 
     21     const GrShaderVar& getUniformVariable(UniformHandle u) const override {
     22         return fUniforms[u.toIndex()].fVariable;
     23     }
     24 
     25     const char* getUniformCStr(UniformHandle u) const override {
     26         return this->getUniformVariable(u).c_str();
     27     }
     28 private:
     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                                           GrSLPrecision precision,
     37                                           const char* name,
     38                                           bool mangleName,
     39                                           int arrayCount,
     40                                           const char** outName) override;
     41 
     42     SamplerHandle addSampler(const GrTexture*, const GrSamplerState&, const char* name,
     43                              const GrShaderCaps*) override;
     44 
     45     const GrShaderVar& samplerVariable(SamplerHandle handle) const override {
     46         return fSamplers[handle.toIndex()].fVariable;
     47     }
     48 
     49     GrSwizzle samplerSwizzle(SamplerHandle handle) const override {
     50         return fSamplerSwizzles[handle.toIndex()];
     51     }
     52 
     53     void appendUniformDecls(GrShaderFlags visibility, SkString*) const override;
     54 
     55     // Manually set uniform locations for all our uniforms.
     56     void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps);
     57 
     58     // Updates the loction of the Uniforms if we cannot bind uniform locations manually
     59     void getUniformLocations(GrGLuint programID, const GrGLCaps& caps);
     60 
     61     const GrGLGpu* glGpu() const;
     62 
     63     typedef GrGLProgramDataManager::UniformInfo UniformInfo;
     64     typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
     65 
     66     UniformInfoArray    fUniforms;
     67     UniformInfoArray    fSamplers;
     68     SkTArray<GrSwizzle> fSamplerSwizzles;
     69 
     70     friend class GrGLProgramBuilder;
     71 
     72     typedef GrGLSLUniformHandler INHERITED;
     73 };
     74 
     75 #endif
     76