OSDN Git Service

Increment the version number.
[android-x86/external-swiftshader.git] / src / Radiance / compiler / ShaderLang.cpp
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 //
8 // Implement the top-level of interface to the compiler,
9 // as defined in ShaderLang.h
10 //
11
12 #include "GLSLANG/ShaderLang.h"
13
14 #include "compiler/InitializeDll.h"
15 #include "compiler/preprocessor/length_limits.h"
16 #include "compiler/ShHandle.h"
17
18 #include <limits.h>
19
20 //
21 // Driver must call this first, once, before doing any other
22 // compiler operations.
23 //
24 int ShInitialize()
25 {
26     return InitProcess() ? 1 : 0;
27 }
28
29 //
30 // Cleanup symbol tables
31 //
32 int ShFinalize()
33 {
34     DetachProcess();
35     return 1;
36 }
37
38 //
39 // Initialize built-in resources with minimum expected values.
40 //
41 void ShInitBuiltInResources(ShBuiltInResources* resources)
42 {
43     // Constants.
44     resources->MaxVertexAttribs = 8;
45     resources->MaxVertexUniformVectors = 128;
46     resources->MaxVaryingVectors = 8;
47     resources->MaxVertexTextureImageUnits = 0;
48     resources->MaxCombinedTextureImageUnits = 8;
49     resources->MaxTextureImageUnits = 8;
50     resources->MaxFragmentUniformVectors = 16;
51     resources->MaxDrawBuffers = 1;
52
53     // Extensions.
54     resources->OES_standard_derivatives = 0;
55         resources->OES_fragment_precision_high = 0;
56     resources->OES_EGL_image_external = 0;
57
58         resources->MaxCallStackDepth = UINT_MAX;
59 }
60
61 //
62 // Driver calls these to create and destroy compiler objects.
63 //
64 ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
65                              const ShBuiltInResources* resources)
66 {
67     TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec));
68     TCompiler* compiler = base->getAsCompiler();
69     if (compiler == 0)
70         return 0;
71
72     // Generate built-in symbol table.
73     if (!compiler->Init(*resources)) {
74         ShDestruct(base);
75         return 0;
76     }
77
78     return reinterpret_cast<void*>(base);
79 }
80
81 void ShDestruct(ShHandle handle)
82 {
83     if (handle == 0)
84         return;
85
86     TShHandleBase* base = static_cast<TShHandleBase*>(handle);
87
88     if (base->getAsCompiler())
89         DeleteCompiler(base->getAsCompiler());
90 }
91
92 //
93 // Do an actual compile on the given strings.  The result is left 
94 // in the given compile object.
95 //
96 // Return:  The return value of ShCompile is really boolean, indicating
97 // success or failure.
98 //
99 int ShCompile(
100     const ShHandle handle,
101     const char* const shaderStrings[],
102     const int numStrings,
103     int compileOptions)
104 {
105     if (handle == 0)
106         return 0;
107
108     TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
109     TCompiler* compiler = base->getAsCompiler();
110     if (compiler == 0)
111         return 0;
112
113     bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
114     return success ? 1 : 0;
115 }
116
117 void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
118 {
119     if (!handle || !params)
120         return;
121
122     TShHandleBase* base = static_cast<TShHandleBase*>(handle);
123     TCompiler* compiler = base->getAsCompiler();
124     if (!compiler) return;
125
126     switch(pname)
127     {
128     case SH_INFO_LOG_LENGTH:
129         *params = compiler->getInfoSink().info.size() + 1;
130         break;
131     case SH_OBJECT_CODE_LENGTH:
132         *params = compiler->getInfoSink().obj.size() + 1;
133         break;
134     case SH_ACTIVE_UNIFORM_MAX_LENGTH:
135         *params = 1 +  MAX_SYMBOL_NAME_LEN;
136         break;
137     case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
138         *params = 1 + MAX_SYMBOL_NAME_LEN;
139         break;
140     default: UNREACHABLE();
141     }
142 }
143
144 //
145 // Return any compiler log of messages for the application.
146 //
147 void ShGetInfoLog(const ShHandle handle, char* infoLog)
148 {
149     if (!handle || !infoLog)
150         return;
151
152     TShHandleBase* base = static_cast<TShHandleBase*>(handle);
153     TCompiler* compiler = base->getAsCompiler();
154     if (!compiler) return;
155
156     TInfoSink& infoSink = compiler->getInfoSink();
157     strcpy(infoLog, infoSink.info.c_str());
158 }
159
160 //
161 // Return any object code.
162 //
163 void ShGetObjectCode(const ShHandle handle, char* objCode)
164 {
165     if (!handle || !objCode)
166         return;
167
168     TShHandleBase* base = static_cast<TShHandleBase*>(handle);
169     TCompiler* compiler = base->getAsCompiler();
170     if (!compiler) return;
171
172     TInfoSink& infoSink = compiler->getInfoSink();
173     strcpy(objCode, infoSink.obj.c_str());
174 }