Lagrange
Viewport.h
1/*
2 * Copyright 2021 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/Entity.h>
15#include <lagrange/ui/components/Layer.h>
16#include <lagrange/ui/types/Camera.h>
17#include <lagrange/ui/types/Color.h>
18#include <lagrange/ui/types/FrameBuffer.h>
19#include <unordered_map>
20
21namespace lagrange {
22namespace ui {
23
24class RenderPassBase;
25class Renderer;
26class Material;
27
28// On or offscreen viewport
30{
31 Entity camera_reference = NullEntity;
32 Camera computed_camera;
33
34
35 bool enabled = true;
36
37 int width = 1;
38 int height = 1;
39 bool auto_nearfar = true;
40
41 std::set<RenderPassBase*> selected_passes;
42 std::shared_ptr<FrameBuffer> fbo;
43
44
45 GLenum query_type;
46
47 Layer visible_layers = Layer(true);
48 Layer hidden_layers = Layer(false);
49 std::shared_ptr<Material> material_override;
50
51
52 std::map<std::string, std::shared_ptr<Material>> post_process_effects;
53
54 Color background = Color(0, 0, 0, 0);
55 GLbitfield clear_bits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
56};
57
58inline Camera& get_viewport_camera(Registry& r, ViewportComponent& viewport)
59{
60 if (r.valid(viewport.camera_reference)) {
61 return r.get<Camera>(viewport.camera_reference);
62 } else {
63 return viewport.computed_camera;
64 }
65}
66
67inline const Camera& get_viewport_camera(const Registry& r, const ViewportComponent& viewport)
68{
69 if (r.valid(viewport.camera_reference)) {
70 return r.get<Camera>(viewport.camera_reference);
71 } else {
72 return viewport.computed_camera;
73 }
74}
75
76inline Camera& get_viewport_camera(Registry& r, Entity e)
77{
78 assert(r.all_of<ViewportComponent>(e));
79 return get_viewport_camera(r, r.get<ViewportComponent>(e));
80}
81
82inline const Camera& get_viewport_camera(const Registry& r, Entity e)
83{
84 assert(r.all_of<ViewportComponent>(e));
85 return get_viewport_camera(r, r.get<ViewportComponent>(e));
86}
87
88} // namespace ui
89} // namespace lagrange
Camera class.
Definition: Camera.h:38
Definition: Color.h:24
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Definition: Layer.h:29
Definition: Viewport.h:30