| 1 | // |
| 2 | // Copyright (c) 2017 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // ClampPointSize.cpp: Limit the value that is written to gl_PointSize. |
| 7 | // |
| 8 | |
| 9 | #include "compiler/translator/tree_ops/ClampPointSize.h" |
| 10 | |
| 11 | #include "compiler/translator/SymbolTable.h" |
| 12 | #include "compiler/translator/tree_util/BuiltIn_autogen.h" |
| 13 | #include "compiler/translator/tree_util/FindSymbolNode.h" |
| 14 | #include "compiler/translator/tree_util/IntermNode_util.h" |
| 15 | #include "compiler/translator/tree_util/RunAtTheEndOfShader.h" |
| 16 | |
| 17 | namespace sh |
| 18 | { |
| 19 | |
| 20 | void ClampPointSize(TIntermBlock *root, float maxPointSize, TSymbolTable *symbolTable) |
| 21 | { |
| 22 | // Only clamp gl_PointSize if it's used in the shader. |
| 23 | if (!FindSymbolNode(root, ImmutableString("gl_PointSize" ))) |
| 24 | { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | TIntermSymbol *pointSizeNode = new TIntermSymbol(BuiltInVariable::gl_PointSize()); |
| 29 | |
| 30 | TConstantUnion *maxPointSizeConstant = new TConstantUnion(); |
| 31 | maxPointSizeConstant->setFConst(maxPointSize); |
| 32 | TIntermConstantUnion *maxPointSizeNode = |
| 33 | new TIntermConstantUnion(maxPointSizeConstant, TType(EbtFloat, EbpHigh, EvqConst)); |
| 34 | |
| 35 | // min(gl_PointSize, maxPointSize) |
| 36 | TIntermSequence *minArguments = new TIntermSequence(); |
| 37 | minArguments->push_back(pointSizeNode->deepCopy()); |
| 38 | minArguments->push_back(maxPointSizeNode); |
| 39 | TIntermTyped *clampedPointSize = |
| 40 | CreateBuiltInFunctionCallNode("min" , minArguments, *symbolTable, 100); |
| 41 | |
| 42 | // gl_PointSize = min(gl_PointSize, maxPointSize) |
| 43 | TIntermBinary *assignPointSize = new TIntermBinary(EOpAssign, pointSizeNode, clampedPointSize); |
| 44 | |
| 45 | RunAtTheEndOfShader(root, assignPointSize, symbolTable); |
| 46 | } |
| 47 | |
| 48 | } // namespace sh |
| 49 | |