Ocean
Loading...
Searching...
No Matches
ContextAssociated.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_PLATFORM_GL_CONTEXT_ASSOCIATED_H
9#define META_OCEAN_PLATFORM_GL_CONTEXT_ASSOCIATED_H
10
13
14namespace Ocean
15{
16
17namespace Platform
18{
19
20namespace GL
21{
22
23/**
24 * This class implements the base class for all object which have an associated context.
25 * Objects derived from this class need a valid associated context before they can be used or applied.<br>
26 * Once an associated context has been set it cannot be changed anymore.<br>
27 * @see setContext().
28 * @ingroup platformgl
29 */
30class OCEAN_PLATFORM_GL_EXPORT ContextAssociated
31{
32 public:
33
34 /**
35 * Destructs this object.
36 */
38
39 /**
40 * Sets the context of this object.
41 * The context must not be set more than once!<br>
42 * Beware: Do not call any function of this framebuffer unless a valid context has been set!<br>
43 * @param context The context to set
44 * @return True, if succeeded
45 */
46 virtual bool setContext(Context& context);
47
48 /**
49 * Returns the associated context of this object.
50 * Beware: Ensure that this context has a valid associated context before calling this function.<br>
51 * @return The context
52 * @see hasContext().
53 */
54 inline Context& context();
55
56 /**
57 * Returns whether this object has a valid associated context.
58 * @return True, if so
59 */
60 inline bool hasContext() const;
61
62 protected:
63
64 /**
65 * Creates a new object without associated context.
66 */
67 ContextAssociated() = default;
68
69 /**
70 * Creates a new object with given associated context.
71 * @param context The associated context
72 */
73 explicit inline ContextAssociated(Context& context);
74
75 protected:
76
77 /// The OpenGL context which is associated with this framebuffer.
78 Context* associatedContext_ = nullptr;
79};
80
82 associatedContext_(&context)
83{
84 // nothing to do here
85}
86
88{
89 ocean_assert(associatedContext_ != nullptr);
90
91 return *associatedContext_;
92}
93
95{
96 return associatedContext_ != nullptr;
97}
98
99}
100
101}
102
103}
104
105#endif // META_OCEAN_PLATFORM_GL_CONTEXT_ASSOCIATED_H
This class implements the base class for all object which have an associated context.
Definition ContextAssociated.h:31
ContextAssociated()=default
Creates a new object without associated context.
Context * associatedContext_
The OpenGL context which is associated with this framebuffer.
Definition ContextAssociated.h:78
bool hasContext() const
Returns whether this object has a valid associated context.
Definition ContextAssociated.h:94
virtual ~ContextAssociated()
Destructs this object.
Context & context()
Returns the associated context of this object.
Definition ContextAssociated.h:87
virtual bool setContext(Context &context)
Sets the context of this object.
This class encapsulates an OpenGL context.
Definition platform/gl/Context.h:29
The namespace covering the entire Ocean framework.
Definition Accessor.h:15