Home | History | Annotate | Download | only in gl
      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 "glsl/GrGLSLProgramDataManager.h"
     12 
     13 #include "GrAllocator.h"
     14 #include "gl/GrGLTypes.h"
     15 #include "glsl/GrGLSLShaderVar.h"
     16 
     17 #include "SkTArray.h"
     18 
     19 class GrGLGpu;
     20 class SkMatrix;
     21 class GrGLProgram;
     22 
     23 /** Manages the resources used by a shader program.
     24  * The resources are objects the program uses to communicate with the
     25  * application code.
     26  */
     27 class GrGLProgramDataManager : public GrGLSLProgramDataManager {
     28 public:
     29     struct UniformInfo {
     30         GrGLSLShaderVar fVariable;
     31         uint32_t        fVisibility;
     32         GrGLint         fLocation;
     33     };
     34 
     35     struct VaryingInfo {
     36         GrGLSLShaderVar fVariable;
     37         GrGLint         fLocation;
     38     };
     39 
     40     // This uses an allocator rather than array so that the GrGLSLShaderVars don't move in memory
     41     // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
     42     // name strings. Otherwise, we'd have to hand out copies.
     43     typedef GrTAllocator<UniformInfo> UniformInfoArray;
     44     typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
     45 
     46     GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
     47                            const VaryingInfoArray&);
     48 
     49     /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
     50      *  array of uniforms. arrayCount must be <= the array count of the uniform.
     51      */
     52     void setSampler(UniformHandle, int texUnit) const;
     53 
     54     void set1f(UniformHandle, float v0) const override;
     55     void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
     56     void set2f(UniformHandle, float, float) const override;
     57     void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
     58     void set3f(UniformHandle, float, float, float) const override;
     59     void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
     60     void set4f(UniformHandle, float, float, float, float) const override;
     61     void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
     62     // matrices are column-major, the first three upload a single matrix, the latter three upload
     63     // arrayCount matrices into a uniform array.
     64     void setMatrix3f(UniformHandle, const float matrix[]) const override;
     65     void setMatrix4f(UniformHandle, const float matrix[]) const override;
     66     void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
     67     void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
     68 
     69     // for nvpr only
     70     void setPathFragmentInputTransform(VaryingHandle u, int components,
     71                                        const SkMatrix& matrix) const override;
     72 
     73 private:
     74     enum {
     75         kUnusedUniform = -1,
     76     };
     77 
     78     struct Uniform {
     79         GrGLint     fVSLocation;
     80         GrGLint     fFSLocation;
     81         SkDEBUGCODE(
     82             GrSLType    fType;
     83             int         fArrayCount;
     84         );
     85     };
     86 
     87     enum {
     88         kUnusedPathProcVarying = -1,
     89     };
     90     struct PathProcVarying {
     91         GrGLint     fLocation;
     92         SkDEBUGCODE(
     93             GrSLType    fType;
     94             int         fArrayCount;
     95         );
     96     };
     97 
     98     SkDEBUGCODE(void printUnused(const Uniform&) const;)
     99 
    100     SkTArray<Uniform, true> fUniforms;
    101     SkTArray<PathProcVarying, true> fPathProcVaryings;
    102     GrGLGpu* fGpu;
    103     GrGLuint fProgramID;
    104 
    105     typedef GrGLSLProgramDataManager INHERITED;
    106 };
    107 
    108 #endif
    109