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 #include "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
11 #include "gl/GrGpuGL.h" | 11 #include "gl/GrGpuGL.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 | 13 |
14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ | 14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ |
15 SkASSERT(arrayCount <= uni.fArrayCount || \ | 15 SkASSERT(arrayCount <= uni.fArrayCount || \ |
16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun
t)) | 16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun
t)) |
17 | 17 |
18 GrGLUniformManager::GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) { | 18 GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu) : fGpu(gpu) { |
19 // skbug.com/2056 | 19 // skbug.com/2056 |
20 fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation !=
NULL; | 20 fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation !=
NULL; |
21 } | 21 } |
22 | 22 |
23 GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType typ
e, int arrayCount) { | 23 GrGLProgramDataManager::UniformHandle GrGLProgramDataManager::appendUniform(GrSL
Type type, int arrayCount) { |
24 int idx = fUniforms.count(); | 24 int idx = fUniforms.count(); |
25 Uniform& uni = fUniforms.push_back(); | 25 Uniform& uni = fUniforms.push_back(); |
26 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); | 26 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); |
27 uni.fArrayCount = arrayCount; | 27 uni.fArrayCount = arrayCount; |
28 uni.fType = type; | 28 uni.fType = type; |
29 uni.fVSLocation = kUnusedUniform; | 29 uni.fVSLocation = kUnusedUniform; |
30 uni.fFSLocation = kUnusedUniform; | 30 uni.fFSLocation = kUnusedUniform; |
31 return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx); | 31 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(idx); |
32 } | 32 } |
33 | 33 |
34 void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const { | 34 void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const
{ |
35 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 35 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
36 SkASSERT(uni.fType == kSampler2D_GrSLType); | 36 SkASSERT(uni.fType == kSampler2D_GrSLType); |
37 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 37 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
38 // FIXME: We still insert a single sampler uniform for every stage. If the s
hader does not | 38 // FIXME: We still insert a single sampler uniform for every stage. If the s
hader does not |
39 // reference the sampler then the compiler may have optimized it out. Uncomm
ent this assert | 39 // reference the sampler then the compiler may have optimized it out. Uncomm
ent this assert |
40 // once stages insert their own samplers. | 40 // once stages insert their own samplers. |
41 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); | 41 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); |
42 if (kUnusedUniform != uni.fFSLocation) { | 42 if (kUnusedUniform != uni.fFSLocation) { |
43 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); | 43 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit)); |
44 } | 44 } |
45 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 45 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
46 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); | 46 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit)); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const { | 50 void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { |
51 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 51 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
52 SkASSERT(uni.fType == kFloat_GrSLType); | 52 SkASSERT(uni.fType == kFloat_GrSLType); |
53 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 53 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
54 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 54 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
55 if (kUnusedUniform != uni.fFSLocation) { | 55 if (kUnusedUniform != uni.fFSLocation) { |
56 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); | 56 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0)); |
57 } | 57 } |
58 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 58 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
59 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); | 59 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0)); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 void GrGLUniformManager::set1fv(UniformHandle u, | 63 void GrGLProgramDataManager::set1fv(UniformHandle u, |
64 int arrayCount, | 64 int arrayCount, |
65 const GrGLfloat v[]) const { | 65 const GrGLfloat v[]) const { |
66 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 66 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
67 SkASSERT(uni.fType == kFloat_GrSLType); | 67 SkASSERT(uni.fType == kFloat_GrSLType); |
68 SkASSERT(arrayCount > 0); | 68 SkASSERT(arrayCount > 0); |
69 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 69 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
70 // This assert fires in some instances of the two-pt gradient for its VSPara
ms. | 70 // This assert fires in some instances of the two-pt gradient for its VSPara
ms. |
71 // Once the uniform manager is responsible for inserting the duplicate unifo
rm | 71 // Once the uniform manager is responsible for inserting the duplicate unifo
rm |
72 // arrays in VS and FS driver bug workaround, this can be enabled. | 72 // arrays in VS and FS driver bug workaround, this can be enabled. |
73 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc
ation); | 73 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc
ation); |
74 if (kUnusedUniform != uni.fFSLocation) { | 74 if (kUnusedUniform != uni.fFSLocation) { |
75 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount,
v)); | 75 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount,
v)); |
76 } | 76 } |
77 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 77 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
78 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount,
v)); | 78 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount,
v)); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) cons
t { | 82 void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1)
const { |
83 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 83 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
84 SkASSERT(uni.fType == kVec2f_GrSLType); | 84 SkASSERT(uni.fType == kVec2f_GrSLType); |
85 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 85 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
86 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 86 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
87 if (kUnusedUniform != uni.fFSLocation) { | 87 if (kUnusedUniform != uni.fFSLocation) { |
88 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); | 88 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1)); |
89 } | 89 } |
90 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 90 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
91 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); | 91 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1)); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void GrGLUniformManager::set2fv(UniformHandle u, | 95 void GrGLProgramDataManager::set2fv(UniformHandle u, |
96 int arrayCount, | 96 int arrayCount, |
97 const GrGLfloat v[]) const { | 97 const GrGLfloat v[]) const { |
98 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 98 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
99 SkASSERT(uni.fType == kVec2f_GrSLType); | 99 SkASSERT(uni.fType == kVec2f_GrSLType); |
100 SkASSERT(arrayCount > 0); | 100 SkASSERT(arrayCount > 0); |
101 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 101 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
102 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 102 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
103 if (kUnusedUniform != uni.fFSLocation) { | 103 if (kUnusedUniform != uni.fFSLocation) { |
104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount,
v)); | 104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount,
v)); |
105 } | 105 } |
106 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 106 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
107 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount,
v)); | 107 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount,
v)); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGL
float v2) const { | 111 void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1,
GrGLfloat v2) const { |
112 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 112 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
113 SkASSERT(uni.fType == kVec3f_GrSLType); | 113 SkASSERT(uni.fType == kVec3f_GrSLType); |
114 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 114 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
115 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 115 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
116 if (kUnusedUniform != uni.fFSLocation) { | 116 if (kUnusedUniform != uni.fFSLocation) { |
117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); | 117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2)); |
118 } | 118 } |
119 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 119 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
120 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); | 120 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2)); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void GrGLUniformManager::set3fv(UniformHandle u, | 124 void GrGLProgramDataManager::set3fv(UniformHandle u, |
125 int arrayCount, | 125 int arrayCount, |
126 const GrGLfloat v[]) const { | 126 const GrGLfloat v[]) const { |
127 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 127 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
128 SkASSERT(uni.fType == kVec3f_GrSLType); | 128 SkASSERT(uni.fType == kVec3f_GrSLType); |
129 SkASSERT(arrayCount > 0); | 129 SkASSERT(arrayCount > 0); |
130 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 130 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
131 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 131 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
132 if (kUnusedUniform != uni.fFSLocation) { | 132 if (kUnusedUniform != uni.fFSLocation) { |
133 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount,
v)); | 133 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount,
v)); |
134 } | 134 } |
135 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 135 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
136 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount,
v)); | 136 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount,
v)); |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 void GrGLUniformManager::set4f(UniformHandle u, | 140 void GrGLProgramDataManager::set4f(UniformHandle u, |
141 GrGLfloat v0, | 141 GrGLfloat v0, |
142 GrGLfloat v1, | 142 GrGLfloat v1, |
143 GrGLfloat v2, | 143 GrGLfloat v2, |
144 GrGLfloat v3) const { | 144 GrGLfloat v3) const { |
145 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 145 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
146 SkASSERT(uni.fType == kVec4f_GrSLType); | 146 SkASSERT(uni.fType == kVec4f_GrSLType); |
147 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 147 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
148 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 148 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
149 if (kUnusedUniform != uni.fFSLocation) { | 149 if (kUnusedUniform != uni.fFSLocation) { |
150 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v
3)); | 150 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v
3)); |
151 } | 151 } |
152 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 152 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
153 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v
3)); | 153 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v
3)); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 void GrGLUniformManager::set4fv(UniformHandle u, | 157 void GrGLProgramDataManager::set4fv(UniformHandle u, |
158 int arrayCount, | 158 int arrayCount, |
159 const GrGLfloat v[]) const { | 159 const GrGLfloat v[]) const { |
160 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 160 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
161 SkASSERT(uni.fType == kVec4f_GrSLType); | 161 SkASSERT(uni.fType == kVec4f_GrSLType); |
162 SkASSERT(arrayCount > 0); | 162 SkASSERT(arrayCount > 0); |
163 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 163 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
164 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 164 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
165 if (kUnusedUniform != uni.fFSLocation) { | 165 if (kUnusedUniform != uni.fFSLocation) { |
166 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); | 166 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount,
v)); |
167 } | 167 } |
168 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 168 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
169 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); | 169 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount,
v)); |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[])
const { | 173 void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix
[]) const { |
174 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 174 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
175 SkASSERT(uni.fType == kMat33f_GrSLType); | 175 SkASSERT(uni.fType == kMat33f_GrSLType); |
176 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 176 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
177 // TODO: Re-enable this assert once texture matrices aren't forced on all ef
fects | 177 // TODO: Re-enable this assert once texture matrices aren't forced on all ef
fects |
178 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); | 178 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo
cation); |
179 if (kUnusedUniform != uni.fFSLocation) { | 179 if (kUnusedUniform != uni.fFSLocation) { |
180 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal
se, matrix)); | 180 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal
se, matrix)); |
181 } | 181 } |
182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
183 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal
se, matrix)); | 183 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal
se, matrix)); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[])
const { | 187 void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix
[]) const { |
188 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 188 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
189 SkASSERT(uni.fType == kMat44f_GrSLType); | 189 SkASSERT(uni.fType == kMat44f_GrSLType); |
190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); | 190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); |
191 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 191 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
192 if (kUnusedUniform != uni.fFSLocation) { | 192 if (kUnusedUniform != uni.fFSLocation) { |
193 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal
se, matrix)); | 193 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal
se, matrix)); |
194 } | 194 } |
195 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 195 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
196 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal
se, matrix)); | 196 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal
se, matrix)); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 void GrGLUniformManager::setMatrix3fv(UniformHandle u, | 200 void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, |
201 int arrayCount, | 201 int arrayCount, |
202 const GrGLfloat matrices[]) const { | 202 const GrGLfloat matrices[]) const { |
203 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 203 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
204 SkASSERT(uni.fType == kMat33f_GrSLType); | 204 SkASSERT(uni.fType == kMat33f_GrSLType); |
205 SkASSERT(arrayCount > 0); | 205 SkASSERT(arrayCount > 0); |
206 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 206 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
207 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 207 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
208 if (kUnusedUniform != uni.fFSLocation) { | 208 if (kUnusedUniform != uni.fFSLocation) { |
209 GR_GL_CALL(fGpu->glInterface(), | 209 GR_GL_CALL(fGpu->glInterface(), |
210 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices
)); | 210 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices
)); |
211 } | 211 } |
212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
213 GR_GL_CALL(fGpu->glInterface(), | 213 GR_GL_CALL(fGpu->glInterface(), |
214 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices
)); | 214 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices
)); |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 void GrGLUniformManager::setMatrix4fv(UniformHandle u, | 218 void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, |
219 int arrayCount, | 219 int arrayCount, |
220 const GrGLfloat matrices[]) const { | 220 const GrGLfloat matrices[]) const { |
221 const Uniform& uni = fUniforms[u.toUniformIndex()]; | 221 const Uniform& uni = fUniforms[u.toUniformIndex()]; |
222 SkASSERT(uni.fType == kMat44f_GrSLType); | 222 SkASSERT(uni.fType == kMat44f_GrSLType); |
223 SkASSERT(arrayCount > 0); | 223 SkASSERT(arrayCount > 0); |
224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); | 224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount); |
225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); | 225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat
ion); |
226 if (kUnusedUniform != uni.fFSLocation) { | 226 if (kUnusedUniform != uni.fFSLocation) { |
227 GR_GL_CALL(fGpu->glInterface(), | 227 GR_GL_CALL(fGpu->glInterface(), |
228 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices
)); | 228 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices
)); |
229 } | 229 } |
230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ | 230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation)
{ |
231 GR_GL_CALL(fGpu->glInterface(), | 231 GR_GL_CALL(fGpu->glInterface(), |
232 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices
)); | 232 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices
)); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) co
nst { | 236 void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix
) const { |
237 GrGLfloat mt[] = { | 237 GrGLfloat mt[] = { |
238 matrix.get(SkMatrix::kMScaleX), | 238 matrix.get(SkMatrix::kMScaleX), |
239 matrix.get(SkMatrix::kMSkewY), | 239 matrix.get(SkMatrix::kMSkewY), |
240 matrix.get(SkMatrix::kMPersp0), | 240 matrix.get(SkMatrix::kMPersp0), |
241 matrix.get(SkMatrix::kMSkewX), | 241 matrix.get(SkMatrix::kMSkewX), |
242 matrix.get(SkMatrix::kMScaleY), | 242 matrix.get(SkMatrix::kMScaleY), |
243 matrix.get(SkMatrix::kMPersp1), | 243 matrix.get(SkMatrix::kMPersp1), |
244 matrix.get(SkMatrix::kMTransX), | 244 matrix.get(SkMatrix::kMTransX), |
245 matrix.get(SkMatrix::kMTransY), | 245 matrix.get(SkMatrix::kMTransY), |
246 matrix.get(SkMatrix::kMPersp2), | 246 matrix.get(SkMatrix::kMPersp2), |
247 }; | 247 }; |
248 this->setMatrix3f(u, mt); | 248 this->setMatrix3f(u, mt); |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn
iformArray& uniforms) { | 252 void GrGLProgramDataManager::getUniformLocations(GrGLuint programID, const Build
erUniformArray& uniforms) { |
253 SkASSERT(uniforms.count() == fUniforms.count()); | 253 SkASSERT(uniforms.count() == fUniforms.count()); |
254 int count = fUniforms.count(); | 254 int count = fUniforms.count(); |
255 for (int i = 0; i < count; ++i) { | 255 for (int i = 0; i < count; ++i) { |
256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); | 256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); |
257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou
nt); | 257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou
nt); |
258 GrGLint location; | 258 GrGLint location; |
259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he
re. | 259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he
re. |
260 if (fUsingBindUniform) { | 260 if (fUsingBindUniform) { |
261 location = i; | 261 location = i; |
262 GR_GL_CALL(fGpu->glInterface(), | 262 GR_GL_CALL(fGpu->glInterface(), |
263 BindUniformLocation(programID, location, uniforms[i].fVar
iable.c_str())); | 263 BindUniformLocation(programID, location, uniforms[i].fVar
iable.c_str())); |
264 } else { | 264 } else { |
265 GR_GL_CALL_RET(fGpu->glInterface(), location, | 265 GR_GL_CALL_RET(fGpu->glInterface(), location, |
266 GetUniformLocation(programID, uniforms[i].fVariable.c_str
())); | 266 GetUniformLocation(programID, uniforms[i].fVariable.c_str
())); |
267 } | 267 } |
268 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { | 268 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { |
269 fUniforms[i].fVSLocation = location; | 269 fUniforms[i].fVSLocation = location; |
270 } | 270 } |
271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { | 271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { |
272 fUniforms[i].fFSLocation = location; | 272 fUniforms[i].fFSLocation = location; |
273 } | 273 } |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 const GrGLUniformManager::BuilderUniform& | 277 const GrGLProgramDataManager::BuilderUniform& |
278 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformH
andle handle) const { | 278 GrGLProgramDataManager::getBuilderUniform(const BuilderUniformArray& array, Unif
ormHandle handle) const { |
279 return array[handle.toUniformIndex()]; | 279 return array[handle.toUniformIndex()]; |
280 } | 280 } |
OLD | NEW |