Commit b07132cf authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[ar] Avoid using VR UI code for AR rendering

While VR and AR may one day be able to share code, this will complicate
our lives in the short term. With this change I've added an ArRenderer
to handle the modest GL work that's required by AR.

Bug: 838013
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ibdbcb5729a7f70f0c63ef4c72ffd2804ed351eab
Reviewed-on: https://chromium-review.googlesource.com/1147218
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577301}
parent 4d2a7a01
...@@ -53,6 +53,8 @@ static_library("vr_android") { ...@@ -53,6 +53,8 @@ static_library("vr_android") {
sources += [ sources += [
"arcore_device/ar_image_transport.cc", "arcore_device/ar_image_transport.cc",
"arcore_device/ar_image_transport.h", "arcore_device/ar_image_transport.h",
"arcore_device/ar_renderer.cc",
"arcore_device/ar_renderer.h",
"arcore_device/arcore.h", "arcore_device/arcore.h",
"arcore_device/arcore_device.cc", "arcore_device/arcore_device.cc",
"arcore_device/arcore_device.h", "arcore_device/arcore_device.h",
...@@ -77,7 +79,7 @@ static_library("vr_android") { ...@@ -77,7 +79,7 @@ static_library("vr_android") {
":vr_jni_headers", ":vr_jni_headers",
"//base", "//base",
"//cc", "//cc",
"//chrome/browser/vr:vr_common", "//chrome/browser/vr:vr_gl_utils",
"//components/omnibox/browser", "//components/omnibox/browser",
"//components/rappor", "//components/rappor",
"//content/public/browser", "//content/public/browser",
......
...@@ -75,8 +75,7 @@ bool ARImageTransport::Initialize() { ...@@ -75,8 +75,7 @@ bool ARImageTransport::Initialize() {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
web_vr_renderer_ = std::make_unique<vr::WebVrRenderer>(); ar_renderer_ = std::make_unique<ArRenderer>();
vr::BaseQuadRenderer::CreateBuffers();
glGenTextures(1, &camera_texture_id_arcore_); glGenTextures(1, &camera_texture_id_arcore_);
SetupHardwareBuffers(); SetupHardwareBuffers();
...@@ -192,7 +191,7 @@ gpu::MailboxHolder ARImageTransport::TransferFrame( ...@@ -192,7 +191,7 @@ gpu::MailboxHolder ARImageTransport::TransferFrame(
// Don't need face culling, depth testing, blending, etc. Turn it all off. // Don't need face culling, depth testing, blending, etc. Turn it all off.
// TODO(klausw): see if we can do this one time on initialization. That would // TODO(klausw): see if we can do this one time on initialization. That would
// be a tiny bit more efficient, but is only safe if ARCore and WebVrRenderer // be a tiny bit more efficient, but is only safe if ARCore and ArRenderer
// don't modify these states. // don't modify these states.
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
...@@ -203,7 +202,7 @@ gpu::MailboxHolder ARImageTransport::TransferFrame( ...@@ -203,7 +202,7 @@ gpu::MailboxHolder ARImageTransport::TransferFrame(
// Draw the ARCore texture! // Draw the ARCore texture!
float uv_transform_floats[16]; float uv_transform_floats[16];
uv_transform.matrix().asColMajorf(uv_transform_floats); uv_transform.matrix().asColMajorf(uv_transform_floats);
web_vr_renderer_->Draw(camera_texture_id_arcore_, uv_transform_floats, 0, 0); ar_renderer_->Draw(camera_texture_id_arcore_, uv_transform_floats, 0, 0);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "chrome/browser/vr/renderers/web_vr_renderer.h" #include "chrome/browser/android/vr/arcore_device/ar_renderer.h"
#include "device/vr/public/mojom/vr_service.mojom.h" #include "device/vr/public/mojom/vr_service.mojom.h"
#include "ui/gfx/geometry/size_f.h" #include "ui/gfx/geometry/size_f.h"
...@@ -48,8 +48,7 @@ class ARImageTransport { ...@@ -48,8 +48,7 @@ class ARImageTransport {
void SetupHardwareBuffers(); void SetupHardwareBuffers();
void ResizeSharedBuffer(const gfx::Size& size, SharedFrameBuffer* buffer); void ResizeSharedBuffer(const gfx::Size& size, SharedFrameBuffer* buffer);
bool IsOnGlThread() const; bool IsOnGlThread() const;
// TODO(https://crbug.com/838013): rename WebVRRenderer. std::unique_ptr<ArRenderer> ar_renderer_;
std::unique_ptr<vr::WebVrRenderer> web_vr_renderer_;
// samplerExternalOES texture data for WebXR content image. // samplerExternalOES texture data for WebXR content image.
GLuint camera_texture_id_arcore_ = 0; GLuint camera_texture_id_arcore_ = 0;
GLuint camera_fbo_ = 0; GLuint camera_fbo_ = 0;
......
// Copyright 2018 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.
#include "chrome/browser/android/vr/arcore_device/ar_renderer.h"
#include "base/stl_util.h"
#include "chrome/browser/vr/vr_gl_util.h"
namespace device {
namespace {
static constexpr float kQuadVertices[8] = {
-0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, -0.5f,
};
static constexpr GLushort kQuadIndices[6] = {0, 1, 2, 1, 3, 2};
// clang-format off
static constexpr char const* kVertexShader = SHADER(
precision mediump float;
uniform mat4 u_UvTransform;
attribute vec4 a_Position;
varying vec2 v_TexCoordinate;
uniform float u_XBorder;
uniform float u_YBorder;
void main() {
// The quad vertex coordinate range is [-0.5, 0.5]. Transform to [0, 1],
// scale to cause the borders to wrap the texture, then apply the supplied
// affine transform matrix to get the final UV.
float xposition = a_Position[0] + 0.5;
xposition = xposition * (2.0 * u_XBorder + 1.0) - u_XBorder;
float yposition = a_Position[1] + 0.5;
yposition = yposition * (2.0 * u_YBorder + 1.0) - u_YBorder;
vec4 uv_in = vec4(xposition, yposition, 0.0, 1.0);
vec4 uv_out = u_UvTransform * uv_in;
v_TexCoordinate = vec2(uv_out.x, uv_out.y);
gl_Position = vec4(a_Position.xyz * 2.0, 1.0);
}
);
static constexpr char const* kFragmentShader = OEIE_SHADER(
precision highp float;
uniform samplerExternalOES u_Texture;
varying vec2 v_TexCoordinate;
void main() {
gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
}
);
// clang-format on
} // namespace
ArRenderer::ArRenderer() {
std::string error;
GLuint vertex_shader_handle =
vr::CompileShader(GL_VERTEX_SHADER, kVertexShader, error);
// TODO(crbug.com/866593): fail gracefully if shaders don't compile.
CHECK(vertex_shader_handle) << error << "\nvertex_src\n" << kVertexShader;
GLuint fragment_shader_handle =
vr::CompileShader(GL_FRAGMENT_SHADER, kFragmentShader, error);
CHECK(fragment_shader_handle) << error << "\nfragment_src\n"
<< kFragmentShader;
program_handle_ = vr::CreateAndLinkProgram(vertex_shader_handle,
fragment_shader_handle, error);
CHECK(program_handle_) << error;
// Once the program is linked the shader objects are no longer needed
glDeleteShader(vertex_shader_handle);
glDeleteShader(fragment_shader_handle);
position_handle_ = glGetAttribLocation(program_handle_, "a_Position");
clip_rect_handle_ = glGetUniformLocation(program_handle_, "u_ClipRect");
texture_handle_ = glGetUniformLocation(program_handle_, "u_Texture");
uv_transform_ = glGetUniformLocation(program_handle_, "u_UvTransform");
x_border_handle_ = glGetUniformLocation(program_handle_, "u_XBorder");
y_border_handle_ = glGetUniformLocation(program_handle_, "u_YBorder");
}
void ArRenderer::Draw(int texture_handle,
const float (&uv_transform)[16],
float xborder,
float yborder) {
if (!vertex_buffer_ || !index_buffer_) {
GLuint buffers[2];
glGenBuffersARB(2, buffers);
vertex_buffer_ = buffers[0];
index_buffer_ = buffers[1];
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
glBufferData(GL_ARRAY_BUFFER, base::size(kQuadVertices) * sizeof(float),
kQuadVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
base::size(kQuadIndices) * sizeof(GLushort), kQuadIndices,
GL_STATIC_DRAW);
}
glUseProgram(program_handle_);
// Bind vertex attributes
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
// Set up position attribute.
glVertexAttribPointer(position_handle_, 2, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(position_handle_);
// Bind texture. This is a 1:1 pixel copy since the source surface
// and renderbuffer destination size are resized to match, so use
// GL_NEAREST.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_handle);
vr::SetTexParameters(GL_TEXTURE_EXTERNAL_OES);
glUniform1i(texture_handle_, 0);
glUniform1f(x_border_handle_, xborder);
glUniform1f(y_border_handle_, yborder);
glUniformMatrix4fv(uv_transform_, 1, GL_FALSE, &uv_transform[0]);
// Blit texture to buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_);
glDrawElements(GL_TRIANGLES, base::size(kQuadIndices), GL_UNSIGNED_SHORT, 0);
glDisableVertexAttribArray(position_handle_);
}
// Note that we don't explicitly delete gl objects here, they're deleted
// automatically when we call ShutdownGL, and deleting them here leads to
// segfaults.
ArRenderer::~ArRenderer() = default;
} // namespace device
// Copyright 2018 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.
#ifndef CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_AR_RENDERER_H_
#define CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_AR_RENDERER_H_
#include "base/macros.h"
#include "ui/gl/gl_bindings.h"
namespace device {
// Issues GL for rendering a texture for AR.
// TODO(crbug.com/838013): Share code with WebVrRenderer.
class ArRenderer {
public:
ArRenderer();
~ArRenderer();
void Draw(int texture_handle,
const float (&uv_transform)[16],
float xborder,
float yborder);
private:
GLuint program_handle_ = 0;
GLuint position_handle_ = 0;
GLuint clip_rect_handle_ = 0;
GLuint texture_handle_ = 0;
GLuint uv_transform_ = 0;
GLuint x_border_handle_ = 0;
GLuint y_border_handle_ = 0;
GLuint vertex_buffer_ = 0;
GLuint index_buffer_ = 0;
DISALLOW_COPY_AND_ASSIGN(ArRenderer);
};
} // namespace device
#endif // CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_AR_RENDERER_H_
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "chrome/browser/vr/ui_interface.h" #include "chrome/browser/vr/ui_interface.h"
#include "chrome/browser/vr/ui_scene.h" #include "chrome/browser/vr/ui_scene.h"
#include "chrome/browser/vr/ui_test_input.h" #include "chrome/browser/vr/ui_test_input.h"
#include "chrome/browser/vr/vr_geometry_util.h"
#include "chrome/browser/vr/vr_gl_util.h" #include "chrome/browser/vr/vr_gl_util.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
...@@ -1412,7 +1413,7 @@ void VrShellGl::UpdateEyeInfos(const gfx::Transform& head_pose, ...@@ -1412,7 +1413,7 @@ void VrShellGl::UpdateEyeInfos(const gfx::Transform& head_pose,
eye_info.view_matrix = eye_matrix * head_pose; eye_info.view_matrix = eye_matrix * head_pose;
const gfx::RectF& rect = GfxRectFromUV(vp.GetSourceUv()); const gfx::RectF& rect = GfxRectFromUV(vp.GetSourceUv());
eye_info.viewport = ui_->CalculatePixelSpaceRect(render_size, rect); eye_info.viewport = vr::CalculatePixelSpaceRect(render_size, rect);
eye_info.proj_matrix = eye_info.proj_matrix =
PerspectiveMatrixFromView(vp.GetSourceFov(), kZNear, kZFar); PerspectiveMatrixFromView(vp.GetSourceFov(), kZNear, kZFar);
......
...@@ -20,6 +20,18 @@ buildflag_header("vr_build_features") { ...@@ -20,6 +20,18 @@ buildflag_header("vr_build_features") {
flags = [ "USE_VR_ASSETS_COMPONENT=$use_vr_assets_component" ] flags = [ "USE_VR_ASSETS_COMPONENT=$use_vr_assets_component" ]
} }
source_set("vr_gl_utils") {
sources = [
"vr_gl_util.cc",
"vr_gl_util.h",
]
deps = [
"//skia",
"//ui/gl/init",
]
}
component("vr_common") { component("vr_common") {
sources = [ sources = [
"animation.cc", "animation.cc",
...@@ -244,8 +256,8 @@ component("vr_common") { ...@@ -244,8 +256,8 @@ component("vr_common") {
"ui_unsupported_mode.h", "ui_unsupported_mode.h",
"vr_export.h", "vr_export.h",
"vr_features.h", "vr_features.h",
"vr_gl_util.cc", "vr_geometry_util.cc",
"vr_gl_util.h", "vr_geometry_util.h",
] ]
public_deps = [ public_deps = [
...@@ -254,6 +266,7 @@ component("vr_common") { ...@@ -254,6 +266,7 @@ component("vr_common") {
deps = [ deps = [
":vr_build_features", ":vr_build_features",
":vr_gl_utils",
"//base", "//base",
"//cc/animation", "//cc/animation",
"//cc/paint", "//cc/paint",
...@@ -330,7 +343,7 @@ test("vr_common_unittests") { ...@@ -330,7 +343,7 @@ test("vr_common_unittests") {
"ui_input_manager_unittest.cc", "ui_input_manager_unittest.cc",
"ui_scene_unittest.cc", "ui_scene_unittest.cc",
"ui_unittest.cc", "ui_unittest.cc",
"vr_gl_util_unittest.cc", "vr_geometry_util_unittest.cc",
] ]
# TODO(mthiesse, crbug.com/769373): The dependency on device/vr:fakes requires # TODO(mthiesse, crbug.com/769373): The dependency on device/vr:fakes requires
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "chrome/browser/vr/model/text_input_info.h" #include "chrome/browser/vr/model/text_input_info.h"
#include "chrome/browser/vr/text_input_delegate.h" #include "chrome/browser/vr/text_input_delegate.h"
#include "chrome/browser/vr/ui_scene_constants.h" #include "chrome/browser/vr/ui_scene_constants.h"
#include "chrome/browser/vr/vr_gl_util.h" #include "chrome/browser/vr/vr_geometry_util.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
namespace vr { namespace vr {
......
...@@ -657,14 +657,6 @@ UiScene::Elements Ui::GetWebVrOverlayElementsToDraw() { ...@@ -657,14 +657,6 @@ UiScene::Elements Ui::GetWebVrOverlayElementsToDraw() {
return scene_->GetWebVrOverlayElementsToDraw(); return scene_->GetWebVrOverlayElementsToDraw();
} }
gfx::Rect Ui::CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect) {
const gfx::RectF rect =
ScaleRect(texture_rect, static_cast<float>(texture_size.width()),
static_cast<float>(texture_size.height()));
return gfx::Rect(rect.x(), rect.y(), rect.width(), rect.height());
}
void Ui::HandleInput(base::TimeTicks current_time, void Ui::HandleInput(base::TimeTicks current_time,
const RenderInfo& render_info, const RenderInfo& render_info,
const ControllerModel& controller_model, const ControllerModel& controller_model,
......
...@@ -173,8 +173,6 @@ class VR_EXPORT Ui : public UiInterface, public KeyboardUiInterface { ...@@ -173,8 +173,6 @@ class VR_EXPORT Ui : public UiInterface, public KeyboardUiInterface {
float yborder) override; float yborder) override;
void DrawWebVrOverlayForeground(const RenderInfo& render_info) override; void DrawWebVrOverlayForeground(const RenderInfo& render_info) override;
UiScene::Elements GetWebVrOverlayElementsToDraw() override; UiScene::Elements GetWebVrOverlayElementsToDraw() override;
gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect) override;
void HandleInput(base::TimeTicks current_time, void HandleInput(base::TimeTicks current_time,
const RenderInfo& render_info, const RenderInfo& render_info,
......
...@@ -91,8 +91,6 @@ class UiInterface : public BrowserUiInterface { ...@@ -91,8 +91,6 @@ class UiInterface : public BrowserUiInterface {
float yborder) = 0; float yborder) = 0;
virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0; virtual void DrawWebVrOverlayForeground(const RenderInfo&) = 0;
virtual UiScene::Elements GetWebVrOverlayElementsToDraw() = 0; virtual UiScene::Elements GetWebVrOverlayElementsToDraw() = 0;
virtual gfx::Rect CalculatePixelSpaceRect(const gfx::Size&,
const gfx::RectF&) = 0;
virtual void HandleInput(base::TimeTicks current_time, virtual void HandleInput(base::TimeTicks current_time,
const RenderInfo& render_info, const RenderInfo& render_info,
const ControllerModel& controller_model, const ControllerModel& controller_model,
......
// Copyright 2018 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.
#include "chrome/browser/vr/vr_geometry_util.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/transform.h"
namespace vr {
// This code is adapted from the GVR Treasure Hunt demo source.
gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect) {
const gfx::RectF rect =
ScaleRect(texture_rect, static_cast<float>(texture_size.width()),
static_cast<float>(texture_size.height()));
return gfx::Rect(rect.x(), rect.y(), rect.width(), rect.height());
}
gfx::SizeF CalculateScreenSize(const gfx::Transform& proj_matrix,
float distance,
const gfx::SizeF& size) {
// View matrix is the identity, thus, not needed in the calculation.
gfx::Transform scale_transform;
scale_transform.Scale(size.width(), size.height());
gfx::Transform translate_transform;
translate_transform.Translate3d(0, 0, -distance);
gfx::Transform model_view_proj_matrix =
proj_matrix * translate_transform * scale_transform;
gfx::Point3F projected_upper_right_corner(0.5f, 0.5f, 0.0f);
model_view_proj_matrix.TransformPoint(&projected_upper_right_corner);
gfx::Point3F projected_lower_left_corner(-0.5f, -0.5f, 0.0f);
model_view_proj_matrix.TransformPoint(&projected_lower_left_corner);
// Calculate and return the normalized size in screen space.
return gfx::SizeF((std::abs(projected_upper_right_corner.x()) +
std::abs(projected_lower_left_corner.x())) /
2.0f,
(std::abs(projected_upper_right_corner.y()) +
std::abs(projected_lower_left_corner.y())) /
2.0f);
}
} // namespace vr
// Copyright 2018 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.
#ifndef CHROME_BROWSER_VR_VR_GEOMETRY_UTIL_H_
#define CHROME_BROWSER_VR_VR_GEOMETRY_UTIL_H_
#include "chrome/browser/vr/vr_ui_export.h"
#include "ui/gfx/geometry/rect.h"
namespace gfx {
class RectF;
class Size;
class SizeF;
class Transform;
} // namespace gfx
namespace vr {
VR_UI_EXPORT gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect);
// Returns the normalized size of the element projected into screen space.
// If (1, 1) the element fills the entire buffer.
VR_UI_EXPORT gfx::SizeF CalculateScreenSize(const gfx::Transform& proj_matrix,
float distance,
const gfx::SizeF& size);
} // namespace vr
#endif // CHROME_BROWSER_VR_VR_GEOMETRY_UTIL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/vr/vr_gl_util.h" #include "chrome/browser/vr/vr_geometry_util.h"
#include "chrome/browser/vr/test/constants.h" #include "chrome/browser/vr/test/constants.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace vr { namespace vr {
TEST(VrGlUtilTest, CalculateScreenSize) { TEST(VrGeometryUtilTest, CalculateScreenSize) {
gfx::SizeF size(2.4f, 1.6f); gfx::SizeF size(2.4f, 1.6f);
gfx::SizeF screen_size = gfx::SizeF screen_size =
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include "chrome/browser/vr/vr_gl_util.h" #include "chrome/browser/vr/vr_gl_util.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
namespace vr { namespace vr {
...@@ -18,15 +15,6 @@ std::array<float, 16> MatrixToGLArray(const gfx::Transform& transform) { ...@@ -18,15 +15,6 @@ std::array<float, 16> MatrixToGLArray(const gfx::Transform& transform) {
return result; return result;
} }
// This code is adapted from the GVR Treasure Hunt demo source.
gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect) {
const gfx::RectF rect =
ScaleRect(texture_rect, static_cast<float>(texture_size.width()),
static_cast<float>(texture_size.height()));
return gfx::Rect(rect.x(), rect.y(), rect.width(), rect.height());
}
GLuint CompileShader(GLenum shader_type, GLuint CompileShader(GLenum shader_type,
const GLchar* shader_source, const GLchar* shader_source,
std::string& error) { std::string& error) {
...@@ -96,33 +84,6 @@ GLuint CreateAndLinkProgram(GLuint vertext_shader_handle, ...@@ -96,33 +84,6 @@ GLuint CreateAndLinkProgram(GLuint vertext_shader_handle,
return program_handle; return program_handle;
} }
gfx::SizeF CalculateScreenSize(const gfx::Transform& proj_matrix,
float distance,
const gfx::SizeF& size) {
// View matrix is the identity, thus, not needed in the calculation.
gfx::Transform scale_transform;
scale_transform.Scale(size.width(), size.height());
gfx::Transform translate_transform;
translate_transform.Translate3d(0, 0, -distance);
gfx::Transform model_view_proj_matrix =
proj_matrix * translate_transform * scale_transform;
gfx::Point3F projected_upper_right_corner(0.5f, 0.5f, 0.0f);
model_view_proj_matrix.TransformPoint(&projected_upper_right_corner);
gfx::Point3F projected_lower_left_corner(-0.5f, -0.5f, 0.0f);
model_view_proj_matrix.TransformPoint(&projected_lower_left_corner);
// Calculate and return the normalized size in screen space.
return gfx::SizeF((std::abs(projected_upper_right_corner.x()) +
std::abs(projected_lower_left_corner.x())) /
2.0f,
(std::abs(projected_upper_right_corner.y()) +
std::abs(projected_lower_left_corner.y())) /
2.0f);
}
void SetTexParameters(GLenum texture_type) { void SetTexParameters(GLenum texture_type) {
glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
......
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#include <array> #include <array>
#include <string> #include <string>
#include "chrome/browser/vr/vr_ui_export.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#define SHADER(Src) "#version 100\n" #Src #define SHADER(Src) "#version 100\n" #Src
...@@ -19,9 +17,6 @@ ...@@ -19,9 +17,6 @@
#define VOID_OFFSET(x) reinterpret_cast<void*>(x) #define VOID_OFFSET(x) reinterpret_cast<void*>(x)
namespace gfx { namespace gfx {
class RectF;
class Size;
class SizeF;
class Transform; class Transform;
} // namespace gfx } // namespace gfx
...@@ -29,9 +24,6 @@ namespace vr { ...@@ -29,9 +24,6 @@ namespace vr {
std::array<float, 16> MatrixToGLArray(const gfx::Transform& matrix); std::array<float, 16> MatrixToGLArray(const gfx::Transform& matrix);
VR_UI_EXPORT gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
const gfx::RectF& texture_rect);
// Compile a shader. // Compile a shader.
GLuint CompileShader(GLenum shader_type, GLuint CompileShader(GLenum shader_type,
const GLchar* shader_source, const GLchar* shader_source,
...@@ -42,12 +34,6 @@ GLuint CreateAndLinkProgram(GLuint vertex_shader_handle, ...@@ -42,12 +34,6 @@ GLuint CreateAndLinkProgram(GLuint vertex_shader_handle,
GLuint fragment_shader_handle, GLuint fragment_shader_handle,
std::string& error); std::string& error);
// Returns the normalized size of the element projected into screen space.
// If (1, 1) the element fills the entire buffer.
VR_UI_EXPORT gfx::SizeF CalculateScreenSize(const gfx::Transform& proj_matrix,
float distance,
const gfx::SizeF& size);
// Sets default texture parameters given a texture type. // Sets default texture parameters given a texture type.
void SetTexParameters(GLenum texture_type); void SetTexParameters(GLenum texture_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment