| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file is here so other GLES2 related files can have a common set of | 5 // This file is here so other GLES2 related files can have a common set of |
| 6 // includes where appropriate. | 6 // includes where appropriate. |
| 7 | 7 |
| 8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
| 9 #include "gpu/command_buffer/client/gles2_demo_cc.h" | 9 #include "gpu/command_buffer/client/gles2_demo_cc.h" |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 glBufferData(GL_ARRAY_BUFFER, | 117 glBufferData(GL_ARRAY_BUFFER, |
| 118 sizeof(vertices) + sizeof(texCoords), | 118 sizeof(vertices) + sizeof(texCoords), |
| 119 NULL, | 119 NULL, |
| 120 GL_STATIC_DRAW); | 120 GL_STATIC_DRAW); |
| 121 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); | 121 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); |
| 122 glBufferSubData(GL_ARRAY_BUFFER, g_texCoordOffset, | 122 glBufferSubData(GL_ARRAY_BUFFER, g_texCoordOffset, |
| 123 sizeof(texCoords), texCoords); | 123 sizeof(texCoords), texCoords); |
| 124 CheckGLError(); | 124 CheckGLError(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void Draw() { | |
| 128 // Note: the viewport is automatically set up to cover the entire Canvas. | |
| 129 // Clear the color buffer | |
| 130 glClear(GL_COLOR_BUFFER_BIT); | |
| 131 CheckGLError(); | |
| 132 // Use the program object | |
| 133 glUseProgram(g_programObject); | |
| 134 CheckGLError(); | |
| 135 // Load the vertex data | |
| 136 glBindBuffer(GL_ARRAY_BUFFER, g_vbo); | |
| 137 glEnableVertexAttribArray(0); | |
| 138 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); | |
| 139 glEnableVertexAttribArray(1); | |
| 140 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, | |
| 141 reinterpret_cast<const void*>(g_texCoordOffset)); | |
| 142 CheckGLError(); | |
| 143 // Bind the texture to texture unit 0 | |
| 144 glBindTexture(GL_TEXTURE_2D, g_texture); | |
| 145 CheckGLError(); | |
| 146 // Point the uniform sampler to texture unit 0 | |
| 147 glUniform1i(g_textureLoc, 0); | |
| 148 CheckGLError(); | |
| 149 glDrawArrays(GL_TRIANGLES, 0, 6); | |
| 150 CheckGLError(); | |
| 151 glFlush(); | |
| 152 } | |
| 153 | |
| 154 GLuint CreateCheckerboardTexture() { | 127 GLuint CreateCheckerboardTexture() { |
| 155 static unsigned char pixels[] = { | 128 static unsigned char pixels[] = { |
| 156 255, 255, 255, | 129 255, 255, 255, |
| 157 0, 0, 0, | 130 0, 0, 0, |
| 158 0, 0, 0, | 131 0, 0, 0, |
| 159 255, 255, 255, | 132 255, 255, 255, |
| 160 }; | 133 }; |
| 161 GLuint texture; | 134 GLuint texture; |
| 162 glGenTextures(1, &texture); | 135 glGenTextures(1, &texture); |
| 163 glBindTexture(GL_TEXTURE_2D, texture); | 136 glBindTexture(GL_TEXTURE_2D, texture); |
| 164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 139 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 168 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 141 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 169 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, | 142 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, |
| 170 pixels); | 143 pixels); |
| 171 return texture; | 144 return texture; |
| 172 } | 145 } |
| 173 | 146 |
| 174 void Init() { | 147 } // anonymous namespace. |
| 148 |
| 149 void GLFromCPPInit() { |
| 175 glClearColor(0.f, 0.f, .7f, 1.f); | 150 glClearColor(0.f, 0.f, .7f, 1.f); |
| 176 g_texture = CreateCheckerboardTexture(); | 151 g_texture = CreateCheckerboardTexture(); |
| 177 InitShaders(); | 152 InitShaders(); |
| 178 } | 153 } |
| 179 | 154 |
| 180 } // anonymous namespace. | 155 void GLFromCPPDraw() { |
| 156 // Note: the viewport is automatically set up to cover the entire Canvas. |
| 157 // Clear the color buffer |
| 158 glClear(GL_COLOR_BUFFER_BIT); |
| 159 CheckGLError(); |
| 160 // Use the program object |
| 161 glUseProgram(g_programObject); |
| 162 CheckGLError(); |
| 163 // Load the vertex data |
| 164 glBindBuffer(GL_ARRAY_BUFFER, g_vbo); |
| 165 glEnableVertexAttribArray(0); |
| 166 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 167 glEnableVertexAttribArray(1); |
| 168 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, |
| 169 reinterpret_cast<const void*>(g_texCoordOffset)); |
| 170 CheckGLError(); |
| 171 // Bind the texture to texture unit 0 |
| 172 glBindTexture(GL_TEXTURE_2D, g_texture); |
| 173 CheckGLError(); |
| 174 // Point the uniform sampler to texture unit 0 |
| 175 glUniform1i(g_textureLoc, 0); |
| 176 CheckGLError(); |
| 177 glDrawArrays(GL_TRIANGLES, 0, 6); |
| 178 CheckGLError(); |
| 179 glFlush(); |
| 180 } |
| 181 | 181 |
| 182 void GLFromCPPTestFunction() { | |
| 183 static bool initialized = false; | |
| 184 if (!initialized) { | |
| 185 initialized = true; | |
| 186 Init(); | |
| 187 } | |
| 188 Draw(); | |
| 189 } | |
| OLD | NEW |