Gamp v0.0.7-54-gccdc599
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
Container.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com> (C++, Java) and Rami Santina (Java)
3 * Copyright Gothel Software e.K. and the authors
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11#ifndef JAU_GAMP_GRAPH_UI_CONTAINER_HPP_
12#define JAU_GAMP_GRAPH_UI_CONTAINER_HPP_
13
14#include <jau/basic_types.hpp>
15#include <jau/darray.hpp>
16#include <jau/float_math.hpp>
17#include <jau/float_types.hpp>
18#include <jau/fraction_type.hpp>
21#include <jau/math/vec3f.hpp>
22#include <jau/math/vec4f.hpp>
23#include <jau/math/vec4f.hpp>
25
26#include <gamp/Gamp.hpp>
29
30namespace gamp::graph::ui {
31
32 using namespace jau::math;
33 using namespace jau::math::util;
34 using namespace jau::math::geom;
35
36 using namespace gamp::wt;
37 using namespace gamp::wt::event;
38 using namespace gamp::render;
39
40 using namespace gamp::graph;
41
42 /** \addtogroup Gamp_GraphUI
43 *
44 * @{
45 */
46
47 class Shape;
48 typedef std::shared_ptr<Shape> ShapeRef;
49 typedef std::vector<ShapeRef> ShapeList;
50
51 class RegionRenderer;
52
53 /**
54 * Container interface of UI {@link Shape}s
55 * @see Scene
56 * @see Shape
57 */
58 class Container {
59 public:
60 /** Returns number of {@link Shape}s, see {@link #getShapes()}. */
61 virtual size_t shapeCount() const noexcept = 0;
62
63 /** Returns {@link #addShape(Shape) added} {@link Shape}s. */
64 virtual const ShapeList& shapes() const noexcept = 0;
65
66 /**
67 * Returns {@link #addShape(Shape) added shapes} which are rendered and sorted by z-axis in ascending order toward z-near.
68 * <p>
69 * The rendered shapes are {@link Shape#isVisible() visible} and not deemed outside of this container due to {@link #isCullingEnabled() culling}.
70 * </p>
71 * <p>
72 * Only rendered shapes are considered for picking/activation.
73 * </p>
74 * <p>
75 * The returned list is data-race free, i.e. won't be mutated by the rendering thread
76 * as it gets completely replace at each rendering loop using a local volatile reference.<br/>
77 * Only when disposing the container, the list gets cleared, hence {@Link List#size()} shall be used in the loop.
78 * </p>
79 * @see #addShape(Shape)
80 * @see #isCullingEnabled()
81 * @see Shape#isVisible()
82 * @see #isOutside(PMVMatrix4f, Shape)
83 */
84 virtual ShapeList& renderedShapes() const noexcept = 0;
85
86 /** Adds a {@link Shape}. */
87 virtual void addShape(const ShapeRef& s) const noexcept = 0;
88
89 /**
90 * Removes given shape, w/o {@link Shape#destroy(GL2ES2, RegionRenderer)}.
91 * @return the removed shape or null if not contained
92 */
93 virtual ShapeRef removeShape(const ShapeRef& s) const noexcept = 0;
94
95 /** Removes all given shapes, w/o {@link Shape#destroy(GL2ES2, RegionRenderer)}. */
96 virtual void removeShapes(const ShapeList& shapes) = 0;
97
98 /**
99 * Removes given shape with {@link Shape#destroy(GL2ES2, RegionRenderer)}, if contained.
100 * @param gl GL2ES2 context
101 * @param renderer
102 * @param s the shape to be removed
103 * @return true if given Shape is removed and destroyed
104 */
105 // virtual bool removeShape(RenderContext& rc, final RegionRenderer renderer, const ShapeRef& s) = 0;
106
107 virtual void addShapes(const ShapeList& shapes) = 0;
108
109 /** Removes all given shapes with {@link Shape#destroy(GL2ES2, RegionRenderer)}. */
110 virtual void removeShapes(RenderContext& rc, RegionRenderer& renderer, const ShapeList& shapes) = 0;
111
112 /** Removes all contained shapes with {@link Shape#destroy(GL2ES2, RegionRenderer)}. */
113 virtual void removeAllShapes(RenderContext& rc, RegionRenderer& renderer) = 0;
114
115 virtual bool contains(const Shape& s) = 0;
116
117 virtual Shape& getShapeByIdx(int id) const noexcept = 0;
118 virtual Shape& getShapeByID(int id) const noexcept = 0;
119 virtual Shape& getShapeByName(const std::string& name) const noexcept = 0;
120
121 /** Returns {@link AABBox} dimension of given {@link Shape} from this container's perspective, i.e. world-bounds if performing from the {@link Scene}. */
122 virtual const AABBox3f& bounds(const PMVMat4f& pmv, const Shape& shape) const noexcept = 0;
123
124 /** Enable or disable {@link PMVMatrix4f#getFrustum() Project-Modelview (PMv) frustum} culling per {@link Shape} for this container. Default is disabled. */
125 virtual void setPMvCullingEnabled(bool v) noexcept = 0;
126
127 /** Return whether {@link #setPMvCullingEnabled(bool) Project-Modelview (PMv) frustum culling} is enabled for this container. */
128 virtual bool isPMvCullingEnabled() const noexcept = 0;
129
130 /**
131 * Return whether {@link #setPMvCullingEnabled(bool) Project-Modelview (PMv) frustum culling}
132 * or {@link Group#setClipMvFrustum(com.jogamp.math.geom.Frustum) Group's Modelview (Mv) frustum clipping}
133 * is enabled for this container. Default is disabled.
134 */
135 virtual bool isCullingEnabled() const noexcept = 0;
136
137 /**
138 * Returns whether the given {@link Shape} is completely outside of this container.
139 * <p>
140 * Note: If method returns false, the box may only be partially inside, i.e. intersects with this container
141 * </p>
142 * @param pmv current {@link PMVMatrix4f} of this container
143 * @param shape the {@link Shape} to test
144 * @see #isOutside2(Matrix4f, Shape, PMVMatrix4f)
145 * @see Shape#isOutside()
146 */
147 virtual bool isOutside(const PMVMat4f&, const Shape& shape) const noexcept = 0;
148
149 /**
150 * Returns whether the given {@link Shape} is completely outside of this container.
151 * <p>
152 * Note: If method returns false, the box may only be partially inside, i.e. intersects with this container
153 * </p>
154 * @param mvCont copy of the model-view {@link Matrix4f) of this container
155 * @param shape the {@link Shape} to test
156 * @param pmvShape current {@link PMVMatrix4f} of the shape to test
157 * @see #isOutside(PMVMatrix4f, Shape)
158 * @see Shape#isOutside()
159 */
160 virtual bool isOutside2(const Mat4f& mvCont, const Shape& shape, const PMVMat4f&) const noexcept = 0;
161 };
162
163 /**@}*/
164
165} // namespace gamp::graph::ui
166
167#endif /* JAU_GAMP_GRAPH_UI_CONTAINER_HPP_ */
Container interface of UI Shapes.
Definition Container.hpp:58
virtual void addShape(const ShapeRef &s) const noexcept=0
Adds a Shape.
virtual bool isCullingEnabled() const noexcept=0
Return whether Project-Modelview (PMv) frustum culling or Group's Modelview (Mv) frustum clipping is ...
virtual const ShapeList & shapes() const noexcept=0
Returns added Shapes.
virtual void setPMvCullingEnabled(bool v) noexcept=0
Enable or disable Project-Modelview (PMv) frustum culling per Shape for this container.
virtual void removeShapes(const ShapeList &shapes)=0
Removes all given shapes, w/o Shape#destroy(GL2ES2, RegionRenderer).
virtual const AABBox3f & bounds(const PMVMat4f &pmv, const Shape &shape) const noexcept=0
Returns AABBox dimension of given Shape from this container's perspective, i.e.
virtual ShapeRef removeShape(const ShapeRef &s) const noexcept=0
Removes given shape, w/o Shape#destroy(GL2ES2, RegionRenderer).
virtual size_t shapeCount() const noexcept=0
Returns number of Shapes, see getShapes().
virtual Shape & getShapeByID(int id) const noexcept=0
virtual void addShapes(const ShapeList &shapes)=0
Removes given shape with Shape#destroy(GL2ES2, RegionRenderer), if contained.
virtual Shape & getShapeByIdx(int id) const noexcept=0
virtual Shape & getShapeByName(const std::string &name) const noexcept=0
virtual ShapeList & renderedShapes() const noexcept=0
Returns added shapes which are rendered and sorted by z-axis in ascending order toward z-near.
virtual void removeAllShapes(RenderContext &rc, RegionRenderer &renderer)=0
Removes all contained shapes with Shape#destroy(GL2ES2, RegionRenderer).
virtual bool isOutside2(const Mat4f &mvCont, const Shape &shape, const PMVMat4f &) const noexcept=0
Returns whether the given Shape is completely outside of this container.
virtual bool isOutside(const PMVMat4f &, const Shape &shape) const noexcept=0
Returns whether the given Shape is completely outside of this container.
virtual bool isPMvCullingEnabled() const noexcept=0
Return whether Project-Modelview (PMv) frustum culling is enabled for this container.
virtual bool contains(const Shape &s)=0
Axis Aligned Bounding Box.
Definition aabbox3f.hpp:43
consteval_cxx20 std::string_view name() noexcept
std::vector< ShapeRef > ShapeList
Definition Container.hpp:49
std::shared_ptr< Shape > ShapeRef
Definition Container.hpp:48
Matrix4< float > Mat4f
Definition mat4f.hpp:1968
PMVMatrix4< float > PMVMat4f
Definition pmvmat4.hpp:1463
STL namespace.