Line data Source code
1 : //
2 : // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 : // Use of this source code is governed by a BSD-style license that can be
4 : // found in the LICENSE file.
5 : //
6 :
7 : #include "compiler/translator/OutputGLSL.h"
8 :
9 : namespace sh
10 : {
11 :
12 0 : TOutputGLSL::TOutputGLSL(TInfoSinkBase &objSink,
13 : ShArrayIndexClampingStrategy clampingStrategy,
14 : ShHashFunction64 hashFunction,
15 : NameMap &nameMap,
16 : TSymbolTable &symbolTable,
17 : sh::GLenum shaderType,
18 : int shaderVersion,
19 : ShShaderOutput output,
20 0 : ShCompileOptions compileOptions)
21 : : TOutputGLSLBase(objSink,
22 : clampingStrategy,
23 : hashFunction,
24 : nameMap,
25 : symbolTable,
26 : shaderType,
27 : shaderVersion,
28 : output,
29 0 : compileOptions)
30 : {
31 0 : }
32 :
33 0 : bool TOutputGLSL::writeVariablePrecision(TPrecision)
34 : {
35 0 : return false;
36 : }
37 :
38 0 : void TOutputGLSL::visitSymbol(TIntermSymbol *node)
39 : {
40 0 : TInfoSinkBase& out = objSink();
41 :
42 0 : const TString &symbol = node->getSymbol();
43 0 : if (symbol == "gl_FragDepthEXT")
44 : {
45 0 : out << "gl_FragDepth";
46 : }
47 0 : else if (symbol == "gl_FragColor" && sh::IsGLSL130OrNewer(getShaderOutput()))
48 : {
49 0 : out << "webgl_FragColor";
50 : }
51 0 : else if (symbol == "gl_FragData" && sh::IsGLSL130OrNewer(getShaderOutput()))
52 : {
53 0 : out << "webgl_FragData";
54 : }
55 0 : else if (symbol == "gl_SecondaryFragColorEXT")
56 : {
57 0 : out << "angle_SecondaryFragColor";
58 : }
59 0 : else if (symbol == "gl_SecondaryFragDataEXT")
60 : {
61 0 : out << "angle_SecondaryFragData";
62 : }
63 : else
64 : {
65 0 : TOutputGLSLBase::visitSymbol(node);
66 : }
67 0 : }
68 :
69 0 : TString TOutputGLSL::translateTextureFunction(TString &name)
70 : {
71 : static const char *simpleRename[] = {
72 : "texture2DLodEXT", "texture2DLod",
73 : "texture2DProjLodEXT", "texture2DProjLod",
74 : "textureCubeLodEXT", "textureCubeLod",
75 : "texture2DGradEXT", "texture2DGradARB",
76 : "texture2DProjGradEXT", "texture2DProjGradARB",
77 : "textureCubeGradEXT", "textureCubeGradARB",
78 : NULL, NULL
79 : };
80 : static const char *legacyToCoreRename[] = {
81 : "texture2D", "texture",
82 : "texture2DProj", "textureProj",
83 : "texture2DLod", "textureLod",
84 : "texture2DProjLod", "textureProjLod",
85 : "texture2DRect", "texture",
86 : "textureCube", "texture",
87 : "textureCubeLod", "textureLod",
88 : // Extensions
89 : "texture2DLodEXT", "textureLod",
90 : "texture2DProjLodEXT", "textureProjLod",
91 : "textureCubeLodEXT", "textureLod",
92 : "texture2DGradEXT", "textureGrad",
93 : "texture2DProjGradEXT", "textureProjGrad",
94 : "textureCubeGradEXT", "textureGrad",
95 : NULL, NULL
96 : };
97 : const char **mapping =
98 0 : (sh::IsGLSL130OrNewer(getShaderOutput())) ? legacyToCoreRename : simpleRename;
99 :
100 0 : for (int i = 0; mapping[i] != NULL; i += 2)
101 : {
102 0 : if (name == mapping[i])
103 : {
104 0 : return mapping[i+1];
105 : }
106 : }
107 :
108 0 : return name;
109 : }
110 :
111 : } // namespace sh
|