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
...@@ -14,10 +14,13 @@ ...@@ -14,10 +14,13 @@
namespace rx namespace rx
{ {
class FunctionsGL;
class StateManagerGL;
class ProgramGL : public ProgramImpl class ProgramGL : public ProgramImpl
{ {
public: public:
ProgramGL(); ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager);
~ProgramGL() override; ~ProgramGL() override;
bool usesPointSize() const override; bool usesPointSize() const override;
...@@ -80,8 +83,17 @@ class ProgramGL : public ProgramImpl ...@@ -80,8 +83,17 @@ class ProgramGL : public ProgramImpl
bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader, bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
unsigned int registerIndex, const gl::Caps &caps) override; unsigned int registerIndex, const gl::Caps &caps) override;
void reset() override;
GLuint getProgramID() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(ProgramGL); DISALLOW_COPY_AND_ASSIGN(ProgramGL);
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
GLuint mProgramID;
}; };
} }
......
...@@ -82,7 +82,7 @@ ShaderImpl *RendererGL::createShader(GLenum type) ...@@ -82,7 +82,7 @@ ShaderImpl *RendererGL::createShader(GLenum type)
ProgramImpl *RendererGL::createProgram() ProgramImpl *RendererGL::createProgram()
{ {
return new ProgramGL(); return new ProgramGL(mFunctions, mStateManager);
} }
DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Surface *surface) DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Surface *surface)
......
...@@ -14,9 +14,19 @@ namespace rx ...@@ -14,9 +14,19 @@ namespace rx
{ {
StateManagerGL::StateManagerGL(const FunctionsGL *functions) StateManagerGL::StateManagerGL(const FunctionsGL *functions)
: mFunctions(functions) : mFunctions(functions),
mProgram(0)
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
} }
void StateManagerGL::setProgram(GLuint program)
{
if (mProgram != program)
{
mProgram = program;
mFunctions->useProgram(mProgram);
}
}
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define LIBANGLE_RENDERER_GL_STATEMANAGERGL_H_ #define LIBANGLE_RENDERER_GL_STATEMANAGERGL_H_
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/renderer/gl/functionsgl_typedefs.h"
namespace rx namespace rx
{ {
...@@ -21,10 +22,14 @@ class StateManagerGL ...@@ -21,10 +22,14 @@ class StateManagerGL
public: public:
StateManagerGL(const FunctionsGL *functions); StateManagerGL(const FunctionsGL *functions);
void setProgram(GLuint program);
private: private:
DISALLOW_COPY_AND_ASSIGN(StateManagerGL); DISALLOW_COPY_AND_ASSIGN(StateManagerGL);
const FunctionsGL *mFunctions; const FunctionsGL *mFunctions;
GLuint mProgram;
}; };
} }
......
...@@ -56,3 +56,89 @@ TYPED_TEST(SimpleOperationTest, CompileFragmentShader) ...@@ -56,3 +56,89 @@ TYPED_TEST(SimpleOperationTest, CompileFragmentShader)
EXPECT_GL_NO_ERROR(); 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