13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Win32 GLES3 wrapper platform. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuWin32GLES3Platform.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderConfig.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gl3Context.h" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwInitES30Direct.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct gl3PlatformContext_s 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::wgl::Context* context; 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3PlatformContext_s (void) 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : context(DE_NULL) 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrygl3FunctionPtr gl3PlatformContext_getProcAddress (gl3PlatformContext* platformCtx, const char* procName) 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(platformCtx && platformCtx->context); 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return platformCtx->context->getGLFunction(procName); 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DEFAULT_WINDOW_WIDTH = 400, 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DEFAULT_WINDOW_HEIGHT = 300 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Win32GLES3Context 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Win32GLES3Context : public glu::RenderContext 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Win32GLES3Context (const wgl::Core& wgl, HINSTANCE instance, const glu::RenderConfig& config); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Win32GLES3Context (void); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ContextType getType (void) const { return glu::CONTEXTTYPE_ES3; } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const RenderTarget& getRenderTarget (void) const { return m_renderTarget; } 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void postIterate (void); 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& getFunctions (void) const { return m_functions; } 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Win32GLES3Context (const Win32GLES3Context& other); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Win32GLES3Context& operator= (const Win32GLES3Context& other); 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderTarget m_renderTarget; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Win32Window m_window; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3PlatformContext m_platformCtx; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3Context* m_context; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::Functions m_functions; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef const char* (GL_APIENTRY* glGetStringHackFunc) (GLenum str); 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3Context::Win32GLES3Context (const wgl::Core& wgl, HINSTANCE instance, const glu::RenderConfig& config) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_renderTarget(config.width != glu::RenderConfig::DONT_CARE ? config.width : DEFAULT_WINDOW_WIDTH, 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry config.height != glu::RenderConfig::DONT_CARE ? config.height : DEFAULT_WINDOW_HEIGHT, 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PixelFormat(8, 8, 8, 8), 24, 8, 0) 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_window (instance, m_renderTarget.getWidth(), m_renderTarget.getHeight()) 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_context (DE_NULL) 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const HDC deviceCtx = m_window.getDeviceContext(); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int pixelFormat = wgl::choosePixelFormat(wgl, deviceCtx, config); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (pixelFormat < 0) 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw NotSupportedError("No compatible WGL pixel format found"); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_platformCtx.context = new wgl::Context(&wgl, m_window.getDeviceContext(), wgl::PROFILE_COMPATIBILITY, 3, 3, pixelFormat); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context = gl3Context_create(&m_platformCtx); 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_context) 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw ResourceError("Failed to create GLES3 wrapper context"); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3Context_setCurrentContext(m_context); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::initES30Direct(&m_functions); 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_window.setVisible(config.windowVisibility != glu::RenderConfig::VISIBILITY_HIDDEN); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const wgl::PixelFormatInfo info = wgl.getPixelFormatInfo(deviceCtx, pixelFormat); 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const IVec2 size = m_window.getSize(); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderTarget = tcu::RenderTarget(size.x(), size.y(), 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelFormat(info.redBits, info.greenBits, info.blueBits, info.alphaBits), 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry info.depthBits, info.stencilBits, 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry info.sampleBuffers ? info.samples : 0); 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_context) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3Context_destroy(m_context); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_platformCtx.context; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3Context::~Win32GLES3Context (void) 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_context) 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl3Context_destroy(m_context); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_platformCtx.context; 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Win32GLES3Context::postIterate (void) 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_platformCtx.context->swapBuffers(); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Win32GLES3ContextFactory 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Win32GLES3ContextFactory : public glu::ContextFactory 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Win32GLES3ContextFactory (HINSTANCE instance); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Win32GLES3ContextFactory (void); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual glu::RenderContext* createContext (const glu::RenderConfig& config, const tcu::CommandLine& cmdLine) const; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const HINSTANCE m_instance; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wgl::Core m_wglCore; 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3ContextFactory::Win32GLES3ContextFactory (HINSTANCE instance) 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : glu::ContextFactory ("gles3_wrapper", "GLES3 Wrapper Context") 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_instance (instance) 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wglCore (instance) 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3ContextFactory::~Win32GLES3ContextFactory (void) 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyryglu::RenderContext* Win32GLES3ContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine&) const 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (config.type == glu::CONTEXTTYPE_ES3) 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new Win32GLES3Context(m_wglCore, m_instance, config); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw NotSupportedError("Unsupported rendering context type"); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Win32GLES3Platform 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3Platform::Win32GLES3Platform (void) 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const HINSTANCE instance = GetModuleHandle(NULL); 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Set priority to lower. 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_glContextFactoryRegistry.registerFactory(new Win32GLES3ContextFactory(instance)); 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1883c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWin32GLES3Platform::~Win32GLES3Platform (void) 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool Win32GLES3Platform::processEvents (void) 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MSG msg; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (PeekMessage(&msg, NULL, 0, 0, TRUE)) 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DispatchMessage(&msg); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (msg.message == WM_QUIT) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Platform factory 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::Platform* createPlatform (void) 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new tcu::Win32GLES3Platform(); 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 211