Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #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.
| |
| 6 #include "base/logging.h" | |
| 7 #include "remoting/client/opengl/gl_helpers.h" | |
| 8 #include "remoting/client/opengl/shaders.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 const int kVertexSize = 2; | |
| 13 const int kVertexCount = 4; | |
| 14 | |
| 15 const float k3x3ZeroMatrix[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 namespace remoting { | |
| 20 | |
| 21 GlCanvas::GlCanvas() { | |
| 22 vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert); | |
| 23 fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag); | |
| 24 program_ = CreateProgram(vertex_shader_, fragment_shader_); | |
| 25 glUseProgram(program_); | |
| 26 | |
| 27 transform_loc_ = glGetUniformLocation(program_, "u_transform"); | |
| 28 texture_loc_ = glGetUniformLocation(program_, "u_texture"); | |
| 29 position_loc_ = glGetAttribLocation(program_, "a_position"); | |
| 30 tex_cord_loc_ = glGetAttribLocation(program_, "a_texCoord"); | |
| 31 glEnableVertexAttribArray(position_loc_); | |
| 32 glEnableVertexAttribArray(tex_cord_loc_); | |
| 33 glEnable(GL_BLEND); | |
| 34 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
| 35 | |
| 36 SetNormalizedTransformation(k3x3ZeroMatrix); | |
| 37 } | |
| 38 | |
| 39 GlCanvas::~GlCanvas() { | |
| 40 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 41 glDeleteProgram(program_); | |
| 42 glDeleteShader(vertex_shader_); | |
| 43 glDeleteShader(fragment_shader_); | |
| 44 } | |
| 45 | |
| 46 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
| |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 48 glUniformMatrix3fv(transform_loc_, 1, GL_TRUE, matrix); | |
| 49 } | |
| 50 | |
| 51 void GlCanvas::DrawTexture(int texture_id, | |
| 52 GLuint texture_handle, | |
| 53 GLuint vertex_buffer) { | |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 55 glActiveTexture(GL_TEXTURE0 + texture_id); | |
| 56 glBindTexture(GL_TEXTURE_2D, texture_handle); | |
| 57 glUniform1i(texture_loc_, texture_id); | |
| 58 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); | |
| 59 | |
| 60 glVertexAttribPointer(position_loc_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 0); | |
| 61 glVertexAttribPointer(tex_cord_loc_, kVertexSize, GL_FLOAT, GL_FALSE, 0, | |
| 62 static_cast<float*>(0) + kVertexSize * kVertexCount); | |
| 63 | |
| 64 glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount); | |
| 65 glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 66 glBindTexture(GL_TEXTURE_2D, 0); | |
| 67 } | |
| 68 | |
| 69 } // namespace remoting | |
| OLD | NEW |