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 3plus wrapper context. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluES3PlusWrapperContext.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderConfig.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwInitFunctions.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctionLoader.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluContextFactory.hpp" 307af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry#include "gluContextInfo.hpp" 317af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry#include "gluShaderUtil.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deThreadLocal.hpp" 331f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry#include "deSTLUtil.hpp" 347af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry#include "deUniquePtr.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream> 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <cstring> 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm> 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <map> 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace es3plus 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Context 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 567af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry Context (const glu::RenderContext& ctx); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Context (void); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void addExtension (const char* name); 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl; //!< GL 4.3 core context functions. 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Wrapper state. 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string vendor; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string version; 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string renderer; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string shadingLanguageVersion; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string extensions; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<string> extensionList; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool primitiveRestartEnabled; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 defaultVAO; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool defaultVAOBound; 747af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 757af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry const glu::GLSLVersion nativeGLSLVersion; 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 787af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko PöyryContext::Context (const glu::RenderContext& ctx) 797af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry : gl (ctx.getFunctions()) 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , vendor ("drawElements") 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , version ("OpenGL ES 3.1") 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , renderer ((const char*)gl.getString(GL_RENDERER)) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , shadingLanguageVersion ("OpenGL ES GLSL ES 3.1") 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , primitiveRestartEnabled (false) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , defaultVAO (0) 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , defaultVAOBound (false) 877af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry , nativeGLSLVersion (glu::getContextTypeGLSLVersion(ctx.getType())) 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 897af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry const de::UniquePtr<glu::ContextInfo> ctxInfo(glu::ContextInfo::create(ctx)); 907af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.genVertexArrays(1, &defaultVAO); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (gl.getError() != GL_NO_ERROR || defaultVAO == 0) 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::InternalError("Failed to allocate VAO for emulation"); 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindVertexArray(defaultVAO); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (gl.getError() != GL_NO_ERROR) 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::InternalError("Failed to bind default VAO"); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry defaultVAOBound = true; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable(GL_PROGRAM_POINT_SIZE); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getError(); // supress potential errors, feature is not critical 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable(GL_TEXTURE_CUBE_MAP_SEAMLESS); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.getError(); // suppress 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Extensions 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_texture_stencil8"); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_sample_shading"); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_sample_variables"); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_shader_multisample_interpolation"); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_shader_image_atomic"); 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_OES_texture_storage_multisample_2d_array"); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1147af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // Enable only if base ctx supports these or compatible GL_NV_blend_equation_advanced ext 1157af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry if (ctxInfo->isExtensionSupported("GL_NV_blend_equation_advanced") || 1167af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry ctxInfo->isExtensionSupported("GL_KHR_blend_equation_advanced")) 1177af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 1187af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_KHR_blend_equation_advanced"); 1197af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 1207af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry if (ctxInfo->isExtensionSupported("GL_NV_blend_equation_advanced_coherent") || 1217af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry ctxInfo->isExtensionSupported("GL_KHR_blend_equation_advanced_coherent")) 1227af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 1237af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_KHR_blend_equation_advanced_coherent"); 1247af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_shader_io_blocks"); 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_geometry_shader"); 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_geometry_point_size"); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_tessellation_shader"); 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_tessellation_point_size"); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_gpu_shader5"); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_KHR_debug"); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addExtension("GL_EXT_texture_cube_map_array"); 134da5b95934637f27e7fc3894dd69a49cb73b6d16bPyry Haulos addExtension("GL_EXT_shader_implicit_conversions"); 1351f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry addExtension("GL_EXT_primitive_bounding_box"); 1367af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_EXT_texture_sRGB_decode"); 1377af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_EXT_texture_border_clamp"); 1387af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_EXT_texture_buffer"); 1397af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry addExtension("GL_EXT_draw_buffers_indexed"); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContext::~Context (void) 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (defaultVAO) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.deleteVertexArrays(1, &defaultVAO); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Context::addExtension (const char* name) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!extensions.empty()) 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extensions += " "; 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extensions += name; 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extensionList.push_back(name); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic de::ThreadLocal tls_context; 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid setCurrentContext (Context* context) 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tls_context.set(context); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Context* getCurrentContext (void) 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (Context*)tls_context.get(); 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY getIntegerv (deUint32 pname, deInt32* params) 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (pname == GL_NUM_EXTENSIONS && params) 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *params = (deInt32)context->extensionList.size(); 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.getIntegerv(pname, params); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL const glw::GLubyte* GLW_APIENTRY getString (deUint32 name) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (name) 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_VENDOR: return (const glw::GLubyte*)context->vendor.c_str(); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_VERSION: return (const glw::GLubyte*)context->version.c_str(); 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_RENDERER: return (const glw::GLubyte*)context->renderer.c_str(); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_SHADING_LANGUAGE_VERSION: return (const glw::GLubyte*)context->shadingLanguageVersion.c_str(); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case GL_EXTENSIONS: return (const glw::GLubyte*)context->extensions.c_str(); 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: return context->gl.getString(name); 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return DE_NULL; 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL const glw::GLubyte* GLW_APIENTRY getStringi (deUint32 name, deUint32 index) 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (name == GL_EXTENSIONS) 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((size_t)index < context->extensionList.size()) 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (const glw::GLubyte*)context->extensionList[index].c_str(); 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return context->gl.getStringi(name, ~0u); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return context->gl.getStringi(name, index); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return DE_NULL; 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY enable (deUint32 cap) 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX) 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->primitiveRestartEnabled = true; 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-09-30 pyry] Call to glPrimitiveRestartIndex() is required prior to all draw calls! 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.enable(cap); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY disable (deUint32 cap) 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cap == GL_PRIMITIVE_RESTART_FIXED_INDEX) 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->primitiveRestartEnabled = false; 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.disable(cap); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY bindVertexArray (deUint32 array) 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.bindVertexArray(array == 0 ? context->defaultVAO : array); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->defaultVAOBound = (array == 0); 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY hint (deUint32 target, deUint32 mode) 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (target != GL_GENERATE_MIPMAP_HINT) 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.hint(target, mode); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2013-09-30 pyry] Verify mode. 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2747af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyrystatic void translateShaderSource (deUint32 shaderType, std::ostream& dst, const std::string& src, const std::vector<std::string>& filteredExtensions, GLSLVersion version) 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2761f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry bool foundVersion = false; 2771f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry std::istringstream istr (src); 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string line; 2791f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry int srcLineNdx = 1; 2801f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry bool preprocessorSection = true; 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (std::getline(istr, line, '\n')) 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2847af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry if (preprocessorSection && !line.empty() && line[0] != '#') 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2867af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry preprocessorSection = false; 2877af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 2887af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // ARB_separate_shader_objects requires gl_PerVertex to be explicitly declared 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (shaderType == GL_VERTEX_SHADER) 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << "out gl_PerVertex {\n" 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " vec4 gl_Position;\n" 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " float gl_PointSize;\n" 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << " float gl_ClipDistance[];\n" 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "};\n" 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << "#line " << (srcLineNdx + 1) << "\n"; 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2987af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry else if (shaderType == GL_TESS_CONTROL_SHADER) 2997af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 3007af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry dst << "#extension GL_ARB_tessellation_shader : enable\n" 3017af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "in gl_PerVertex {\n" 3027af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3037af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3047af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "} gl_in[gl_MaxPatchVertices];\n" 3057af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "out gl_PerVertex {\n" 3067af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3077af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3087af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "} gl_out[];\n" 3097af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "#line " << (srcLineNdx + 1) << "\n"; 3107af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 3117af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry else if (shaderType == GL_TESS_EVALUATION_SHADER) 3127af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 3137af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry dst << "#extension GL_ARB_tessellation_shader : enable\n" 3147af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "in gl_PerVertex {\n" 3157af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3167af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3177af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "} gl_in[gl_MaxPatchVertices];\n" 3187af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "out gl_PerVertex {\n" 3197af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3207af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3217af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "};\n" 3227af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "#line " << (srcLineNdx + 1) << "\n"; 3237af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 3247af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry else if (shaderType == GL_GEOMETRY_SHADER) 3257af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 3267af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry dst << "in gl_PerVertex {\n" 3277af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3287af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3297af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "} gl_in[];\n" 3307af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "out gl_PerVertex {\n" 3317af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp vec4 gl_Position;\n" 3327af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << " highp float gl_PointSize;\n" 3337af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "};\n" 3347af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "#line " << (srcLineNdx + 1) << "\n"; 3357af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 3367af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 3377af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // GL_EXT_primitive_bounding_box tessellation no-op fallback 3387af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry if (shaderType == GL_TESS_CONTROL_SHADER) 3397af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 3407af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry dst << "#define gl_BoundingBoxEXT _dummy_unused_output_for_primitive_bbox\n" 3417af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "patch out vec4 _dummy_unused_output_for_primitive_bbox[2];\n" 3427af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry << "#line " << (srcLineNdx + 1) << "\n"; 3437af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 3447af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry } 3457af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 3467af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry if (line == "#version 310 es") 3477af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry { 3487af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry foundVersion = true; 3497af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry dst << glu::getGLSLVersionDeclaration(version) << "\n"; 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (line == "#version 300 es") 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry foundVersion = true; 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << "#version 330\n"; 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (line.substr(0, 10) == "precision ") 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t precPos = 10; 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t precEndPos = line.find(' ', precPos); 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t endPos = line.find(';'); 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (precEndPos != std::string::npos && endPos != std::string::npos && endPos > precEndPos+1) 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t typePos = precEndPos+1; 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string precision = line.substr(precPos, precEndPos-precPos); 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string type = line.substr(typePos, endPos-typePos); 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool precOk = precision == "lowp" || precision == "mediump" || precision == "highp"; 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (precOk && 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (type == "image2D" || type == "uimage2D" || type == "iimage2D" || 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == "imageCube" || type == "uimageCube" || type == "iimageCube" || 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == "image3D" || type == "iimage3D" || type == "uimage3D" || 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == "image2DArray" || type == "iimage2DArray" || type == "uimage2DArray" || 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == "imageCubeArray" || type == "iimageCubeArray" || type == "uimageCubeArray")) 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << "// "; // Filter out statement 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << line << "\n"; 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (line.substr(0, 11) == "#extension ") 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t extNamePos = 11; 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t extNameEndPos = line.find_first_of(" :", extNamePos); 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const size_t behaviorPos = line.find_first_not_of(" :", extNameEndPos); 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (extNameEndPos != std::string::npos && behaviorPos != std::string::npos) 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string extName = line.substr(extNamePos, extNameEndPos-extNamePos); 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::string behavior = line.substr(behaviorPos); 3901f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry const bool filteredExtension = de::contains(filteredExtensions.begin(), filteredExtensions.end(), extName); 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool validBehavior = behavior == "require" || behavior == "enable" || behavior == "warn" || behavior == "disable"; 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (filteredExtension && validBehavior) 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << "// "; // Filter out extension 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << line << "\n"; 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (line.substr(0, 21) == "layout(blend_support_") 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << "// " << line << "\n"; 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst << line << "\n"; 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry srcLineNdx += 1; 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(foundVersion); 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(foundVersion); 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4107af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyrystatic std::string translateShaderSources (deUint32 shaderType, deInt32 count, const char* const* strings, const int* length, const std::vector<std::string>& filteredExtensions, GLSLVersion version) 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream srcIn; 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream srcOut; 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < count; ndx++) 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int len = length && length[ndx] >= 0 ? length[ndx] : (int)strlen(strings[ndx]); 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry srcIn << std::string(strings[ndx], strings[ndx] + len); 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4217af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry translateShaderSource(shaderType, srcOut, srcIn.str(), filteredExtensions, version); 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return srcOut.str(); 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY shaderSource (deUint32 shader, deInt32 count, const char* const* strings, const int* length) 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (count > 0 && strings) 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt32 shaderType = GL_NONE; 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.getShaderiv(shader, GL_SHADER_TYPE, &shaderType); 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4377af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry const std::string translatedSrc = translateShaderSources(shaderType, count, strings, length, context->extensionList, context->nativeGLSLVersion); 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* srcPtr = translatedSrc.c_str(); 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.shaderSource(shader, 1, &srcPtr, DE_NULL); 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.shaderSource(shader, count, strings, length); 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY bindFramebuffer (deUint32 target, deUint32 framebuffer) 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.bindFramebuffer(target, framebuffer); 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Emulate ES behavior where sRGB conversion is only controlled by color buffer format. 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER) 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ((framebuffer != 0) ? context->gl.enable : context->gl.disable)(GL_FRAMEBUFFER_SRGB); 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL void GLW_APIENTRY blendBarrierKHR (void) 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2014-03-18 pyry] Use BlendBarrierNV() if supported 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context->gl.finish(); 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic GLW_APICALL deUint32 GLW_APIENTRY createShaderProgramv (deUint32 type, deInt32 count, const char* const* strings) 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Context* context = getCurrentContext(); 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (context) 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (count > 0 && strings) 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4807af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry const std::string translatedSrc = translateShaderSources(type, count, strings, DE_NULL, context->extensionList, context->nativeGLSLVersion); 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* srcPtr = translatedSrc.c_str(); 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return context->gl.createShaderProgramv(type, 1, &srcPtr); 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return context->gl.createShaderProgramv(type, count, strings); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 0; 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4901f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyrystatic GLW_APICALL void GLW_APIENTRY dummyPrimitiveBoundingBox (float minX, float minY, float minZ, float minW, float maxX, float maxY, float maxZ, float maxW) 4911f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry{ 4921f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry // dummy no-op. No-op is a valid implementation. States queries are not emulated. 4931f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(minX); 4941f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(minY); 4951f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(minZ); 4961f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(minW); 4971f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(maxX); 4981f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(maxY); 4991f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(maxZ); 5001f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry DE_UNREF(maxW); 5011f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry} 5021f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void initFunctions (glw::Functions* dst, const glw::Functions& src) 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Functions directly passed to GL context. 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluES3PlusWrapperFuncs.inl" 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Wrapped functions. 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->bindVertexArray = bindVertexArray; 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->disable = disable; 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->enable = enable; 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->getIntegerv = getIntegerv; 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->getString = getString; 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->getStringi = getStringi; 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->hint = hint; 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->shaderSource = shaderSource; 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->createShaderProgramv = createShaderProgramv; 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->bindFramebuffer = bindFramebuffer; 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Extension functions 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry using std::map; 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry class ExtFuncLoader : public glw::FunctionLoader 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry public: 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ExtFuncLoader (const map<string, glw::GenericFuncType>& extFuncs) 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_extFuncs(extFuncs) 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::GenericFuncType get (const char* name) const 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry map<string, glw::GenericFuncType>::const_iterator pos = m_extFuncs.find(name); 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return pos != m_extFuncs.end() ? pos->second : DE_NULL; 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry private: 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const map<string, glw::GenericFuncType>& m_extFuncs; 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry map<string, glw::GenericFuncType> extFuncMap; 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ExtFuncLoader extFuncLoader (extFuncMap); 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // OES_sample_shading 5468852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glMinSampleShadingOES"] = (glw::GenericFuncType)src.minSampleShading; 5478852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry 5488852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry // OES_texture_storage_multisample_2d_array 5498852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glTexStorage3DMultisampleOES"] = (glw::GenericFuncType)src.texStorage3DMultisample; 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // KHR_blend_equation_advanced 5528852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glBlendBarrierKHR"] = (glw::GenericFuncType)blendBarrierKHR; 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // EXT_tessellation_shader 5558852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glPatchParameteriEXT"] = (glw::GenericFuncType)src.patchParameteri; 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // EXT_geometry_shader 5588852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glFramebufferTextureEXT"] = (glw::GenericFuncType)src.framebufferTexture; 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // KHR_debug 5618852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glDebugMessageControlKHR"] = (glw::GenericFuncType)src.debugMessageControl; 5628852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glDebugMessageInsertKHR"] = (glw::GenericFuncType)src.debugMessageInsert; 5638852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glDebugMessageCallbackKHR"] = (glw::GenericFuncType)src.debugMessageCallback; 5648852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glGetDebugMessageLogKHR"] = (glw::GenericFuncType)src.getDebugMessageLog; 5658852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glGetPointervKHR"] = (glw::GenericFuncType)src.getPointerv; 5668852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glPushDebugGroupKHR"] = (glw::GenericFuncType)src.pushDebugGroup; 5678852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glPopDebugGroupKHR"] = (glw::GenericFuncType)src.popDebugGroup; 5688852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glObjectLabelKHR"] = (glw::GenericFuncType)src.objectLabel; 5698852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glGetObjectLabelKHR"] = (glw::GenericFuncType)src.getObjectLabel; 5708852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glObjectPtrLabelKHR"] = (glw::GenericFuncType)src.objectPtrLabel; 5718852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry extFuncMap["glGetObjectPtrLabelKHR"] = (glw::GenericFuncType)src.getObjectPtrLabel; 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5731f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry // GL_EXT_primitive_bounding_box (dummy no-op) 5741f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry extFuncMap["glPrimitiveBoundingBoxEXT"] = (glw::GenericFuncType)dummyPrimitiveBoundingBox; 5751f99d6991ce9a27d32ec0543d95646fe4e7bf001Jarkko Pöyry 5767af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // GL_EXT_texture_border_clamp 5777af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glTexParameterIivEXT"] = (glw::GenericFuncType)src.texParameterIiv; 5787af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glTexParameterIuivEXT"] = (glw::GenericFuncType)src.texParameterIuiv; 5797af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glGetTexParameterIivEXT"] = (glw::GenericFuncType)src.getTexParameterIiv; 5807af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glGetTexParameterIuivEXT"] = (glw::GenericFuncType)src.getTexParameterIuiv; 5817af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glSamplerParameterIivEXT"] = (glw::GenericFuncType)src.samplerParameterIiv; 5827af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glSamplerParameterIuivEXT"] = (glw::GenericFuncType)src.samplerParameterIuiv; 5837af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glGetSamplerParameterIivEXT"] = (glw::GenericFuncType)src.getSamplerParameterIiv; 5847af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glGetSamplerParameterIuivEXT"] = (glw::GenericFuncType)src.getSamplerParameterIuiv; 5857af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 5867af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // GL_EXT_texture_buffer 5877af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glTexBufferEXT"] = (glw::GenericFuncType)src.texBuffer; 5887af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glTexBufferRangeEXT"] = (glw::GenericFuncType)src.texBufferRange; 5897af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 5907af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry // GL_EXT_draw_buffers_indexed 5917af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glEnableiEXT"] = (glw::GenericFuncType)src.enablei; 5927af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glDisableiEXT"] = (glw::GenericFuncType)src.disablei; 5937af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glBlendEquationiEXT"] = (glw::GenericFuncType)src.blendEquationi; 5947af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glBlendEquationSeparateiEXT"] = (glw::GenericFuncType)src.blendEquationSeparatei; 5957af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glBlendFunciEXT"] = (glw::GenericFuncType)src.blendFunci; 5967af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glBlendFuncSeparateiEXT"] = (glw::GenericFuncType)src.blendFuncSeparatei; 5977af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glColorMaskiEXT"] = (glw::GenericFuncType)src.colorMaski; 5987af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry extFuncMap["glIsEnablediEXT"] = (glw::GenericFuncType)src.isEnabledi; 5997af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numExts = 0; 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst->getIntegerv(GL_NUM_EXTENSIONS, &numExts); 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (numExts > 0) 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<const char*> extStr(numExts); 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numExts; ndx++) 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry extStr[ndx] = (const char*)dst->getStringi(GL_EXTENSIONS, ndx); 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glw::initExtensionsES(dst, &extFuncLoader, (int)extStr.size(), &extStr[0]); 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // es3plus 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6193c827367444ee418f129b2c238299f49d3264554Jarkko PoyryES3PlusWrapperContext::ES3PlusWrapperContext (const ContextFactory& factory, const RenderConfig& config, const tcu::CommandLine& cmdLine) 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_context (DE_NULL) 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapperCtx (DE_NULL) 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Flags that are valid for both core & es context. Currently only excludes CONTEXT_FORWARD_COMPATIBLE 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ContextFlags validContextFlags = CONTEXT_ROBUST | CONTEXT_DEBUG; 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const ContextType wrappableNativeTypes[] = 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ContextType(ApiType::core(4,4), config.type.getFlags() & validContextFlags), // !< higher in the list, preferred 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ContextType(ApiType::core(4,3), config.type.getFlags() & validContextFlags), 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (config.type.getAPI() != ApiType::es(3,1)) 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Unsupported context type (ES3.1 wrapper supports only ES3.1)"); 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // try to create any wrappable context 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int nativeCtxNdx = 0; nativeCtxNdx < DE_LENGTH_OF_ARRAY(wrappableNativeTypes); ++nativeCtxNdx) 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ContextType nativeContext = wrappableNativeTypes[nativeCtxNdx]; 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderConfig nativeConfig = config; 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry nativeConfig.type = nativeContext; 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context = factory.createContext(nativeConfig, cmdLine); 6477af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry m_wrapperCtx = new es3plus::Context(*m_context); 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry es3plus::setCurrentContext(m_wrapperCtx); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry es3plus::initFunctions(&m_functions, m_context->getFunctions()); 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry es3plus::setCurrentContext(DE_NULL); 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_wrapperCtx; 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_context; 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_wrapperCtx = DE_NULL; 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_context = DE_NULL; 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // throw only if all tries failed (that is, this was the last potential target) 6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (nativeCtxNdx + 1 == DE_LENGTH_OF_ARRAY(wrappableNativeTypes)) 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6723c827367444ee418f129b2c238299f49d3264554Jarkko PoyryES3PlusWrapperContext::~ES3PlusWrapperContext (void) 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_wrapperCtx; 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_context; 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6783c827367444ee418f129b2c238299f49d3264554Jarkko PoyryContextType ES3PlusWrapperContext::getType (void) const 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ContextType(ApiType::es(3,1), m_context->getType().getFlags()); 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu 684