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 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 9 | TOutputGLSL::TOutputGLSL(TInfoSinkBase& objSink, |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 10 | ShArrayIndexClampingStrategy clampingStrategy, |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 11 | ShHashFunction64 hashFunction, |
| 12 | NameMap& nameMap, |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 13 | TSymbolTable& symbolTable, |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 14 | int shaderVersion, |
| 15 | ShShaderOutput output) |
| 16 | : TOutputGLSLBase(objSink, |
| 17 | clampingStrategy, |
| 18 | hashFunction, |
| 19 | nameMap, |
| 20 | symbolTable, |
| 21 | shaderVersion, |
| 22 | output) |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 23 | { |
| 24 | } |
| 25 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 26 | bool TOutputGLSL::writeVariablePrecision(TPrecision) |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 27 | { |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 28 | return false; |
| 29 | } |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 30 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 31 | void TOutputGLSL::visitSymbol(TIntermSymbol *node) |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 32 | { |
| 33 | TInfoSinkBase& out = objSink(); |
| 34 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 35 | const TString &symbol = node->getSymbol(); |
| 36 | if (symbol == "gl_FragDepthEXT") |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 37 | { |
| 38 | out << "gl_FragDepth"; |
| 39 | } |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 40 | else if (symbol == "gl_FragColor" && IsGLSL130OrNewer(getShaderOutput())) |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 41 | { |
| 42 | out << "webgl_FragColor"; |
| 43 | } |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 44 | else if (symbol == "gl_FragData" && IsGLSL130OrNewer(getShaderOutput())) |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 45 | { |
| 46 | out << "webgl_FragData"; |
| 47 | } |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 48 | else if (symbol == "gl_SecondaryFragColorEXT") |
| 49 | { |
| 50 | out << "angle_SecondaryFragColor"; |
| 51 | } |
| 52 | else if (symbol == "gl_SecondaryFragDataEXT") |
| 53 | { |
| 54 | out << "angle_SecondaryFragData"; |
| 55 | } |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 56 | else |
| 57 | { |
| 58 | TOutputGLSLBase::visitSymbol(node); |
| 59 | } |
| 60 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 61 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 62 | TString TOutputGLSL::translateTextureFunction(TString &name) |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 63 | { |
| 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 Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 73 | static const char *legacyToCoreRename[] = { |
| 74 | "texture2D", "texture", |
| 75 | "texture2DProj", "textureProj", |
| 76 | "texture2DLod", "textureLod", |
| 77 | "texture2DProjLod", "textureProjLod", |
Christopher Cameron | 7e92161 | 2015-10-01 14:00:04 -0700 | [diff] [blame] | 78 | "texture2DRect", "texture", |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 79 | "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 Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 90 | const char **mapping = (IsGLSL130OrNewer(getShaderOutput())) ? |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 91 | legacyToCoreRename : simpleRename; |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 92 | |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 93 | for (int i = 0; mapping[i] != NULL; i += 2) |
| 94 | { |
| 95 | if (name == mapping[i]) |
| 96 | { |
| 97 | return mapping[i+1]; |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | return name; |
| 102 | } |