1 #ifndef _GLURENDERCONTEXT_HPP
2 #define _GLURENDERCONTEXT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
5 * ------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief OpenGL ES rendering context.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
49 PROFILE_ES = 0, //!< OpenGL ES
50 PROFILE_CORE, //!< OpenGL Core Profile
51 PROFILE_COMPATIBILITY, //!< OpenGL Compatibility Profile
58 CONTEXT_ROBUST = (1<<0), //!< Robust context
59 CONTEXT_DEBUG = (1<<1), //!< Debug context
60 CONTEXT_FORWARD_COMPATIBLE = (1<<2) //!< Forward-compatible context
63 inline ContextFlags operator| (ContextFlags a, ContextFlags b) { return ContextFlags((deUint32)a|(deUint32)b); }
64 inline ContextFlags operator& (ContextFlags a, ContextFlags b) { return ContextFlags((deUint32)a&(deUint32)b); }
65 inline ContextFlags operator~ (ContextFlags a) { return ContextFlags(~(deUint32)a); }
67 /*--------------------------------------------------------------------*//*!
68 * \brief Rendering API version and profile.
69 *//*--------------------------------------------------------------------*/
73 ApiType (void) : m_bits(pack(0, 0, PROFILE_LAST)) {}
74 ApiType (int major, int minor, Profile profile) : m_bits(pack(major, minor, profile)) {}
76 int getMajorVersion (void) const { return int((m_bits>>MAJOR_SHIFT) & ((1u<<MAJOR_BITS)-1u)); }
77 int getMinorVersion (void) const { return int((m_bits>>MINOR_SHIFT) & ((1u<<MINOR_BITS)-1u)); }
78 Profile getProfile (void) const { return Profile((m_bits>>PROFILE_SHIFT) & ((1u<<PROFILE_BITS)-1u)); }
80 bool operator== (ApiType other) const { return m_bits == other.m_bits; }
81 bool operator!= (ApiType other) const { return m_bits != other.m_bits; }
83 deUint32 getPacked (void) const { return m_bits; }
86 static ApiType es (int major, int minor) { return ApiType(major, minor, PROFILE_ES); }
87 static ApiType core (int major, int minor) { return ApiType(major, minor, PROFILE_CORE); }
88 static ApiType compatibility (int major, int minor) { return ApiType(major, minor, PROFILE_COMPATIBILITY); }
91 ApiType (deUint32 bits) : m_bits(bits) {}
92 static ApiType fromBits (deUint32 bits) { return ApiType(bits); }
94 static deUint32 pack (int major, int minor, Profile profile);
103 TOTAL_API_BITS = MAJOR_BITS+MINOR_BITS+PROFILE_BITS,
106 MINOR_SHIFT = MAJOR_SHIFT+MAJOR_BITS,
107 PROFILE_SHIFT = MINOR_SHIFT+MINOR_BITS
109 } DE_WARN_UNUSED_TYPE;
111 inline deUint32 ApiType::pack (int major, int minor, Profile profile)
115 DE_ASSERT((deUint32(major) & ~((1<<MAJOR_BITS)-1)) == 0);
116 DE_ASSERT((deUint32(minor) & ~((1<<MINOR_BITS)-1)) == 0);
117 DE_ASSERT((deUint32(profile) & ~((1<<PROFILE_BITS)-1)) == 0);
119 bits |= deUint32(major) << MAJOR_SHIFT;
120 bits |= deUint32(minor) << MINOR_SHIFT;
121 bits |= deUint32(profile) << PROFILE_SHIFT;
126 /*--------------------------------------------------------------------*//*!
127 * \brief Rendering context type.
129 * ContextType differs from API type by adding context flags. They are
130 * crucial in for example determining when GL core context supports
131 * certain API version (forward-compatible bit).
133 * \note You should NEVER compare ContextTypes against each other, as
134 * you most likely don't want to take flags into account. For example
135 * the test code almost certainly doesn't want to check that you have
136 * EXACTLY ES3.1 context with debug, but without for example robustness.
137 *//*--------------------------------------------------------------------*/
138 class ContextType : private ApiType
141 ContextType (void) {}
142 ContextType (int major, int minor, Profile profile, ContextFlags flags = ContextFlags(0));
143 explicit ContextType (ApiType apiType, ContextFlags flags = ContextFlags(0));
145 ApiType getAPI (void) const { return ApiType::fromBits(m_bits & ((1u<<TOTAL_API_BITS)-1u)); }
146 ContextFlags getFlags (void) const { return ContextFlags((m_bits>>FLAGS_SHIFT) & ((1u<<FLAGS_BITS)-1u)); }
148 using ApiType::getMajorVersion;
149 using ApiType::getMinorVersion;
150 using ApiType::getProfile;
153 static deUint32 pack (deUint32 apiBits, ContextFlags flags);
158 TOTAL_CONTEXT_BITS = TOTAL_API_BITS+FLAGS_BITS,
159 FLAGS_SHIFT = TOTAL_API_BITS
161 } DE_WARN_UNUSED_TYPE;
163 inline ContextType::ContextType (int major, int minor, Profile profile, ContextFlags flags)
164 : ApiType(major, minor, profile)
166 m_bits = pack(m_bits, flags);
169 inline ContextType::ContextType (ApiType apiType, ContextFlags flags)
172 m_bits = pack(m_bits, flags);
175 inline deUint32 ContextType::pack (deUint32 apiBits, ContextFlags flags)
177 deUint32 bits = apiBits;
179 DE_ASSERT((deUint32(flags) & ~((1<<FLAGS_BITS)-1)) == 0);
180 bits |= deUint32(flags) << FLAGS_SHIFT;
185 inline bool isContextTypeES (ContextType type) { return type.getAPI().getProfile() == PROFILE_ES; }
186 inline bool isContextTypeGLCore (ContextType type) { return type.getAPI().getProfile() == PROFILE_CORE; }
187 inline bool isContextTypeGLCompatibility(ContextType type) { return type.getAPI().getProfile() == PROFILE_COMPATIBILITY; }
188 bool contextSupports (ContextType ctxType, ApiType requiredApiType);
190 /*--------------------------------------------------------------------*//*!
191 * \brief Rendering context abstraction.
192 *//*--------------------------------------------------------------------*/
196 RenderContext (void) {}
197 virtual ~RenderContext (void) {}
199 //! Get context type. Must match to type given to ContextFactory::createContext().
200 virtual ContextType getType (void) const = DE_NULL;
202 //! Get GL function table. Should be filled with all core entry points for context type.
203 virtual const glw::Functions& getFunctions (void) const = DE_NULL;
205 //! Get render target information.
206 virtual const tcu::RenderTarget& getRenderTarget (void) const = DE_NULL;
208 //! Do post-render actions (swap buffers for example).
209 virtual void postIterate (void) = DE_NULL;
211 //! Get default framebuffer.
212 virtual deUint32 getDefaultFramebuffer (void) const { return 0; }
215 RenderContext (const RenderContext& other); // Not allowed!
216 RenderContext& operator= (const RenderContext& other); // Not allowed!
221 RenderContext* createDefaultRenderContext (tcu::Platform& platform, const tcu::CommandLine& cmdLine, ApiType apiType);
223 void initCoreFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
224 void initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType, int numExtensions, const char* const* extensions);
226 // \note initFunctions() and initExtensionFunctions() without explicit extension list
227 // use glGetString* to query list of extensions, so it needs current GL context.
228 void initFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
229 void initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
231 bool hasExtension (const glw::Functions& gl, ApiType apiType, const std::string& extension);
235 #endif // _GLURENDERCONTEXT_HPP