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

Side by Side Diff: examples/sample_app/spinning_cube.cc

Issue 940293003: Add a Display and ContextProvider concept to mojom, use to recreate (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: android fixes Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 example program is based on Simple_VertexShader.c from: 5 // This example program is based on Simple_VertexShader.c from:
6 6
7 // 7 //
8 // Book: OpenGL(R) ES 2.0 Programming Guide 8 // Book: OpenGL(R) ES 2.0 Programming Guide
9 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner 9 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
10 // ISBN-10: 0321502795 10 // ISBN-10: 0321502795
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (!initialized_) 432 if (!initialized_)
433 return; 433 return;
434 if (state_->vbo_vertices_) 434 if (state_->vbo_vertices_)
435 glDeleteBuffers(1, &state_->vbo_vertices_); 435 glDeleteBuffers(1, &state_->vbo_vertices_);
436 if (state_->vbo_indices_) 436 if (state_->vbo_indices_)
437 glDeleteBuffers(1, &state_->vbo_indices_); 437 glDeleteBuffers(1, &state_->vbo_indices_);
438 if (state_->program_object_) 438 if (state_->program_object_)
439 glDeleteProgram(state_->program_object_); 439 glDeleteProgram(state_->program_object_);
440 } 440 }
441 441
442 void SpinningCube::Init(uint32_t width, uint32_t height) { 442 void SpinningCube::Init() {
443 width_ = width;
444 height_ = height;
445
446 const char vertex_shader_source[] = 443 const char vertex_shader_source[] =
447 "uniform mat4 u_mvpMatrix; \n" 444 "uniform mat4 u_mvpMatrix; \n"
448 "attribute vec4 a_position; \n" 445 "attribute vec4 a_position; \n"
449 "attribute vec4 a_normal; \n" 446 "attribute vec4 a_normal; \n"
450 "varying vec4 v_color; \n" 447 "varying vec4 v_color; \n"
451 "void main() \n" 448 "void main() \n"
452 "{ \n" 449 "{ \n"
453 " gl_Position = u_mvpMatrix * a_position; \n" 450 " gl_Position = u_mvpMatrix * a_position; \n"
454 " vec4 rotated_normal = u_mvpMatrix * a_normal; \n" 451 " vec4 rotated_normal = u_mvpMatrix * a_normal; \n"
455 " vec4 light_direction = normalize(vec4(0.0, 1.0, -1.0, 0.0)); \n" 452 " vec4 light_direction = normalize(vec4(0.0, 1.0, -1.0, 0.0)); \n"
(...skipping 21 matching lines...) Expand all
477 state_->mvp_location_ = glGetUniformLocation( 474 state_->mvp_location_ = glGetUniformLocation(
478 state_->program_object_, "u_mvpMatrix"); 475 state_->program_object_, "u_mvpMatrix");
479 state_->num_indices_ = GenerateCube( 476 state_->num_indices_ = GenerateCube(
480 &state_->vbo_vertices_, &state_->vbo_indices_); 477 &state_->vbo_vertices_, &state_->vbo_indices_);
481 478
482 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 479 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
483 glEnable(GL_DEPTH_TEST); 480 glEnable(GL_DEPTH_TEST);
484 initialized_ = true; 481 initialized_ = true;
485 } 482 }
486 483
487 void SpinningCube::OnGLContextLost() { 484 void SpinningCube::OnGLContextLost() {
qsr 2015/02/23 12:32:52 If I recall correctly, we never sent this. If you
jamesr 2015/03/04 00:19:51 Oh, good catch. Added a call in GLES2ClientImpl::
488 initialized_ = false; 485 initialized_ = false;
489 height_ = 0;
490 width_ = 0;
491 state_->OnGLContextLost(); 486 state_->OnGLContextLost();
492 } 487 }
493 488
494 void SpinningCube::SetFlingMultiplier(float drag_distance, 489 void SpinningCube::SetFlingMultiplier(float drag_distance,
495 float drag_time) { 490 float drag_time) {
496 fling_multiplier_ = RotationForDragDistance(drag_distance) / 491 fling_multiplier_ = RotationForDragDistance(drag_distance) /
497 RotationForTimeDelta(drag_time); 492 RotationForTimeDelta(drag_time);
498 493
499 } 494 }
500 495
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 543
549 ESMatrix modelview; 544 ESMatrix modelview;
550 modelview.LoadIdentity(); 545 modelview.LoadIdentity();
551 modelview.Translate(0.0, 0.0, -2.0); 546 modelview.Translate(0.0, 0.0, -2.0);
552 modelview.Rotate(state_->angle_ * direction_, 1.0, 0.0, 1.0); 547 modelview.Rotate(state_->angle_ * direction_, 1.0, 0.0, 1.0);
553 548
554 state_->mvp_matrix_.Multiply(&modelview, &perspective); 549 state_->mvp_matrix_.Multiply(&modelview, &perspective);
555 } 550 }
556 551
557 } // namespace examples 552 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698