internal/driver: Add Graphics.Initialize

This commit is contained in:
Hajime Hoshi 2021-07-07 13:58:42 +09:00
parent 519363930a
commit 6213c17abc
5 changed files with 19 additions and 8 deletions

View File

@ -41,6 +41,7 @@ type Graphics interface {
SetVertices(vertices []float32, indices []uint16)
NewImage(width, height int) (Image, error)
NewScreenFramebufferImage(width, height int) (Image, error)
Initialize() error
Reset() error
SetVsyncEnabled(enabled bool)
FramebufferYDirection() YDirection

View File

@ -654,7 +654,14 @@ func (c *newShaderCommand) Exec(indexOffset int) error {
return err
}
// ResetGraphicsDriverState resets or initializes the current graphics driver state.
// InitializeGraphicsDriverState initialize the current graphics driver state.
func InitializeGraphicsDriverState() error {
return runOnMainThread(func() error {
return theGraphicsDriver.Initialize()
})
}
// ResetGraphicsDriverState resets the current graphics driver state.
func ResetGraphicsDriverState() error {
return runOnMainThread(func() error {
return theGraphicsDriver.Reset()

View File

@ -565,12 +565,7 @@ func operationToBlendFactor(c driver.Operation) mtl.BlendFactor {
}
}
func (g *Graphics) Reset() error {
if g.cq != (mtl.CommandQueue{}) {
g.cq.Release()
g.cq = mtl.CommandQueue{}
}
func (g *Graphics) Initialize() error {
// Creating *State objects are expensive and reuse them whenever possible.
// See https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Cmd-Submiss/Cmd-Submiss.html
@ -753,6 +748,10 @@ func (g *Graphics) Reset() error {
return nil
}
func (g *Graphics) Reset() error {
panic("metal: Reset is not implemented")
}
func (g *Graphics) flushRenderCommandEncoderIfNeeded() {
if g.rce == (mtl.RenderCommandEncoder{}) {
return

View File

@ -129,6 +129,10 @@ func (g *Graphics) removeImage(img *Image) {
delete(g.images, img.id)
}
func (g *Graphics) Initialize() error {
return g.state.reset(&g.context)
}
// Reset resets or initializes the current OpenGL state.
func (g *Graphics) Reset() error {
return g.state.reset(&g.context)

View File

@ -272,7 +272,7 @@ func (i *images) restore() error {
// InitializeGraphicsDriverState initializes the graphics driver state.
func InitializeGraphicsDriverState() error {
return graphicscommand.ResetGraphicsDriverState()
return graphicscommand.InitializeGraphicsDriverState()
}
// MaxImageSize returns the maximum size of an image.