alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/OutputGLSL.h" |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 8 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 9 | namespace sh |
| 10 | { |
| 11 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 12 | TOutputGLSL::TOutputGLSL(TInfoSinkBase& objSink, |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 13 | ShArrayIndexClampingStrategy clampingStrategy, |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 14 | ShHashFunction64 hashFunction, |
| 15 | NameMap& nameMap, |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 16 | TSymbolTable& symbolTable, |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 17 | int shaderVersion, |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 18 | ShShaderOutput output, |
| 19 | ShCompileOptions compileOptions) |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 20 | : TOutputGLSLBase(objSink, |
| 21 | clampingStrategy, |
| 22 | hashFunction, |
| 23 | nameMap, |
| 24 | symbolTable, |
| 25 | shaderVersion, |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 26 | output, |
| 27 | compileOptions) |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 31 | bool TOutputGLSL::writeVariablePrecision(TPrecision) |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 32 | { |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 33 | return false; |
| 34 | } |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 35 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 36 | void TOutputGLSL::visitSymbol(TIntermSymbol *node) |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 37 | { |
| 38 | TInfoSinkBase& out = objSink(); |
| 39 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 40 | const TString &symbol = node->getSymbol(); |
| 41 | if (symbol == "gl_FragDepthEXT") |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 42 | { |
| 43 | out << "gl_FragDepth"; |
| 44 | } |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 45 | else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput())) |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 46 | { |
| 47 | out << "webgl_FragColor"; |
| 48 | } |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 49 | else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput())) |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 50 | { |
| 51 | out << "webgl_FragData"; |
| 52 | } |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 53 | else if (symbol == "gl_SecondaryFragColorEXT") |
| 54 | { |
| 55 | out << "angle_SecondaryFragColor"; |
| 56 | } |
| 57 | else if (symbol == "gl_SecondaryFragDataEXT") |
| 58 | { |
| 59 | out << "angle_SecondaryFragData"; |
| 60 | } |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 61 | else |
| 62 | { |
| 63 | TOutputGLSLBase::visitSymbol(node); |
| 64 | } |
| 65 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 66 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 67 | TString TOutputGLSL::translateTextureFunction(TString &name) |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 68 | { |
| 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 Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 78 | static const char *legacyToCoreRename[] = { |
| 79 | "texture2D", "texture", |
| 80 | "texture2DProj", "textureProj", |
| 81 | "texture2DLod", "textureLod", |
| 82 | "texture2DProjLod", "textureProjLod", |
Christopher Cameron | 7e92161 | 2015-10-01 14:00:04 -0700 | [diff] [blame] | 83 | "texture2DRect", "texture", |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 84 | "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 Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 95 | const char **mapping = |
| 96 | (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename; |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 97 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 98 | for (int i = 0; mapping[i] != NULL; i += 2) |
| 99 | { |
| 100 | if (name == mapping[i]) |
| 101 | { |
| 102 | return mapping[i+1]; |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | return name; |
| 107 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 108 | |
| 109 | } // namespace sh |