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 GrGLUniformManager_DEFINED | 8 #ifndef GrGLUniformManager_DEFINED |
9 #define GrGLUniformManager_DEFINED | 9 #define GrGLUniformManager_DEFINED |
10 | 10 |
11 #include "gl/GrGLShaderVar.h" | 11 #include "gl/GrGLShaderVar.h" |
12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
13 #include "GrAllocator.h" | 13 #include "GrAllocator.h" |
14 | 14 |
15 #include "SkTArray.h" | 15 #include "SkTArray.h" |
16 | 16 |
17 class GrGLContext; | 17 class GrGLContext; |
18 class SkMatrix; | 18 class SkMatrix; |
19 | 19 |
20 /** Manages a program's uniforms. | 20 /** Manages a program's uniforms. |
21 */ | 21 */ |
22 class GrGLUniformManager { | 22 class GrGLUniformManager { |
23 public: | 23 public: |
24 // Opaque handle to a uniform | 24 // Opaque handle to a uniform |
25 typedef int UniformHandle; | 25 class UniformHandle { |
26 static const UniformHandle kInvalidUniformHandle = 0; | 26 public: |
| 27 static UniformHandle CreateFromUniformIndex(int i); |
| 28 |
| 29 bool isValid() const { return 0 != fValue; } |
| 30 |
| 31 bool operator==(const UniformHandle& other) const { return other.fValue
== fValue; } |
| 32 |
| 33 UniformHandle() |
| 34 : fValue(0) { |
| 35 } |
| 36 |
| 37 private: |
| 38 UniformHandle(int value) |
| 39 : fValue(~value) { |
| 40 GrAssert(isValid()); |
| 41 } |
| 42 |
| 43 int toUniformIndex() const { GrAssert(isValid()); return ~fValue; } |
| 44 |
| 45 int fValue; |
| 46 friend class GrGLUniformManager; // For accessing toUniformIndex(). |
| 47 }; |
27 | 48 |
28 GrGLUniformManager(const GrGLContext& context) : fContext(context) {} | 49 GrGLUniformManager(const GrGLContext& context) : fContext(context) {} |
29 | 50 |
30 UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::k
NonArray); | 51 UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::k
NonArray); |
31 | 52 |
32 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an | 53 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an |
33 * array of uniforms. offset + arrayCount must be <= the array count of the
uniform. | 54 * array of uniforms. offset + arrayCount must be <= the array count of the
uniform. |
34 */ | 55 */ |
35 void setSampler(UniformHandle, GrGLint texUnit) const; | 56 void setSampler(UniformHandle, GrGLint texUnit) const; |
36 void set1f(UniformHandle, GrGLfloat v0) const; | 57 void set1f(UniformHandle, GrGLfloat v0) const; |
(...skipping 21 matching lines...) Expand all Loading... |
58 // This uses an allocator rather than array so that the GrGLShaderVars don't
move in memory | 79 // This uses an allocator rather than array so that the GrGLShaderVars don't
move in memory |
59 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their | 80 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their |
60 // name strings. Otherwise, we'd have to hand out copies. | 81 // name strings. Otherwise, we'd have to hand out copies. |
61 typedef GrTAllocator<BuilderUniform> BuilderUniformArray; | 82 typedef GrTAllocator<BuilderUniform> BuilderUniformArray; |
62 | 83 |
63 /** | 84 /** |
64 * Called by the GrGLShaderBuilder to get GL locations for all uniforms. | 85 * Called by the GrGLShaderBuilder to get GL locations for all uniforms. |
65 */ | 86 */ |
66 void getUniformLocations(GrGLuint programID, const BuilderUniformArray& unif
orms); | 87 void getUniformLocations(GrGLuint programID, const BuilderUniformArray& unif
orms); |
67 | 88 |
| 89 /** |
| 90 * Called by the GrGLShaderBuilder to access the array by the handle (index)
. |
| 91 */ |
| 92 const BuilderUniform& getBuilderUniform(const BuilderUniformArray&, GrGLUnif
ormManager::UniformHandle) const; |
| 93 |
68 private: | 94 private: |
69 enum { | 95 enum { |
70 kUnusedUniform = -1, | 96 kUnusedUniform = -1, |
71 }; | 97 }; |
72 | 98 |
73 struct Uniform { | 99 struct Uniform { |
74 GrGLint fVSLocation; | 100 GrGLint fVSLocation; |
75 GrGLint fFSLocation; | 101 GrGLint fFSLocation; |
76 GrSLType fType; | 102 GrSLType fType; |
77 int fArrayCount; | 103 int fArrayCount; |
78 }; | 104 }; |
79 | 105 |
80 SkTArray<Uniform, true> fUniforms; | 106 SkTArray<Uniform, true> fUniforms; |
81 const GrGLContext& fContext; | 107 const GrGLContext& fContext; |
82 }; | 108 }; |
83 | 109 |
84 #endif | 110 #endif |
OLD | NEW |