Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/boids/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"runtime"
"strconv"
"strings"
"time"

"github.com/go-gl/glfw/v3.4/glfw"
"github.com/oliverbestmann/webgpu/wgpu"
Expand Down Expand Up @@ -310,8 +309,7 @@ func (s *State) Render() error {

nextTexture, ok := surfaceTexture.Get()
if !ok {
// maybe occluded, retry layter
time.Sleep(16 * time.Millisecond)
// todo: in this case you actually want to re-configure the surface!
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions examples/cube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"runtime"
"strings"
"time"
"unsafe"

"github.com/go-gl/glfw/v3.4/glfw"
Expand Down Expand Up @@ -349,8 +348,7 @@ func (s *State) Render() error {

nextTexture, ok := surfaceTexture.Get()
if !ok {
// maybe occluded, retry layter
time.Sleep(16 * time.Millisecond)
// todo: in this case you actually want to re-configure the surface!
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions examples/triangle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"os"
"runtime"
"time"

"github.com/oliverbestmann/webgpu/wgpu"

Expand Down Expand Up @@ -148,8 +147,7 @@ func (s *State) Render() error {

nextTexture, ok := surfaceTexture.Get()
if !ok {
// maybe occluded, retry layter
time.Sleep(16 * time.Millisecond)
// todo: in this case you actually want to re-configure the surface!
return nil
}

Expand Down
44 changes: 27 additions & 17 deletions wgpu/surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import "C"
import (
"errors"
"runtime"
"time"
"unsafe"

"github.com/go-gl/glfw/v3.4/glfw"
)

func (g *Surface) GetCapabilities(adapter *Adapter) (ret SurfaceCapabilities) {
Expand Down Expand Up @@ -133,28 +136,35 @@ func (g *Surface) TryGetCurrentTexture() (SurfaceTexture, error) {
errh := acquireErrorCallback()
defer errh.Done()

surfaceTexture := C.gowebgpu_surface_get_current_texture(
g.ref,
g.device,
errh.ToPointer(),
)
if errh.err != nil {
if surfaceTexture.texture != nil {
C.wgpuTextureRelease(surfaceTexture.texture)
for {
surfaceTexture := C.gowebgpu_surface_get_current_texture(
g.ref,
g.device,
errh.ToPointer(),
)
if errh.err != nil {
if surfaceTexture.texture != nil {
C.wgpuTextureRelease(surfaceTexture.texture)
}

return SurfaceTexture{}, errh.err
}

return SurfaceTexture{}, errh.err
}
status := SurfaceGetCurrentTextureStatus(surfaceTexture.status)
if status == SurfaceGetCurrentTextureStatusOccluded {
time.Sleep(16 * time.Millisecond)
glfw.PollEvents()
continue
}

status := SurfaceGetCurrentTextureStatus(surfaceTexture.status)
var texture *Texture
if surfaceTexture.texture != nil {
C.wgpuDeviceAddRef(g.device)
texture = &Texture{device: g.device, ref: surfaceTexture.texture}
}

var texture *Texture
if surfaceTexture.texture != nil {
C.wgpuDeviceAddRef(g.device)
texture = &Texture{device: g.device, ref: surfaceTexture.texture}
return SurfaceTexture{Texture: texture, Status: status}, nil
}

return SurfaceTexture{Texture: texture, Status: status}, nil
}

func (g *Surface) Present() {
Expand Down
Loading