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.
8 // Implement the top-level of interface to the compiler,
9 // as defined in ShaderLang.h
12 #include "GLSLANG/ShaderLang.h"
14 #include "compiler/InitializeDll.h"
15 #include "compiler/preprocessor/length_limits.h"
16 #include "compiler/ShHandle.h"
21 // Driver must call this first, once, before doing any other
22 // compiler operations.
26 return InitProcess() ? 1 : 0;
30 // Cleanup symbol tables
39 // Initialize built-in resources with minimum expected values.
41 void ShInitBuiltInResources(ShBuiltInResources* resources)
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;
54 resources->OES_standard_derivatives = 0;
55 resources->OES_fragment_precision_high = 0;
56 resources->OES_EGL_image_external = 0;
58 resources->MaxCallStackDepth = UINT_MAX;
62 // Driver calls these to create and destroy compiler objects.
64 ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
65 const ShBuiltInResources* resources)
67 TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec));
68 TCompiler* compiler = base->getAsCompiler();
72 // Generate built-in symbol table.
73 if (!compiler->Init(*resources)) {
78 return reinterpret_cast<void*>(base);
81 void ShDestruct(ShHandle handle)
86 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
88 if (base->getAsCompiler())
89 DeleteCompiler(base->getAsCompiler());
93 // Do an actual compile on the given strings. The result is left
94 // in the given compile object.
96 // Return: The return value of ShCompile is really boolean, indicating
97 // success or failure.
100 const ShHandle handle,
101 const char* const shaderStrings[],
102 const int numStrings,
108 TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
109 TCompiler* compiler = base->getAsCompiler();
113 bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
114 return success ? 1 : 0;
117 void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
119 if (!handle || !params)
122 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
123 TCompiler* compiler = base->getAsCompiler();
124 if (!compiler) return;
128 case SH_INFO_LOG_LENGTH:
129 *params = compiler->getInfoSink().info.size() + 1;
131 case SH_OBJECT_CODE_LENGTH:
132 *params = compiler->getInfoSink().obj.size() + 1;
134 case SH_ACTIVE_UNIFORM_MAX_LENGTH:
135 *params = 1 + MAX_SYMBOL_NAME_LEN;
137 case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
138 *params = 1 + MAX_SYMBOL_NAME_LEN;
140 default: UNREACHABLE();
145 // Return any compiler log of messages for the application.
147 void ShGetInfoLog(const ShHandle handle, char* infoLog)
149 if (!handle || !infoLog)
152 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
153 TCompiler* compiler = base->getAsCompiler();
154 if (!compiler) return;
156 TInfoSink& infoSink = compiler->getInfoSink();
157 strcpy(infoLog, infoSink.info.c_str());
161 // Return any object code.
163 void ShGetObjectCode(const ShHandle handle, char* objCode)
165 if (!handle || !objCode)
168 TShHandleBase* base = static_cast<TShHandleBase*>(handle);
169 TCompiler* compiler = base->getAsCompiler();
170 if (!compiler) return;
172 TInfoSink& infoSink = compiler->getInfoSink();
173 strcpy(objCode, infoSink.obj.c_str());