blob: 1bad05dab9354c56d75a2661fd748435bffcbfd7 [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
Olli Etuahocccf2b02017-07-05 14:50:54 +03009#include "compiler/translator/Compiler.h"
10
Jamie Madill45bcc782016-11-07 13:58:48 -050011namespace sh
12{
13
Qiankun Miao89dd8f32016-11-09 12:59:30 +000014TOutputGLSL::TOutputGLSL(TInfoSinkBase &objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000015 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000016 ShHashFunction64 hashFunction,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000017 NameMap &nameMap,
Olli Etuahoa5e693a2017-07-13 16:07:26 +030018 TSymbolTable *symbolTable,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000019 sh::GLenum shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080020 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080021 ShShaderOutput output,
22 ShCompileOptions compileOptions)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080023 : TOutputGLSLBase(objSink,
24 clampingStrategy,
25 hashFunction,
26 nameMap,
27 symbolTable,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000028 shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080029 shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080030 output,
31 compileOptions)
alokp@chromium.org76b82082010-03-24 17:59:39 +000032{
33}
34
zmo@google.com5601ea02011-06-10 18:23:25 +000035bool TOutputGLSL::writeVariablePrecision(TPrecision)
alokp@chromium.org76b82082010-03-24 17:59:39 +000036{
alokp@chromium.org76b82082010-03-24 17:59:39 +000037 return false;
38}
Jamie Madill2aeb26a2013-07-08 14:02:55 -040039
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080040void TOutputGLSL::visitSymbol(TIntermSymbol *node)
Jamie Madill2aeb26a2013-07-08 14:02:55 -040041{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050042 TInfoSinkBase &out = objSink();
Jamie Madill2aeb26a2013-07-08 14:02:55 -040043
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080044 const TString &symbol = node->getSymbol();
45 if (symbol == "gl_FragDepthEXT")
Jamie Madill2aeb26a2013-07-08 14:02:55 -040046 {
47 out << "gl_FragDepth";
48 }
Jamie Madillacb4b812016-11-07 13:50:29 -050049 else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080050 {
51 out << "webgl_FragColor";
52 }
Jamie Madillacb4b812016-11-07 13:50:29 -050053 else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080054 {
55 out << "webgl_FragData";
56 }
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030057 else if (symbol == "gl_SecondaryFragColorEXT")
58 {
59 out << "angle_SecondaryFragColor";
60 }
61 else if (symbol == "gl_SecondaryFragDataEXT")
62 {
63 out << "angle_SecondaryFragData";
64 }
Jamie Madill2aeb26a2013-07-08 14:02:55 -040065 else
66 {
67 TOutputGLSLBase::visitSymbol(node);
68 }
69}
Nicolas Capens46485082014-04-15 13:12:50 -040070
Olli Etuahoec9232b2017-03-27 17:01:37 +030071TString TOutputGLSL::translateTextureFunction(const TString &name)
Nicolas Capens46485082014-04-15 13:12:50 -040072{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050073 static const char *simpleRename[] = {"texture2DLodEXT",
74 "texture2DLod",
75 "texture2DProjLodEXT",
76 "texture2DProjLod",
77 "textureCubeLodEXT",
78 "textureCubeLod",
79 "texture2DGradEXT",
80 "texture2DGradARB",
81 "texture2DProjGradEXT",
82 "texture2DProjGradARB",
83 "textureCubeGradEXT",
84 "textureCubeGradARB",
Yunchao Hef81ce4a2017-04-24 10:49:17 +080085 nullptr,
86 nullptr};
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080087 static const char *legacyToCoreRename[] = {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050088 "texture2D", "texture", "texture2DProj", "textureProj", "texture2DLod", "textureLod",
89 "texture2DProjLod", "textureProjLod", "texture2DRect", "texture", "textureCube", "texture",
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080090 "textureCubeLod", "textureLod",
91 // Extensions
Jamie Madilld7b1ab52016-12-12 14:42:19 -050092 "texture2DLodEXT", "textureLod", "texture2DProjLodEXT", "textureProjLod",
93 "textureCubeLodEXT", "textureLod", "texture2DGradEXT", "textureGrad",
Yunchao Hef81ce4a2017-04-24 10:49:17 +080094 "texture2DProjGradEXT", "textureProjGrad", "textureCubeGradEXT", "textureGrad", nullptr,
95 nullptr};
Jamie Madillacb4b812016-11-07 13:50:29 -050096 const char **mapping =
97 (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename;
Nicolas Capens46485082014-04-15 13:12:50 -040098
Yunchao He4f285442017-04-21 12:15:49 +080099 for (int i = 0; mapping[i] != nullptr; i += 2)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -0800100 {
101 if (name == mapping[i])
102 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500103 return mapping[i + 1];
Nicolas Capens46485082014-04-15 13:12:50 -0400104 }
105 }
106
107 return name;
108}
Jamie Madill45bcc782016-11-07 13:58:48 -0500109
110} // namespace sh