github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/app/headless/headless_darwin.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package headless
     4  
     5  import "github.com/gop9/olt/gio/app/internal/gl"
     6  
     7  /*
     8  #cgo CFLAGS: -DGL_SILENCE_DEPRECATION -Werror -Wno-deprecated-declarations -fmodules -fobjc-arc -x objective-c
     9  
    10  #include <CoreFoundation/CoreFoundation.h>
    11  #include "headless_darwin.h"
    12  */
    13  import "C"
    14  
    15  type nsContext struct {
    16  	c        *gl.Functions
    17  	ctx      C.CFTypeRef
    18  	prepared bool
    19  }
    20  
    21  func newContext() (context, error) {
    22  	ctx := C.gio_headless_newContext()
    23  	return &nsContext{ctx: ctx, c: new(gl.Functions)}, nil
    24  }
    25  
    26  func (c *nsContext) MakeCurrent() error {
    27  	C.gio_headless_makeCurrentContext(c.ctx)
    28  	if !c.prepared {
    29  		C.gio_headless_prepareContext(c.ctx)
    30  		c.prepared = true
    31  	}
    32  	return nil
    33  }
    34  
    35  func (c *nsContext) ReleaseCurrent() {
    36  	C.gio_headless_clearCurrentContext(c.ctx)
    37  }
    38  
    39  func (c *nsContext) Functions() *gl.Functions {
    40  	return c.c
    41  }
    42  
    43  func (d *nsContext) Release() {
    44  	if d.ctx != 0 {
    45  		C.gio_headless_releaseContext(d.ctx)
    46  		d.ctx = 0
    47  	}
    48  }