Implemented functionality to collect and return info for attributes and uniforms.
BUG=26
Review URL: http://codereview.appspot.com/2206046
git-svn-id: https://angleproject.googlecode.com/svn/trunk@440 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index 5383f7b..bab6423 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -11,17 +11,56 @@
#include "GLSLANG/ShaderLang.h"
-#include "compiler/Initialize.h"
#include "compiler/InitializeDll.h"
-#include "compiler/ParseHelper.h"
#include "compiler/ShHandle.h"
-#include "compiler/SymbolTable.h"
//
// This is the platform independent interface between an OGL driver
// and the shading language compiler.
//
+static int getVariableMaxLength(const TVariableInfoList& varList)
+{
+ TString::size_type maxLen = 0;
+ for (TVariableInfoList::const_iterator i = varList.begin();
+ i != varList.end(); ++i)
+ {
+ maxLen = std::max(maxLen, i->name.size());
+ }
+ // Add 1 to include null-termination character.
+ return static_cast<int>(maxLen) + 1;
+}
+
+static void getVariableInfo(EShInfo varType,
+ const ShHandle handle,
+ int index,
+ int* length,
+ int* size,
+ EShDataType* type,
+ char* name)
+{
+ if (!handle || !size || !type || !name)
+ return;
+ ASSERT((varType == SH_ACTIVE_ATTRIBUTES) ||
+ (varType == SH_ACTIVE_UNIFORMS));
+
+ TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
+ TCompiler* compiler = base->getAsCompiler();
+ if (compiler == 0)
+ return;
+
+ const TVariableInfoList& varList = varType == SH_ACTIVE_ATTRIBUTES ?
+ compiler->getAttribs() : compiler->getUniforms();
+ if (index < 0 || index >= static_cast<int>(varList.size()))
+ return;
+
+ const TVariableInfo& varInfo = varList[index];
+ if (length) *length = varInfo.name.size();
+ *size = varInfo.size;
+ *type = varInfo.type;
+ strcpy(name, varInfo.name.c_str());
+}
+
//
// Driver must call this first, once, before doing any other
// compiler operations.
@@ -151,16 +190,16 @@
*params = compiler->getInfoSink().obj.size() + 1;
break;
case SH_ACTIVE_UNIFORMS:
- UNIMPLEMENTED();
+ *params = compiler->getUniforms().size();
break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH:
- UNIMPLEMENTED();
+ *params = getVariableMaxLength(compiler->getUniforms());
break;
case SH_ACTIVE_ATTRIBUTES:
- UNIMPLEMENTED();
+ *params = compiler->getAttribs().size();
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
- UNIMPLEMENTED();
+ *params = getVariableMaxLength(compiler->getAttribs());
break;
default: UNREACHABLE();
@@ -206,7 +245,8 @@
EShDataType* type,
char* name)
{
- UNIMPLEMENTED();
+ getVariableInfo(SH_ACTIVE_ATTRIBUTES,
+ handle, index, length, size, type, name);
}
void ShGetActiveUniform(const ShHandle handle,
@@ -216,5 +256,7 @@
EShDataType* type,
char* name)
{
- UNIMPLEMENTED();
+ getVariableInfo(SH_ACTIVE_UNIFORMS,
+ handle, index, length, size, type, name);
}
+