Index: remoting/client/opengl/gl_canvas.cc |
diff --git a/remoting/client/opengl/gl_canvas.cc b/remoting/client/opengl/gl_canvas.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5258839c8d22f07ce8b9a17214d55183da0e7c82 |
--- /dev/null |
+++ b/remoting/client/opengl/gl_canvas.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "remoting/client/opengl/gl_canvas.h" |
Sergey Ulanov
2016/06/27 23:15:29
please add empty line after this one
Yuwei
2016/06/28 22:51:11
Done.
|
+#include "base/logging.h" |
+#include "remoting/client/opengl/gl_helpers.h" |
+#include "remoting/client/opengl/shaders.h" |
+ |
+namespace { |
+ |
+const int kVertexSize = 2; |
+const int kVertexCount = 4; |
+ |
+const float k3x3ZeroMatrix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; |
+ |
+} // namespace |
+ |
+namespace remoting { |
+ |
+GlCanvas::GlCanvas() { |
+ vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert); |
+ fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag); |
+ program_ = CreateProgram(vertex_shader_, fragment_shader_); |
+ glUseProgram(program_); |
+ |
+ transform_loc_ = glGetUniformLocation(program_, "u_transform"); |
+ texture_loc_ = glGetUniformLocation(program_, "u_texture"); |
+ position_loc_ = glGetAttribLocation(program_, "a_position"); |
+ tex_cord_loc_ = glGetAttribLocation(program_, "a_texCoord"); |
+ glEnableVertexAttribArray(position_loc_); |
+ glEnableVertexAttribArray(tex_cord_loc_); |
+ glEnable(GL_BLEND); |
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
+ |
+ SetNormalizedTransformation(k3x3ZeroMatrix); |
+} |
+ |
+GlCanvas::~GlCanvas() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ glDeleteProgram(program_); |
+ glDeleteShader(vertex_shader_); |
+ glDeleteShader(fragment_shader_); |
+} |
+ |
+void GlCanvas::SetNormalizedTransformation(const float* matrix) { |
Sergey Ulanov
2016/06/27 23:15:29
This is called only from the constructor. Do you n
Yuwei
2016/06/28 01:31:20
Sorry that current CL doesn't show enough use case
|
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ glUniformMatrix3fv(transform_loc_, 1, GL_TRUE, matrix); |
+} |
+ |
+void GlCanvas::DrawTexture(int texture_id, |
+ GLuint texture_handle, |
+ GLuint vertex_buffer) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ glActiveTexture(GL_TEXTURE0 + texture_id); |
+ glBindTexture(GL_TEXTURE_2D, texture_handle); |
+ glUniform1i(texture_loc_, texture_id); |
+ glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); |
+ |
+ glVertexAttribPointer(position_loc_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 0); |
+ glVertexAttribPointer(tex_cord_loc_, kVertexSize, GL_FLOAT, GL_FALSE, 0, |
+ static_cast<float*>(0) + kVertexSize * kVertexCount); |
+ |
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount); |
+ glBindBuffer(GL_ARRAY_BUFFER, 0); |
+ glBindTexture(GL_TEXTURE_2D, 0); |
+} |
+ |
+} // namespace remoting |