github.com/Seikaijyu/gio@v0.0.1/gpu/headless/headless_windows.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package headless
     4  
     5  import (
     6  	"unsafe"
     7  
     8  	"github.com/Seikaijyu/gio/gpu"
     9  	"github.com/Seikaijyu/gio/internal/d3d11"
    10  )
    11  
    12  type d3d11Context struct {
    13  	dev *d3d11.Device
    14  }
    15  
    16  func init() {
    17  	newContextPrimary = func() (context, error) {
    18  		dev, ctx, _, err := d3d11.CreateDevice(
    19  			d3d11.DRIVER_TYPE_HARDWARE,
    20  			0,
    21  		)
    22  		if err != nil {
    23  			return nil, err
    24  		}
    25  		// Don't need it.
    26  		d3d11.IUnknownRelease(unsafe.Pointer(ctx), ctx.Vtbl.Release)
    27  		return &d3d11Context{dev: dev}, nil
    28  	}
    29  }
    30  
    31  func (c *d3d11Context) API() gpu.API {
    32  	return gpu.Direct3D11{Device: unsafe.Pointer(c.dev)}
    33  }
    34  
    35  func (c *d3d11Context) MakeCurrent() error {
    36  	return nil
    37  }
    38  
    39  func (c *d3d11Context) ReleaseCurrent() {
    40  }
    41  
    42  func (c *d3d11Context) Release() {
    43  	d3d11.IUnknownRelease(unsafe.Pointer(c.dev), c.dev.Vtbl.Release)
    44  	c.dev = nil
    45  }