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; }
77 WGLContext (const WGLContext& other);
78 WGLContext& operator= (const WGLContext& other);
80 glu::ContextType m_contextType;
82 win32::Window m_window;
83 wgl::Context* m_context;
85 tcu::RenderTarget m_renderTarget;
86 glw::Functions m_functions;
89 WGLContext::WGLContext (HINSTANCE instance, const wgl::Core& wglCore, const glu::RenderConfig& config)
90 : m_contextType (config.type)
92 config.width != glu::RenderConfig::DONT_CARE ? config.width : DEFAULT_WINDOW_WIDTH,
93 config.height != glu::RenderConfig::DONT_CARE ? config.height : DEFAULT_WINDOW_HEIGHT)
96 if (config.surfaceType != glu::RenderConfig::SURFACETYPE_WINDOW &&
97 config.surfaceType != glu::RenderConfig::SURFACETYPE_DONT_CARE)
98 throw NotSupportedError("Unsupported surface type");
100 HDC deviceCtx = m_window.getDeviceContext();
103 if (config.id != glu::RenderConfig::DONT_CARE)
104 pixelFormat = config.id;
106 pixelFormat = wgl::choosePixelFormat(wglCore, deviceCtx, config);
109 throw NotSupportedError("Compatible WGL pixel format not found");
111 m_context = new wgl::Context(&wglCore, deviceCtx, config.type, pixelFormat);
115 // Describe selected config & get render target props.
116 const wgl::PixelFormatInfo info = wglCore.getPixelFormatInfo(deviceCtx, pixelFormat);
117 const IVec2 size = m_window.getSize();
119 m_renderTarget = tcu::RenderTarget(size.x(), size.y(),
120 tcu::PixelFormat(info.redBits, info.greenBits, info.blueBits, info.alphaBits),
121 info.depthBits, info.stencilBits,
122 info.sampleBuffers ? info.samples : 0);
126 WGLFunctionLoader funcLoader(*m_context);
127 glu::initFunctions(&m_functions, &funcLoader, config.type.getAPI());
130 if (config.windowVisibility != glu::RenderConfig::VISIBILITY_VISIBLE &&
131 config.windowVisibility != glu::RenderConfig::VISIBILITY_HIDDEN)
132 throw NotSupportedError("Unsupported window visibility mode");
134 m_window.setVisible(config.windowVisibility != glu::RenderConfig::VISIBILITY_HIDDEN);
143 WGLContext::~WGLContext (void)
148 void WGLContext::postIterate (void)
150 m_context->swapBuffers();
151 m_window.processEvents();
156 ContextFactory::ContextFactory (HINSTANCE instance)
157 : glu::ContextFactory ("wgl", "Windows WGL OpenGL context")
158 , m_instance (instance)
159 , m_wglCore (instance)
163 glu::RenderContext* ContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine&) const
165 return new WGLContext(m_instance, m_wglCore, config);