Commit 295ed4c4 by Geoff Lang

Implement ShaderGL.

BUG=angle:882 Change-Id: I1a8c7b551b308c9362e56ce564ebde7d579c05a3 Reviewed-on: https://chromium-review.googlesource.com/251541Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7825f619
...@@ -72,7 +72,7 @@ CompilerImpl *RendererGL::createCompiler(const gl::Data &data) ...@@ -72,7 +72,7 @@ CompilerImpl *RendererGL::createCompiler(const gl::Data &data)
ShaderImpl *RendererGL::createShader(GLenum type) ShaderImpl *RendererGL::createShader(GLenum type)
{ {
return new ShaderGL(); return new ShaderGL(type, mFunctions);
} }
ProgramImpl *RendererGL::createProgram() ProgramImpl *RendererGL::createProgram()
......
...@@ -9,27 +9,143 @@ ...@@ -9,27 +9,143 @@
#include "libANGLE/renderer/gl/ShaderGL.h" #include "libANGLE/renderer/gl/ShaderGL.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
template <typename VarT>
static std::vector<VarT> GetFilteredShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
std::vector<VarT> result;
for (size_t varIndex = 0; varIndex < variableList->size(); varIndex++)
{
const VarT &var = variableList->at(varIndex);
if (var.staticUse)
{
result.push_back(var);
}
}
return result;
}
template <typename VarT>
static const std::vector<VarT> &GetShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
return *variableList;
}
namespace rx namespace rx
{ {
ShaderGL::ShaderGL() ShaderGL::ShaderGL(GLenum type, const FunctionsGL *functions)
: ShaderImpl() : ShaderImpl(),
{} mFunctions(functions),
mType(type),
mShaderID(0)
{
ASSERT(mFunctions);
}
ShaderGL::~ShaderGL() ShaderGL::~ShaderGL()
{} {
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
}
}
bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source) bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source)
{ {
UNIMPLEMENTED(); // Reset the previous state
return bool(); mActiveAttributes.clear();
mVaryings.clear();
mUniforms.clear();
mInterfaceBlocks.clear();
mActiveOutputVariables.clear();
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
}
// Translate the ESSL into GLSL
CompilerGL *compilerGL = GetImplAs<CompilerGL>(compiler);
ShHandle compilerHandle = compilerGL->getCompilerHandle(mType);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES);
const char* sourceCString = source.c_str();
if (!ShCompile(compilerHandle, &sourceCString, 1, compileOptions))
{
mInfoLog = ShGetInfoLog(compilerHandle);
TRACE("\n%s", mInfoLog.c_str());
return false;
}
mTranslatedSource = ShGetObjectCode(compilerHandle);
const char* translatedSourceCString = mTranslatedSource.c_str();
// Generate a shader object and set the source
mShaderID = mFunctions->createShader(mType);
mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr);
mFunctions->compileShader(mShaderID);
// Check for compile errors from the native driver
GLint compileStatus = GL_FALSE;
mFunctions->getShaderiv(mShaderID, GL_COMPILE_STATUS, &compileStatus);
ASSERT(compileStatus == GL_TRUE);
if (compileStatus == GL_FALSE)
{
// Compilation failed, put the error into the info log
GLint infoLogLength = 0;
mFunctions->getShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<char> buf(infoLogLength);
mFunctions->getShaderInfoLog(mShaderID, infoLogLength, nullptr, &buf[0]);
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
mInfoLog = &buf[0];
TRACE("\n%s", mInfoLog.c_str());
return false;
}
// Gather the shader information
// TODO: refactor this out, gathering of the attributes, varyings and outputs should be done
// at the gl::Shader level
if (mType == GL_VERTEX_SHADER)
{
mActiveAttributes = GetFilteredShaderVariables(ShGetAttributes(compilerHandle));
}
const std::vector<sh::Varying> &varyings = GetShaderVariables(ShGetVaryings(compilerHandle));
for (size_t varyingIndex = 0; varyingIndex < varyings.size(); varyingIndex++)
{
mVaryings.push_back(gl::PackedVarying(varyings[varyingIndex]));
}
mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
if (mType == GL_FRAGMENT_SHADER)
{
mActiveOutputVariables = GetFilteredShaderVariables(ShGetOutputVariables(compilerHandle));
}
return true;
} }
std::string ShaderGL::getDebugInfo() const std::string ShaderGL::getDebugInfo() const
{ {
UNIMPLEMENTED();
return std::string(); return std::string();
} }
GLuint ShaderGL::getShaderID() const
{
return mShaderID;
}
} }
...@@ -14,17 +14,26 @@ ...@@ -14,17 +14,26 @@
namespace rx namespace rx
{ {
class FunctionsGL;
class ShaderGL : public ShaderImpl class ShaderGL : public ShaderImpl
{ {
public: public:
ShaderGL(); ShaderGL(GLenum type, const FunctionsGL *functions);
~ShaderGL() override; ~ShaderGL() override;
bool compile(gl::Compiler *compiler, const std::string &source) override; bool compile(gl::Compiler *compiler, const std::string &source) override;
std::string getDebugInfo() const override; std::string getDebugInfo() const override;
GLuint getShaderID() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(ShaderGL); DISALLOW_COPY_AND_ASSIGN(ShaderGL);
const FunctionsGL *mFunctions;
GLenum mType;
GLuint mShaderID;
}; };
} }
......
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