blob: 431425020a741c006bde96a5257d0038906ad258 [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,
15 ShShaderOutput output)
16 : TOutputGLSLBase(objSink,
17 clampingStrategy,
18 hashFunction,
19 nameMap,
20 symbolTable,
21 shaderVersion,
22 output)
alokp@chromium.org76b82082010-03-24 17:59:39 +000023{
24}
25
zmo@google.com5601ea02011-06-10 18:23:25 +000026bool TOutputGLSL::writeVariablePrecision(TPrecision)
alokp@chromium.org76b82082010-03-24 17:59:39 +000027{
alokp@chromium.org76b82082010-03-24 17:59:39 +000028 return false;
29}
Jamie Madill2aeb26a2013-07-08 14:02:55 -040030
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080031void TOutputGLSL::visitSymbol(TIntermSymbol *node)
Jamie Madill2aeb26a2013-07-08 14:02:55 -040032{
33 TInfoSinkBase& out = objSink();
34
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080035 const TString &symbol = node->getSymbol();
36 if (symbol == "gl_FragDepthEXT")
Jamie Madill2aeb26a2013-07-08 14:02:55 -040037 {
38 out << "gl_FragDepth";
39 }
Qingqing Dengad0d0792015-04-08 14:25:06 -070040 else if (symbol == "gl_FragColor" && IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080041 {
42 out << "webgl_FragColor";
43 }
Qingqing Dengad0d0792015-04-08 14:25:06 -070044 else if (symbol == "gl_FragData" && IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080045 {
46 out << "webgl_FragData";
47 }
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030048 else if (symbol == "gl_SecondaryFragColorEXT")
49 {
50 out << "angle_SecondaryFragColor";
51 }
52 else if (symbol == "gl_SecondaryFragDataEXT")
53 {
54 out << "angle_SecondaryFragData";
55 }
Jamie Madill2aeb26a2013-07-08 14:02:55 -040056 else
57 {
58 TOutputGLSLBase::visitSymbol(node);
59 }
60}
Nicolas Capens46485082014-04-15 13:12:50 -040061
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080062TString TOutputGLSL::translateTextureFunction(TString &name)
Nicolas Capens46485082014-04-15 13:12:50 -040063{
64 static const char *simpleRename[] = {
65 "texture2DLodEXT", "texture2DLod",
66 "texture2DProjLodEXT", "texture2DProjLod",
67 "textureCubeLodEXT", "textureCubeLod",
68 "texture2DGradEXT", "texture2DGradARB",
69 "texture2DProjGradEXT", "texture2DProjGradARB",
70 "textureCubeGradEXT", "textureCubeGradARB",
71 NULL, NULL
72 };
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080073 static const char *legacyToCoreRename[] = {
74 "texture2D", "texture",
75 "texture2DProj", "textureProj",
76 "texture2DLod", "textureLod",
77 "texture2DProjLod", "textureProjLod",
Christopher Cameron7e921612015-10-01 14:00:04 -070078 "texture2DRect", "texture",
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080079 "textureCube", "texture",
80 "textureCubeLod", "textureLod",
81 // Extensions
82 "texture2DLodEXT", "textureLod",
83 "texture2DProjLodEXT", "textureProjLod",
84 "textureCubeLodEXT", "textureLod",
85 "texture2DGradEXT", "textureGrad",
86 "texture2DProjGradEXT", "textureProjGrad",
87 "textureCubeGradEXT", "textureGrad",
88 NULL, NULL
89 };
Qingqing Dengad0d0792015-04-08 14:25:06 -070090 const char **mapping = (IsGLSL130OrNewer(getShaderOutput())) ?
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080091 legacyToCoreRename : simpleRename;
Nicolas Capens46485082014-04-15 13:12:50 -040092
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080093 for (int i = 0; mapping[i] != NULL; i += 2)
94 {
95 if (name == mapping[i])
96 {
97 return mapping[i+1];
Nicolas Capens46485082014-04-15 13:12:50 -040098 }
99 }
100
101 return name;
102}