blob: 5a7de9382850cfdf6d04d616c58f037a9c1dd1f2 [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
Qiankun Miao89dd8f32016-11-09 12:59:30 +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,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000015 NameMap &nameMap,
16 TSymbolTable &symbolTable,
17 sh::GLenum shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080018 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080019 ShShaderOutput output,
20 ShCompileOptions compileOptions)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080021 : TOutputGLSLBase(objSink,
22 clampingStrategy,
23 hashFunction,
24 nameMap,
25 symbolTable,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000026 shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080027 shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080028 output,
29 compileOptions)
alokp@chromium.org76b82082010-03-24 17:59:39 +000030{
31}
32
zmo@google.com5601ea02011-06-10 18:23:25 +000033bool TOutputGLSL::writeVariablePrecision(TPrecision)
alokp@chromium.org76b82082010-03-24 17:59:39 +000034{
alokp@chromium.org76b82082010-03-24 17:59:39 +000035 return false;
36}
Jamie Madill2aeb26a2013-07-08 14:02:55 -040037
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080038void TOutputGLSL::visitSymbol(TIntermSymbol *node)
Jamie Madill2aeb26a2013-07-08 14:02:55 -040039{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050040 TInfoSinkBase &out = objSink();
Jamie Madill2aeb26a2013-07-08 14:02:55 -040041
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080042 const TString &symbol = node->getSymbol();
43 if (symbol == "gl_FragDepthEXT")
Jamie Madill2aeb26a2013-07-08 14:02:55 -040044 {
45 out << "gl_FragDepth";
46 }
Jamie Madillacb4b812016-11-07 13:50:29 -050047 else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080048 {
49 out << "webgl_FragColor";
50 }
Jamie Madillacb4b812016-11-07 13:50:29 -050051 else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput()))
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080052 {
53 out << "webgl_FragData";
54 }
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +030055 else if (symbol == "gl_SecondaryFragColorEXT")
56 {
57 out << "angle_SecondaryFragColor";
58 }
59 else if (symbol == "gl_SecondaryFragDataEXT")
60 {
61 out << "angle_SecondaryFragData";
62 }
Jamie Madill2aeb26a2013-07-08 14:02:55 -040063 else
64 {
65 TOutputGLSLBase::visitSymbol(node);
66 }
67}
Nicolas Capens46485082014-04-15 13:12:50 -040068
Olli Etuahoec9232b2017-03-27 17:01:37 +030069TString TOutputGLSL::translateTextureFunction(const TString &name)
Nicolas Capens46485082014-04-15 13:12:50 -040070{
Jamie Madilld7b1ab52016-12-12 14:42:19 -050071 static const char *simpleRename[] = {"texture2DLodEXT",
72 "texture2DLod",
73 "texture2DProjLodEXT",
74 "texture2DProjLod",
75 "textureCubeLodEXT",
76 "textureCubeLod",
77 "texture2DGradEXT",
78 "texture2DGradARB",
79 "texture2DProjGradEXT",
80 "texture2DProjGradARB",
81 "textureCubeGradEXT",
82 "textureCubeGradARB",
Yunchao Hef81ce4a2017-04-24 10:49:17 +080083 nullptr,
84 nullptr};
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080085 static const char *legacyToCoreRename[] = {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050086 "texture2D", "texture", "texture2DProj", "textureProj", "texture2DLod", "textureLod",
87 "texture2DProjLod", "textureProjLod", "texture2DRect", "texture", "textureCube", "texture",
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080088 "textureCubeLod", "textureLod",
89 // Extensions
Jamie Madilld7b1ab52016-12-12 14:42:19 -050090 "texture2DLodEXT", "textureLod", "texture2DProjLodEXT", "textureProjLod",
91 "textureCubeLodEXT", "textureLod", "texture2DGradEXT", "textureGrad",
Yunchao Hef81ce4a2017-04-24 10:49:17 +080092 "texture2DProjGradEXT", "textureProjGrad", "textureCubeGradEXT", "textureGrad", nullptr,
93 nullptr};
Jamie Madillacb4b812016-11-07 13:50:29 -050094 const char **mapping =
95 (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename;
Nicolas Capens46485082014-04-15 13:12:50 -040096
Yunchao He4f285442017-04-21 12:15:49 +080097 for (int i = 0; mapping[i] != nullptr; i += 2)
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080098 {
99 if (name == mapping[i])
100 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500101 return mapping[i + 1];
Nicolas Capens46485082014-04-15 13:12:50 -0400102 }
103 }
104
105 return name;
106}
Jamie Madill45bcc782016-11-07 13:58:48 -0500107
108} // namespace sh