Commit 624fbdcf by Olli Etuaho Committed by Commit Bot

Refactor CompileProgram utility

Tests often need to call gl functions to set up program related state after glCreateProgram has been called but prior to glLinkProgram is called. Add a callback function to the CompileProgram utility function to fulfill this need. This reduces code duplication considerably in several tests. An alternative way to improve CompileProgram would be to split it into several different utility functions. This might be slightly easier to read, but would also be a larger refactoring and require more checks at the call site. This will make it easier to implement EXT_blend_func_extended tests, which need to bind fragment outputs to different slots. BUG=angleproject:1085 TEST=angle_end2end_tests Change-Id: I3ac8b7bdc21c6a1f14517bc7df0cf6f35abd7612 Reviewed-on: https://chromium-review.googlesource.com/1254062 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 079a6bc3
......@@ -985,21 +985,10 @@ TEST_P(VertexAttributeTest, DisabledAttribArrays)
for (GLint colorIndex = 0; colorIndex < maxVertexAttribs; ++colorIndex)
{
GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
ASSERT_NE(0u, vs);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
ASSERT_NE(0u, fs);
GLuint program = glCreateProgram();
glBindAttribLocation(program, colorIndex, "a_color");
glAttachShader(program, vs);
glDeleteShader(vs);
glAttachShader(program, fs);
glDeleteShader(fs);
ASSERT_TRUE(LinkAttachedProgram(program));
GLuint program = CompileProgram(vsSource, fsSource, [&](GLuint program) {
glBindAttribLocation(program, colorIndex, "a_color");
});
ASSERT_NE(0u, program);
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
......
......@@ -116,24 +116,11 @@ GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages)
return program;
}
GLuint CompileProgramWithTransformFeedback(
const std::string &vsSource,
const std::string &fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode)
static GLuint CompileProgramInternal(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource,
const std::function<void(GLuint)> &preLinkCallback)
{
return CompileProgramWithGSAndTransformFeedback(vsSource, "", fsSource,
transformFeedbackVaryings, bufferMode);
}
static GLuint CompileAndLinkProgram(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode)
{
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
......@@ -141,19 +128,22 @@ static GLuint CompileAndLinkProgram(const std::string &vsSource,
{
glDeleteShader(fs);
glDeleteShader(vs);
glDeleteProgram(program);
return 0;
}
GLuint program = glCreateProgram();
glAttachShader(program, vs);
glDeleteShader(vs);
glAttachShader(program, fs);
glDeleteShader(fs);
GLuint gs = 0;
if (!gsSource.empty())
{
GLuint gs = CompileShader(GL_GEOMETRY_SHADER_EXT, gsSource);
gs = CompileShader(GL_GEOMETRY_SHADER_EXT, gsSource);
if (gs == 0)
{
glDeleteShader(vs);
......@@ -166,52 +156,58 @@ static GLuint CompileAndLinkProgram(const std::string &vsSource,
glDeleteShader(gs);
}
if (transformFeedbackVaryings.size() > 0)
if (preLinkCallback)
{
std::vector<const char *> constCharTFVaryings;
for (const std::string &transformFeedbackVarying : transformFeedbackVaryings)
{
constCharTFVaryings.push_back(transformFeedbackVarying.c_str());
}
glTransformFeedbackVaryings(program, static_cast<GLsizei>(transformFeedbackVaryings.size()),
&constCharTFVaryings[0], bufferMode);
preLinkCallback(program);
}
glLinkProgram(program);
return program;
return CheckLinkStatusAndReturnProgram(program, true);
}
GLuint CompileProgramWithGSAndTransformFeedback(
GLuint CompileProgramWithTransformFeedback(
const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode)
{
GLuint program =
CompileAndLinkProgram(vsSource, gsSource, fsSource, transformFeedbackVaryings, bufferMode);
if (program == 0)
{
return 0;
}
return CheckLinkStatusAndReturnProgram(program, true);
auto preLink = [&](GLuint program) {
if (transformFeedbackVaryings.size() > 0)
{
std::vector<const char *> constCharTFVaryings;
for (const std::string &transformFeedbackVarying : transformFeedbackVaryings)
{
constCharTFVaryings.push_back(transformFeedbackVarying.c_str());
}
glTransformFeedbackVaryings(program,
static_cast<GLsizei>(transformFeedbackVaryings.size()),
&constCharTFVaryings[0], bufferMode);
}
};
return CompileProgramInternal(vsSource, "", fsSource, preLink);
}
GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource)
{
return CompileProgramWithGS(vsSource, "", fsSource);
return CompileProgramInternal(vsSource, "", fsSource, nullptr);
}
GLuint CompileProgram(const std::string &vsSource,
const std::string &fsSource,
const std::function<void(GLuint)> &preLinkCallback)
{
return CompileProgramInternal(vsSource, "", fsSource, preLinkCallback);
}
GLuint CompileProgramWithGS(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource)
{
std::vector<std::string> emptyVector;
return CompileProgramWithGSAndTransformFeedback(vsSource, gsSource, fsSource, emptyVector,
GL_NONE);
return CompileProgramInternal(vsSource, gsSource, fsSource, nullptr);
}
GLuint CompileProgramFromFiles(const std::string &vsPath, const std::string &fsPath)
......
......@@ -15,6 +15,7 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <functional>
#include <string>
#include <vector>
......@@ -27,14 +28,13 @@ CompileProgramWithTransformFeedback(const std::string &vsSource,
const std::string &fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode);
ANGLE_EXPORT GLuint
CompileProgramWithGSAndTransformFeedback(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum bufferMode);
ANGLE_EXPORT GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource);
ANGLE_EXPORT GLuint CompileProgram(const std::string &vsSource,
const std::string &fsSource,
const std::function<void(GLuint)> &preLinkCallback);
ANGLE_EXPORT GLuint CompileProgramWithGS(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource);
......
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