GrGLProgramDataManager.h 4.4 KB

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