<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.5.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAOpenGLLayer/copyCGLContext(forPixelFormat:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CAOpenGLLayer(im)copyCGLContextForPixelFormat:"
  },
  "title" : "copyCGLContext(forPixelFormat:)"
}
-->

# copyCGLContext(forPixelFormat:)

Returns the rendering context the receiver requires for the specified pixel format.

```
func copyCGLContext(forPixelFormat pf: CGLPixelFormatObj) -> CGLContextObj
```

## Parameters

`pf`

The pixel format for the rendering context.

## Return Value

A new `CGLContext` with renderers for `pixelFormat`.

## Discussion

This method is called when a rendering context is needed by the receiver. The default implementation allocates a new context with a null share context.

You should not call this method directly, it is intended to be overridden by subclasses.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)