GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, bool) : m_currentWidth(0) , m_currentHeight(0) , m_attrs(attrs) , m_texture(0) , m_compositorTexture(0) , m_fbo(0) #if defined(QT_OPENGL_ES_2) , m_depthBuffer(0) , m_stencilBuffer(0) #else , m_depthStencilBuffer(0) #endif , m_layerComposited(false) , m_internalColorFormat(0) , m_boundFBO(0) , m_activeTexture(GL_TEXTURE0) , m_boundTexture0(0) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(adoptPtr(new GraphicsContext3DPrivate(this, hostWindow))) { #if !defined(QT_OPENGL_ES_2) validateAttributes(); #endif if (!m_private->m_surface) { LOG_ERROR("GraphicsContext3D: QGLWidget initialization failed."); m_private = nullptr; return; } static bool initialized = false; static bool success = true; if (!initialized) { success = initializeOpenGLShims(); initialized = true; } if (!success) { m_private = nullptr; return; } // Create buffers for the canvas FBO. glGenFramebuffers(/* count */ 1, &m_fbo); glGenTextures(1, &m_texture); glBindTexture(GraphicsContext3D::TEXTURE_2D, m_texture); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); glBindTexture(GraphicsContext3D::TEXTURE_2D, 0); // Create a multisample FBO. if (m_attrs.antialias) { glGenFramebuffers(1, &m_multisampleFBO); glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); m_boundFBO = m_multisampleFBO; glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } else { // Bind canvas FBO. glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); m_boundFBO = m_fbo; #if defined(QT_OPENGL_ES_2) if (m_attrs.depth) glGenRenderbuffers(1, &m_depthBuffer); if (m_attrs.stencil) glGenRenderbuffers(1, &m_stencilBuffer); #else if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_depthStencilBuffer); #endif } #if !defined(QT_OPENGL_ES_2) // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; m_compiler.setResources(ANGLEResources); glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif glClearColor(0.0, 0.0, 0.0, 0.0); }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_attrs(attributes) , m_texture(0) , m_fbo(0) , m_depthStencilBuffer(0) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(GraphicsContext3DPrivate::create(this, renderStyle)) { makeContextCurrent(); validateAttributes(); if (renderStyle == RenderOffscreen) { // Create a texture to render into. ::glGenTextures(1, &m_texture); ::glBindTexture(GL_TEXTURE_2D, m_texture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); // Create an FBO. ::glGenFramebuffers(1, &m_fbo); ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); m_state.boundFBO = m_fbo; if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) ::glGenRenderbuffers(1, &m_depthStencilBuffer); // Create a multisample FBO. if (m_attrs.antialias) { ::glGenFramebuffers(1, &m_multisampleFBO); ::glBindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); m_state.boundFBO = m_multisampleFBO; ::glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) ::glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } } // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; GC3Dint range[2], precision; getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); m_compiler.setResources(ANGLEResources); #if !USE(OPENGL_ES_2) ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); ::glEnable(GL_POINT_SPRITE); #endif ::glClearColor(0, 0, 0, 0); }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_context(BlackBerry::Platform::Graphics::createWebGLContext()) , m_compiler(SH_ESSL_OUTPUT) , m_attrs(attrs) , m_texture(0) , m_fbo(0) , m_depthStencilBuffer(0) , m_layerComposited(false) , m_internalColorFormat(GL_RGBA) , m_isImaginationHardware(0) { if (renderStyle != RenderDirectlyToHostWindow) { #if USE(ACCELERATED_COMPOSITING) m_compositingLayer = WebGLLayerWebKitThread::create(); #endif makeContextCurrent(); // Create a texture to render into. ::glGenTextures(1, &m_texture); ::glBindTexture(GL_TEXTURE_2D, m_texture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); // Create an FBO. ::glGenFramebuffers(1, &m_fbo); ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); if (m_attrs.stencil || m_attrs.depth) ::glGenRenderbuffers(1, &m_depthStencilBuffer); m_state.boundFBO = m_fbo; #if USE(ACCELERATED_COMPOSITING) static_cast<WebGLLayerWebKitThread*>(m_compositingLayer.get())->setWebGLContext(this); #endif } makeContextCurrent(); const char* renderer = reinterpret_cast<const char*>(::glGetString(GL_RENDERER)); m_isImaginationHardware = std::strstr(renderer, "PowerVR SGX"); // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); GC3Dint range[2], precision; getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); m_compiler.setResources(ANGLEResources); ::glClearColor(0, 0, 0, 0); }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attributes, HostWindow*, bool) : m_currentWidth(0) , m_currentHeight(0) , m_attrs(attributes) , m_texture(0) , m_fbo(0) , m_depthStencilBuffer(0) , m_boundFBO(0) , m_activeTexture(GL_TEXTURE0) , m_boundTexture0(0) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(GraphicsContext3DPrivate::create(this)) { makeContextCurrent(); validateAttributes(); // Create a texture to render into. ::glGenTextures(1, &m_texture); ::glBindTexture(GL_TEXTURE_2D, m_texture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); ::glBindTexture(GL_TEXTURE_2D, 0); // Create an FBO. ::glGenFramebuffersEXT(1, &m_fbo); ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo); m_boundFBO = m_fbo; if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) ::glGenRenderbuffersEXT(1, &m_depthStencilBuffer); // Create a multisample FBO. if (m_attrs.antialias) { ::glGenFramebuffersEXT(1, &m_multisampleFBO); ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO); m_boundFBO = m_multisampleFBO; ::glGenRenderbuffersEXT(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) ::glGenRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer); } // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; m_compiler.setResources(ANGLEResources); ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); ::glEnable(GL_POINT_SPRITE); ::glClearColor(0, 0, 0, 0); }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_compiler(isGLES2Compliant() ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT) , m_attrs(attrs) , m_renderStyle(renderStyle) , m_texture(0) , m_compositorTexture(0) , m_fbo(0) #if USE(OPENGL_ES_2) , m_depthBuffer(0) , m_stencilBuffer(0) #endif , m_depthStencilBuffer(0) , m_layerComposited(false) , m_internalColorFormat(0) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(GraphicsContext3DPrivate::create(this, hostWindow)) { if (!m_private) return; validateAttributes(); if (renderStyle == RenderOffscreen) { // Create buffers for the canvas FBO. glGenFramebuffers(1, &m_fbo); // Create a texture to render into. glGenTextures(1, &m_texture); glBindTexture(GraphicsContext3D::TEXTURE_2D, m_texture); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); glBindTexture(GraphicsContext3D::TEXTURE_2D, 0); // Create a multisample FBO. if (m_attrs.antialias) { glGenFramebuffers(1, &m_multisampleFBO); glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); m_state.boundFBO = m_multisampleFBO; glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } else { // Bind canvas FBO. glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); m_state.boundFBO = m_fbo; #if USE(OPENGL_ES_2) if (m_attrs.depth) glGenRenderbuffers(1, &m_depthBuffer); if (m_attrs.stencil) glGenRenderbuffers(1, &m_stencilBuffer); #endif if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_depthStencilBuffer); } } // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; GC3Dint range[2], precision; getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); m_compiler.setResources(ANGLEResources); #if !USE(OPENGL_ES_2) glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif if (renderStyle != RenderToCurrentGLContext) glClearColor(0.0, 0.0, 0.0, 0.0); }
inline std::array<GLint, N> getIntegers(GLenum const pname) { std::array<GLint, N> params; getIntegerv(pname, params.data()); return params; }
//! Convenience. inline GLint getInteger(GLenum const pname) { GLint param = 0; getIntegerv(pname, ¶m); return param; }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_compiler(isGLES2Compliant() ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT) , m_attrs(attrs) , m_renderStyle(renderStyle) , m_texture(0) , m_compositorTexture(0) , m_fbo(0) #if USE(OPENGL_ES_2) , m_depthBuffer(0) , m_stencilBuffer(0) #endif , m_depthStencilBuffer(0) , m_layerComposited(false) , m_internalColorFormat(0) , m_boundFBO(0) , m_activeTexture(GL_TEXTURE0) , m_boundTexture0(0) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(adoptPtr(new GraphicsContext3DPrivate(this, hostWindow, renderStyle))) { validateAttributes(); if (!m_private) return; static bool initializedShims = false; static bool success = true; if (!initializedShims) { success = initializeOpenGLShims(); initializedShims = true; } if (!success) { m_private = nullptr; return; } if (renderStyle == RenderToCurrentGLContext) { // Evas doesn't allow including gl headers and Evas_GL headers at the same time, // so we need to query the current gl context/surface here instead of in GraphicsContext3DPrivate. void* currentContext = (void*)glXGetCurrentContext(); void* currentSurface = (void*)glXGetCurrentDrawable(); m_private->setCurrentGLContext(currentContext, currentSurface); } if (renderStyle == RenderOffscreen) { // Create buffers for the canvas FBO. glGenFramebuffers(/* count */ 1, &m_fbo); // Create a texture to render into. glGenTextures(1, &m_texture); glBindTexture(GraphicsContext3D::TEXTURE_2D, m_texture); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR); glTexParameterf(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE); glTexParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); glBindTexture(GraphicsContext3D::TEXTURE_2D, 0); // Create a multisample FBO. if (m_attrs.antialias) { glGenFramebuffers(1, &m_multisampleFBO); glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); m_boundFBO = m_multisampleFBO; glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } else { // Bind canvas FBO. glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); m_boundFBO = m_fbo; #if USE(OPENGL_ES_2) if (m_attrs.depth) glGenRenderbuffers(1, &m_depthBuffer); if (m_context->m_attrs.stencil) glGenRenderbuffers(1, &m_stencilBuffer); #endif if (m_attrs.stencil || m_attrs.depth) glGenRenderbuffers(1, &m_depthStencilBuffer); } } // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; m_compiler.setResources(ANGLEResources); #if !USE(OPENGL_ES_2) glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_attrs(attributes) , m_texture(0) , m_compositorTexture(0) , m_fbo(0) #if USE(COORDINATED_GRAPHICS_THREADED) , m_intermediateTexture(0) #endif , m_depthStencilBuffer(0) , m_layerComposited(false) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(std::make_unique<GraphicsContext3DPrivate>(this, renderStyle)) { makeContextCurrent(); validateAttributes(); if (renderStyle == RenderOffscreen) { // Create a texture to render into. ::glGenTextures(1, &m_texture); ::glBindTexture(GL_TEXTURE_2D, m_texture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); // Create an FBO. ::glGenFramebuffers(1, &m_fbo); ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); #if USE(COORDINATED_GRAPHICS_THREADED) ::glGenTextures(1, &m_compositorTexture); ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glGenTextures(1, &m_intermediateTexture); ::glBindTexture(GL_TEXTURE_2D, m_intermediateTexture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); #endif m_state.boundFBO = m_fbo; if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) ::glGenRenderbuffers(1, &m_depthStencilBuffer); // Create a multisample FBO. if (m_attrs.antialias) { ::glGenFramebuffers(1, &m_multisampleFBO); ::glBindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); m_state.boundFBO = m_multisampleFBO; ::glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) ::glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } } #if !USE(OPENGL_ES_2) ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); if (GLContext::current()->version() >= 320) { // From version 3.2 on we use the OpenGL Core profile, so request that ouput to the shader compiler. // OpenGL version 3.2 uses GLSL version 1.50. m_compiler = ANGLEWebKitBridge(SH_GLSL_150_CORE_OUTPUT); // From version 3.2 on we use the OpenGL Core profile, and we need a VAO for rendering. // A VAO could be created and bound by each component using GL rendering (TextureMapper, WebGL, etc). This is // a simpler solution: the first GraphicsContext3D created on a GLContext will create and bind a VAO for that context. GC3Dint currentVAO = 0; getIntegerv(GraphicsContext3D::VERTEX_ARRAY_BINDING, ¤tVAO); if (!currentVAO) { m_vao = createVertexArray(); bindVertexArray(m_vao); } } else { // For lower versions request the compatibility output to the shader compiler. m_compiler = ANGLEWebKitBridge(SH_GLSL_COMPATIBILITY_OUTPUT); // GL_POINT_SPRITE is needed in lower versions. ::glEnable(GL_POINT_SPRITE); } #else m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT); #endif // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; GC3Dint range[2], precision; getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); m_compiler.setResources(ANGLEResources); ::glClearColor(0, 0, 0, 0); }