Commit 4de44cb6 by Zhenyao Mo

Change ShaderLang APIs from c style to c++ style.

BUG=angle:816 TEST=gpu_unittests,angle_unittests,webgl_conformance Change-Id: I0b46c11f6055a82511bb946a6dc491360835526e Reviewed-on: https://chromium-review.googlesource.com/226410Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent f108df24
......@@ -80,7 +80,7 @@ class TCompiler : public TShHandleBase
TSymbolTable& getSymbolTable() { return symbolTable; }
ShShaderSpec getShaderSpec() const { return shaderSpec; }
ShShaderOutput getOutputType() const { return outputType; }
std::string getBuiltInResourcesString() const { return builtInResourcesString; }
const std::string &getBuiltInResourcesString() const { return builtInResourcesString; }
// Get the resources set by InitBuiltInSymbolTable
const ShBuiltInResources& getResources() const;
......
......@@ -102,7 +102,7 @@ void ShaderD3D::initializeCompiler()
{
if (!mFragmentCompiler)
{
int result = ShInitialize();
bool result = ShInitialize();
if (result)
{
......@@ -252,23 +252,16 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH);
}
size_t shaderVersion = 100;
ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
mShaderVersion = ShGetShaderVersion(compiler);
mShaderVersion = static_cast<int>(shaderVersion);
if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
if (mShaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
{
mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
TRACE("\n%s", mInfoLog.c_str());
}
else if (result)
{
size_t objCodeLen = 0;
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
std::vector<char> outputHLSL(objCodeLen);
ShGetObjectCode(compiler, outputHLSL.data());
mHlsl = ShGetObjectCode(compiler);
#ifdef _DEBUG
// Prefix hlsl shader with commented out glsl shader
......@@ -288,10 +281,8 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
}
hlslStream << "\n\n";
hlslStream << outputHLSL.data();
hlslStream << mHlsl;
mHlsl = hlslStream.str();
#else
mHlsl = outputHLSL.data();
#endif
mUniforms = *GetShaderVariables(ShGetUniforms(compiler));
......@@ -303,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (uniform.staticUse)
{
unsigned int index = -1;
bool result = ShGetUniformRegister(compiler, uniform.name.c_str(), &index);
bool result = ShGetUniformRegister(compiler, uniform.name, &index);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result);
......@@ -320,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (interfaceBlock.staticUse)
{
unsigned int index = -1;
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index);
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name, &index);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result);
......@@ -330,14 +321,9 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
}
else
{
size_t infoLogLen = 0;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = ShGetInfoLog(compiler);
std::vector<char> infoLog(infoLogLen);
ShGetInfoLog(compiler, infoLog.data());
mInfoLog = infoLog.data();
TRACE("\n%s", infoLog.data());
TRACE("\n%s", mInfoLog.c_str());
}
}
......@@ -419,10 +405,7 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
default: UNREACHABLE(); return SH_HLSL9_OUTPUT;
}
size_t outputType = 0;
ShGetInfo(compiler, SH_OUTPUT_TYPE, &outputType);
return static_cast<ShShaderOutput>(outputType);
return ShGetShaderOutputType(compiler);
}
bool ShaderD3D::compile(const std::string &source)
......
......@@ -144,19 +144,18 @@ protected:
// substring in the error log. This way we know the error is specific
// to the issue we are testing.
bool CheckShaderCompilation(ShHandle compiler,
const char* source,
const char *source,
int compileOptions,
const char* expected_error) {
const char *expected_error)
{
bool success = ShCompile(compiler, &source, 1, compileOptions) != 0;
if (success) {
if (success)
{
success = !expected_error;
} else {
size_t bufferLen = 0;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen);
char* buffer(new char [bufferLen]);
ShGetInfoLog(compiler, buffer);
std::string log(buffer, buffer + bufferLen);
delete [] buffer;
}
else
{
std::string log = ShGetInfoLog(compiler);
if (expected_error)
success = log.find(expected_error) != std::string::npos;
......
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