Home | History | Annotate | Download | only in glsl
      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 GrGLSLUniformHandler_DEFINED
      9 #define GrGLSLUniformHandler_DEFINED
     10 
     11 #include "GrGLSLProgramDataManager.h"
     12 #include "GrGLSLShaderVar.h"
     13 
     14 class GrGLSLProgramBuilder;
     15 
     16 class GrGLSLUniformHandler {
     17 public:
     18     virtual ~GrGLSLUniformHandler() {}
     19 
     20     typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
     21 
     22     /** Add a uniform variable to the current program, that has visibility in one or more shaders.
     23         visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform
     24         should be accessible. At least one bit must be set. Geometry shader uniforms are not
     25         supported at this time. The actual uniform name will be mangled. If outName is not nullptr
     26         then it will refer to the final uniform name after return. Use the addUniformArray variant
     27         to add an array of uniforms. */
     28     UniformHandle addUniform(uint32_t visibility,
     29                              GrSLType type,
     30                              GrSLPrecision precision,
     31                              const char* name,
     32                              const char** outName = nullptr) {
     33         return this->addUniformArray(visibility, type, precision, name, 0, outName);
     34     }
     35 
     36     UniformHandle addUniformArray(uint32_t visibility,
     37                                   GrSLType type,
     38                                   GrSLPrecision precision,
     39                                   const char* name,
     40                                   int arrayCount,
     41                                   const char** outName = nullptr) {
     42         return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
     43                                              outName);
     44     }
     45 
     46     virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
     47 
     48     /**
     49      * Shortcut for getUniformVariable(u).c_str()
     50      */
     51     virtual const char* getUniformCStr(UniformHandle u) const = 0;
     52 protected:
     53     explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {}
     54 
     55     // This is not owned by the class
     56     GrGLSLProgramBuilder* fProgramBuilder;
     57 
     58 private:
     59     virtual UniformHandle internalAddUniformArray(uint32_t visibility,
     60                                                   GrSLType type,
     61                                                   GrSLPrecision precision,
     62                                                   const char* name,
     63                                                   bool mangleName,
     64                                                   int arrayCount,
     65                                                   const char** outName) = 0;
     66 
     67     virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0;
     68 
     69     friend class GrGLSLProgramBuilder;
     70 };
     71 
     72 #endif
     73 
     74