| 1 |
/* |
| 2 |
* Copyright 2017 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 "src/gpu/ganesh/glsl/GrGLSLVertexGeoBuilder.h" |
| 9 |
|
| 10 |
#include "include/private/base/SkAssert.h" |
| 11 |
#include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h" |
| 12 |
#include "src/gpu/ganesh/glsl/GrGLSLVarying.h" |
| 13 |
|
| 14 |
void GrGLSLVertexGeoBuilder::emitNormalizedSkPosition(SkString* out, const char* devPos, |
| 15 |
SkSLType devPosType) { |
| 16 |
if (this->getProgramBuilder()->snapVerticesToPixelCenters()) { |
| 17 |
if (SkSLType::kFloat3 == devPosType) { |
| 18 |
const char* p = devPos; |
| 19 |
out->appendf("{float2 _posTmp = %s.xy / %s.z;", p, p); |
| 20 |
} else { |
| 21 |
SkASSERT(SkSLType::kFloat2 == devPosType); |
| 22 |
out->appendf("{float2 _posTmp = %s;", devPos); |
| 23 |
} |
| 24 |
out->appendf("_posTmp = floor(_posTmp) + float2(0.5);" |
| 25 |
"sk_Position = _posTmp.xy01;}"); |
| 26 |
} else if (SkSLType::kFloat3 == devPosType) { |
| 27 |
out->appendf("sk_Position = %s.xy0z;", devPos); |
| 28 |
} else { |
| 29 |
SkASSERT(SkSLType::kFloat2 == devPosType); |
| 30 |
out->appendf("sk_Position = %s.xy01;", devPos); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
void GrGLSLVertexBuilder::onFinalize() { |
| 35 |
// We could have the GrGeometryProcessor do this, but its just easier to have it performed |
| 36 |
// here. If we ever need to set variable pointsize, then we can reinvestigate. |
| 37 |
if (this->getProgramBuilder()->hasPointSize()) { |
| 38 |
this->codeAppend("sk_PointSize = 1.0;"); |
| 39 |
} |
| 40 |
fProgramBuilder->varyingHandler()->getVertexDecls(&this->inputs(), &this->outputs()); |
| 41 |
} |