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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_renderer.cc

Issue 2902043005: [vr] Add incognito coloring (Closed)
Patch Set: merged changes from aldo and amp Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 uniform vec4 u_CopyRect; // rectangle 131 uniform vec4 u_CopyRect; // rectangle
132 varying vec2 v_TexCoordinate; 132 varying vec2 v_TexCoordinate;
133 uniform lowp vec4 color; 133 uniform lowp vec4 color;
134 uniform mediump float opacity; 134 uniform mediump float opacity;
135 135
136 void main() { 136 void main() {
137 vec2 scaledTex = 137 vec2 scaledTex =
138 vec2(u_CopyRect[0] + v_TexCoordinate.x * u_CopyRect[2], 138 vec2(u_CopyRect[0] + v_TexCoordinate.x * u_CopyRect[2],
139 u_CopyRect[1] + v_TexCoordinate.y * u_CopyRect[3]); 139 u_CopyRect[1] + v_TexCoordinate.y * u_CopyRect[3]);
140 lowp vec4 color = texture2D(u_Texture, scaledTex); 140 lowp vec4 color = texture2D(u_Texture, scaledTex);
141 gl_FragColor = vec4(color.xyz, color.w * opacity); 141 // premultiply opacity
tiborg 2017/05/25 00:47:18 Nit: capital P and period in the end.
142 gl_FragColor = color * opacity;
142 } 143 }
143 /* clang-format on */); 144 /* clang-format on */);
144 case vr_shell::ShaderID::WEBVR_VERTEX_SHADER: 145 case vr_shell::ShaderID::WEBVR_VERTEX_SHADER:
145 return SHADER( 146 return SHADER(
146 /* clang-format off */ 147 /* clang-format off */
147 precision mediump float; 148 precision mediump float;
148 attribute vec3 a_Position; 149 attribute vec3 a_Position;
149 attribute vec2 a_TexCoordinate; 150 attribute vec2 a_TexCoordinate;
150 varying highp vec2 v_TexCoordinate; 151 varying highp vec2 v_TexCoordinate;
151 152
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER: 245 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER:
245 return SHADER( 246 return SHADER(
246 /* clang-format off */ 247 /* clang-format off */
247 precision mediump float; 248 precision mediump float;
248 uniform sampler2D u_texture; 249 uniform sampler2D u_texture;
249 varying vec2 v_TexCoordinate; 250 varying vec2 v_TexCoordinate;
250 uniform mediump float u_Opacity; 251 uniform mediump float u_Opacity;
251 252
252 void main() { 253 void main() {
253 lowp vec4 texture_color = texture2D(u_texture, v_TexCoordinate); 254 lowp vec4 texture_color = texture2D(u_texture, v_TexCoordinate);
254 gl_FragColor = vec4(texture_color.xyz, texture_color.w * u_Opacity); 255 // premultiply alpha
tiborg 2017/05/25 00:47:18 Here too.
256 gl_FragColor = texture_color * u_Opacity;
255 } 257 }
256 /* clang-format on */); 258 /* clang-format on */);
257 default: 259 default:
258 LOG(ERROR) << "Shader source requested for unknown shader"; 260 LOG(ERROR) << "Shader source requested for unknown shader";
259 return ""; 261 return "";
260 } 262 }
261 } 263 }
262 264
263 } // namespace 265 } // namespace
264 266
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 VOID_OFFSET(kPositionDataOffset)); 410 VOID_OFFSET(kPositionDataOffset));
409 glEnableVertexAttribArray(position_handle_); 411 glEnableVertexAttribArray(position_handle_);
410 412
411 // Set up texture coordinate attribute. 413 // Set up texture coordinate attribute.
412 glVertexAttribPointer(tex_coord_handle_, kTextureCoordinateDataSize, GL_FLOAT, 414 glVertexAttribPointer(tex_coord_handle_, kTextureCoordinateDataSize, GL_FLOAT,
413 false, kTextureQuadDataStride, 415 false, kTextureQuadDataStride,
414 VOID_OFFSET(kTextureCoordinateDataOffset)); 416 VOID_OFFSET(kTextureCoordinateDataOffset));
415 glEnableVertexAttribArray(tex_coord_handle_); 417 glEnableVertexAttribArray(tex_coord_handle_);
416 418
417 glEnable(GL_BLEND); 419 glEnable(GL_BLEND);
418 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 420 // Our textures have premultiplied alpha
tiborg 2017/05/25 00:47:18 Nit: period in the end.
421 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
419 422
420 // Link texture data with texture unit. 423 // Link texture data with texture unit.
421 glActiveTexture(GL_TEXTURE0); 424 glActiveTexture(GL_TEXTURE0);
422 glUniform1i(tex_uniform_handle_, 0); 425 glUniform1i(tex_uniform_handle_, 0);
423 426
424 // TODO(bajones): This should eventually be changed to use instancing so that 427 // TODO(bajones): This should eventually be changed to use instancing so that
425 // the entire queue can be processed in one draw call. For now this still 428 // the entire queue can be processed in one draw call. For now this still
426 // significantly reduces the amount of state changes made per draw. 429 // significantly reduces the amount of state changes made per draw.
427 while (!quad_queue_.empty()) { 430 while (!quad_queue_.empty()) {
428 const SkiaQuad& quad = quad_queue_.front(); 431 const SkiaQuad& quad = quad_queue_.front();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 glVertexAttribPointer(position_handle_, position_components_, position_type_, 663 glVertexAttribPointer(position_handle_, position_components_, position_type_,
661 GL_FALSE, position_stride_, position_offset_); 664 GL_FALSE, position_stride_, position_offset_);
662 glEnableVertexAttribArray(position_handle_); 665 glEnableVertexAttribArray(position_handle_);
663 666
664 glVertexAttribPointer(tex_coord_handle_, tex_coord_components_, 667 glVertexAttribPointer(tex_coord_handle_, tex_coord_components_,
665 tex_coord_type_, GL_FALSE, tex_coord_stride_, 668 tex_coord_type_, GL_FALSE, tex_coord_stride_,
666 tex_coord_offset_); 669 tex_coord_offset_);
667 glEnableVertexAttribArray(tex_coord_handle_); 670 glEnableVertexAttribArray(tex_coord_handle_);
668 671
669 glEnable(GL_BLEND); 672 glEnable(GL_BLEND);
670 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 673 // Our textures have premultiplied alpha.
674 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
671 675
672 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_); 676 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_);
673 677
674 glActiveTexture(GL_TEXTURE0); 678 glActiveTexture(GL_TEXTURE0);
675 glBindTexture(GL_TEXTURE_2D, texture_handles_[state]); 679 glBindTexture(GL_TEXTURE_2D, texture_handles_[state]);
676 glUniform1i(tex_uniform_handle_, 0); 680 glUniform1i(tex_uniform_handle_, 0);
677 681
678 glDrawElements(draw_mode_, indices_count_, indices_type_, indices_offset_); 682 glDrawElements(draw_mode_, indices_count_, indices_type_, indices_offset_);
679 } 683 }
680 684
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 GradientGridRenderer* VrShellRenderer::GetGradientGridRenderer() { 856 GradientGridRenderer* VrShellRenderer::GetGradientGridRenderer() {
853 Flush(); 857 Flush();
854 return gradient_grid_renderer_.get(); 858 return gradient_grid_renderer_.get();
855 } 859 }
856 860
857 void VrShellRenderer::Flush() { 861 void VrShellRenderer::Flush() {
858 textured_quad_renderer_->Flush(); 862 textured_quad_renderer_->Flush();
859 } 863 }
860 864
861 } // namespace vr_shell 865 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698