| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrGLVertexShaderBuilder.h" | 8 #include "GrGLVertexShaderBuilder.h" |
| 9 #include "GrGLFullProgramBuilder.h" | 9 #include "GrGLFullProgramBuilder.h" |
| 10 #include "GrGLShaderStringBuilder.h" | 10 #include "GrGLShaderStringBuilder.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 bool GrGLVertexShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 112 bool GrGLVertexShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 113 SkTDArray<GrGLuint>* shaderIds) const { | 113 SkTDArray<GrGLuint>* shaderIds) const { |
| 114 GrGpuGL* gpu = fProgramBuilder->gpu(); | 114 GrGpuGL* gpu = fProgramBuilder->gpu(); |
| 115 const GrGLContext& glCtx = gpu->glContext(); | 115 const GrGLContext& glCtx = gpu->glContext(); |
| 116 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); | 116 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); |
| 117 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); | 117 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); |
| 118 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility,
&vertShaderSrc); | 118 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility,
&vertShaderSrc); |
| 119 fProgramBuilder->appendDecls(fInputs, &vertShaderSrc); | 119 fProgramBuilder->appendDecls(fInputs, &vertShaderSrc); |
| 120 fProgramBuilder->appendDecls(fOutputs, &vertShaderSrc); | 120 fProgramBuilder->appendDecls(fOutputs, &vertShaderSrc); |
| 121 vertShaderSrc.append("void main() {\n"); | 121 vertShaderSrc.append("void main() {"); |
| 122 vertShaderSrc.append(fCode); | 122 vertShaderSrc.append(fCode); |
| 123 vertShaderSrc.append("}\n"); | 123 vertShaderSrc.append("}"); |
| 124 GrGLuint vertShaderId = GrGLCompileAndAttachShader(glCtx, programId, | 124 GrGLuint vertShaderId = GrGLCompileAndAttachShader(glCtx, programId, |
| 125 GR_GL_VERTEX_SHADER, vertShaderSrc); | 125 GR_GL_VERTEX_SHADER, vertShaderSrc); |
| 126 if (!vertShaderId) { | 126 if (!vertShaderId) { |
| 127 return false; | 127 return false; |
| 128 } | 128 } |
| 129 *shaderIds->append() = vertShaderId; | 129 *shaderIds->append() = vertShaderId; |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void GrGLVertexShaderBuilder::emitCodeAfterEffects() { | 133 void GrGLVertexShaderBuilder::emitCodeAfterEffects() { |
| 134 const char* rtAdjustName; | 134 const char* rtAdjustName; |
| 135 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = | 135 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = |
| 136 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 136 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
| 137 kVec4f_GrSLType, | 137 kVec4f_GrSLType, |
| 138 "rtAdjustment", | 138 "rtAdjustment", |
| 139 &rtAdjustName); | 139 &rtAdjustName); |
| 140 | 140 |
| 141 // Transform from Skia's device coords to GL's normalized device coords. | 141 // Transform from Skia's device coords to GL's normalized device coords. |
| 142 this->codeAppendf( | 142 this->codeAppendf( |
| 143 "\tgl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.
z);\n", | 143 "gl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.z)
;", |
| 144 rtAdjustName, rtAdjustName); | 144 rtAdjustName, rtAdjustName); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void GrGLVertexShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLEx
pr4* coverage) { | 147 void GrGLVertexShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLEx
pr4* coverage) { |
| 148 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader
(); | 148 const GrGLProgramDesc::KeyHeader& header = fProgramBuilder->desc().getHeader
(); |
| 149 | 149 |
| 150 fPositionVar = &fInputs.push_back(); | 150 fPositionVar = &fInputs.push_back(); |
| 151 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); | 151 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
inPosition"); |
| 152 if (-1 != header.fLocalCoordAttributeIndex) { | 152 if (-1 != header.fLocalCoordAttributeIndex) { |
| 153 fLocalCoordsVar = &fInputs.push_back(); | 153 fLocalCoordsVar = &fInputs.push_back(); |
| 154 fLocalCoordsVar->set(kVec2f_GrSLType, | 154 fLocalCoordsVar->set(kVec2f_GrSLType, |
| 155 GrGLShaderVar::kAttribute_TypeModifier, | 155 GrGLShaderVar::kAttribute_TypeModifier, |
| 156 "aLocalCoords"); | 156 "inLocalCoords"); |
| 157 } else { | 157 } else { |
| 158 fLocalCoordsVar = fPositionVar; | 158 fLocalCoordsVar = fPositionVar; |
| 159 } | 159 } |
| 160 | 160 |
| 161 const char* viewMName; | 161 const char* viewMName; |
| 162 fProgramBuilder->fUniformHandles.fViewMatrixUni = | 162 fProgramBuilder->fUniformHandles.fViewMatrixUni = |
| 163 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 163 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
| 164 kMat33f_GrSLType, | 164 kMat33f_GrSLType, |
| 165 "ViewM", | 165 "ViewM", |
| 166 &viewMName); | 166 &viewMName); |
| 167 | 167 |
| 168 // Transform the position into Skia's device coords. | 168 // Transform the position into Skia's device coords. |
| 169 this->codeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n", | 169 this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", |
| 170 viewMName, fPositionVar->c_str()); | 170 viewMName, fPositionVar->c_str()); |
| 171 | 171 |
| 172 // we output point size in the GS if present | 172 // we output point size in the GS if present |
| 173 if (header.fEmitsPointSize | 173 if (header.fEmitsPointSize |
| 174 #if GR_GL_EXPERIMENTAL_GS | 174 #if GR_GL_EXPERIMENTAL_GS |
| 175 && !header.fExperimentalGS | 175 && !header.fExperimentalGS |
| 176 #endif | 176 #endif |
| 177 ) { | 177 ) { |
| 178 this->codeAppend("\tgl_PointSize = 1.0;\n"); | 178 this->codeAppend("gl_PointSize = 1.0;"); |
| 179 } | 179 } |
| 180 | 180 |
| 181 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { | 181 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { |
| 182 this->addAttribute(GrShaderVar(color_attribute_name(), | 182 this->addAttribute(GrShaderVar(color_attribute_name(), |
| 183 kVec4f_GrSLType, | 183 kVec4f_GrSLType, |
| 184 GrShaderVar::kAttribute_TypeModifier)); | 184 GrShaderVar::kAttribute_TypeModifier)); |
| 185 const char *vsName, *fsName; | 185 const char *vsName, *fsName; |
| 186 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsNa
me); | 186 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsNa
me); |
| 187 this->codeAppendf("\t%s = %s;\n", vsName, color_attribute_name()); | 187 this->codeAppendf("%s = %s;", vsName, color_attribute_name()); |
| 188 *color = fsName; | 188 *color = fsName; |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { | 191 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { |
| 192 this->addAttribute(GrShaderVar(coverage_attribute_name(), | 192 this->addAttribute(GrShaderVar(coverage_attribute_name(), |
| 193 kVec4f_GrSLType, | 193 kVec4f_GrSLType, |
| 194 GrShaderVar::kAttribute_TypeModifier)); | 194 GrShaderVar::kAttribute_TypeModifier)); |
| 195 const char *vsName, *fsName; | 195 const char *vsName, *fsName; |
| 196 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &f
sName); | 196 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &f
sName); |
| 197 this->codeAppendf("\t%s = %s;\n", vsName, coverage_attribute_name()); | 197 this->codeAppendf("%s = %s;", vsName, coverage_attribute_name()); |
| 198 *coverage = fsName; | 198 *coverage = fsName; |
| 199 } | 199 } |
| 200 fEffectAttribOffset = fInputs.count(); | 200 fEffectAttribOffset = fInputs.count(); |
| 201 } | 201 } |
| OLD | NEW |