github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/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/cybriq/giocore/gpu"
     9  	"github.com/cybriq/giocore/internal/d3d11"
    10  )
    11  
    12  type d3d11Context struct {
    13  	dev *d3d11.Device
    14  }
    15  
    16  func newContext() (context, error) {
    17  	dev, ctx, _, err := d3d11.CreateDevice(
    18  		d3d11.DRIVER_TYPE_HARDWARE,
    19  		0,
    20  	)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	// Don't need it.
    25  	d3d11.IUnknownRelease(unsafe.Pointer(ctx), ctx.Vtbl.Release)
    26  	return &d3d11Context{dev: dev}, nil
    27  }
    28  
    29  func (c *d3d11Context) API() gpu.API {
    30  	return gpu.Direct3D11{Device: unsafe.Pointer(c.dev)}
    31  }
    32  
    33  func (c *d3d11Context) MakeCurrent() error {
    34  	return nil
    35  }
    36  
    37  func (c *d3d11Context) ReleaseCurrent() {
    38  }
    39  
    40  func (c *d3d11Context) Release() {
    41  	d3d11.IUnknownRelease(unsafe.Pointer(c.dev), c.dev.Vtbl.Release)
    42  	c.dev = nil
    43  }