blob: 5c214dd4fb04fa5fa10267f0c9edb14329d45e4f [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 Madill033dae62014-06-18 12:56:28 -040012#include "compiler/translator/Types.h"
Jamie Madillf51639a2014-06-25 16:04:57 -040013#include "angle_gl.h"
Jamie Madill033dae62014-06-18 12:56:28 -040014#include "common/shadervars.h"
15
Zhenyao Mof1d723c2013-09-23 14:57:07 -040016// atof_clamp is like atof but
17// 1. it forces C locale, i.e. forcing '.' as decimal point.
18// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
19// Return false if overflow happens.
20extern bool atof_clamp(const char *str, float *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000021
Zhenyao Mof1d723c2013-09-23 14:57:07 -040022// If overflow happens, clamp the value to INT_MIN or INT_MAX.
23// Return false if overflow happens.
24extern bool atoi_clamp(const char *str, int *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000025
Jamie Madill033dae62014-06-18 12:56:28 -040026namespace sh
27{
28
29GLenum GLVariableType(const TType &type);
30GLenum GLVariablePrecision(const TType &type);
31bool IsVaryingIn(TQualifier qualifier);
32bool IsVaryingOut(TQualifier qualifier);
33bool IsVarying(TQualifier qualifier);
Jamie Madillf2575982014-06-25 16:04:54 -040034InterpolationType GetInterpolationType(TQualifier qualifier);
Jamie Madilld5512cd2014-07-10 17:50:08 -040035BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage);
Jamie Madill033dae62014-06-18 12:56:28 -040036TString ArrayString(const TType &type);
37
Jamie Madill77f74852014-07-08 15:02:34 -040038template <typename VarT>
39class GetVariableTraverser
40{
41 public:
Jamie Madill28f70c32014-07-18 10:33:10 -040042 GetVariableTraverser(std::vector<VarT> *output);
Jamie Madill77f74852014-07-08 15:02:34 -040043 void traverse(const TType &type, const TString &name);
44
45 protected:
Jamie Madill28f70c32014-07-18 10:33:10 -040046 // May be overloaded
47 virtual void visitVariable(VarT *newVar) {}
Jamie Madill77f74852014-07-08 15:02:34 -040048
49 private:
50 std::stack<std::vector<VarT> *> mOutputStack;
51};
52
53struct GetInterfaceBlockFieldTraverser : public GetVariableTraverser<InterfaceBlockField>
54{
55 public:
56 GetInterfaceBlockFieldTraverser(std::vector<InterfaceBlockField> *output, bool isRowMajorMatrix);
57
58 private:
59 virtual void visitVariable(InterfaceBlockField *newField);
60
61 bool mIsRowMajorMatrix;
62};
63
Jamie Madill033dae62014-06-18 12:56:28 -040064}
65
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000066#endif // COMPILER_UTIL_H