Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: gpu/command_buffer/client/gles2_demo_cc.cc

Issue 566021: [GPU] GLES2 lost context recovery (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/client/gles2_demo_cc.h ('k') | gpu/command_buffer/client/gles2_lib.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_demo_cc.h ('k') | gpu/command_buffer/client/gles2_lib.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698