Pono
Pono

Reputation: 11776

Using EAGLContext with CIContext on MacOS

I have a simple Swift command-line MacOS application and I'm struggling to set EAGLContext:

let openGLContext = EAGLContext(API: .OpenGLES3)
let context = CIContext(EAGLContext: openGLContext)

The above code gives me:

Use of unresolved identifier 'EAGLContext'

no matter what modules I load:

import CoreImage
import OpenGL
import QuartzCore
import GLKit

Now the question is: does CIContext use OpenGL rendering by default?

When I initialize a new CIContext without any options:

let context = CIContext()

and set env variable CI_PRINT_TREE to 1 the console output gives me:

initial graph image_get_cgimage (opengl context 1 frame 1)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^

so it does process my filter in the GPU context, right?. Is there a way to explicitly set GPU rendering or is GPU a default context?

Upvotes: 2

Views: 1389

Answers (2)

Pono
Pono

Reputation: 11776

Just found the answer in the Apple docs available here:

Rendering with an Automatic Context

If you don’t have constraints on how your app interoperates with other graphics technologies, creating a Core Image context is simple: just use the basic init or initWithOptions: initializer. When you do so, Core Image automatically manages resources internally, choosing the appropriate or best available CPU or GPU rendering technology based on the current device and any options you specify.

Upvotes: 1

Coldsteel48
Coldsteel48

Reputation: 3512

According to Docs

There is a way to initialize CIContext on CPU or GPU explicitly

Also you can specify Metal or OpenGL

Creating a Context for CPU-Based Rendering

init(cgContext: CGContext, options: [String : Any]? = nil)

Creates a Core Image context from a Quartz context, using the specified options.

Creating a Context for GPU-Based Rendering with OpenGL:

init(cglContext: CGLContextObj, pixelFormat: CGLPixelFormatObj?, colorSpace: CGColorSpace?, options: [String : Any]? = nil)

Creates a Core Image context from a CGL context, using the specified options, color space, and pixel format object.

init(eaglContext: EAGLContext)

Creates a Core Image context from an EAGL context.

init(eaglContext: EAGLContext, options: [String : Any]? = nil)

Creates a Core Image context from an EAGL context using the specified options.

init?(forOfflineGPUAt: UInt32)

Creates an OpenGL-based Core Image context using a GPU that is not currently driving a display.

init?(forOfflineGPUAt: UInt32, colorSpace: CGColorSpace?, options: [String : Any]? = nil, sharedContext: CGLContextObj?)

Creates an OpenGL-based Core Image context using a GPU that is not currently driving a display, with the specified options.

Creating a Context for GPU-Based Rendering with Metal

init(mtlDevice: MTLDevice)

Creates a Core Image context using the specified Metal device.

init(mtlDevice: MTLDevice, options: [String : Any]? = nil)

Creates a Core Image context using the specified Metal device and options.

Upvotes: 1

Related Questions