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/ios/display/gl_demo_screen.h" | |
| 6 | |
| 7 #import <Foundation/Foundation.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "remoting/client/gl_canvas.h" | |
| 12 #include "remoting/client/gl_math.h" | |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 const GLfloat square[] = {-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0}; | |
|
Yuwei
2016/12/19 23:26:09
kSquare?
https://google.github.io/styleguide/cppg
| |
| 17 | |
| 18 const GLchar* fragmentShaderSource = | |
| 19 "precision mediump float;" | |
| 20 "void main() {" | |
| 21 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);" | |
| 22 "} "; | |
| 23 | |
| 24 const GLchar* vertexShaderSource = | |
| 25 "precision mediump float;" | |
| 26 "attribute vec4 a_position;" | |
| 27 "void main() {" | |
| 28 " gl_Position = a_position;" | |
| 29 "}"; | |
| 30 | |
| 31 const GLchar* a_position = "a_position"; | |
|
Yuwei
2016/12/19 23:26:09
Maybe |kAPositionAttribute|?
| |
| 32 | |
| 33 GlDemoScreen::GlDemoScreen() {} | |
| 34 | |
| 35 GlDemoScreen::~GlDemoScreen() {} | |
| 36 | |
| 37 void GlDemoScreen::SetCanvas(GlCanvas* canvas) { | |
| 38 canvas_ = canvas; | |
| 39 | |
| 40 // Create and compile vertex shader | |
| 41 GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); | |
| 42 glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); | |
| 43 glCompileShader(vertexShader); | |
| 44 | |
| 45 // Create and compile fragment shader | |
| 46 GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); | |
| 47 glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); | |
| 48 glCompileShader(fragmentShader); | |
| 49 | |
| 50 // Create and link program | |
| 51 program = glCreateProgram(); | |
| 52 glAttachShader(program, vertexShader); | |
| 53 glAttachShader(program, fragmentShader); | |
| 54 glLinkProgram(program); | |
| 55 } | |
| 56 | |
| 57 void GlDemoScreen::Draw() { | |
| 58 if (!canvas_) { | |
| 59 return; | |
| 60 } | |
| 61 | |
| 62 int width = 640; | |
| 63 int height = 1024; | |
| 64 square_size++; | |
| 65 if (square_size > 300) { | |
| 66 square_size = 1; | |
| 67 } | |
| 68 | |
| 69 // Set the viewport | |
| 70 glViewport(0, 0, width, height); | |
| 71 | |
| 72 // Clear | |
| 73 glClearColor(0, 1, 0, 1); | |
| 74 glClear(GL_COLOR_BUFFER_BIT); | |
| 75 | |
| 76 // Use program | |
| 77 glUseProgram(program); | |
|
Yuwei
2016/12/19 23:26:09
GlCanvas was supposed to be used to draw textures
| |
| 78 | |
| 79 int skip = 0; | |
| 80 for (int i = 0; i < width; i += square_size) { | |
| 81 if (skip == square_size) { | |
| 82 skip = 0; | |
| 83 } else { | |
| 84 skip = square_size; | |
| 85 } | |
| 86 for (int j = skip; j < height; j += square_size * 2) { | |
| 87 glViewport(i, j, square_size, square_size); | |
| 88 | |
| 89 // Send geometry to vertex shader | |
| 90 GLuint aPosition = glGetAttribLocation(program, a_position); | |
|
Yuwei
2016/12/19 23:26:09
Nit: maybe getting it once and store it in SetCanv
| |
| 91 | |
| 92 glVertexAttribPointer(aPosition, 2, GL_FLOAT, GL_FALSE, 0, square); | |
| 93 glEnableVertexAttribArray(aPosition); | |
| 94 | |
| 95 // Draw | |
| 96 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 } // namespace remoting | |
| OLD | NEW |