Index: remoting/client/ios/display/gl_demo_screen.mm |
diff --git a/remoting/client/ios/display/gl_demo_screen.mm b/remoting/client/ios/display/gl_demo_screen.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f637fcfb9bd17a2818aa2d6fb9863ba57872141 |
--- /dev/null |
+++ b/remoting/client/ios/display/gl_demo_screen.mm |
@@ -0,0 +1,101 @@ |
+// 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/ios/display/gl_demo_screen.h" |
+ |
+#import <Foundation/Foundation.h> |
+ |
+#include "base/logging.h" |
+#include "base/memory/ptr_util.h" |
+#include "remoting/client/gl_canvas.h" |
+#include "remoting/client/gl_math.h" |
+ |
+namespace remoting { |
+ |
+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
|
+ |
+const GLchar* fragmentShaderSource = |
+ "precision mediump float;" |
+ "void main() {" |
+ " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);" |
+ "} "; |
+ |
+const GLchar* vertexShaderSource = |
+ "precision mediump float;" |
+ "attribute vec4 a_position;" |
+ "void main() {" |
+ " gl_Position = a_position;" |
+ "}"; |
+ |
+const GLchar* a_position = "a_position"; |
Yuwei
2016/12/19 23:26:09
Maybe |kAPositionAttribute|?
|
+ |
+GlDemoScreen::GlDemoScreen() {} |
+ |
+GlDemoScreen::~GlDemoScreen() {} |
+ |
+void GlDemoScreen::SetCanvas(GlCanvas* canvas) { |
+ canvas_ = canvas; |
+ |
+ // Create and compile vertex shader |
+ GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); |
+ glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); |
+ glCompileShader(vertexShader); |
+ |
+ // Create and compile fragment shader |
+ GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); |
+ glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); |
+ glCompileShader(fragmentShader); |
+ |
+ // Create and link program |
+ program = glCreateProgram(); |
+ glAttachShader(program, vertexShader); |
+ glAttachShader(program, fragmentShader); |
+ glLinkProgram(program); |
+} |
+ |
+void GlDemoScreen::Draw() { |
+ if (!canvas_) { |
+ return; |
+ } |
+ |
+ int width = 640; |
+ int height = 1024; |
+ square_size++; |
+ if (square_size > 300) { |
+ square_size = 1; |
+ } |
+ |
+ // Set the viewport |
+ glViewport(0, 0, width, height); |
+ |
+ // Clear |
+ glClearColor(0, 1, 0, 1); |
+ glClear(GL_COLOR_BUFFER_BIT); |
+ |
+ // Use program |
+ glUseProgram(program); |
Yuwei
2016/12/19 23:26:09
GlCanvas was supposed to be used to draw textures
|
+ |
+ int skip = 0; |
+ for (int i = 0; i < width; i += square_size) { |
+ if (skip == square_size) { |
+ skip = 0; |
+ } else { |
+ skip = square_size; |
+ } |
+ for (int j = skip; j < height; j += square_size * 2) { |
+ glViewport(i, j, square_size, square_size); |
+ |
+ // Send geometry to vertex shader |
+ GLuint aPosition = glGetAttribLocation(program, a_position); |
Yuwei
2016/12/19 23:26:09
Nit: maybe getting it once and store it in SetCanv
|
+ |
+ glVertexAttribPointer(aPosition, 2, GL_FLOAT, GL_FALSE, 0, square); |
+ glEnableVertexAttribArray(aPosition); |
+ |
+ // Draw |
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
+ } |
+ } |
+} |
+ |
+} // namespace remoting |