Project import generated by Copybara.

GitOrigin-RevId: 3864d8399e063cfcacc9e3f6e7ba653ea9045c52
This commit is contained in:
MediaPipe Team
2020-06-09 18:35:58 -04:00
committed by chuoling
parent b09cc090d4
commit 59ee17c1f3
19 changed files with 130 additions and 685 deletions
+29 -4
View File
@@ -84,6 +84,8 @@ FrameRotation FrameRotationFromDegrees(int degrees_ccw) {
scale_unif_ = glGetUniformLocation(program_, "scale");
RET_CHECK(scale_unif_ != -1) << "could not find uniform 'scale'";
glGenBuffers(2, vbo_);
return ::mediapipe::OkStatus();
}
@@ -92,6 +94,11 @@ void QuadRenderer::GlTeardown() {
glDeleteProgram(program_);
program_ = 0;
}
if (vbo_[0]) {
glDeleteBuffers(2, vbo_);
vbo_[0] = 0;
vbo_[1] = 0;
}
}
::mediapipe::Status QuadRenderer::GlRender(
@@ -155,13 +162,31 @@ void QuadRenderer::GlTeardown() {
}
// Draw.
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, vertices);
// TODO: In practice, our vertex attributes almost never change, so
// convert this to being actually static, with initialization done in the
// GLSetup.
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(
ATTRIB_TEXTURE_POSITION, 2, GL_FLOAT, 0, 0,
flip_texture ? kBasicTextureVerticesFlipY : kBasicTextureVertices);
glBindBuffer(GL_ARRAY_BUFFER, vbo_[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(mediapipe::kBasicSquareVertices),
mediapipe::kBasicSquareVertices, GL_STATIC_DRAW);
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, nullptr);
glEnableVertexAttribArray(ATTRIB_TEXTURE_POSITION);
glBindBuffer(GL_ARRAY_BUFFER, vbo_[1]);
glBufferData(
GL_ARRAY_BUFFER,
flip_texture ? sizeof(mediapipe::kBasicTextureVerticesFlipY)
: sizeof(mediapipe::kBasicTextureVertices),
flip_texture ? kBasicTextureVerticesFlipY : kBasicTextureVertices,
GL_STATIC_DRAW);
glVertexAttribPointer(ATTRIB_TEXTURE_POSITION, 2, GL_FLOAT, 0, 0, nullptr);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(ATTRIB_VERTEX);
glDisableVertexAttribArray(ATTRIB_TEXTURE_POSITION);
glBindBuffer(GL_ARRAY_BUFFER, 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 vbo_[2] = {0, 0}; // for vertex buffer storage
};
::mediapipe::Status FrameRotationFromInt(FrameRotation* rotation,
+1 -1
View File
@@ -57,7 +57,7 @@ class GlThreadCollector {
return active_threads_ == 0;
};
absl::MutexLock l(&mutex_);
mutex_.Await(Condition(&done));
mutex_.Await(absl::Condition(&done));
}
absl::Mutex mutex_;