1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_VR_ELEMENTS_RETICLE_H_
6 #define CHROME_BROWSER_VR_ELEMENTS_RETICLE_H_
7 
8 #include "chrome/browser/vr/elements/ui_element.h"
9 #include "chrome/browser/vr/renderers/base_quad_renderer.h"
10 #include "ui/gfx/geometry/point3_f.h"
11 
12 namespace vr {
13 
14 class UiScene;
15 struct Model;
16 
17 class Reticle : public UiElement {
18  public:
19   Reticle(UiScene* scene, Model* model);
20   ~Reticle() override;
21 
22   UiElement* TargetElement() const;
23 
24   class Renderer : public BaseQuadRenderer {
25    public:
26     Renderer();
27     ~Renderer() override;
28 
29     void Draw(float opacity, const gfx::Transform& view_proj_matrix);
30 
31     static const char* VertexShader();
32 
33    private:
34     GLuint model_view_proj_matrix_handle_;
35     GLuint color_handle_;
36     GLuint ring_diameter_handle_;
37     GLuint inner_hole_handle_;
38     GLuint inner_ring_end_handle_;
39     GLuint inner_ring_thickness_handle_;
40     GLuint mid_ring_end_handle_;
41     GLuint mid_ring_opacity_handle_;
42     GLuint opacity_handle_;
43 
44     DISALLOW_COPY_AND_ASSIGN(Renderer);
45   };
46 
47  private:
48   void Render(UiElementRenderer* renderer,
49               const CameraModel& model) const final;
50   gfx::Transform LocalTransform() const final;
51   gfx::Transform GetTargetLocalTransform() const final;
52   bool ShouldUpdateWorldSpaceTransform(
53       bool parent_transform_changed) const final;
54 
55   gfx::Point3F origin_;
56   gfx::Point3F target_;
57 
58   // This is used to convert the target id into a UiElement instance. We are not
59   // permitted to retain pointers to UiElements since they may be destructed,
60   // but the scene itself is constant, so we will look up our elements on the
61   // fly.
62   UiScene* scene_;
63 
64   // Unlike other UiElements which bind their values form the model, the reticle
65   // must derive values from the model late in the pipeline after the scene has
66   // fully updated its geometry. We therefore retain a pointer to the model and
67   // make use of it in |Render|.
68   Model* model_;
69 
70   DISALLOW_COPY_AND_ASSIGN(Reticle);
71 };
72 
73 }  // namespace vr
74 
75 #endif  // CHROME_BROWSER_VR_ELEMENTS_RETICLE_H_
76