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 typedef std::unordered_map<int, unsigned int> AttributeCounterMap; // workaround due to compiler bug
51#else
52 typedef std::unordered_map<ObjectType, unsigned int> AttributeCounterMap;
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 */
91 inline GLESShaderProgramRef shaderProgram() const;
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.
132 GLESAttribute::ProgramType shaderProgramType_ = GLESAttribute::PT_UNKNOWN;
133
134 /// True, if the shader has been changed since the last usage.
135 bool shaderProgramTypeChanged_ = true;
136
137 /// The map counting the number of attributes;
139
140 /// True, if the current shader program was created for a light source.
141 bool shaderProgramTypeIsBasedOnLight_ = false;
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
This class is the base class for all attribute set objects.
Definition AttributeSet.h:43
This class wraps a GLESceneGraph attribute object.
Definition GLESAttribute.h:36
ProgramType
Definition of different shader functionalities.
Definition GLESAttribute.h:43
This class implements a GLESceneGraph attribute set object.
Definition GLESAttributeSet.h:40
~GLESAttributeSet() override
Destructs a GLESceneGraph attribute set object.
std::unordered_map< int, unsigned int > AttributeCounterMap
Definition of an unordered map mapping attribute types to counters.
Definition GLESAttributeSet.h:50
AttributeCounterMap attributeCounterMap_
The map counting the number of attributes;.
Definition GLESAttributeSet.h:138
std::unordered_map< ObjectType, unsigned int > AttributeCounterMap
Definition GLESAttributeSet.h:52
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
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 class factory for all GLESceneGraph objects.
Definition GLESFactory.h:30
This class implements a base for all GLESceneGraph framebuffers.
Definition rendering/glescenegraph/GLESFramebuffer.h:34
This class is the base class for all GLESceneGraph objects.
Definition GLESObject.h:57
Definition GLESPhantomAttribute.h:30
Lock objectLock
Lock for the object.
Definition Object.h:305
ObjectType
Definition of different object type.
Definition Object.h:63
This class implements a smart rendering object reference.
Definition rendering/ObjectRef.h:34
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
std::vector< LightPair > Lights
Definition of a set holding light sources.
Definition GLESLightSource.h:44
The namespace covering the entire Ocean framework.
Definition Accessor.h:15