Ocean
Loading...
Searching...
No Matches
GLESAttributeSet.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_RENDERING_GLES_ATTRIBUTE_SET_H
9#define META_OCEAN_RENDERING_GLES_ATTRIBUTE_SET_H
10
17
19
23
24namespace Ocean
25{
26
27namespace Rendering
28{
29
30namespace GLESceneGraph
31{
32
33/**
34 * This class implements a GLESceneGraph attribute set object.
35 * @ingroup renderinggles
36 */
37class OCEAN_RENDERING_GLES_EXPORT GLESAttributeSet :
38 virtual public GLESObject,
39 virtual public AttributeSet
40{
41 friend class GLESFactory;
43
44 protected:
45
46 /**
47 * Definition of an unordered map mapping attribute types to counters.
48 */
49#if defined(OCEAN_GCC_VERSION) && OCEAN_GCC_VERSION > 0 && OCEAN_GCC_VERSION < 50000
50 using AttributeCounterMap = std::unordered_map<int, unsigned int>;
51#else
52 using AttributeCounterMap = std::unordered_map<ObjectType, unsigned int>;
53#endif
54
55 public:
56
57 /**
58 * Adds a new attribute to this attribute set.
59 * @see AttributeSet::addAttribute().
60 */
61 void addAttribute(const AttributeRef& attribute) override;
62
63 /**
64 * Removes a registered attribute from this attribute ses.
65 * @see AttributeSet::removeAttribute().
66 */
67 void removeAttribute(const AttributeRef& attribute) override;
68
69 /**
70 * Binds the attributes of this set to the internal OpenGL ES shader program as uniforms.
71 * @param framebuffer Framebuffer initiated the rendering process
72 * @param projection The projection matrix used for this node
73 * @param camera_T_model The transformation between model and camera (aka Modelview matrix), must be valid
74 * @param camera_T_world The transformation between world and camera, must be valid
75 * @param normalMatrix Normal transformation matrix with is the transposed inverse of the upper 3x3 model view matrix
76 * @param lights The lights used to render the scene
77 * @param additionalProgramTypes Optional additional program type(s) which is not reflected in this attribute set automatically
78 * @param additionalAttribute Optional additional attribute which is not part of this attribute set
79 */
80 void bindAttributes(const GLESFramebuffer& framebuffer, const SquareMatrix4& projection, const HomogenousMatrix4& camera_T_model, const HomogenousMatrix4& camera_T_world, const SquareMatrix3& normalMatrix, const Lights& lights, const GLESAttribute::ProgramType additionalProgramTypes = GLESAttribute::PT_UNKNOWN, GLESAttribute* const additionalAttribute = nullptr);
81
82 /**
83 * Unbinds all attributes of this set.
84 */
86
87 /**
88 * Returns the shader of this attribute set.
89 * @return Shader
90 */
92
93 /**
94 * Returns whether this attribute set contains at least one attribute of a specific type.
95 * @param attributeType The attribute type to check
96 * @return True, if so
97 */
98 inline bool containsAttribute(const ObjectType attributeType) const;
99
100 /**
101 * Resets the shader program e.g., because child element has changed after the shader has been selected.
102 */
103 inline void resetShaderProgram();
104
105 protected:
106
107 /**
108 * Creates a new GLESceneGraph attribute set object.
109 */
111
112 /**
113 * Destructs a GLESceneGraph attribute set object.
114 */
116
117 /**
118 * Determines which shader program to use for this entire attribute set
119 * @param lights The lights used to render the scene
120 * @param additionalProgramTypes Optional additional program type(s) which is not reflected in this attribute set automatically
121 * @param additionalAttribute Optional additional attribute which is not part of this attribute set
122 * @return Shader program type
123 */
124 GLESAttribute::ProgramType determineShaderType(const Lights& lights, const GLESAttribute::ProgramType additionalProgramTypes = GLESAttribute::PT_UNKNOWN, const GLESAttribute* additionalAttribute = nullptr) const;
125
126 protected:
127
128 /// Shader program specific for this attribute set.
130
131 /// Shader type necessary for this attribute set.
133
134 /// True, if the shader has been changed since the last usage.
136
137 /// The map counting the number of attributes;
139
140 /// True, if the current shader program was created for a light source.
142};
143
145{
146 const ScopedLock scopedLock(objectLock_);
147
148 return shaderProgram_;
149}
150
151inline bool GLESAttributeSet::containsAttribute(const ObjectType attributeType) const
152{
153 const ScopedLock scopedLock(objectLock_);
154
155 return attributeCounterMap_.find(attributeType) != attributeCounterMap_.cend();
156}
157
159{
160 const ScopedLock scopedLock(objectLock_);
161
163}
164
165}
166
167}
168
169}
170
171#endif // META_OCEAN_RENDERING_GLES_ATTRIBUTE_SET_H
virtual AttributeRef attribute(const unsigned int index) const
Returns an attribute specified by the index.
AttributeSet()
Creates a new attribute set object.
This class wraps a GLESceneGraph attribute object.
Definition GLESAttribute.h:36
ProgramType
Definition of different shader functionalities.
Definition GLESAttribute.h:43
@ PT_UNKNOWN
Not specified shader program.
Definition GLESAttribute.h:45
friend class GLESFactory
Definition GLESAttributeSet.h:41
~GLESAttributeSet() override
Destructs a GLESceneGraph attribute set object.
AttributeCounterMap attributeCounterMap_
The map counting the number of attributes;.
Definition GLESAttributeSet.h:138
friend class GLESPhantomAttribute
Definition GLESAttributeSet.h:42
GLESAttribute::ProgramType shaderProgramType_
Shader type necessary for this attribute set.
Definition GLESAttributeSet.h:132
GLESShaderProgramRef shaderProgram() const
Returns the shader of this attribute set.
Definition GLESAttributeSet.h:144
GLESShaderProgramRef shaderProgram_
Shader program specific for this attribute set.
Definition GLESAttributeSet.h:129
std::unordered_map< int, unsigned int > AttributeCounterMap
Definition of an unordered map mapping attribute types to counters.
Definition GLESAttributeSet.h:50
bool shaderProgramTypeIsBasedOnLight_
True, if the current shader program was created for a light source.
Definition GLESAttributeSet.h:141
void resetShaderProgram()
Resets the shader program e.g., because child element has changed after the shader has been selected.
Definition GLESAttributeSet.h:158
void addAttribute(const AttributeRef &attribute) override
Adds a new attribute to this attribute set.
bool containsAttribute(const ObjectType attributeType) const
Returns whether this attribute set contains at least one attribute of a specific type.
Definition GLESAttributeSet.h:151
bool shaderProgramTypeChanged_
True, if the shader has been changed since the last usage.
Definition GLESAttributeSet.h:135
GLESAttributeSet()
Creates a new GLESceneGraph attribute set object.
GLESAttribute::ProgramType determineShaderType(const Lights &lights, const GLESAttribute::ProgramType additionalProgramTypes=GLESAttribute::PT_UNKNOWN, const GLESAttribute *additionalAttribute=nullptr) const
Determines which shader program to use for this entire attribute set.
void unbindAttributes()
Unbinds all attributes of this set.
void removeAttribute(const AttributeRef &attribute) override
Removes a registered attribute from this attribute ses.
void bindAttributes(const GLESFramebuffer &framebuffer, const SquareMatrix4 &projection, const HomogenousMatrix4 &camera_T_model, const HomogenousMatrix4 &camera_T_world, const SquareMatrix3 &normalMatrix, const Lights &lights, const GLESAttribute::ProgramType additionalProgramTypes=GLESAttribute::PT_UNKNOWN, GLESAttribute *const additionalAttribute=nullptr)
Binds the attributes of this set to the internal OpenGL ES shader program as uniforms.
This class implements a base for all GLESceneGraph framebuffers.
Definition rendering/glescenegraph/GLESFramebuffer.h:34
GLESObject()
Creates a new GLESceneGraph object.
Lock objectLock_
Lock for the object.
Definition Object.h:304
ObjectType
Definition of different object type.
Definition Object.h:62
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:147
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition SquareMatrix3.h:43
SquareMatrixT4< Scalar > SquareMatrix4
Definition of the SquareMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition SquareMatrix4.h:39
SmartObjectRef< Attribute > AttributeRef
Definition of a smart object reference holding an attribute.
Definition Attribute.h:29
std::vector< LightPair > Lights
Definition of a set holding light sources.
Definition GLESLightSource.h:44
SmartObjectRef< GLESShaderProgram > GLESShaderProgramRef
Definition of an object reference for shader program containers.
Definition GLESShaderProgram.h:44
Namespace of the Rendering GLESceneGraph library.
Definition rendering/glescenegraph/android/Android.h:20
Namespace of the Rendering library.
Definition AbsoluteTransform.h:18
The namespace covering the entire Ocean framework.
Definition Accessor.h:15