PassOwnPtr<GLContextEGL> GLContextEGL::createContext(EGLNativeWindowType window, GLContext* sharingContext) { if (!sharedEGLDisplay()) return nullptr; static bool initialized = false; static bool success = true; if (!initialized) { #if !USE(OPENGL_ES_2) success = initializeOpenGLShims(); #endif initialized = true; } if (!success) return nullptr; EGLContext eglSharingContext = sharingContext ? static_cast<GLContextEGL*>(sharingContext)->m_context : 0; OwnPtr<GLContextEGL> context = window ? createWindowContext(window, sharingContext) : nullptr; if (!context) context = createPixmapContext(eglSharingContext); if (!context) context = createPbufferContext(eglSharingContext); return context.release(); }
PassOwnPtr<GLPlatformContext> GLPlatformContext::createContext(GraphicsContext3D::RenderStyle renderStyle) { #if !USE(OPENGL_ES_2) if (!initializeOpenGLShims()) return nullptr; #endif switch (renderStyle) { case GraphicsContext3D::RenderOffscreen: if (OwnPtr<GLPlatformContext> context = createOffScreenContext()) return context.release(); break; case GraphicsContext3D::RenderToCurrentGLContext: if (OwnPtr<GLPlatformContext> context = adoptPtr(new GLCurrentContextWrapper())) return context.release(); break; case GraphicsContext3D::RenderDirectlyToHostWindow: ASSERT_NOT_REACHED(); break; } return nullptr; }
static bool initializeOpenGLShimsIfNeeded() { #if USE(OPENGL_ES_2) return true; #else static bool initialized = false; static bool success = true; if (!initialized) { success = initializeOpenGLShims(); initialized = true; } return success; #endif }
PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attributes, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) { // This implementation doesn't currently support rendering directly to the HostWindow. if (renderStyle == RenderDirectlyToHostWindow) return 0; static bool initialized = false; static bool success = true; if (!initialized) { success = initializeOpenGLShims(); initialized = true; } if (!success) return 0; RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(attributes, hostWindow, false)); return context.release(); }
RefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attributes, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) { // This implementation doesn't currently support rendering directly to the HostWindow. if (renderStyle == RenderDirectlyToHostWindow) return 0; static bool initialized = false; static bool success = true; if (!initialized) { #if !USE(OPENGL_ES_2) success = initializeOpenGLShims(); #endif initialized = true; } if (!success) return 0; return adoptRef(new GraphicsContext3D(attributes, hostWindow, renderStyle)); }
PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create() { if (!sharedDisplay()) return nullptr; static bool initialized = false; static bool success = true; if (!initialized) { success = initializeOpenGLShims(); initialized = true; } if (!success) return nullptr; GraphicsContext3DPrivate* internal = createPbufferContext(); if (!internal) internal = createPixmapContext(); if (!internal) return nullptr; // The GraphicsContext3D constructor requires that this context is the current OpenGL context. internal->makeContextCurrent(); return adoptPtr(internal); }
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 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 }