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