github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/app/internal/window/egl_windows.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package window
     4  
     5  import (
     6  	"unsafe"
     7  
     8  	"github.com/gop9/olt/gio/app/internal/egl"
     9  )
    10  
    11  type context struct {
    12  	win *window
    13  	*egl.Context
    14  }
    15  
    16  func (w *window) NewContext() (Context, error) {
    17  	disp := egl.NativeDisplayType(unsafe.Pointer(w.HDC()))
    18  	ctx, err := egl.NewContext(disp)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	return &context{win: w, Context: ctx}, nil
    23  }
    24  
    25  func (c *context) Release() {
    26  	if c.Context != nil {
    27  		c.Context.Release()
    28  		c.Context = nil
    29  	}
    30  }
    31  
    32  func (c *context) MakeCurrent() error {
    33  	c.Context.ReleaseSurface()
    34  	win, width, height := c.win.HWND()
    35  	eglSurf := egl.NativeWindowType(win)
    36  	if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
    37  		return err
    38  	}
    39  	if err := c.Context.MakeCurrent(); err != nil {
    40  		return err
    41  	}
    42  	c.Context.EnableVSync(true)
    43  	return nil
    44  }
    45  
    46  func (c *context) Lock() {}
    47  
    48  func (c *context) Unlock() {}