Index: ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
diff --git a/mojo/examples/sample_app/spinning_cube.cc b/ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
similarity index 87% |
copy from mojo/examples/sample_app/spinning_cube.cc |
copy to ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
index 7983563fd60ebf55eeb415aceefb1b89e7a28e50..c4d33ddc87ec46b3c372dd1aeb9c906966134c2e 100644 |
--- a/mojo/examples/sample_app/spinning_cube.cc |
+++ b/ppapi/examples/gles2_spinning_cube/spinning_cube.cc |
@@ -1,4 +1,4 @@ |
-// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Copyright 2014 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. |
@@ -14,16 +14,15 @@ |
// http://www.opengles-book.com |
// |
-#include "mojo/examples/sample_app/spinning_cube.h" |
+#include "ppapi/examples/gles2_spinning_cube/spinning_cube.h" |
#include <math.h> |
#include <stdlib.h> |
#include <string.h> |
-#include <GLES2/gl2.h> |
-#include <GLES2/gl2ext.h> |
-namespace mojo { |
-namespace examples { |
+#include <algorithm> |
+ |
+#include "ppapi/lib/gl/include/GLES2/gl2.h" |
namespace { |
@@ -353,41 +352,47 @@ SpinningCube::~SpinningCube() { |
glDeleteBuffers(1, &state_->vbo_indices_); |
if (state_->program_object_) |
glDeleteProgram(state_->program_object_); |
+ |
+ delete state_; |
} |
void SpinningCube::Init(uint32_t width, uint32_t height) { |
width_ = width; |
height_ = height; |
- const char vertext_shader_source[] = |
- "uniform mat4 u_mvpMatrix; \n" |
- "attribute vec4 a_position; \n" |
- "void main() \n" |
- "{ \n" |
- " gl_Position = u_mvpMatrix * a_position; \n" |
- "} \n"; |
- |
- const char fragment_shader_source[] = |
- "precision mediump float; \n" |
- "void main() \n" |
- "{ \n" |
- " gl_FragColor = vec4( 0.0, 1.0, 0.0, 1.0 ); \n" |
- "} \n"; |
- |
- state_->program_object_ = LoadProgram( |
- vertext_shader_source, fragment_shader_source); |
- state_->position_location_ = glGetAttribLocation( |
- state_->program_object_, "a_position"); |
- state_->mvp_location_ = glGetUniformLocation( |
- state_->program_object_, "u_mvpMatrix"); |
- state_->num_indices_ = GenerateCube( |
- &state_->vbo_vertices_, &state_->vbo_indices_); |
- |
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
- initialized_ = true; |
+ if (!initialized_) { |
+ initialized_ = true; |
+ const char vertext_shader_source[] = |
+ "uniform mat4 u_mvpMatrix; \n" |
+ "attribute vec4 a_position; \n" |
+ "void main() \n" |
+ "{ \n" |
+ " gl_Position = u_mvpMatrix * a_position; \n" |
+ "} \n"; |
+ |
+ const char fragment_shader_source[] = |
+ "precision mediump float; \n" |
+ "void main() \n" |
+ "{ \n" |
+ " gl_FragColor = vec4( 0.0, 0.0, 1.0, 1.0 ); \n" |
+ "} \n"; |
+ |
+ state_->program_object_ = LoadProgram( |
+ vertext_shader_source, fragment_shader_source); |
+ state_->position_location_ = glGetAttribLocation( |
+ state_->program_object_, "a_position"); |
+ state_->mvp_location_ = glGetUniformLocation( |
+ state_->program_object_, "u_mvpMatrix"); |
+ state_->num_indices_ = GenerateCube( |
+ &state_->vbo_vertices_, &state_->vbo_indices_); |
+ |
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
+ } |
} |
void SpinningCube::OnGLContextLost() { |
+ // TODO(yzshen): Is it correct that in this case we don't need to do cleanup |
+ // for program and buffers? |
initialized_ = false; |
height_ = 0; |
width_ = 0; |
@@ -459,6 +464,3 @@ void SpinningCube::Update() { |
state_->mvp_matrix_.Multiply(&modelview, &perspective); |
} |
- |
-} // namespace examples |
-} // namespace mojo |