• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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.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 
ClampPointSize(TCompiler * compiler,TIntermBlock * root,float minPointSize,float maxPointSize,TSymbolTable * symbolTable)20 bool ClampPointSize(TCompiler *compiler,
21                     TIntermBlock *root,
22                     float minPointSize,
23                     float maxPointSize,
24                     TSymbolTable *symbolTable)
25 {
26     // Only clamp gl_PointSize if it's used in the shader.
27     const TIntermSymbol *glPointSize = FindSymbolNode(root, ImmutableString("gl_PointSize"));
28     if (glPointSize == nullptr)
29     {
30         return true;
31     }
32 
33     TIntermTyped *pointSizeNode = glPointSize->deepCopy();
34 
35     TConstantUnion *minPointSizeConstant = new TConstantUnion();
36     TConstantUnion *maxPointSizeConstant = new TConstantUnion();
37     minPointSizeConstant->setFConst(minPointSize);
38     maxPointSizeConstant->setFConst(maxPointSize);
39     TIntermConstantUnion *minPointSizeNode =
40         new TIntermConstantUnion(minPointSizeConstant, TType(EbtFloat, EbpHigh, EvqConst));
41     TIntermConstantUnion *maxPointSizeNode =
42         new TIntermConstantUnion(maxPointSizeConstant, TType(EbtFloat, EbpHigh, EvqConst));
43 
44     // clamp(gl_PointSize, minPointSize, maxPointSize)
45     TIntermSequence clampArguments;
46     clampArguments.push_back(pointSizeNode->deepCopy());
47     clampArguments.push_back(minPointSizeNode);
48     clampArguments.push_back(maxPointSizeNode);
49     TIntermTyped *clampedPointSize =
50         CreateBuiltInFunctionCallNode("clamp", &clampArguments, *symbolTable, 100);
51 
52     // gl_PointSize = clamp(gl_PointSize, minPointSize, maxPointSize)
53     TIntermBinary *assignPointSize = new TIntermBinary(EOpAssign, pointSizeNode, clampedPointSize);
54 
55     return RunAtTheEndOfShader(compiler, root, assignPointSize, symbolTable);
56 }
57 
58 }  // namespace sh
59