blob: 6b2d59fc0426838ef2cf7b794d3d9e860b87ae98 [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
Jamie Madill45bcc782016-11-07 13:58:48 -05009namespace sh
10{
11
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000012TOutputGLSL::TOutputGLSL(TInfoSinkBase& objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000013 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000014 ShHashFunction64 hashFunction,
15 NameMap& nameMap,
Jamie Madill02f20dd2013-09-12 12:07:42 -040016 TSymbolTable& symbolTable,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080017 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080018 ShShaderOutput output,
19 ShCompileOptions compileOptions)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080020 : TOutputGLSLBase(objSink,
21 clampingStrategy,
22 hashFunction,
23 nameMap,
24 symbolTable,
25 shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080026 output,
27 compileOptions)
alokp@chromium.org76b82082010-03-24 17:59:39 +000028{
29}
30
zmo@google.com5601ea02011-06-10 18:23:25 +000031bool TOutputGLSL::writeVariablePrecision(TPrecision)
alokp@chromium.org76b82082010-03-24 17:59:39 +000032{
alokp@chromium.org76b82082010-03-24 17:59:39 +000033 return false;
34}
Jamie Madill2aeb26a2013-07-08 14:02:55 -040035
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080036void TOutputGLSL::visitSymbol(TIntermSymbol *node)
Jamie Madill2aeb26a2013-07-08 14:02:55 -040037{
38 TInfoSinkBase& out = objSink();
39
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080040 const TString &symbol = node->getSymbol();
41 if (symbol == "gl_FragDepthEXT")
Jamie Madill2aeb26a2013-07-08 14:02:55 -040042 {
43 out << "gl_FragDepth";
44 }
Jamie Madillacb4b812016-11-07 13:50:29 -050045 else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080046 {
47 out << "webgl_FragColor";
48 }
Jamie Madillacb4b812016-11-07 13:50:29 -050049 else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080050 {
51 out << "webgl_FragData";
52 }
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030053 else if (symbol == "gl_SecondaryFragColorEXT")
54 {
55 out << "angle_SecondaryFragColor";
56 }
57 else if (symbol == "gl_SecondaryFragDataEXT")
58 {
59 out << "angle_SecondaryFragData";
60 }
Jamie Madill2aeb26a2013-07-08 14:02:55 -040061 else
62 {
63 TOutputGLSLBase::visitSymbol(node);
64 }
65}
Nicolas Capens46485082014-04-15 13:12:50 -040066
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080067TString TOutputGLSL::translateTextureFunction(TString &name)
Nicolas Capens46485082014-04-15 13:12:50 -040068{
69 static const char *simpleRename[] = {
70 "texture2DLodEXT", "texture2DLod",
71 "texture2DProjLodEXT", "texture2DProjLod",
72 "textureCubeLodEXT", "textureCubeLod",
73 "texture2DGradEXT", "texture2DGradARB",
74 "texture2DProjGradEXT", "texture2DProjGradARB",
75 "textureCubeGradEXT", "textureCubeGradARB",
76 NULL, NULL
77 };
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080078 static const char *legacyToCoreRename[] = {
79 "texture2D", "texture",
80 "texture2DProj", "textureProj",
81 "texture2DLod", "textureLod",
82 "texture2DProjLod", "textureProjLod",
Christopher Cameron7e921612015-10-01 14:00:04 -070083 "texture2DRect", "texture",
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080084 "textureCube", "texture",
85 "textureCubeLod", "textureLod",
86 // Extensions
87 "texture2DLodEXT", "textureLod",
88 "texture2DProjLodEXT", "textureProjLod",
89 "textureCubeLodEXT", "textureLod",
90 "texture2DGradEXT", "textureGrad",
91 "texture2DProjGradEXT", "textureProjGrad",
92 "textureCubeGradEXT", "textureGrad",
93 NULL, NULL
94 };
Jamie Madillacb4b812016-11-07 13:50:29 -050095 const char **mapping =
96 (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename;
Nicolas Capens46485082014-04-15 13:12:50 -040097
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080098 for (int i = 0; mapping[i] != NULL; i += 2)
99 {
100 if (name == mapping[i])
101 {
102 return mapping[i+1];
Nicolas Capens46485082014-04-15 13:12:50 -0400103 }
104 }
105
106 return name;
107}
Jamie Madill45bcc782016-11-07 13:58:48 -0500108
109} // namespace sh