1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief WGL GL context factory.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuWGLContextFactory.hpp"
26 #include "gluRenderConfig.hpp"
27 #include "tcuRenderTarget.hpp"
28 #include "tcuWin32Window.hpp"
29 #include "glwFunctions.hpp"
30 #include "glwInitFunctions.hpp"
44 DEFAULT_WINDOW_WIDTH = 400,
45 DEFAULT_WINDOW_HEIGHT = 300
48 class WGLFunctionLoader : public glw::FunctionLoader
51 WGLFunctionLoader (const wgl::Context& context)
56 glw::GenericFuncType get (const char* name) const
58 return (glw::GenericFuncType)m_context.getGLFunction(name);
62 const wgl::Context& m_context;
65 class WGLContext : public glu::RenderContext
68 WGLContext (HINSTANCE instance, const wgl::Core& wglCore, const glu::RenderConfig& config);
71 glu::ContextType getType (void) const { return m_contextType; }
72 const RenderTarget& getRenderTarget (void) const { return m_renderTarget; }
73 void postIterate (void);
74 const glw::Functions& getFunctions (void) const { return m_functions; }
76 glw::GenericFuncType getProcAddress (const char* name) const;
78 void makeCurrent (void);
81 WGLContext (const WGLContext& other);
82 WGLContext& operator= (const WGLContext& other);
84 glu::ContextType m_contextType;
86 win32::Window m_window;
87 wgl::Context* m_context;
89 tcu::RenderTarget m_renderTarget;
90 glw::Functions m_functions;
93 WGLContext::WGLContext (HINSTANCE instance, const wgl::Core& wglCore, const glu::RenderConfig& config)
94 : m_contextType (config.type)
96 config.width != glu::RenderConfig::DONT_CARE ? config.width : DEFAULT_WINDOW_WIDTH,
97 config.height != glu::RenderConfig::DONT_CARE ? config.height : DEFAULT_WINDOW_HEIGHT)
100 if (config.surfaceType != glu::RenderConfig::SURFACETYPE_WINDOW &&
101 config.surfaceType != glu::RenderConfig::SURFACETYPE_DONT_CARE)
102 throw NotSupportedError("Unsupported surface type");
104 HDC deviceCtx = m_window.getDeviceContext();
107 if (config.id != glu::RenderConfig::DONT_CARE)
108 pixelFormat = config.id;
110 pixelFormat = wgl::choosePixelFormat(wglCore, deviceCtx, config);
113 throw NotSupportedError("Compatible WGL pixel format not found");
115 m_context = new wgl::Context(&wglCore, deviceCtx, config.type, pixelFormat, config.resetNotificationStrategy);
119 // Describe selected config & get render target props.
120 const wgl::PixelFormatInfo info = wglCore.getPixelFormatInfo(deviceCtx, pixelFormat);
121 const IVec2 size = m_window.getSize();
123 m_renderTarget = tcu::RenderTarget(size.x(), size.y(),
124 tcu::PixelFormat(info.redBits, info.greenBits, info.blueBits, info.alphaBits),
125 info.depthBits, info.stencilBits,
126 info.sampleBuffers ? info.samples : 0);
130 WGLFunctionLoader funcLoader(*m_context);
131 glu::initFunctions(&m_functions, &funcLoader, config.type.getAPI());
134 if (config.windowVisibility != glu::RenderConfig::VISIBILITY_VISIBLE &&
135 config.windowVisibility != glu::RenderConfig::VISIBILITY_HIDDEN)
136 throw NotSupportedError("Unsupported window visibility mode");
138 m_window.setVisible(config.windowVisibility != glu::RenderConfig::VISIBILITY_HIDDEN);
147 WGLContext::~WGLContext (void)
152 glw::GenericFuncType WGLContext::getProcAddress (const char* name) const
154 return m_context->getGLFunction(name);
157 void WGLContext::makeCurrent (void)
159 m_context->makeCurrent();
162 void WGLContext::postIterate (void)
164 m_context->swapBuffers();
165 m_window.processEvents();
170 ContextFactory::ContextFactory (HINSTANCE instance)
171 : glu::ContextFactory ("wgl", "Windows WGL OpenGL context")
172 , m_instance (instance)
173 , m_wglCore (instance)
177 glu::RenderContext* ContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine&) const
179 return new WGLContext(m_instance, m_wglCore, config);