blob: 928c0738f3287707632e04de66b9bd30b5733c2c [file] [log] [blame]
alokp@chromium.org76b82082010-03-24 17:59:39 +00001//
Jamie Madill02f20dd2013-09-12 12:07:42 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org76b82082010-03-24 17:59:39 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang17732822013-08-29 13:46:49 -04007#include "compiler/translator/OutputGLSL.h"
alokp@chromium.org76b82082010-03-24 17:59:39 +00008
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +00009TOutputGLSL::TOutputGLSL(TInfoSinkBase& objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000010 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000011 ShHashFunction64 hashFunction,
12 NameMap& nameMap,
Jamie Madill02f20dd2013-09-12 12:07:42 -040013 TSymbolTable& symbolTable,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080014 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080015 ShShaderOutput output,
16 ShCompileOptions compileOptions)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080017 : TOutputGLSLBase(objSink,
18 clampingStrategy,
19 hashFunction,
20 nameMap,
21 symbolTable,
22 shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080023 output,
24 compileOptions)
alokp@chromium.org76b82082010-03-24 17:59:39 +000025{
26}
27
zmo@google.com5601ea02011-06-10 18:23:25 +000028bool TOutputGLSL::writeVariablePrecision(TPrecision)
alokp@chromium.org76b82082010-03-24 17:59:39 +000029{
alokp@chromium.org76b82082010-03-24 17:59:39 +000030 return false;
31}
Jamie Madill2aeb26a2013-07-08 14:02:55 -040032
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080033void TOutputGLSL::visitSymbol(TIntermSymbol *node)
Jamie Madill2aeb26a2013-07-08 14:02:55 -040034{
35 TInfoSinkBase& out = objSink();
36
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080037 const TString &symbol = node->getSymbol();
38 if (symbol == "gl_FragDepthEXT")
Jamie Madill2aeb26a2013-07-08 14:02:55 -040039 {
40 out << "gl_FragDepth";
41 }
Qingqing Dengad0d0792015-04-08 14:25:06 -070042 else if (symbol == "gl_FragColor" && IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080043 {
44 out << "webgl_FragColor";
45 }
Qingqing Dengad0d0792015-04-08 14:25:06 -070046 else if (symbol == "gl_FragData" && IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080047 {
48 out << "webgl_FragData";
49 }
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030050 else if (symbol == "gl_SecondaryFragColorEXT")
51 {
52 out << "angle_SecondaryFragColor";
53 }
54 else if (symbol == "gl_SecondaryFragDataEXT")
55 {
56 out << "angle_SecondaryFragData";
57 }
Jamie Madill2aeb26a2013-07-08 14:02:55 -040058 else
59 {
60 TOutputGLSLBase::visitSymbol(node);
61 }
62}
Nicolas Capens46485082014-04-15 13:12:50 -040063
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080064TString TOutputGLSL::translateTextureFunction(TString &name)
Nicolas Capens46485082014-04-15 13:12:50 -040065{
66 static const char *simpleRename[] = {
67 "texture2DLodEXT", "texture2DLod",
68 "texture2DProjLodEXT", "texture2DProjLod",
69 "textureCubeLodEXT", "textureCubeLod",
70 "texture2DGradEXT", "texture2DGradARB",
71 "texture2DProjGradEXT", "texture2DProjGradARB",
72 "textureCubeGradEXT", "textureCubeGradARB",
73 NULL, NULL
74 };
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080075 static const char *legacyToCoreRename[] = {
76 "texture2D", "texture",
77 "texture2DProj", "textureProj",
78 "texture2DLod", "textureLod",
79 "texture2DProjLod", "textureProjLod",
Christopher Cameron7e921612015-10-01 14:00:04 -070080 "texture2DRect", "texture",
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080081 "textureCube", "texture",
82 "textureCubeLod", "textureLod",
83 // Extensions
84 "texture2DLodEXT", "textureLod",
85 "texture2DProjLodEXT", "textureProjLod",
86 "textureCubeLodEXT", "textureLod",
87 "texture2DGradEXT", "textureGrad",
88 "texture2DProjGradEXT", "textureProjGrad",
89 "textureCubeGradEXT", "textureGrad",
90 NULL, NULL
91 };
Qingqing Dengad0d0792015-04-08 14:25:06 -070092 const char **mapping = (IsGLSL130OrNewer(getShaderOutput())) ?
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080093 legacyToCoreRename : simpleRename;
Nicolas Capens46485082014-04-15 13:12:50 -040094
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080095 for (int i = 0; mapping[i] != NULL; i += 2)
96 {
97 if (name == mapping[i])
98 {
99 return mapping[i+1];
Nicolas Capens46485082014-04-15 13:12:50 -0400100 }
101 }
102
103 return name;
104}