13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities 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 OpenGL ES rendering context. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderConfig.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluES3PlusWrapperContext.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluFboRenderContext.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPlatform.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwInitFunctions.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuPlatform.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool versionGreaterOrEqual (ApiType a, ApiType b) 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return a.getMajorVersion() > b.getMajorVersion() || 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (a.getMajorVersion() == b.getMajorVersion() && a.getMinorVersion() >= b.getMinorVersion()); 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool contextSupports (ContextType ctxType, ApiType requiredApiType) 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2014-10-06 pyry] Check exact forward-compatible restrictions. 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool forwardCompatible = (ctxType.getFlags() & CONTEXT_FORWARD_COMPATIBLE) != 0; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (isContextTypeES(ctxType)) 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!forwardCompatible); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return requiredApiType.getProfile() == PROFILE_ES && 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry versionGreaterOrEqual(ctxType.getAPI(), requiredApiType); 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (isContextTypeGLCore(ctxType)) 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (forwardCompatible) 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ctxType.getAPI() == requiredApiType; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return requiredApiType.getProfile() == PROFILE_CORE && 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry versionGreaterOrEqual(ctxType.getAPI(), requiredApiType); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (isContextTypeGLCompatibility(ctxType)) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!forwardCompatible); 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (requiredApiType.getProfile() == PROFILE_CORE || requiredApiType.getProfile() == PROFILE_COMPATIBILITY) && 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry versionGreaterOrEqual(ctxType.getAPI(), requiredApiType); 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic ContextFlags parseContextFlags (const std::string& flagsStr) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<std::string> flagNames = de::splitString(flagsStr, ','); 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ContextFlags flags = ContextFlags(0); 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ContextFlags flag; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } s_flagMap[] = 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "debug", CONTEXT_DEBUG }, 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "robust", CONTEXT_ROBUST } 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<std::string>::const_iterator flagIter = flagNames.begin(); flagIter != flagNames.end(); ++flagIter) 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int ndx; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_flagMap); ndx++) 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (*flagIter == s_flagMap[ndx].name) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry flags = flags | s_flagMap[ndx].flag; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (ndx == DE_LENGTH_OF_ARRAY(s_flagMap)) 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print("ERROR: Unrecognized GL context flag '%s'\n", flagIter->c_str()); 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print("Supported GL context flags:\n"); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_flagMap); ndx++) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print(" %s\n", s_flagMap[ndx].name); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError((std::string("Unknown GL context flag '") + *flagIter + "'").c_str(), DE_NULL, __FILE__, __LINE__); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return flags; 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryRenderContext* createDefaultRenderContext (tcu::Platform& platform, const tcu::CommandLine& cmdLine, ApiType apiType) 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ContextFactoryRegistry& registry = platform.getGLPlatform().getContextFactoryRegistry(); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RenderConfig config; 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* factoryName = cmdLine.getGLContextType(); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ContextFactory* factory = DE_NULL; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ContextFlags ctxFlags = ContextFlags(0); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (registry.empty()) 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("OpenGL is not supported", DE_NULL, __FILE__, __LINE__); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cmdLine.getGLContextFlags()) 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctxFlags = parseContextFlags(cmdLine.getGLContextFlags()); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry config.type = glu::ContextType(apiType, ctxFlags); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parseRenderConfig(&config, cmdLine); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (factoryName) 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry factory = registry.getFactoryByName(factoryName); 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!factory) 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print("ERROR: Unknown or unsupported GL context type '%s'\n", factoryName); 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print("Supported GL context types:\n"); 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int factoryNdx = 0; factoryNdx < (int)registry.getFactoryCount(); factoryNdx++) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ContextFactory* curFactory = registry.getFactoryByIndex(factoryNdx); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print(" %s: %s\n", curFactory->getName(), curFactory->getDescription()); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError((std::string("Unknown GL context type '") + factoryName + "'").c_str(), DE_NULL, __FILE__, __LINE__); 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry factory = registry.getDefaultFactory(); 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cmdLine.getSurfaceType() == tcu::SURFACETYPE_FBO) 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new FboRenderContext(*factory, config, cmdLine); 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return factory->createContext(config, cmdLine); 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // If ES31 context is not available, try using wrapper. 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (config.type.getAPI() == ApiType::es(3,1)) 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::print("Warning: Unable to create native OpenGL ES 3.1 context, will use wrapper context.\n"); 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return new ES3PlusWrapperContext(*factory, config, cmdLine); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic std::vector<std::string> getExtensions (const glw::Functions& gl, ApiType apiType) 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry using std::vector; 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry using std::string; 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (apiType.getProfile() == PROFILE_ES && apiType.getMajorVersion() == 2) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.getString); 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* extStr = (const char*)gl.getString(GL_EXTENSIONS); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetString(GL_EXTENSIONS)"); 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (extStr) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return de::splitString(extStr); 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("glGetString(GL_EXTENSIONS) returned null pointer", DE_NULL, __FILE__, __LINE__); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numExtensions = 0; 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<string> extensions; 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK(gl.getIntegerv && gl.getStringi); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getIntegerv(GL_NUM_EXTENSIONS, &numExtensions); 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetIntegerv(GL_NUM_EXTENSIONS)"); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (numExtensions > 0) 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extensions.resize(numExtensions); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numExtensions; ndx++) 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const ext = (const char*)gl.getStringi(GL_EXTENSIONS, ndx); 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glGetStringi(GL_EXTENSIONS)"); 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (ext) 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extensions[ndx] = ext; 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::TestError("glGetStringi(GL_EXTENSIONS) returned null pointer", DE_NULL, __FILE__, __LINE__); 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return extensions; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid initCoreFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType) 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ApiType apiType; 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void (*initFunc) (glw::Functions* gl, const glw::FunctionLoader* loader); 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } s_initFuncs[] = 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::es(2,0), glw::initES20 }, 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::es(3,0), glw::initES30 }, 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::es(3,1), glw::initES31 }, 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(3,0), glw::initGL30Core }, 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(3,1), glw::initGL31Core }, 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(3,2), glw::initGL32Core }, 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(3,3), glw::initGL33Core }, 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(4,0), glw::initGL40Core }, 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(4,1), glw::initGL41Core }, 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(4,2), glw::initGL42Core }, 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(4,3), glw::initGL43Core }, 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { ApiType::core(4,4), glw::initGL44Core }, 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_initFuncs); ndx++) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (s_initFuncs[ndx].apiType == apiType) 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry s_initFuncs[ndx].initFunc(dst, loader); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::InternalError(std::string("Don't know how to load functions for ") + de::toString(apiType)); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 260ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyryvoid initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType) 261ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry{ 262ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry std::vector<std::string> extensions = getExtensions(*dst, apiType); 263ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 264ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry if (!extensions.empty()) 265ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry { 266ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry std::vector<const char*> extStr(extensions.size()); 267ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 268ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry for (size_t ndx = 0; ndx < extensions.size(); ndx++) 269ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry extStr[ndx] = extensions[ndx].c_str(); 270ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 271ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry initExtensionFunctions(dst, loader, apiType, (int)extStr.size(), &extStr[0]); 272ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry } 273ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry} 274ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid initExtensionFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType, int numExtensions, const char* const* extensions) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (apiType.getProfile() == PROFILE_ES) 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::initExtensionsES(dst, loader, numExtensions, extensions); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::initExtensionsGL(dst, loader, numExtensions, extensions); 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid initFunctions (glw::Functions* dst, const glw::FunctionLoader* loader, ApiType apiType) 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry initCoreFunctions(dst, loader, apiType); 286ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry initExtensionFunctions(dst, loader, apiType); 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu 290