Commit b1f435e4 by Geoff Lang

Implement basic functionality of ProgramGL.

BUG=angle:882 Change-Id: I1d859197011081729c4c5733b78ac10491fe926c Reviewed-on: https://chromium-review.googlesource.com/251542Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent f1e85927
......@@ -9,16 +9,31 @@
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "common/debug.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
namespace rx
{
ProgramGL::ProgramGL()
: ProgramImpl()
{}
ProgramGL::ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager)
: ProgramImpl(),
mFunctions(functions),
mStateManager(stateManager),
mProgramID(0)
{
ASSERT(mFunctions);
ASSERT(mStateManager);
}
ProgramGL::~ProgramGL()
{}
{
if (mProgramID != 0)
{
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
}
}
bool ProgramGL::usesPointSize() const
{
......@@ -63,128 +78,237 @@ LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog,
int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *outputVariables)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
// Reset the program state, delete the current program if one exists
reset();
ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(vertexShader);
ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(fragmentShader);
// Generate a new program, make sure one doesn't already exist
ASSERT(mProgramID == 0);
mProgramID = mFunctions->createProgram();
// Attach the shaders
mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID());
mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID());
// TODO: bind attribute locations?
// Link and verify
mFunctions->linkProgram(mProgramID);
GLint linkStatus = GL_FALSE;
mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
ASSERT(linkStatus == GL_TRUE);
if (linkStatus == GL_FALSE)
{
// Linking failed, put the error into the info log
GLint infoLogLength = 0;
mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<char> buf(infoLogLength);
mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]);
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
infoLog.append(&buf[0]);
TRACE("\n%s", &buf[0]);
// TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case
return LinkResult(false, gl::Error(GL_NO_ERROR));
}
// Query the uniform information
// TODO: A lot of this logic should be done at the gl::Program level
GLint activeUniformMaxLength = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength);
std::vector<GLchar> uniformNameBuffer(activeUniformMaxLength);
GLint uniformCount = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_UNIFORMS, &uniformCount);
for (GLint i = 0; i < uniformCount; i++)
{
GLsizei uniformNameLength = 0;
GLint uniformSize = 0;
GLenum uniformType = GL_NONE;
mFunctions->getActiveUniform(mProgramID, i, uniformNameBuffer.size(), &uniformNameLength, &uniformSize, &uniformType, &uniformNameBuffer[0]);
std::string uniformName(&uniformNameBuffer[0], uniformNameLength);
// TODO: determine uniform precision
mUniforms.push_back(new gl::LinkedUniform(uniformType, GL_NONE, uniformName, uniformSize, -1, sh::BlockMemberInfo::getDefaultBlockInfo()));
mUniformIndex.push_back(gl::VariableLocation(uniformName, 0, i));
}
// Query the attribute information
GLint activeAttributeMaxLength = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength);
std::vector<GLchar> attributeNameBuffer(activeAttributeMaxLength);
GLint attributeCount = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTES, &attributeCount);
for (GLint i = 0; i < attributeCount; i++)
{
GLsizei attributeNameLength = 0;
GLint attributeSize = 0;
GLenum attributeType = GL_NONE;
mFunctions->getActiveAttrib(mProgramID, i, attributeNameBuffer.size(), &attributeNameLength, &attributeSize, &attributeType, &attributeNameBuffer[0]);
std::string attributeName(&attributeNameBuffer[0], attributeNameLength);
mShaderAttributes[i].type = attributeType;
// TODO: determine attribute precision
mShaderAttributes[i].precision = GL_NONE;
mShaderAttributes[i].name = attributeName;
mShaderAttributes[i].arraySize = attributeSize;
mShaderAttributes[i].location = i;
}
return LinkResult(true, gl::Error(GL_NO_ERROR));
}
void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform1fv(location, count, v);
}
void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform2fv(location, count, v);
}
void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform3fv(location, count, v);
}
void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform4fv(location, count, v);
}
void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform1iv(location, count, v);
}
void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform2iv(location, count, v);
}
void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform3iv(location, count, v);
}
void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform4iv(location, count, v);
}
void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform1uiv(location, count, v);
}
void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform2uiv(location, count, v);
}
void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform3uiv(location, count, v);
}
void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniform4uiv(location, count, v);
}
void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix3fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix2x3fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix3x2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix2x4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix4x2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix3x4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
UNIMPLEMENTED();
mStateManager->setProgram(mProgramID);
mFunctions->uniformMatrix4x3fv(location, count, transpose, value);
}
void ProgramGL::getUniformfv(GLint location, GLfloat *params)
{
UNIMPLEMENTED();
mFunctions->getUniformfv(mProgramID, location, params);
}
void ProgramGL::getUniformiv(GLint location, GLint *params)
{
UNIMPLEMENTED();
mFunctions->getUniformiv(mProgramID, location, params);
}
void ProgramGL::getUniformuiv(GLint location, GLuint *params)
{
UNIMPLEMENTED();
mFunctions->getUniformuiv(mProgramID, location, params);
}
GLint ProgramGL::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const
......@@ -213,21 +337,21 @@ void ProgramGL::updateSamplerMapping()
bool ProgramGL::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
{
UNIMPLEMENTED();
return bool();
return true;
}
LinkResult ProgramGL::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
int registers)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
//UNIMPLEMENTED();
return LinkResult(true, gl::Error(GL_NO_ERROR));
}
bool ProgramGL::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
const gl::Caps &caps)
{
UNIMPLEMENTED();
return bool();
//UNIMPLEMENTED();
return true;
}
bool ProgramGL::defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock,
......@@ -256,4 +380,20 @@ bool ProgramGL::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBloc
return bool();
}
void ProgramGL::reset()
{
ProgramImpl::reset();
if (mProgramID)
{
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
}
}
GLuint ProgramGL::getProgramID() const
{
return mProgramID;
}
}
......@@ -14,10 +14,13 @@
namespace rx
{
class FunctionsGL;
class StateManagerGL;
class ProgramGL : public ProgramImpl
{
public:
ProgramGL();
ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager);
~ProgramGL() override;
bool usesPointSize() const override;
......@@ -80,8 +83,17 @@ class ProgramGL : public ProgramImpl
bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
unsigned int registerIndex, const gl::Caps &caps) override;
void reset() override;
GLuint getProgramID() const;
private:
DISALLOW_COPY_AND_ASSIGN(ProgramGL);
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
GLuint mProgramID;
};
}
......
......@@ -82,7 +82,7 @@ ShaderImpl *RendererGL::createShader(GLenum type)
ProgramImpl *RendererGL::createProgram()
{
return new ProgramGL();
return new ProgramGL(mFunctions, mStateManager);
}
DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Surface *surface)
......
......@@ -14,9 +14,19 @@ namespace rx
{
StateManagerGL::StateManagerGL(const FunctionsGL *functions)
: mFunctions(functions)
: mFunctions(functions),
mProgram(0)
{
ASSERT(mFunctions);
}
void StateManagerGL::setProgram(GLuint program)
{
if (mProgram != program)
{
mProgram = program;
mFunctions->useProgram(mProgram);
}
}
}
......@@ -10,6 +10,7 @@
#define LIBANGLE_RENDERER_GL_STATEMANAGERGL_H_
#include "common/debug.h"
#include "libANGLE/renderer/gl/functionsgl_typedefs.h"
namespace rx
{
......@@ -21,10 +22,14 @@ class StateManagerGL
public:
StateManagerGL(const FunctionsGL *functions);
void setProgram(GLuint program);
private:
DISALLOW_COPY_AND_ASSIGN(StateManagerGL);
const FunctionsGL *mFunctions;
GLuint mProgram;
};
}
......
......@@ -56,3 +56,89 @@ TYPED_TEST(SimpleOperationTest, CompileFragmentShader)
EXPECT_GL_NO_ERROR();
}
TYPED_TEST(SimpleOperationTest, LinkProgram)
{
const std::string vsSource = SHADER_SOURCE
(
void main()
{
gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
}
);
const std::string fsSource = SHADER_SOURCE
(
void main()
{
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
);
GLuint program = CompileProgram(vsSource, fsSource);
EXPECT_NE(program, 0u);
glDeleteProgram(program);
EXPECT_GL_NO_ERROR();
}
TYPED_TEST(SimpleOperationTest, LinkProgramWithUniforms)
{
const std::string vsSource = SHADER_SOURCE
(
void main()
{
gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
}
);
const std::string fsSource = SHADER_SOURCE
(
precision mediump float;
uniform vec4 u_input;
void main()
{
gl_FragColor = u_input;
}
);
GLuint program = CompileProgram(vsSource, fsSource);
EXPECT_NE(program, 0u);
GLint uniformLoc = glGetUniformLocation(program, "u_input");
EXPECT_NE(-1, uniformLoc);
glDeleteProgram(program);
EXPECT_GL_NO_ERROR();
}
TYPED_TEST(SimpleOperationTest, LinkProgramWithAttributes)
{
const std::string vsSource = SHADER_SOURCE
(
attribute vec4 a_input;
void main()
{
gl_Position = a_input;
}
);
const std::string fsSource = SHADER_SOURCE
(
void main()
{
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
);
GLuint program = CompileProgram(vsSource, fsSource);
EXPECT_NE(program, 0u);
GLint attribLoc = glGetAttribLocation(program, "a_input");
EXPECT_NE(-1, attribLoc);
glDeleteProgram(program);
EXPECT_GL_NO_ERROR();
}
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