Line data Source code
1 : /*
2 : * Copyright 2014 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #include "GrGLSLVertexShaderBuilder.h"
9 : #include "glsl/GrGLSLProgramBuilder.h"
10 : #include "glsl/GrGLSLUniformHandler.h"
11 : #include "glsl/GrGLSLVarying.h"
12 :
13 0 : GrGLSLVertexBuilder::GrGLSLVertexBuilder(GrGLSLProgramBuilder* program)
14 0 : : INHERITED(program) {
15 0 : }
16 :
17 0 : void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar,
18 : const char* rtAdjustName) {
19 : // setup RT Uniform
20 0 : if (this->getProgramBuilder()->desc()->header().fSnapVerticesToPixelCenters) {
21 0 : if (kVec3f_GrSLType == posVar.getType()) {
22 0 : const char* p = posVar.c_str();
23 0 : this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p);
24 : } else {
25 0 : SkASSERT(kVec2f_GrSLType == posVar.getType());
26 0 : this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str());
27 : }
28 0 : this->codeAppendf("_posTmp = floor(_posTmp) + vec2(0.5, 0.5);"
29 : "gl_Position = vec4(_posTmp.x * %s.x + %s.y,"
30 : "_posTmp.y * %s.z + %s.w, 0, 1);}",
31 0 : rtAdjustName, rtAdjustName, rtAdjustName, rtAdjustName);
32 0 : } else if (kVec3f_GrSLType == posVar.getType()) {
33 0 : this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
34 : posVar.c_str(), rtAdjustName,
35 : posVar.c_str(), rtAdjustName,
36 0 : posVar.c_str());
37 : } else {
38 0 : SkASSERT(kVec2f_GrSLType == posVar.getType());
39 0 : this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);",
40 : posVar.c_str(), rtAdjustName, rtAdjustName,
41 0 : posVar.c_str(), rtAdjustName, rtAdjustName);
42 : }
43 : // We could have the GrGeometryProcessor do this, but its just easier to have it performed
44 : // here. If we ever need to set variable pointsize, then we can reinvestigate.
45 0 : if (this->getProgramBuilder()->desc()->header().fHasPointSize) {
46 0 : this->codeAppend("gl_PointSize = 1.0;");
47 : }
48 0 : }
49 :
50 0 : void GrGLSLVertexBuilder::onFinalize() {
51 0 : fProgramBuilder->varyingHandler()->getVertexDecls(&this->inputs(), &this->outputs());
52 0 : }
|