| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLProgramDataManager_DEFINED | 8 #ifndef GrGLProgramDataManager_DEFINED |
| 9 #define GrGLProgramDataManager_DEFINED | 9 #define GrGLProgramDataManager_DEFINED |
| 10 | 10 |
| 11 #include "glsl/GrGLSLProgramDataManager.h" |
| 12 |
| 11 #include "GrAllocator.h" | 13 #include "GrAllocator.h" |
| 12 #include "gl/GrGLTypes.h" | 14 #include "gl/GrGLTypes.h" |
| 13 #include "glsl/GrGLSLShaderVar.h" | 15 #include "glsl/GrGLSLShaderVar.h" |
| 14 | 16 |
| 15 #include "SkTArray.h" | 17 #include "SkTArray.h" |
| 16 | 18 |
| 17 class GrGLGpu; | 19 class GrGLGpu; |
| 18 class SkMatrix; | 20 class SkMatrix; |
| 19 class GrGLProgram; | 21 class GrGLProgram; |
| 20 class GrGLProgramBuilder; | 22 class GrGLProgramBuilder; |
| 21 | 23 |
| 22 /** Manages the resources used by a shader program. | 24 /** Manages the resources used by a shader program. |
| 23 * The resources are objects the program uses to communicate with the | 25 * The resources are objects the program uses to communicate with the |
| 24 * application code. | 26 * application code. |
| 25 */ | 27 */ |
| 26 class GrGLProgramDataManager : SkNoncopyable { | 28 class GrGLProgramDataManager : public GrGLSLProgramDataManager { |
| 27 public: | 29 public: |
| 28 // Opaque handle to a resource | |
| 29 class ShaderResourceHandle { | |
| 30 public: | |
| 31 ShaderResourceHandle(int value) | |
| 32 : fValue(value) { | |
| 33 SkASSERT(this->isValid()); | |
| 34 } | |
| 35 | |
| 36 ShaderResourceHandle() | |
| 37 : fValue(kInvalid_ShaderResourceHandle) { | |
| 38 } | |
| 39 | |
| 40 bool operator==(const ShaderResourceHandle& other) const { return other.
fValue == fValue; } | |
| 41 bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } | |
| 42 int toIndex() const { SkASSERT(this->isValid()); return fValue; } | |
| 43 | |
| 44 private: | |
| 45 static const int kInvalid_ShaderResourceHandle = -1; | |
| 46 int fValue; | |
| 47 }; | |
| 48 | |
| 49 typedef ShaderResourceHandle UniformHandle; | |
| 50 | |
| 51 struct UniformInfo { | 30 struct UniformInfo { |
| 52 GrGLSLShaderVar fVariable; | 31 GrGLSLShaderVar fVariable; |
| 53 uint32_t fVisibility; | 32 uint32_t fVisibility; |
| 54 GrGLint fLocation; | 33 GrGLint fLocation; |
| 55 }; | 34 }; |
| 56 | 35 |
| 57 struct SeparableVaryingInfo { | 36 struct SeparableVaryingInfo { |
| 58 GrGLSLShaderVar fVariable; | 37 GrGLSLShaderVar fVariable; |
| 59 GrGLint fLocation; | 38 GrGLint fLocation; |
| 60 }; | 39 }; |
| 61 | 40 |
| 62 // This uses an allocator rather than array so that the GrGLSLShaderVars don
't move in memory | 41 // This uses an allocator rather than array so that the GrGLSLShaderVars don
't move in memory |
| 63 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their | 42 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their |
| 64 // name strings. Otherwise, we'd have to hand out copies. | 43 // name strings. Otherwise, we'd have to hand out copies. |
| 65 typedef GrTAllocator<UniformInfo> UniformInfoArray; | 44 typedef GrTAllocator<UniformInfo> UniformInfoArray; |
| 66 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; | 45 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; |
| 67 | 46 |
| 68 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&
, | 47 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&
, |
| 69 const SeparableVaryingInfoArray&); | 48 const SeparableVaryingInfoArray&); |
| 70 | 49 |
| 71 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an | 50 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an |
| 72 * array of uniforms. arrayCount must be <= the array count of the uniform. | 51 * array of uniforms. arrayCount must be <= the array count of the uniform. |
| 73 */ | 52 */ |
| 74 void setSampler(UniformHandle, GrGLint texUnit) const; | 53 void setSampler(UniformHandle, int texUnit) const; |
| 75 void set1f(UniformHandle, GrGLfloat v0) const; | 54 |
| 76 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 55 void set1f(UniformHandle, float v0) const override; |
| 77 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; | 56 void set1fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 78 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 57 void set2f(UniformHandle, float, float) const override; |
| 79 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; | 58 void set2fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 80 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 59 void set3f(UniformHandle, float, float, float) const override; |
| 81 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; | 60 void set3fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 82 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; | 61 void set4f(UniformHandle, float, float, float, float) const override; |
| 62 void set4fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 83 // matrices are column-major, the first three upload a single matrix, the la
tter three upload | 63 // matrices are column-major, the first three upload a single matrix, the la
tter three upload |
| 84 // arrayCount matrices into a uniform array. | 64 // arrayCount matrices into a uniform array. |
| 85 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; | 65 void setMatrix3f(UniformHandle, const float matrix[]) const override; |
| 86 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; | 66 void setMatrix4f(UniformHandle, const float matrix[]) const override; |
| 87 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; | 67 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) con
st override; |
| 88 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[])
const; | 68 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) con
st override; |
| 89 | 69 |
| 90 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform | 70 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
| 91 void setSkMatrix(UniformHandle, const SkMatrix&) const; | 71 void setSkMatrix(UniformHandle, const SkMatrix&) const override; |
| 92 | 72 |
| 93 // for nvpr only | 73 // for nvpr only |
| 94 typedef GrGLProgramDataManager::ShaderResourceHandle SeparableVaryingHandle; | |
| 95 void setPathFragmentInputTransform(SeparableVaryingHandle u, int components, | 74 void setPathFragmentInputTransform(SeparableVaryingHandle u, int components, |
| 96 const SkMatrix& matrix) const; | 75 const SkMatrix& matrix) const override; |
| 97 | 76 |
| 98 private: | 77 private: |
| 99 enum { | 78 enum { |
| 100 kUnusedUniform = -1, | 79 kUnusedUniform = -1, |
| 101 }; | 80 }; |
| 102 | 81 |
| 103 struct Uniform { | 82 struct Uniform { |
| 104 GrGLint fVSLocation; | 83 GrGLint fVSLocation; |
| 105 GrGLint fFSLocation; | 84 GrGLint fFSLocation; |
| 106 SkDEBUGCODE( | 85 SkDEBUGCODE( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 ); | 99 ); |
| 121 }; | 100 }; |
| 122 | 101 |
| 123 SkDEBUGCODE(void printUnused(const Uniform&) const;) | 102 SkDEBUGCODE(void printUnused(const Uniform&) const;) |
| 124 | 103 |
| 125 SkTArray<Uniform, true> fUniforms; | 104 SkTArray<Uniform, true> fUniforms; |
| 126 SkTArray<SeparableVarying, true> fSeparableVaryings; | 105 SkTArray<SeparableVarying, true> fSeparableVaryings; |
| 127 GrGLGpu* fGpu; | 106 GrGLGpu* fGpu; |
| 128 GrGLuint fProgramID; | 107 GrGLuint fProgramID; |
| 129 | 108 |
| 130 typedef SkNoncopyable INHERITED; | 109 typedef GrGLSLProgramDataManager INHERITED; |
| 131 }; | 110 }; |
| 132 | 111 |
| 133 #endif | 112 #endif |
| OLD | NEW |