Commit 4888ceb6 by alokp@chromium.org

Made the API of shader translator library consistent.

- We recently started using OpenGL-type enums. This CL makes all old enums consistent with the new scheme. - Renamed TBuiltInResource to ShBuiltInResources to have a consistent prefix BUG=46 Review URL: http://codereview.appspot.com/2328041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@443 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2fa73694
...@@ -17,7 +17,61 @@ extern "C" { ...@@ -17,7 +17,61 @@ extern "C" {
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented everytime the API changes. // It is incremented everytime the API changes.
#define SH_VERSION 100 #define SH_VERSION 101
//
// The names of the following enums have been derived by replacing GL prefix
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
// The enum values are also equal to the values of their GL counterpart. This
// is done to make it easier for applications to use the shader library.
//
typedef enum {
SH_FRAGMENT_SHADER = 0x8B30,
SH_VERTEX_SHADER = 0x8B31
} ShShaderType;
typedef enum {
SH_GLES2_SPEC = 0x8B40,
SH_WEBGL_SPEC = 0x8B41
} ShShaderSpec;
typedef enum {
SH_NONE = 0,
SH_INT = 0x1404,
SH_FLOAT = 0x1406,
SH_FLOAT_VEC2 = 0x8B50,
SH_FLOAT_VEC3 = 0x8B51,
SH_FLOAT_VEC4 = 0x8B52,
SH_INT_VEC2 = 0x8B53,
SH_INT_VEC3 = 0x8B54,
SH_INT_VEC4 = 0x8B55,
SH_BOOL = 0x8B56,
SH_BOOL_VEC2 = 0x8B57,
SH_BOOL_VEC3 = 0x8B58,
SH_BOOL_VEC4 = 0x8B59,
SH_FLOAT_MAT2 = 0x8B5A,
SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C,
SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60
} ShDataType;
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A
} ShShaderInfo;
// Compile options.
typedef enum {
SH_VALIDATE = 0,
SH_INTERMEDIATE_TREE = 0x001,
SH_OBJECT_CODE = 0x002,
SH_ATTRIBUTES_UNIFORMS = 0x004
} ShCompileOptions;
// //
// Driver must call this first, once, before doing any other // Driver must call this first, once, before doing any other
...@@ -30,23 +84,6 @@ int ShInitialize(); ...@@ -30,23 +84,6 @@ int ShInitialize();
// If the function succeeds, the return value is nonzero, else zero. // If the function succeeds, the return value is nonzero, else zero.
// //
int ShFinalize(); int ShFinalize();
//
// Types of languages the compiler can consume.
//
typedef enum {
EShLangVertex,
EShLangFragment,
EShLangCount,
} EShLanguage;
//
// The language specification compiler conforms to.
// It currently supports OpenGL ES and WebGL specifications.
//
typedef enum {
EShSpecGLES2,
EShSpecWebGL,
} EShSpec;
// //
// Implementation dependent built-in resources (constants and extensions). // Implementation dependent built-in resources (constants and extensions).
...@@ -67,12 +104,12 @@ typedef struct ...@@ -67,12 +104,12 @@ typedef struct
// Extensions. // Extensions.
// Set to 1 to enable the extension, else 0. // Set to 1 to enable the extension, else 0.
int OES_standard_derivatives; int OES_standard_derivatives;
} TBuiltInResource; } ShBuiltInResources;
// //
// Initialize built-in resources with minimum expected values. // Initialize built-in resources with minimum expected values.
// //
void ShInitBuiltInResource(TBuiltInResource* resources); void ShInitBuiltInResources(ShBuiltInResources* resources);
// //
// ShHandle held by but opaque to the driver. It is allocated, // ShHandle held by but opaque to the driver. It is allocated,
...@@ -86,74 +123,41 @@ typedef void* ShHandle; ...@@ -86,74 +123,41 @@ typedef void* ShHandle;
// //
// Driver calls these to create and destroy compiler objects. // Driver calls these to create and destroy compiler objects.
// //
ShHandle ShConstructCompiler(EShLanguage, EShSpec, const TBuiltInResource*); // Returns the handle of constructed compiler.
void ShDestruct(ShHandle); // Parameters:
// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER.
// spec: Specifies the language spec the compiler must conform to -
// SH_GLES2_SPEC or SH_WEBGL_SPEC.
// resources: Specifies the built-in resources.
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources);
void ShDestruct(ShHandle handle);
typedef enum { //
// Performs validations only. // Compiles the given shader source.
EShOptNone = 0x000, // If the function succeeds, the return value is nonzero, else zero.
// Writes intermediate tree to info log. // Parameters:
// Can be queried by calling ShGetInfoLog(). // handle: Specifies the handle of compiler to be used.
EShOptIntermediateTree = 0x001, // shaderStrings: Specifies an array of pointers to null-terminated strings
// Translates intermediate tree to glsl or hlsl shader. // containing the shader source code.
// Can be queried by calling ShGetObjectCode(). // numStrings: Specifies the number of elements in shaderStrings array.
EShOptObjectCode = 0x002, // compileOptions: A mask containing the following parameters:
// Extracts attributes and uniforms. // SH_VALIDATE: Performs validations only.
// Can be queried by calling ShGetActiveAttrib() and ShGetActiveUniform(). // SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
EShOptAttribsUniforms = 0x004, // Can be queried by calling ShGetInfoLog().
} EShCompileOptions; // SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
// // SH_ATTRIBUTES_UNIFORMS: Extracts attributes and uniforms.
// The return value of ShCompile is boolean, indicating // Can be queried by calling ShGetActiveAttrib() and
// success or failure. // ShGetActiveUniform().
//
// The info-log should be written by ShCompile into
// ShHandle, so it can answer future queries.
// //
int ShCompile( int ShCompile(
const ShHandle, const ShHandle handle,
const char* const shaderStrings[], const char* const shaderStrings[],
const int numStrings, const int numStrings,
int compileOptions int compileOptions
); );
// The names of the following enums have been derived by replacing GL prefix
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
// The enum values are also equal to the values of their GL counterpart. This
// is done to make it easier for applications to use the shader library.
//
// The only exception to this rule is SH_OBJECT_CODE_LENGTH, which does not
// have a GL equivalent. It uses the value of GL_SHADER_SOURCE_LENGTH instead.
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // equal to GL_SHADER_SOURCE_LENGTH.
SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
} EShInfo;
typedef enum {
SH_NONE = 0,
SH_FLOAT = 0x1406,
SH_FLOAT_VEC2 = 0x8B50,
SH_FLOAT_VEC3 = 0x8B51,
SH_FLOAT_VEC4 = 0x8B52,
SH_FLOAT_MAT2 = 0x8B5A,
SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C,
SH_INT = 0x1404,
SH_INT_VEC2 = 0x8B53,
SH_INT_VEC3 = 0x8B54,
SH_INT_VEC4 = 0x8B55,
SH_BOOL = 0x8B56,
SH_BOOL_VEC2 = 0x8B57,
SH_BOOL_VEC3 = 0x8B58,
SH_BOOL_VEC4 = 0x8B59,
SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60,
} EShDataType;
// Returns a parameter from a compiled shader. // Returns a parameter from a compiled shader.
// Parameters: // Parameters:
// handle: Specifies the compiler // handle: Specifies the compiler
...@@ -173,7 +177,7 @@ typedef enum { ...@@ -173,7 +177,7 @@ typedef enum {
// termination character. // termination character.
// //
// params: Requested parameter // params: Requested parameter
void ShGetInfo(const ShHandle handle, EShInfo pname, int* params); void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params);
// Returns nul-terminated information log for a compiled shader. // Returns nul-terminated information log for a compiled shader.
// Parameters: // Parameters:
...@@ -213,7 +217,7 @@ void ShGetActiveAttrib(const ShHandle handle, ...@@ -213,7 +217,7 @@ void ShGetActiveAttrib(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
EShDataType* type, ShDataType* type,
char* name); char* name);
// Returns information about an active uniform variable. // Returns information about an active uniform variable.
...@@ -234,7 +238,7 @@ void ShGetActiveUniform(const ShHandle handle, ...@@ -234,7 +238,7 @@ void ShGetActiveUniform(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
EShDataType* type, ShDataType* type,
char* name); char* name);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -22,13 +22,13 @@ enum TFailCode { ...@@ -22,13 +22,13 @@ enum TFailCode {
EFailCompilerCreate, EFailCompilerCreate,
}; };
static EShLanguage FindLanguage(char *lang); static ShShaderType FindShaderType(char *lang);
bool CompileFile(char *fileName, ShHandle, int); static bool CompileFile(char *fileName, ShHandle, int);
void usage(); static void usage();
void FreeFileData(char **data); static void FreeFileData(char **data);
char** ReadFileData(char *fileName); static char** ReadFileData(char *fileName);
void LogMsg(char* msg, const char* name, const int num, const char* logName); static void LogMsg(char* msg, const char* name, const int num, const char* logName);
void PrintActiveVariables(ShHandle compiler, EShInfo varType); static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType);
//Added to accomodate the multiple strings. //Added to accomodate the multiple strings.
int OutputMultipleStrings = 1; int OutputMultipleStrings = 1;
...@@ -36,9 +36,9 @@ int OutputMultipleStrings = 1; ...@@ -36,9 +36,9 @@ int OutputMultipleStrings = 1;
// //
// Set up the per compile resources // Set up the per compile resources
// //
void GenerateResources(TBuiltInResource* resources) void GenerateResources(ShBuiltInResources* resources)
{ {
ShInitBuiltInResource(resources); ShInitBuiltInResources(resources);
resources->MaxVertexAttribs = 8; resources->MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128; resources->MaxVertexUniformVectors = 128;
...@@ -66,7 +66,7 @@ int main(int argc, char* argv[]) ...@@ -66,7 +66,7 @@ int main(int argc, char* argv[])
ShInitialize(); ShInitialize();
TBuiltInResource resources; ShBuiltInResources resources;
GenerateResources(&resources); GenerateResources(&resources);
argc--; argc--;
...@@ -74,22 +74,22 @@ int main(int argc, char* argv[]) ...@@ -74,22 +74,22 @@ int main(int argc, char* argv[])
for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) { for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) {
if (argv[0][0] == '-' || argv[0][0] == '/') { if (argv[0][0] == '-' || argv[0][0] == '/') {
switch (argv[0][1]) { switch (argv[0][1]) {
case 'i': compileOptions |= EShOptIntermediateTree; break; case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break;
case 'o': compileOptions |= EShOptObjectCode; break; case 'o': compileOptions |= SH_OBJECT_CODE; break;
case 'u': compileOptions |= EShOptAttribsUniforms; break; case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { } else {
ShHandle compiler = 0; ShHandle compiler = 0;
switch (FindLanguage(argv[0])) { switch (FindShaderType(argv[0])) {
case EShLangVertex: case SH_VERTEX_SHADER:
if (vertexCompiler == 0) if (vertexCompiler == 0)
vertexCompiler = ShConstructCompiler(EShLangVertex, EShSpecGLES2, &resources); vertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, &resources);
compiler = vertexCompiler; compiler = vertexCompiler;
break; break;
case EShLangFragment: case SH_FRAGMENT_SHADER:
if (fragmentCompiler == 0) if (fragmentCompiler == 0)
fragmentCompiler = ShConstructCompiler(EShLangFragment, EShSpecGLES2, &resources); fragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources);
compiler = fragmentCompiler; compiler = fragmentCompiler;
break; break;
default: break; default: break;
...@@ -105,7 +105,7 @@ int main(int argc, char* argv[]) ...@@ -105,7 +105,7 @@ int main(int argc, char* argv[])
LogMsg("END", "COMPILER", numCompiles, "INFO LOG"); LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
printf("\n\n"); printf("\n\n");
if (compiled && (compileOptions & EShOptObjectCode)) { if (compiled && (compileOptions & SH_OBJECT_CODE)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE"); LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen); ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char)); buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
...@@ -114,7 +114,7 @@ int main(int argc, char* argv[]) ...@@ -114,7 +114,7 @@ int main(int argc, char* argv[])
LogMsg("END", "COMPILER", numCompiles, "OBJ CODE"); LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
printf("\n\n"); printf("\n\n");
} }
if (compiled && (compileOptions & EShOptAttribsUniforms)) { if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES); PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES);
LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
...@@ -151,16 +151,16 @@ int main(int argc, char* argv[]) ...@@ -151,16 +151,16 @@ int main(int argc, char* argv[])
} }
// //
// Deduce the language from the filename. Files must end in one of the // Deduce the shader type from the filename. Files must end in one of the
// following extensions: // following extensions:
// //
// .frag* = fragment programs // .frag* = fragment shader
// .vert* = vertex programs // .vert* = vertex shader
// //
static EShLanguage FindLanguage(char *name) ShShaderType FindShaderType(char *name)
{ {
if (!name) if (!name)
return EShLangFragment; return SH_FRAGMENT_SHADER;
char *ext = strrchr(name, '.'); char *ext = strrchr(name, '.');
...@@ -168,11 +168,11 @@ static EShLanguage FindLanguage(char *name) ...@@ -168,11 +168,11 @@ static EShLanguage FindLanguage(char *name)
for (; ext > name && ext[0] != '.'; ext--); for (; ext > name && ext[0] != '.'; ext--);
if (ext = strrchr(name, '.')) { if (ext = strrchr(name, '.')) {
if (strncmp(ext, ".frag", 4) == 0) return EShLangFragment; if (strncmp(ext, ".frag", 4) == 0) return SH_FRAGMENT_SHADER;
if (strncmp(ext, ".vert", 4) == 0) return EShLangVertex; if (strncmp(ext, ".vert", 4) == 0) return SH_VERTEX_SHADER;
} }
return EShLangFragment; return SH_FRAGMENT_SHADER;
} }
// //
...@@ -274,7 +274,7 @@ void LogMsg(char* msg, const char* name, const int num, const char* logName) ...@@ -274,7 +274,7 @@ void LogMsg(char* msg, const char* name, const int num, const char* logName)
printf("#### %s %s %d %s ####\n", msg, name, num, logName); printf("#### %s %s %d %s ####\n", msg, name, num, logName);
} }
void PrintActiveVariables(ShHandle compiler, EShInfo varType) void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType)
{ {
int nameSize = 0; int nameSize = 0;
switch (varType) { switch (varType) {
...@@ -290,7 +290,7 @@ void PrintActiveVariables(ShHandle compiler, EShInfo varType) ...@@ -290,7 +290,7 @@ void PrintActiveVariables(ShHandle compiler, EShInfo varType)
char* name = (char*) malloc(nameSize * sizeof(char)); char* name = (char*) malloc(nameSize * sizeof(char));
int activeVars = 0, size = 0; int activeVars = 0, size = 0;
EShDataType type; ShDataType type = SH_NONE;
char* typeName = NULL; char* typeName = NULL;
ShGetInfo(compiler, varType, &activeVars); ShGetInfo(compiler, varType, &activeVars);
for (int i = 0; i < activeVars; ++i) { for (int i = 0; i < activeVars; ++i) {
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
// compile object used by higher level code. It returns // compile object used by higher level code. It returns
// a subclass of TCompiler. // a subclass of TCompiler.
// //
TCompiler* ConstructCompiler(EShLanguage language, EShSpec spec) TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec)
{ {
return new TranslatorGLSL(language, spec); return new TranslatorGLSL(type, spec);
} }
// //
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
// compile object used by higher level code. It returns // compile object used by higher level code. It returns
// a subclass of TCompiler. // a subclass of TCompiler.
// //
TCompiler* ConstructCompiler(EShLanguage language, EShSpec spec) TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec)
{ {
return new TranslatorHLSL(language, spec); return new TranslatorHLSL(type, spec);
} }
// //
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
static bool InitializeSymbolTable( static bool InitializeSymbolTable(
const TBuiltInStrings& builtInStrings, const TBuiltInStrings& builtInStrings,
EShLanguage language, EShSpec spec, const TBuiltInResource& resources, ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
TInfoSink& infoSink, TSymbolTable& symbolTable) TInfoSink& infoSink, TSymbolTable& symbolTable)
{ {
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TExtensionBehavior extBehavior; TExtensionBehavior extBehavior;
TParseContext parseContext(symbolTable, extBehavior, intermediate, language, spec, infoSink); TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, infoSink);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
...@@ -53,7 +53,7 @@ static bool InitializeSymbolTable( ...@@ -53,7 +53,7 @@ static bool InitializeSymbolTable(
} }
} }
IdentifyBuiltIns(language, spec, resources, symbolTable); IdentifyBuiltIns(type, spec, resources, symbolTable);
FinalizePreprocessor(); FinalizePreprocessor();
...@@ -68,7 +68,17 @@ static void DefineExtensionMacros(const TExtensionBehavior& extBehavior) ...@@ -68,7 +68,17 @@ static void DefineExtensionMacros(const TExtensionBehavior& extBehavior)
} }
} }
bool TCompiler::Init(const TBuiltInResource& resources) TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec)
{
}
TCompiler::~TCompiler()
{
}
bool TCompiler::Init(const ShBuiltInResources& resources)
{ {
// Generate built-in symbol table. // Generate built-in symbol table.
if (!InitBuiltInSymbolTable(resources)) if (!InitBuiltInSymbolTable(resources))
...@@ -89,7 +99,7 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -89,7 +99,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TParseContext parseContext(symbolTable, extensionBehavior, intermediate, TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
language, spec, infoSink); shaderType, shaderSpec, infoSink);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
setInitialState(); setInitialState();
...@@ -110,13 +120,13 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -110,13 +120,13 @@ bool TCompiler::compile(const char* const shaderStrings[],
if (success) { if (success) {
success = intermediate.postProcess(parseContext.treeRoot); success = intermediate.postProcess(parseContext.treeRoot);
if (success && (compileOptions & EShOptIntermediateTree)) if (success && (compileOptions & SH_INTERMEDIATE_TREE))
intermediate.outputTree(parseContext.treeRoot); intermediate.outputTree(parseContext.treeRoot);
if (success && (compileOptions & EShOptObjectCode)) if (success && (compileOptions & SH_OBJECT_CODE))
translate(parseContext.treeRoot); translate(parseContext.treeRoot);
if (success && (compileOptions & EShOptAttribsUniforms)) if (success && (compileOptions & SH_ATTRIBUTES_UNIFORMS))
collectAttribsUniforms(parseContext.treeRoot); collectAttribsUniforms(parseContext.treeRoot);
} }
...@@ -131,12 +141,13 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -131,12 +141,13 @@ bool TCompiler::compile(const char* const shaderStrings[],
return success; return success;
} }
bool TCompiler::InitBuiltInSymbolTable(const TBuiltInResource& resources) bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources)
{ {
TBuiltIns builtIns; TBuiltIns builtIns;
builtIns.initialize(language, spec, resources); builtIns.initialize(shaderType, shaderSpec, resources);
return InitializeSymbolTable(builtIns.getBuiltInStrings(), language, spec, resources, infoSink, symbolTable); return InitializeSymbolTable(builtIns.getBuiltInStrings(),
shaderType, shaderSpec, resources, infoSink, symbolTable);
} }
void TCompiler::clearResults() void TCompiler::clearResults()
......
...@@ -341,7 +341,7 @@ static TString BuiltInFunctionsCommon() ...@@ -341,7 +341,7 @@ static TString BuiltInFunctionsCommon()
// Prototypes for built-in functions seen by vertex shaders only. // Prototypes for built-in functions seen by vertex shaders only.
// //
//============================================================================ //============================================================================
static TString BuiltInFunctionsVertex(const TBuiltInResource& resources) static TString BuiltInFunctionsVertex(const ShBuiltInResources& resources)
{ {
TString s; TString s;
...@@ -373,7 +373,7 @@ static TString BuiltInFunctionsVertex(const TBuiltInResource& resources) ...@@ -373,7 +373,7 @@ static TString BuiltInFunctionsVertex(const TBuiltInResource& resources)
// Prototypes for built-in functions seen by fragment shaders only. // Prototypes for built-in functions seen by fragment shaders only.
// //
//============================================================================ //============================================================================
static TString BuiltInFunctionsFragment(const TBuiltInResource& resources) static TString BuiltInFunctionsFragment(const ShBuiltInResources& resources)
{ {
TString s; TString s;
...@@ -467,7 +467,7 @@ static TString DefaultPrecisionFragment() ...@@ -467,7 +467,7 @@ static TString DefaultPrecisionFragment()
// Implementation dependent built-in constants. // Implementation dependent built-in constants.
// //
//============================================================================ //============================================================================
static TString BuiltInConstants(const TBuiltInResource &resources) static TString BuiltInConstants(const ShBuiltInResources &resources)
{ {
TStringStream s; TStringStream s;
...@@ -484,17 +484,18 @@ static TString BuiltInConstants(const TBuiltInResource &resources) ...@@ -484,17 +484,18 @@ static TString BuiltInConstants(const TBuiltInResource &resources)
return s.str(); return s.str();
} }
void TBuiltIns::initialize(EShLanguage language, EShSpec spec, const TBuiltInResource& resources) void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources)
{ {
switch (language) { switch (type) {
case EShLangFragment: case SH_FRAGMENT_SHADER:
builtInStrings.push_back(DefaultPrecisionFragment()); builtInStrings.push_back(DefaultPrecisionFragment());
builtInStrings.push_back(BuiltInFunctionsCommon()); builtInStrings.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsFragment(resources)); builtInStrings.push_back(BuiltInFunctionsFragment(resources));
builtInStrings.push_back(StandardUniforms()); builtInStrings.push_back(StandardUniforms());
break; break;
case EShLangVertex: case SH_VERTEX_SHADER:
builtInStrings.push_back(DefaultPrecisionVertex()); builtInStrings.push_back(DefaultPrecisionVertex());
builtInStrings.push_back(BuiltInFunctionsCommon()); builtInStrings.push_back(BuiltInFunctionsCommon());
builtInStrings.push_back(BuiltInFunctionsVertex(resources)); builtInStrings.push_back(BuiltInFunctionsVertex(resources));
...@@ -507,14 +508,16 @@ void TBuiltIns::initialize(EShLanguage language, EShSpec spec, const TBuiltInRes ...@@ -507,14 +508,16 @@ void TBuiltIns::initialize(EShLanguage language, EShSpec spec, const TBuiltInRes
builtInStrings.push_back(BuiltInConstants(resources)); builtInStrings.push_back(BuiltInConstants(resources));
} }
void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources, TSymbolTable& symbolTable) void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
TSymbolTable& symbolTable)
{ {
// //
// First, insert some special built-in variables that are not in // First, insert some special built-in variables that are not in
// the built-in header files. // the built-in header files.
// //
switch(language) { switch(type) {
case EShLangFragment: case SH_FRAGMENT_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
...@@ -522,7 +525,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -522,7 +525,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
break; break;
case EShLangVertex: case SH_VERTEX_SHADER:
symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break; break;
...@@ -590,10 +593,10 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -590,10 +593,10 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
symbolTable.relateToOperator("all", EOpAll); symbolTable.relateToOperator("all", EOpAll);
// Map language-specific operators. // Map language-specific operators.
switch(language) { switch(type) {
case EShLangVertex: case SH_VERTEX_SHADER:
break; break;
case EShLangFragment: case SH_FRAGMENT_SHADER:
if (resources.OES_standard_derivatives) { if (resources.OES_standard_derivatives) {
symbolTable.relateToOperator("dFdx", EOpDFdx); symbolTable.relateToOperator("dFdx", EOpDFdx);
symbolTable.relateToOperator("dFdy", EOpDFdy); symbolTable.relateToOperator("dFdy", EOpDFdy);
...@@ -608,8 +611,8 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -608,8 +611,8 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
} }
// Finally add resource-specific variables. // Finally add resource-specific variables.
switch(language) { switch(type) {
case EShLangFragment: { case SH_FRAGMENT_SHADER: {
// Set up gl_FragData. The array size. // Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragColor, 4, false, true); TType fragData(EbtFloat, EbpMedium, EvqFragColor, 4, false, true);
fragData.setArraySize(resources.MaxDrawBuffers); fragData.setArraySize(resources.MaxDrawBuffers);
...@@ -620,7 +623,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -620,7 +623,7 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
} }
} }
void InitExtensionBehavior(const TBuiltInResource& resources, void InitExtensionBehavior(const ShBuiltInResources& resources,
TExtensionBehavior& extBehavior) TExtensionBehavior& extBehavior)
{ {
if (resources.OES_standard_derivatives) if (resources.OES_standard_derivatives)
......
...@@ -17,17 +17,19 @@ class TBuiltIns { ...@@ -17,17 +17,19 @@ class TBuiltIns {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
void initialize(EShLanguage language, EShSpec spec, const TBuiltInResource& resources); void initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources);
const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; } const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; }
protected: protected:
TBuiltInStrings builtInStrings; TBuiltInStrings builtInStrings;
}; };
void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources, void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
TSymbolTable& symbolTable); TSymbolTable& symbolTable);
void InitExtensionBehavior(const TBuiltInResource& resources, void InitExtensionBehavior(const ShBuiltInResources& resources,
TExtensionBehavior& extensionBehavior); TExtensionBehavior& extensionBehavior);
extern "C" int InitPreprocessor(void); extern "C" int InitPreprocessor(void);
......
...@@ -96,7 +96,7 @@ int OutputHLSL::vectorSize(const TType &type) const ...@@ -96,7 +96,7 @@ int OutputHLSL::vectorSize(const TType &type) const
void OutputHLSL::header() void OutputHLSL::header()
{ {
EShLanguage language = mContext.language; ShShaderType shaderType = mContext.shaderType;
TInfoSinkBase &out = mHeader; TInfoSinkBase &out = mHeader;
for (StructDeclarations::iterator structDeclaration = mStructDeclarations.begin(); structDeclaration != mStructDeclarations.end(); structDeclaration++) for (StructDeclarations::iterator structDeclaration = mStructDeclarations.begin(); structDeclaration != mStructDeclarations.end(); structDeclaration++)
...@@ -109,7 +109,7 @@ void OutputHLSL::header() ...@@ -109,7 +109,7 @@ void OutputHLSL::header()
out << *constructor; out << *constructor;
} }
if (language == EShLangFragment) if (shaderType == SH_FRAGMENT_SHADER)
{ {
TString uniforms; TString uniforms;
TString varyings; TString varyings;
...@@ -946,7 +946,7 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node) ...@@ -946,7 +946,7 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{ {
EShLanguage language = mContext.language; ShShaderType shaderType = mContext.shaderType;
TInfoSinkBase &out = mBody; TInfoSinkBase &out = mBody;
switch (node->getOp()) switch (node->getOp())
......
...@@ -415,7 +415,7 @@ bool TParseContext::reservedErrorCheck(int line, const TString& identifier) ...@@ -415,7 +415,7 @@ bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
error(line, reservedErrMsg, "gl_", ""); error(line, reservedErrMsg, "gl_", "");
return true; return true;
} }
if (spec == EShSpecWebGL) { if (shaderSpec == SH_WEBGL_SPEC) {
if (identifier.substr(0, 6) == TString("webgl_")) { if (identifier.substr(0, 6) == TString("webgl_")) {
error(line, reservedErrMsg, "webgl_", ""); error(line, reservedErrMsg, "webgl_", "");
return true; return true;
......
...@@ -30,16 +30,16 @@ struct TPragma { ...@@ -30,16 +30,16 @@ struct TPragma {
// they can be passed to the parser without needing a global. // they can be passed to the parser without needing a global.
// //
struct TParseContext { struct TParseContext {
TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) : TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, TInfoSink& is) :
intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), language(l), spec(s), treeRoot(0), intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), shaderType(type), shaderSpec(spec), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
inTypeParen(false), contextPragma(true, false) { } inTypeParen(false), contextPragma(true, false) { }
TIntermediate& intermediate; // to hold and build a parse tree TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior. TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior.
TInfoSink& infoSink; TInfoSink& infoSink;
EShLanguage language; // vertex or fragment language (future: pack or unpack) ShShaderType shaderType; // vertex or fragment language (future: pack or unpack)
EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL. ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
TIntermNode* treeRoot; // root of parse tree being created TIntermNode* treeRoot; // root of parse tree being created
bool recoveredFromError; // true if a parse error has occurred, but we continue to parse bool recoveredFromError; // true if a parse error has occurred, but we continue to parse
int numErrors; int numErrors;
......
...@@ -39,11 +39,11 @@ public: ...@@ -39,11 +39,11 @@ public:
// //
class TCompiler : public TShHandleBase { class TCompiler : public TShHandleBase {
public: public:
TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s) {} TCompiler(ShShaderType type, ShShaderSpec spec);
virtual ~TCompiler() {} virtual ~TCompiler();
virtual TCompiler* getAsCompiler() { return this; } virtual TCompiler* getAsCompiler() { return this; }
bool Init(const TBuiltInResource& resources); bool Init(const ShBuiltInResources& resources);
bool compile(const char* const shaderStrings[], bool compile(const char* const shaderStrings[],
const int numStrings, const int numStrings,
int compileOptions); int compileOptions);
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
protected: protected:
// Initialize symbol-table with built-in symbols. // Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const TBuiltInResource& resources); bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
// Clears the results from the previous compilation. // Clears the results from the previous compilation.
void clearResults(); void clearResults();
// Collect info for all attribs and uniforms. // Collect info for all attribs and uniforms.
...@@ -64,8 +64,8 @@ protected: ...@@ -64,8 +64,8 @@ protected:
virtual void translate(TIntermNode* root) = 0; virtual void translate(TIntermNode* root) = 0;
private: private:
EShLanguage language; ShShaderType shaderType;
EShSpec spec; ShShaderSpec shaderSpec;
// Built-in symbol table for the given language, spec, and resources. // Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile. // It is preserved from compile-to-compile.
...@@ -88,7 +88,7 @@ private: ...@@ -88,7 +88,7 @@ private:
// destroy the machine dependent objects, which contain the // destroy the machine dependent objects, which contain the
// above machine independent information. // above machine independent information.
// //
TCompiler* ConstructCompiler(EShLanguage, EShSpec); TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
void DeleteCompiler(TCompiler*); void DeleteCompiler(TCompiler*);
#endif // _SHHANDLE_INCLUDED_ #endif // _SHHANDLE_INCLUDED_
...@@ -31,12 +31,12 @@ static int getVariableMaxLength(const TVariableInfoList& varList) ...@@ -31,12 +31,12 @@ static int getVariableMaxLength(const TVariableInfoList& varList)
return static_cast<int>(maxLen) + 1; return static_cast<int>(maxLen) + 1;
} }
static void getVariableInfo(EShInfo varType, static void getVariableInfo(ShShaderInfo varType,
const ShHandle handle, const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
EShDataType* type, ShDataType* type,
char* name) char* name)
{ {
if (!handle || !size || !type || !name) if (!handle || !size || !type || !name)
...@@ -87,7 +87,7 @@ int ShFinalize() ...@@ -87,7 +87,7 @@ int ShFinalize()
// //
// Initialize built-in resources with minimum expected values. // Initialize built-in resources with minimum expected values.
// //
void ShInitBuiltInResource(TBuiltInResource* resources) void ShInitBuiltInResources(ShBuiltInResources* resources)
{ {
// Constants. // Constants.
resources->MaxVertexAttribs = 8; resources->MaxVertexAttribs = 8;
...@@ -106,12 +106,13 @@ void ShInitBuiltInResource(TBuiltInResource* resources) ...@@ -106,12 +106,13 @@ void ShInitBuiltInResource(TBuiltInResource* resources)
// //
// Driver calls these to create and destroy compiler objects. // Driver calls these to create and destroy compiler objects.
// //
ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInResource* resources) ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources)
{ {
if (!InitThread()) if (!InitThread())
return 0; return 0;
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, spec)); TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec));
TCompiler* compiler = base->getAsCompiler(); TCompiler* compiler = base->getAsCompiler();
if (compiler == 0) if (compiler == 0)
return 0; return 0;
...@@ -172,7 +173,7 @@ int ShCompile( ...@@ -172,7 +173,7 @@ int ShCompile(
return success ? 1 : 0; return success ? 1 : 0;
} }
void ShGetInfo(const ShHandle handle, EShInfo pname, int* params) void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
{ {
if (!handle || !params) if (!handle || !params)
return; return;
...@@ -242,7 +243,7 @@ void ShGetActiveAttrib(const ShHandle handle, ...@@ -242,7 +243,7 @@ void ShGetActiveAttrib(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
EShDataType* type, ShDataType* type,
char* name) char* name)
{ {
getVariableInfo(SH_ACTIVE_ATTRIBUTES, getVariableInfo(SH_ACTIVE_ATTRIBUTES,
...@@ -253,7 +254,7 @@ void ShGetActiveUniform(const ShHandle handle, ...@@ -253,7 +254,7 @@ void ShGetActiveUniform(const ShHandle handle,
int index, int index,
int* length, int* length,
int* size, int* size,
EShDataType* type, ShDataType* type,
char* name) char* name)
{ {
getVariableInfo(SH_ACTIVE_UNIFORMS, getVariableInfo(SH_ACTIVE_UNIFORMS,
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "compiler/OutputGLSL.h" #include "compiler/OutputGLSL.h"
TranslatorGLSL::TranslatorGLSL(EShLanguage lang, EShSpec spec) TranslatorGLSL::TranslatorGLSL(ShShaderType type, ShShaderSpec spec)
: TCompiler(lang, spec) { : TCompiler(type, spec) {
} }
void TranslatorGLSL::translate(TIntermNode* root) { void TranslatorGLSL::translate(TIntermNode* root) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
class TranslatorGLSL : public TCompiler { class TranslatorGLSL : public TCompiler {
public: public:
TranslatorGLSL(EShLanguage lang, EShSpec spec); TranslatorGLSL(ShShaderType type, ShShaderSpec spec);
protected: protected:
virtual void translate(TIntermNode* root); virtual void translate(TIntermNode* root);
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "compiler/OutputHLSL.h" #include "compiler/OutputHLSL.h"
TranslatorHLSL::TranslatorHLSL(EShLanguage lang, EShSpec spec) TranslatorHLSL::TranslatorHLSL(ShShaderType type, ShShaderSpec spec)
: TCompiler(lang, spec) : TCompiler(type, spec)
{ {
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
class TranslatorHLSL : public TCompiler { class TranslatorHLSL : public TCompiler {
public: public:
TranslatorHLSL(EShLanguage lang, EShSpec spec); TranslatorHLSL(ShShaderType type, ShShaderSpec spec);
protected: protected:
virtual void translate(TIntermNode* root); virtual void translate(TIntermNode* root);
......
...@@ -14,7 +14,7 @@ static TString arrayBrackets(int index) ...@@ -14,7 +14,7 @@ static TString arrayBrackets(int index)
} }
// Returns the data type for an attribute or uniform. // Returns the data type for an attribute or uniform.
static EShDataType getVariableDataType(const TType& type) static ShDataType getVariableDataType(const TType& type)
{ {
switch (type.getBasicType()) { switch (type.getBasicType()) {
case EbtFloat: case EbtFloat:
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// It is currently being used to store info about active attribs and uniforms. // It is currently being used to store info about active attribs and uniforms.
struct TVariableInfo { struct TVariableInfo {
TPersistString name; TPersistString name;
EShDataType type; ShDataType type;
int size; int size;
}; };
typedef std::vector<TVariableInfo> TVariableInfoList; typedef std::vector<TVariableInfo> TVariableInfoList;
......
...@@ -40,48 +40,26 @@ compiler/tools. Remove it when we can exclusively use the newer version. ...@@ -40,48 +40,26 @@ compiler/tools. Remove it when we can exclusively use the newer version.
#define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal) #define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)
extern void yyerror(const char*); extern void yyerror(const char*);
#define FRAG_VERT_ONLY(S, L) { \ #define FRAG_VERT_ONLY(S, L) { \
if (parseContext->language != EShLangFragment && \ if (parseContext->shaderType != SH_FRAGMENT_SHADER && \
parseContext->language != EShLangVertex) { \ parseContext->shaderType != SH_VERTEX_SHADER) { \
parseContext->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \ parseContext->error(L, " supported in vertex/fragment shaders only ", S, "", ""); \
parseContext->recover(); \ parseContext->recover(); \
} \ } \
} }
#define VERTEX_ONLY(S, L) { \ #define VERTEX_ONLY(S, L) { \
if (parseContext->language != EShLangVertex) { \ if (parseContext->shaderType != SH_VERTEX_SHADER) { \
parseContext->error(L, " supported in vertex shaders only ", S, "", ""); \ parseContext->error(L, " supported in vertex shaders only ", S, "", ""); \
parseContext->recover(); \ parseContext->recover(); \
} \ } \
} }
#define FRAG_ONLY(S, L) { \ #define FRAG_ONLY(S, L) { \
if (parseContext->language != EShLangFragment) { \ if (parseContext->shaderType != SH_FRAGMENT_SHADER) { \
parseContext->error(L, " supported in fragment shaders only ", S, "", ""); \ parseContext->error(L, " supported in fragment shaders only ", S, "", ""); \
parseContext->recover(); \ parseContext->recover(); \
} \ } \
}
#define PACK_ONLY(S, L) { \
if (parseContext->language != EShLangPack) { \
parseContext->error(L, " supported in pack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define UNPACK_ONLY(S, L) { \
if (parseContext->language != EShLangUnpack) { \
parseContext->error(L, " supported in unpack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
}
#define PACK_UNPACK_ONLY(S, L) { \
if (parseContext->language != EShLangUnpack && \
parseContext->language != EShLangPack) { \
parseContext->error(L, " supported in pack/unpack shaders only ", S, "", ""); \
parseContext->recover(); \
} \
} }
%} %}
%union { %union {
...@@ -1498,7 +1476,7 @@ type_qualifier ...@@ -1498,7 +1476,7 @@ type_qualifier
| VARYING { | VARYING {
if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "varying")) if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "varying"))
parseContext->recover(); parseContext->recover();
if (parseContext->language == EShLangVertex) if (parseContext->shaderType == SH_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, $1.line); $$.setBasic(EbtVoid, EvqVaryingOut, $1.line);
else else
$$.setBasic(EbtVoid, EvqVaryingIn, $1.line); $$.setBasic(EbtVoid, EvqVaryingIn, $1.line);
...@@ -1506,7 +1484,7 @@ type_qualifier ...@@ -1506,7 +1484,7 @@ type_qualifier
| INVARIANT VARYING { | INVARIANT VARYING {
if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "invariant varying")) if (parseContext->globalErrorCheck($1.line, parseContext->symbolTable.atGlobalLevel(), "invariant varying"))
parseContext->recover(); parseContext->recover();
if (parseContext->language == EShLangVertex) if (parseContext->shaderType == SH_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqInvariantVaryingOut, $1.line); $$.setBasic(EbtVoid, EvqInvariantVaryingOut, $1.line);
else else
$$.setBasic(EbtVoid, EvqInvariantVaryingIn, $1.line); $$.setBasic(EbtVoid, EvqInvariantVaryingIn, $1.line);
......
...@@ -34,8 +34,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso ...@@ -34,8 +34,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
if (result) if (result)
{ {
TBuiltInResource resources; ShBuiltInResources resources;
ShInitBuiltInResource(&resources); ShInitBuiltInResources(&resources);
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS; resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS; resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS; resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
...@@ -46,8 +46,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso ...@@ -46,8 +46,8 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
resources.MaxDrawBuffers = MAX_DRAW_BUFFERS; resources.MaxDrawBuffers = MAX_DRAW_BUFFERS;
resources.OES_standard_derivatives = 1; resources.OES_standard_derivatives = 1;
mFragmentCompiler = ShConstructCompiler(EShLangFragment, EShSpecGLES2, &resources); mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources);
mVertexCompiler = ShConstructCompiler(EShLangVertex, EShSpecGLES2, &resources); mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, &resources);
} }
} }
...@@ -281,7 +281,7 @@ void Shader::compileToHLSL(void *compiler) ...@@ -281,7 +281,7 @@ void Shader::compileToHLSL(void *compiler)
delete[] mInfoLog; delete[] mInfoLog;
mInfoLog = NULL; mInfoLog = NULL;
int result = ShCompile(compiler, &mSource, 1, EShOptObjectCode); int result = ShCompile(compiler, &mSource, 1, SH_OBJECT_CODE);
if (result) if (result)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment