Project import generated by Copybara.

GitOrigin-RevId: f7d09ed033907b893638a8eb4148efa11c0f09a6
This commit is contained in:
MediaPipe Team
2020-11-04 19:09:58 -05:00
committed by chuoling
parent a8d6ce95c4
commit f96eadd6df
250 changed files with 15261 additions and 4620 deletions
+7
View File
@@ -84,6 +84,7 @@ FrameRotation FrameRotationFromDegrees(int degrees_ccw) {
scale_unif_ = glGetUniformLocation(program_, "scale");
RET_CHECK(scale_unif_ != -1) << "could not find uniform 'scale'";
glGenVertexArrays(1, &vao_);
glGenBuffers(2, vbo_);
return ::mediapipe::OkStatus();
@@ -94,6 +95,10 @@ void QuadRenderer::GlTeardown() {
glDeleteProgram(program_);
program_ = 0;
}
if (vao_) {
glDeleteVertexArrays(1, &vao_);
vao_ = 0;
}
if (vbo_[0]) {
glDeleteBuffers(2, vbo_);
vbo_[0] = 0;
@@ -166,6 +171,7 @@ void QuadRenderer::GlTeardown() {
// TODO: In practice, our vertex attributes almost never change, so
// convert this to being actually static, with initialization done in the
// GLSetup.
glBindVertexArray(vao_);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(mediapipe::kBasicSquareVertices),
@@ -187,6 +193,7 @@ void QuadRenderer::GlTeardown() {
glDisableVertexAttribArray(ATTRIB_VERTEX);
glDisableVertexAttribArray(ATTRIB_TEXTURE_POSITION);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
return ::mediapipe::OkStatus();
}
+1
View File
@@ -83,6 +83,7 @@ class QuadRenderer {
GLuint program_ = 0;
GLint scale_unif_ = -1;
std::vector<GLint> frame_unifs_;
GLuint vao_; // vertex array object
GLuint vbo_[2] = {0, 0}; // for vertex buffer storage
};
+2 -2
View File
@@ -215,7 +215,7 @@ REGISTER_CALCULATOR(GlScalerCalculator);
src1 = helper_.CreateSourceTexture(input, 0);
src2 = helper_.CreateSourceTexture(input, 1);
} else // NOLINT(readability/braces)
#endif // __APPLE__
#endif // __APPLE__
{
src1 = helper_.CreateSourceTexture(input);
#ifdef __ANDROID__
@@ -227,7 +227,7 @@ REGISTER_CALCULATOR(GlScalerCalculator);
}
renderer = ext_rgb_renderer_.get();
} else // NOLINT(readability/braces)
#endif // __ANDROID__
#endif // __ANDROID__
{
if (!rgb_renderer_) {
rgb_renderer_ = absl::make_unique<QuadRenderer>();
+6 -5
View File
@@ -69,6 +69,7 @@ namespace mediapipe {
"#elif __VERSION__ > 320 && !defined(GL_ES)\n" \
"out vec4 frag_out; \n" \
"#define gl_FragColor frag_out\n" \
"#define texture2D texture\n" \
"#endif // __VERSION__ < 130\n"
const GLchar* const kMediaPipeVertexShaderPreamble = VERTEX_PREAMBLE;
@@ -104,7 +105,7 @@ const GLchar* const kBasicTexturedFragmentShader = FRAGMENT_PREAMBLE _STRINGIFY(
in mediump vec2 sample_coordinate; // texture coordinate (0..1)
uniform sampler2D video_frame;
void main() { gl_FragColor = texture2D(video_frame, sample_coordinate); });
void main() { gl_FragColor = texture(video_frame, sample_coordinate); });
const GLchar* const kBasicTexturedFragmentShaderOES = FRAGMENT_PREAMBLE
"#extension GL_OES_EGL_image_external : require\n" _STRINGIFY(
@@ -114,7 +115,7 @@ const GLchar* const kBasicTexturedFragmentShaderOES = FRAGMENT_PREAMBLE
uniform samplerExternalOES video_frame;
void main() {
gl_FragColor = texture2D(video_frame, sample_coordinate);
gl_FragColor = texture(video_frame, sample_coordinate);
});
const GLchar* const kFlatColorFragmentShader = FRAGMENT_PREAMBLE _STRINGIFY(
@@ -131,7 +132,7 @@ const GLchar* const kRgbWeightFragmentShader = FRAGMENT_PREAMBLE _STRINGIFY(
uniform sampler2D video_frame; uniform vec3 weights; // r,g,b weights
void main() {
vec4 color = texture2D(video_frame, sample_coordinate);
vec4 color = texture(video_frame, sample_coordinate);
gl_FragColor.bgra = vec4(weights.z * color.b, weights.y * color.g,
weights.x * color.r, color.a);
});
@@ -145,10 +146,10 @@ const GLchar* const kYUV2TexToRGBFragmentShader = FRAGMENT_PREAMBLE _STRINGIFY(
void main() {
mediump vec3 yuv;
lowp vec3 rgb;
yuv.r = texture2D(video_frame_y, sample_coordinate).r;
yuv.r = texture(video_frame_y, sample_coordinate).r;
// Subtract (0.5, 0.5) because conversion is done assuming UV color
// midpoint of (128, 128).
yuv.gb = texture2D(video_frame_uv, sample_coordinate).rg - vec2(0.5, 0.5);
yuv.gb = texture(video_frame_uv, sample_coordinate).rg - vec2(0.5, 0.5);
// Using BT.709 which is the standard for HDTV.
rgb = mat3(1, 1, 1, 0, -0.18732, 1.8556, 1.57481, -0.46813, 0) * yuv;
gl_FragColor = vec4(rgb, 1);