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"
28 // glw::GenericFuncType
29 #include "glwFunctionLoader.hpp"
53 PROFILE_ES = 0, //!< OpenGL ES
54 PROFILE_CORE, //!< OpenGL Core Profile
55 PROFILE_COMPATIBILITY, //!< OpenGL Compatibility Profile
62 CONTEXT_ROBUST = (1<<0), //!< Robust context
63 CONTEXT_DEBUG = (1<<1), //!< Debug context
64 CONTEXT_FORWARD_COMPATIBLE = (1<<2), //!< Forward-compatible context
65 CONTEXT_NO_ERROR = (1<<3) //!< No error context
68 inline ContextFlags operator| (ContextFlags a, ContextFlags b) { return ContextFlags((deUint32)a|(deUint32)b); }
69 inline ContextFlags operator& (ContextFlags a, ContextFlags b) { return ContextFlags((deUint32)a&(deUint32)b); }
70 inline ContextFlags operator~ (ContextFlags a) { return ContextFlags(~(deUint32)a); }
72 /*--------------------------------------------------------------------*//*!
73 * \brief Rendering API version and profile.
74 *//*--------------------------------------------------------------------*/
78 ApiType (void) : m_bits(pack(0, 0, PROFILE_LAST)) {}
79 ApiType (int major, int minor, Profile profile) : m_bits(pack(major, minor, profile)) {}
81 int getMajorVersion (void) const { return int((m_bits>>MAJOR_SHIFT) & ((1u<<MAJOR_BITS)-1u)); }
82 int getMinorVersion (void) const { return int((m_bits>>MINOR_SHIFT) & ((1u<<MINOR_BITS)-1u)); }
83 Profile getProfile (void) const { return Profile((m_bits>>PROFILE_SHIFT) & ((1u<<PROFILE_BITS)-1u)); }
85 bool operator== (ApiType other) const { return m_bits == other.m_bits; }
86 bool operator!= (ApiType other) const { return m_bits != other.m_bits; }
88 deUint32 getPacked (void) const { return m_bits; }
91 static ApiType es (int major, int minor) { return ApiType(major, minor, PROFILE_ES); }
92 static ApiType core (int major, int minor) { return ApiType(major, minor, PROFILE_CORE); }
93 static ApiType compatibility (int major, int minor) { return ApiType(major, minor, PROFILE_COMPATIBILITY); }
96 ApiType (deUint32 bits) : m_bits(bits) {}
97 static ApiType fromBits (deUint32 bits) { return ApiType(bits); }
99 static deUint32 pack (int major, int minor, Profile profile);
108 TOTAL_API_BITS = MAJOR_BITS+MINOR_BITS+PROFILE_BITS,
111 MINOR_SHIFT = MAJOR_SHIFT+MAJOR_BITS,
112 PROFILE_SHIFT = MINOR_SHIFT+MINOR_BITS
114 } DE_WARN_UNUSED_TYPE;
116 inline deUint32 ApiType::pack (int major, int minor, Profile profile)
120 DE_ASSERT((deUint32(major) & ~((1<<MAJOR_BITS)-1)) == 0);
121 DE_ASSERT((deUint32(minor) & ~((1<<MINOR_BITS)-1)) == 0);
122 DE_ASSERT((deUint32(profile) & ~((1<<PROFILE_BITS)-1)) == 0);
124 bits |= deUint32(major) << MAJOR_SHIFT;
125 bits |= deUint32(minor) << MINOR_SHIFT;
126 bits |= deUint32(profile) << PROFILE_SHIFT;
131 /*--------------------------------------------------------------------*//*!
132 * \brief Rendering context type.
134 * ContextType differs from API type by adding context flags. They are
135 * crucial in for example determining when GL core context supports
136 * certain API version (forward-compatible bit).
138 * \note You should NEVER compare ContextTypes against each other, as
139 * you most likely don't want to take flags into account. For example
140 * the test code almost certainly doesn't want to check that you have
141 * EXACTLY ES3.1 context with debug, but without for example robustness.
142 *//*--------------------------------------------------------------------*/
143 class ContextType : private ApiType
146 ContextType (void) {}
147 ContextType (int major, int minor, Profile profile, ContextFlags flags = ContextFlags(0));
148 explicit ContextType (ApiType apiType, ContextFlags flags = ContextFlags(0));
150 ApiType getAPI (void) const { return ApiType::fromBits(m_bits & ((1u<<TOTAL_API_BITS)-1u)); }
151 ContextFlags getFlags (void) const { return ContextFlags((m_bits>>FLAGS_SHIFT) & ((1u<<FLAGS_BITS)-1u)); }
153 using ApiType::getMajorVersion;
154 using ApiType::getMinorVersion;
155 using ApiType::getProfile;
158 static deUint32 pack (deUint32 apiBits, ContextFlags flags);
163 TOTAL_CONTEXT_BITS = TOTAL_API_BITS+FLAGS_BITS,
164 FLAGS_SHIFT = TOTAL_API_BITS
166 } DE_WARN_UNUSED_TYPE;
168 inline ContextType::ContextType (int major, int minor, Profile profile, ContextFlags flags)
169 : ApiType(major, minor, profile)
171 m_bits = pack(m_bits, flags);
174 inline ContextType::ContextType (ApiType apiType, ContextFlags flags)
177 m_bits = pack(m_bits, flags);
180 inline deUint32 ContextType::pack (deUint32 apiBits, ContextFlags flags)
182 deUint32 bits = apiBits;
184 DE_ASSERT((deUint32(flags) & ~((1u<<FLAGS_BITS)-1u)) == 0);
186 bits |= deUint32(flags) << FLAGS_SHIFT;
191 inline bool isContextTypeES (ContextType type) { return type.getAPI().getProfile() == PROFILE_ES; }
192 inline bool isContextTypeGLCore (ContextType type) { return type.getAPI().getProfile() == PROFILE_CORE; }
193 inline bool isContextTypeGLCompatibility(ContextType type) { return type.getAPI().getProfile() == PROFILE_COMPATIBILITY; }
194 bool contextSupports (ContextType ctxType, ApiType requiredApiType);
196 const char* getApiTypeDescription (ApiType type);
198 /*--------------------------------------------------------------------*//*!
199 * \brief Rendering context abstraction.
200 *//*--------------------------------------------------------------------*/
204 RenderContext (void) {}
205 virtual ~RenderContext (void) {}
207 //! Get context type. Must match to type given to ContextFactory::createContext().
208 virtual ContextType getType (void) const = DE_NULL;
210 //! Get GL function table. Should be filled with all core entry points for context type.
211 virtual const glw::Functions& getFunctions (void) const = DE_NULL;
213 //! Get render target information.
214 virtual const tcu::RenderTarget& getRenderTarget (void) const = DE_NULL;
216 //! Do post-render actions (swap buffers for example).
217 virtual void postIterate (void) = DE_NULL;
219 //! Get default framebuffer.
220 virtual deUint32 getDefaultFramebuffer (void) const { return 0; }
222 //! Get extension function address.
223 virtual glw::GenericFuncType getProcAddress (const char* name) const;
225 //! Make context current in thread. Optional to support.
226 virtual void makeCurrent (void);
229 RenderContext (const RenderContext& other); // Not allowed!
230 RenderContext& operator= (const RenderContext& other); // Not allowed!
235 RenderContext* createRenderContext (tcu::Platform& platform, const tcu::CommandLine& cmdLine, const RenderConfig& config);
236 RenderContext* createDefaultRenderContext (tcu::Platform& platform, const tcu::CommandLine& cmdLine, ApiType apiType);
238 void initCoreFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
239 void initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType, int numExtensions, const char* const* extensions);
241 // \note initFunctions() and initExtensionFunctions() without explicit extension list
242 // use glGetString* to query list of extensions, so it needs current GL context.
243 void initFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
244 void initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType);
246 bool hasExtension (const glw::Functions& gl, ApiType apiType, const std::string& extension);
250 #endif // _GLURENDERCONTEXT_HPP