OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 }; | 124 }; |
125 | 125 |
126 //////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////// |
127 | 127 |
128 #if SK_SUPPORT_GPU | 128 #if SK_SUPPORT_GPU |
129 | 129 |
130 #include "GrCoordTransform.h" | 130 #include "GrCoordTransform.h" |
131 #include "GrFragmentProcessor.h" | 131 #include "GrFragmentProcessor.h" |
132 #include "GrTextureAccess.h" | 132 #include "GrTextureAccess.h" |
133 #include "gl/GrGLFragmentProcessor.h" | 133 #include "gl/GrGLFragmentProcessor.h" |
134 #include "gl/builders/GrGLProgramBuilder.h" | 134 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 135 #include "glsl/GrGLSLProgramBuilder.h" |
135 #include "glsl/GrGLSLProgramDataManager.h" | 136 #include "glsl/GrGLSLProgramDataManager.h" |
136 #include "SkGr.h" | 137 #include "SkGr.h" |
137 #include "SkGrPriv.h" | 138 #include "SkGrPriv.h" |
138 | 139 |
139 class LightingFP : public GrFragmentProcessor { | 140 class LightingFP : public GrFragmentProcessor { |
140 public: | 141 public: |
141 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, | 142 LightingFP(GrTexture* diffuse, GrTexture* normal, const SkMatrix& diffMatrix
, |
142 const SkMatrix& normMatrix, const GrTextureParams& diffParams, | 143 const SkMatrix& normMatrix, const GrTextureParams& diffParams, |
143 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, | 144 const GrTextureParams& normParams, const SkLightingShader::Lights
* lights, |
144 const SkVector& invNormRotation) | 145 const SkVector& invNormRotation) |
(...skipping 26 matching lines...) Expand all Loading... |
171 public: | 172 public: |
172 LightingGLFP() { | 173 LightingGLFP() { |
173 fLightDir.fX = 10000.0f; | 174 fLightDir.fX = 10000.0f; |
174 fLightColor.fX = 0.0f; | 175 fLightColor.fX = 0.0f; |
175 fAmbientColor.fX = 0.0f; | 176 fAmbientColor.fX = 0.0f; |
176 fInvNormRotation.set(0.0f, 0.0f); | 177 fInvNormRotation.set(0.0f, 0.0f); |
177 } | 178 } |
178 | 179 |
179 void emitCode(EmitArgs& args) override { | 180 void emitCode(EmitArgs& args) override { |
180 | 181 |
181 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder()
; | 182 GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder
(); |
182 | 183 |
183 // add uniforms | 184 // add uniforms |
184 const char* lightDirUniName = nullptr; | 185 const char* lightDirUniName = nullptr; |
185 fLightDirUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragme
nt_Visibility, | 186 fLightDirUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFrag
ment_Visibility, |
186 kVec3f_GrSLType, kDefault_G
rSLPrecision, | 187 kVec3f_GrSLType, kDefault_G
rSLPrecision, |
187 "LightDir", &lightDirUniNam
e); | 188 "LightDir", &lightDirUniNam
e); |
188 | 189 |
189 const char* lightColorUniName = nullptr; | 190 const char* lightColorUniName = nullptr; |
190 fLightColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFrag
ment_Visibility, | 191 fLightColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFr
agment_Visibility, |
191 kVec3f_GrSLType, kDefault
_GrSLPrecision, | 192 kVec3f_GrSLType, kDefault
_GrSLPrecision, |
192 "LightColor", &lightColor
UniName); | 193 "LightColor", &lightColor
UniName); |
193 | 194 |
194 const char* ambientColorUniName = nullptr; | 195 const char* ambientColorUniName = nullptr; |
195 fAmbientColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFr
agment_Visibility, | 196 fAmbientColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::k
Fragment_Visibility, |
196 kVec3f_GrSLType, kDefau
lt_GrSLPrecision, | 197 kVec3f_GrSLType, kDefau
lt_GrSLPrecision, |
197 "AmbientColor", &ambien
tColorUniName); | 198 "AmbientColor", &ambien
tColorUniName); |
198 | 199 |
199 const char* xformUniName = nullptr; | 200 const char* xformUniName = nullptr; |
200 fXformUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 201 fXformUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
201 kVec2f_GrSLType, kDefault_GrSL
Precision, | 202 kVec2f_GrSLType, kDefault_GrSL
Precision, |
202 "Xform", &xformUniName); | 203 "Xform", &xformUniName); |
203 | 204 |
204 fpb->codeAppend("vec4 diffuseColor = "); | 205 fpb->codeAppend("vec4 diffuseColor = "); |
205 fpb->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers
[0], | 206 fpb->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers
[0], |
206 args.fCoords[0].c_str(), | 207 args.fCoords[0].c_str(), |
207 args.fCoords[0].getType()); | 208 args.fCoords[0].getType()); |
208 fpb->codeAppend(";"); | 209 fpb->codeAppend(";"); |
209 | 210 |
210 fpb->codeAppend("vec4 normalColor = "); | 211 fpb->codeAppend("vec4 normalColor = "); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 normLocalM); | 714 normLocalM); |
714 } | 715 } |
715 | 716 |
716 /////////////////////////////////////////////////////////////////////////////// | 717 /////////////////////////////////////////////////////////////////////////////// |
717 | 718 |
718 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 719 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
719 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 720 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
720 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 721 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
721 | 722 |
722 /////////////////////////////////////////////////////////////////////////////// | 723 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |