Merge vk-gl-cts/opengl-es-cts-3.2.3 into vk-gl-cts/opengl-es-cts-3.2.4
[platform/upstream/VK-GL-CTS.git] / framework / egl / egluGLContextFactory.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief GL context factory using EGL.
22  *//*--------------------------------------------------------------------*/
23
24 #include "egluGLContextFactory.hpp"
25
26 #include "tcuRenderTarget.hpp"
27 #include "tcuPlatform.hpp"
28 #include "tcuCommandLine.hpp"
29
30 #include "gluDefs.hpp"
31
32 #include "egluDefs.hpp"
33 #include "egluUtil.hpp"
34 #include "egluGLUtil.hpp"
35 #include "egluNativeWindow.hpp"
36 #include "egluNativePixmap.hpp"
37 #include "egluStrUtil.hpp"
38
39 #include "eglwLibrary.hpp"
40 #include "eglwEnums.hpp"
41
42 #include "glwInitFunctions.hpp"
43 #include "glwInitES20Direct.hpp"
44 #include "glwInitES30Direct.hpp"
45 #include "glwInitES31Direct.hpp"
46 #include "glwInitES32Direct.hpp"
47
48 #include "deDynamicLibrary.hpp"
49 #include "deSTLUtil.hpp"
50
51 #include <string>
52 #include <string>
53 #include <sstream>
54
55 using std::string;
56 using std::vector;
57
58 // \todo [2014-03-12 pyry] Use command line arguments for libraries?
59
60 // Default library names
61 #if !defined(DEQP_GLES2_LIBRARY_PATH)
62 #       if (DE_OS == DE_OS_WIN32)
63 #               define DEQP_GLES2_LIBRARY_PATH "libGLESv2.dll"
64 #       else
65 #               define DEQP_GLES2_LIBRARY_PATH "libGLESv2.so"
66 #       endif
67 #endif
68
69 #if !defined(DEQP_GLES3_LIBRARY_PATH)
70 #       define DEQP_GLES3_LIBRARY_PATH DEQP_GLES2_LIBRARY_PATH
71 #endif
72
73 #if !defined(DEQP_OPENGL_LIBRARY_PATH)
74 #       if (DE_OS == DE_OS_WIN32)
75 #               define DEQP_OPENGL_LIBRARY_PATH "opengl32.dll"
76 #       else
77 #               define DEQP_OPENGL_LIBRARY_PATH "libGL.so"
78 #       endif
79 #endif
80
81 namespace eglu
82 {
83
84 using namespace eglw;
85
86 namespace
87 {
88
89 enum
90 {
91         DEFAULT_OFFSCREEN_WIDTH         = 512,
92         DEFAULT_OFFSCREEN_HEIGHT        = 512
93 };
94
95 class GetProcFuncLoader : public glw::FunctionLoader
96 {
97 public:
98         GetProcFuncLoader (const Library& egl)
99                 : m_egl(egl)
100         {
101         }
102
103         glw::GenericFuncType get (const char* name) const
104         {
105                 return (glw::GenericFuncType)m_egl.getProcAddress(name);
106         }
107
108 protected:
109         const Library& m_egl;
110 };
111
112 class DynamicFuncLoader : public glw::FunctionLoader
113 {
114 public:
115         DynamicFuncLoader       (de::DynamicLibrary* library)
116                 : m_library(library)
117         {
118         }
119
120         glw::GenericFuncType get (const char* name) const
121         {
122                 return (glw::GenericFuncType)m_library->getFunction(name);
123         }
124
125 private:
126         de::DynamicLibrary*     m_library;
127 };
128
129 class RenderContext : public GLRenderContext
130 {
131 public:
132                                                                                 RenderContext                   (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config);
133         virtual                                                         ~RenderContext                  (void);
134
135         virtual glu::ContextType                        getType                                 (void) const { return m_renderConfig.type;              }
136         virtual const glw::Functions&           getFunctions                    (void) const { return m_glFunctions;                    }
137         virtual const tcu::RenderTarget&        getRenderTarget                 (void) const { return m_glRenderTarget;                 }
138         virtual void                                            postIterate                             (void);
139
140         virtual EGLDisplay                                      getEGLDisplay                   (void) const { return m_eglDisplay;                             }
141         virtual EGLContext                                      getEGLContext                   (void) const { return m_eglContext;                             }
142         virtual EGLConfig                                       getEGLConfig                    (void) const { return m_eglConfig;                              }
143         virtual const eglw::Library&            getLibrary                              (void) const { return m_display->getLibrary();  }
144
145         virtual eglw::GenericFuncType           getProcAddress                  (const char* name) const;
146
147         virtual void                                            makeCurrent                             (void);
148
149 private:
150         void                                                            create                                  (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config);
151         void                                                            destroy                                 (void);
152
153         const glu::RenderConfig                         m_renderConfig;
154         const NativeWindowFactory* const        m_nativeWindowFactory;  // Stored in case window must be re-created
155
156         NativeDisplay*                                          m_display;
157         NativeWindow*                                           m_window;
158         NativePixmap*                                           m_pixmap;
159
160         EGLDisplay                                                      m_eglDisplay;
161         EGLConfig                                                       m_eglConfig;
162         EGLSurface                                                      m_eglSurface;
163         EGLContext                                                      m_eglContext;
164
165         tcu::RenderTarget                                       m_glRenderTarget;
166         de::DynamicLibrary*                                     m_dynamicGLLibrary;
167         glw::Functions                                          m_glFunctions;
168 };
169
170 RenderContext::RenderContext (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config)
171         : m_renderConfig                (config)
172         , m_nativeWindowFactory (windowFactory)
173         , m_display                             (DE_NULL)
174         , m_window                              (DE_NULL)
175         , m_pixmap                              (DE_NULL)
176
177         , m_eglDisplay                  (EGL_NO_DISPLAY)
178         , m_eglSurface                  (EGL_NO_SURFACE)
179         , m_eglContext                  (EGL_NO_CONTEXT)
180
181         , m_dynamicGLLibrary    (DE_NULL)
182 {
183         DE_ASSERT(displayFactory);
184
185         try
186         {
187                 create(displayFactory, windowFactory, pixmapFactory, config);
188         }
189         catch (...)
190         {
191                 destroy();
192                 throw;
193         }
194 }
195
196 RenderContext::~RenderContext(void)
197 {
198         try
199         {
200                 destroy();
201         }
202         catch (...)
203         {
204                 // destroy() calls EGL functions that are checked and may throw exceptions
205         }
206
207         delete m_window;
208         delete m_pixmap;
209         delete m_display;
210         delete m_dynamicGLLibrary;
211 }
212
213 static WindowParams::Visibility getNativeWindowVisibility (glu::RenderConfig::Visibility visibility)
214 {
215         using glu::RenderConfig;
216
217         switch (visibility)
218         {
219                 case RenderConfig::VISIBILITY_HIDDEN:           return WindowParams::VISIBILITY_HIDDEN;
220                 case RenderConfig::VISIBILITY_VISIBLE:          return WindowParams::VISIBILITY_VISIBLE;
221                 case RenderConfig::VISIBILITY_FULLSCREEN:       return WindowParams::VISIBILITY_FULLSCREEN;
222                 default:
223                         DE_ASSERT((int)visibility == RenderConfig::DONT_CARE);
224                         return WindowParams::VISIBILITY_DONT_CARE;
225         }
226 }
227
228 typedef std::pair<NativeWindow*, EGLSurface> WindowSurfacePair;
229 typedef std::pair<NativePixmap*, EGLSurface> PixmapSurfacePair;
230
231 WindowSurfacePair createWindow (NativeDisplay* nativeDisplay, const NativeWindowFactory* windowFactory, EGLDisplay eglDisplay, EGLConfig eglConfig, const glu::RenderConfig& config)
232 {
233         const int                                               width                   = (config.width         == glu::RenderConfig::DONT_CARE ? WindowParams::SIZE_DONT_CARE  : config.width);
234         const int                                               height                  = (config.height        == glu::RenderConfig::DONT_CARE ? WindowParams::SIZE_DONT_CARE  : config.height);
235         const WindowParams::Visibility  visibility              = getNativeWindowVisibility(config.windowVisibility);
236         NativeWindow*                                   nativeWindow    = DE_NULL;
237         EGLSurface                                              surface                 = EGL_NO_SURFACE;
238         const EGLAttrib                                 attribList[]    = { EGL_NONE };
239
240         nativeWindow = windowFactory->createWindow(nativeDisplay, eglDisplay, eglConfig, &attribList[0], WindowParams(width, height, visibility));
241
242         try
243         {
244                 surface = eglu::createWindowSurface(*nativeDisplay, *nativeWindow, eglDisplay, eglConfig, attribList);
245         }
246         catch (...)
247         {
248                 delete nativeWindow;
249                 throw;
250         }
251
252         return WindowSurfacePair(nativeWindow, surface);
253 }
254
255 PixmapSurfacePair createPixmap (NativeDisplay* nativeDisplay, const NativePixmapFactory* pixmapFactory, EGLDisplay eglDisplay, EGLConfig eglConfig, const glu::RenderConfig& config)
256 {
257         const int                       width                   = (config.width         == glu::RenderConfig::DONT_CARE ? DEFAULT_OFFSCREEN_WIDTH       : config.width);
258         const int                       height                  = (config.height        == glu::RenderConfig::DONT_CARE ? DEFAULT_OFFSCREEN_HEIGHT      : config.height);
259         NativePixmap*           nativePixmap    = DE_NULL;
260         EGLSurface                      surface                 = EGL_NO_SURFACE;
261         const EGLAttrib         attribList[]    = { EGL_NONE };
262
263         nativePixmap = pixmapFactory->createPixmap(nativeDisplay, eglDisplay, eglConfig, &attribList[0], width, height);
264
265         try
266         {
267                 surface = eglu::createPixmapSurface(*nativeDisplay, *nativePixmap, eglDisplay, eglConfig, attribList);
268         }
269         catch (...)
270         {
271                 delete nativePixmap;
272                 throw;
273         }
274
275         return PixmapSurfacePair(nativePixmap, surface);
276 }
277
278 EGLSurface createPBuffer (const Library& egl, EGLDisplay display, EGLConfig eglConfig, const glu::RenderConfig& config)
279 {
280         const int               width                   = (config.width         == glu::RenderConfig::DONT_CARE ? DEFAULT_OFFSCREEN_WIDTH       : config.width);
281         const int               height                  = (config.height        == glu::RenderConfig::DONT_CARE ? DEFAULT_OFFSCREEN_HEIGHT      : config.height);
282         EGLSurface              surface;
283         const EGLint    attribList[]    =
284         {
285                 EGL_WIDTH,      width,
286                 EGL_HEIGHT,     height,
287                 EGL_NONE
288         };
289
290         surface = egl.createPbufferSurface(display, eglConfig, &(attribList[0]));
291         EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
292
293         return surface;
294 }
295
296 void RenderContext::makeCurrent (void)
297 {
298         const Library& egl = m_display->getLibrary();
299
300         EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
301 }
302
303 glw::GenericFuncType RenderContext::getProcAddress (const char* name) const
304 {
305         return (glw::GenericFuncType)m_display->getLibrary().getProcAddress(name);
306 }
307
308 void RenderContext::create (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config)
309 {
310         glu::RenderConfig::SurfaceType  surfaceType     = config.surfaceType;
311
312         DE_ASSERT(displayFactory);
313
314         m_display               = displayFactory->createDisplay();
315         m_eglDisplay    = eglu::getDisplay(*m_display);
316
317         const Library& egl = m_display->getLibrary();
318
319         {
320                 EGLint major = 0;
321                 EGLint minor = 0;
322                 EGLU_CHECK_CALL(egl, initialize(m_eglDisplay, &major, &minor));
323         }
324
325         m_eglConfig     = chooseConfig(egl, m_eglDisplay, config);
326
327         if (surfaceType == glu::RenderConfig::SURFACETYPE_DONT_CARE)
328         {
329                 // Choose based on what selected configuration supports
330                 const EGLint supportedTypes = eglu::getConfigAttribInt(egl, m_eglDisplay, m_eglConfig, EGL_SURFACE_TYPE);
331
332                 if ((supportedTypes & EGL_WINDOW_BIT) != 0)
333                         surfaceType = glu::RenderConfig::SURFACETYPE_WINDOW;
334                 else if ((supportedTypes & EGL_PBUFFER_BIT) != 0)
335                         surfaceType = glu::RenderConfig::SURFACETYPE_OFFSCREEN_GENERIC;
336                 else if ((supportedTypes & EGL_PIXMAP_BIT) != 0)
337                         surfaceType = glu::RenderConfig::SURFACETYPE_OFFSCREEN_NATIVE;
338                 else
339                         throw tcu::NotSupportedError("Selected EGL config doesn't support any surface types", DE_NULL, __FILE__, __LINE__);
340         }
341
342         switch (surfaceType)
343         {
344                 case glu::RenderConfig::SURFACETYPE_WINDOW:
345                 {
346                         if (windowFactory)
347                         {
348                                 const WindowSurfacePair windowSurface = createWindow(m_display, windowFactory, m_eglDisplay, m_eglConfig, config);
349                                 m_window                = windowSurface.first;
350                                 m_eglSurface    = windowSurface.second;
351                         }
352                         else
353                                 throw tcu::NotSupportedError("EGL platform doesn't support windows", DE_NULL, __FILE__, __LINE__);
354                         break;
355                 }
356
357                 case glu::RenderConfig::SURFACETYPE_OFFSCREEN_NATIVE:
358                 {
359                         if (pixmapFactory)
360                         {
361                                 const PixmapSurfacePair pixmapSurface = createPixmap(m_display, pixmapFactory, m_eglDisplay, m_eglConfig, config);
362                                 m_pixmap                = pixmapSurface.first;
363                                 m_eglSurface    = pixmapSurface.second;
364                         }
365                         else
366                                 throw tcu::NotSupportedError("EGL platform doesn't support pixmaps", DE_NULL, __FILE__, __LINE__);
367                         break;
368                 }
369
370                 case glu::RenderConfig::SURFACETYPE_OFFSCREEN_GENERIC:
371                         m_eglSurface = createPBuffer(egl, m_eglDisplay, m_eglConfig, config);
372                         break;
373
374                 default:
375                         throw tcu::InternalError("Invalid surface type");
376         }
377
378         m_eglContext = createGLContext(egl, m_eglDisplay, m_eglConfig, config.type, config.resetNotificationStrategy);
379
380         EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
381
382         // Init core functions
383
384         if (hasExtension(egl, m_eglDisplay, "EGL_KHR_get_all_proc_addresses"))
385         {
386                 // Use eglGetProcAddress() for core functions
387                 GetProcFuncLoader funcLoader(egl);
388                 glu::initCoreFunctions(&m_glFunctions, &funcLoader, config.type.getAPI());
389         }
390 #if defined(DEQP_GLES2_DIRECT_LINK)
391         else if (config.type.getAPI() == glu::ApiType::es(2,0))
392         {
393                 glw::initES20Direct(&m_glFunctions);
394         }
395 #endif
396 #if defined(DEQP_GLES3_DIRECT_LINK)
397         else if (config.type.getAPI() == glu::ApiType::es(3,0))
398         {
399                 glw::initES30Direct(&m_glFunctions);
400         }
401 #endif
402 #if defined(DEQP_GLES31_DIRECT_LINK)
403         else if (config.type.getAPI() == glu::ApiType::es(3,1))
404         {
405                 glw::initES31Direct(&m_glFunctions);
406         }
407 #endif
408 #if defined(DEQP_GLES32_DIRECT_LINK)
409         else if (config.type.getAPI() == glu::ApiType::es(3,2))
410         {
411                 glw::initES32Direct(&m_glFunctions);
412         }
413 #endif
414         else
415         {
416                 const char* libraryPath = DE_NULL;
417
418                 if (glu::isContextTypeES(config.type))
419                 {
420                         if (config.type.getMinorVersion() <= 2)
421                                 libraryPath = DEQP_GLES2_LIBRARY_PATH;
422                         else
423                                 libraryPath = DEQP_GLES3_LIBRARY_PATH;
424                 }
425                 else
426                         libraryPath = DEQP_OPENGL_LIBRARY_PATH;
427
428                 m_dynamicGLLibrary = new de::DynamicLibrary(libraryPath);
429
430                 DynamicFuncLoader funcLoader(m_dynamicGLLibrary);
431                 glu::initCoreFunctions(&m_glFunctions, &funcLoader, config.type.getAPI());
432         }
433
434         // Init extension functions
435         {
436                 GetProcFuncLoader extLoader(egl);
437                 glu::initExtensionFunctions(&m_glFunctions, &extLoader, config.type.getAPI());
438         }
439
440         {
441                 EGLint                          width, height, depthBits, stencilBits, numSamples;
442                 tcu::PixelFormat        pixelFmt;
443
444                 egl.querySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH,         &width);
445                 egl.querySurface(m_eglDisplay, m_eglSurface, EGL_HEIGHT,        &height);
446
447                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_RED_SIZE,            &pixelFmt.redBits);
448                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_GREEN_SIZE,          &pixelFmt.greenBits);
449                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_BLUE_SIZE,           &pixelFmt.blueBits);
450                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_ALPHA_SIZE,          &pixelFmt.alphaBits);
451
452                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_DEPTH_SIZE,          &depthBits);
453                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_STENCIL_SIZE,        &stencilBits);
454                 egl.getConfigAttrib(m_eglDisplay, m_eglConfig, EGL_SAMPLES,                     &numSamples);
455
456                 EGLU_CHECK_MSG(egl, "Failed to query config attributes");
457
458                 m_glRenderTarget = tcu::RenderTarget(width, height, pixelFmt, depthBits, stencilBits, numSamples);
459         }
460 }
461
462 void RenderContext::destroy (void)
463 {
464         if (m_eglDisplay != EGL_NO_DISPLAY)
465         {
466                 const Library& egl = m_display->getLibrary();
467
468                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
469
470                 if (m_eglSurface != EGL_NO_SURFACE)
471                         EGLU_CHECK_CALL(egl, destroySurface(m_eglDisplay, m_eglSurface));
472
473                 if (m_eglContext != EGL_NO_CONTEXT)
474                         EGLU_CHECK_CALL(egl, destroyContext(m_eglDisplay, m_eglContext));
475
476                 EGLU_CHECK_CALL(egl, terminate(m_eglDisplay));
477
478                 m_eglDisplay    = EGL_NO_DISPLAY;
479                 m_eglSurface    = EGL_NO_SURFACE;
480                 m_eglContext    = EGL_NO_CONTEXT;
481         }
482
483         delete m_window;
484         delete m_pixmap;
485         delete m_display;
486         delete m_dynamicGLLibrary;
487
488         m_window                        = DE_NULL;
489         m_pixmap                        = DE_NULL;
490         m_display                       = DE_NULL;
491         m_dynamicGLLibrary      = DE_NULL;
492 }
493
494 void RenderContext::postIterate (void)
495 {
496         const Library& egl = m_display->getLibrary();
497
498         if (m_window)
499         {
500                 EGLBoolean      swapOk          = egl.swapBuffers(m_eglDisplay, m_eglSurface);
501                 EGLint          error           = egl.getError();
502                 const bool      badWindow       = error == EGL_BAD_SURFACE || error == EGL_BAD_NATIVE_WINDOW;
503
504                 if (!swapOk && !badWindow)
505                         throw tcu::ResourceError(string("eglSwapBuffers() failed: ") + getErrorStr(error).toString());
506
507                 try
508                 {
509                         m_window->processEvents();
510                 }
511                 catch (const WindowDestroyedError&)
512                 {
513                         tcu::print("Warning: Window destroyed, recreating...\n");
514
515                         EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
516                         EGLU_CHECK_CALL(egl, destroySurface(m_eglDisplay, m_eglSurface));
517                         m_eglSurface = EGL_NO_SURFACE;
518
519                         delete m_window;
520                         m_window = DE_NULL;
521
522                         try
523                         {
524                                 WindowSurfacePair windowSurface = createWindow(m_display, m_nativeWindowFactory, m_eglDisplay, m_eglConfig, m_renderConfig);
525                                 m_window                = windowSurface.first;
526                                 m_eglSurface    = windowSurface.second;
527
528                                 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
529
530                                 swapOk  = EGL_TRUE;
531                                 error   = EGL_SUCCESS;
532                         }
533                         catch (const std::exception& e)
534                         {
535                                 if (m_eglSurface)
536                                 {
537                                         egl.makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
538                                         egl.destroySurface(m_eglDisplay, m_eglSurface);
539                                         m_eglSurface = EGL_NO_SURFACE;
540                                 }
541
542                                 delete m_window;
543                                 m_window = DE_NULL;
544
545                                 throw tcu::ResourceError(string("Failed to re-create window: ") + e.what());
546                         }
547                 }
548
549                 if (!swapOk)
550                 {
551                         DE_ASSERT(badWindow);
552                         throw tcu::ResourceError(string("eglSwapBuffers() failed: ") + getErrorStr(error).toString());
553                 }
554
555                 // Refresh dimensions
556                 {
557                         int     newWidth        = 0;
558                         int     newHeight       = 0;
559
560                         egl.querySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH,         &newWidth);
561                         egl.querySurface(m_eglDisplay, m_eglSurface, EGL_HEIGHT,        &newHeight);
562                         EGLU_CHECK_MSG(egl, "Failed to query window size");
563
564                         if (newWidth    != m_glRenderTarget.getWidth() ||
565                                 newHeight       != m_glRenderTarget.getHeight())
566                         {
567                                 tcu::print("Warning: Window size changed (%dx%d -> %dx%d), test results might be invalid!\n",
568                                                    m_glRenderTarget.getWidth(), m_glRenderTarget.getHeight(), newWidth, newHeight);
569
570                                 m_glRenderTarget = tcu::RenderTarget(newWidth, newHeight,
571                                                                                                          m_glRenderTarget.getPixelFormat(),
572                                                                                                          m_glRenderTarget.getDepthBits(),
573                                                                                                          m_glRenderTarget.getStencilBits(),
574                                                                                                          m_glRenderTarget.getNumSamples());
575                         }
576                 }
577         }
578         else
579                 m_glFunctions.flush();
580 }
581
582 } // anonymous
583
584 GLContextFactory::GLContextFactory (const NativeDisplayFactoryRegistry& displayFactoryRegistry)
585         : glu::ContextFactory           ("egl", "EGL OpenGL Context")
586         , m_displayFactoryRegistry      (displayFactoryRegistry)
587 {
588 }
589
590 glu::RenderContext* GLContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine& cmdLine) const
591 {
592         const NativeDisplayFactory& displayFactory = selectNativeDisplayFactory(m_displayFactoryRegistry, cmdLine);
593
594         const NativeWindowFactory*      windowFactory;
595         const NativePixmapFactory*      pixmapFactory;
596
597         try
598         {
599                 windowFactory = &selectNativeWindowFactory(displayFactory, cmdLine);
600         }
601         catch (const tcu::NotSupportedError&)
602         {
603                 windowFactory = DE_NULL;
604         }
605
606         try
607         {
608                 pixmapFactory = &selectNativePixmapFactory(displayFactory, cmdLine);
609         }
610         catch (const tcu::NotSupportedError&)
611         {
612                 pixmapFactory = DE_NULL;
613         }
614
615         return new RenderContext(&displayFactory, windowFactory, pixmapFactory, config);
616 }
617
618 } // eglu