blob: 95e355b092373a8ff622bf7f724a12c7d9b05c90 [file] [log] [blame]
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00001//
2// Copyright (c) 2002-2010 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
7#ifndef COMPILER_UTIL_H
8#define COMPILER_UTIL_H
9
Jamie Madill77f74852014-07-08 15:02:34 -040010#include <stack>
11
Jamie Madillf51639a2014-06-25 16:04:57 -040012#include "angle_gl.h"
Jamie Madill13cfd272014-07-17 14:16:28 -040013#include <GLSLANG/ShaderVars.h>
14
15#include "compiler/translator/Types.h"
Jamie Madill033dae62014-06-18 12:56:28 -040016
Zhenyao Mof1d723c2013-09-23 14:57:07 -040017// atof_clamp is like atof but
18// 1. it forces C locale, i.e. forcing '.' as decimal point.
19// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
20// Return false if overflow happens.
21extern bool atof_clamp(const char *str, float *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000022
Zhenyao Mof1d723c2013-09-23 14:57:07 -040023// If overflow happens, clamp the value to INT_MIN or INT_MAX.
24// Return false if overflow happens.
25extern bool atoi_clamp(const char *str, int *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000026
Jamie Madill033dae62014-06-18 12:56:28 -040027namespace sh
28{
29
30GLenum GLVariableType(const TType &type);
31GLenum GLVariablePrecision(const TType &type);
32bool IsVaryingIn(TQualifier qualifier);
33bool IsVaryingOut(TQualifier qualifier);
34bool IsVarying(TQualifier qualifier);
Jamie Madillf2575982014-06-25 16:04:54 -040035InterpolationType GetInterpolationType(TQualifier qualifier);
Jamie Madilld5512cd2014-07-10 17:50:08 -040036BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage);
Jamie Madill033dae62014-06-18 12:56:28 -040037TString ArrayString(const TType &type);
38
Jamie Madill77f74852014-07-08 15:02:34 -040039template <typename VarT>
40class GetVariableTraverser
41{
42 public:
Jamie Madill28f70c32014-07-18 10:33:10 -040043 GetVariableTraverser(std::vector<VarT> *output);
Jamie Madill77f74852014-07-08 15:02:34 -040044 void traverse(const TType &type, const TString &name);
45
46 protected:
Jamie Madill28f70c32014-07-18 10:33:10 -040047 // May be overloaded
48 virtual void visitVariable(VarT *newVar) {}
Jamie Madill77f74852014-07-08 15:02:34 -040049
50 private:
51 std::stack<std::vector<VarT> *> mOutputStack;
52};
53
54struct GetInterfaceBlockFieldTraverser : public GetVariableTraverser<InterfaceBlockField>
55{
56 public:
57 GetInterfaceBlockFieldTraverser(std::vector<InterfaceBlockField> *output, bool isRowMajorMatrix);
58
59 private:
60 virtual void visitVariable(InterfaceBlockField *newField);
61
62 bool mIsRowMajorMatrix;
63};
64
Jamie Madill033dae62014-06-18 12:56:28 -040065}
66
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000067#endif // COMPILER_UTIL_H