-
|
Here is a gogpu window that draws a triangle: Here is a gg.Context that draws a circle: How do you combine these to draw a circle in a gogpu.App ? The DrawTriangle is commented as being put there for demo... well, what is the proper way of using gg.Context functionality to render in a gogpu.App ? |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 14 replies
-
|
Hi @amortaza, Great question!
Both share the same gogpu/wgpu (Pure Go WebGPU) foundation. Current Architecture: Current State: gg renders to a Workaround — Texture Upload: // 1. Draw with gg
dc := gg.NewContext(800, 600)
dc.SetRGB(1, 0, 0)
dc.DrawCircle(170, 170, 150)
dc.Fill()
img := dc.Image() // *image.RGBA
// 2. Upload to gogpu texture (manual for now)
app.OnDraw(func(gc *gogpu.Context) {
// Create texture from img, draw as quad
})Future Integration (Planned): A Would you like to open a feature request for this integration? It would help us prioritize. |
Beta Was this translation helpful? Give feedback.
-
✅ Integration Available in gg v0.21.0!Great news! The gg ↔ gogpu integration is now available in gg v0.21.0. New: render/ packageimport (
"github.com/gogpu/gg/render"
"github.com/gogpu/gogpu"
)
func main() {
app := gogpu.NewApp(gogpu.DefaultConfig().
WithTitle("GoGPU + gg Integration").
WithSize(800, 600))
var renderer render.Renderer
var scene *render.Scene
app.OnInit(func(gc *gogpu.Context) {
// gg receives device from gogpu (DeviceProvider pattern)
renderer = render.NewGPURenderer(gc.DeviceHandle())
scene = render.NewScene()
})
app.OnDraw(func(gc *gogpu.Context) {
scene.Reset()
// Draw with gg's Scene API
scene.SetFillColor(color.RGBA{255, 0, 0, 255})
scene.Circle(170, 170, 150)
scene.Fill()
// Render to gogpu surface
renderer.Render(gc.SurfaceTarget(), scene)
})
app.Run()
}Key Components
Shared InfrastructureBoth gogpu and gg now use gpucontext for shared interfaces:
DocumentationLet us know if you have questions about the new integration! |
Beta Was this translation helpful? Give feedback.
-
|
The sample code does not compile. In particular app.OnInit() is not defined - searching for OnInit at the organization level in github gives 1 result - the code in this discussion :) Also gc.DeviceHandle() is not defined... gc.SurfaceTarget() is not defined. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @amortaza, Thanks for catching this! The method names were changed before release, but we forgot to update the documentation. Correct API: // ✅ These methods exist:
provider := app.GPUContextProvider() // gpucontext.DeviceProvider
events := app.EventSource() // gpucontext.EventSource
// ❌ These do NOT exist:
// app.OnInit()
// gc.DeviceHandle()
// gc.SurfaceTarget()Working pattern: var initialized bool
app.OnDraw(func(dc *gogpu.Context) {
if !initialized {
provider := app.GPUContextProvider()
if provider != nil {
// Use provider.Device(), provider.Queue(), etc.
initialized = true
}
}
dc.DrawTriangleColor(gmath.CornflowerBlue)
})See: We'll fix the docs. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Touch Input SupportTouch input is planned but not yet implemented. Current Status
The What's Needed
This is on our roadmap. If you need this feature urgently, please open a feature request issue so we can prioritize accordingly. |
Beta Was this translation helpful? Give feedback.
-
|
You linked the file examples/gpucontext_integration/main.go in that file it gives the sample code: However, gg.NewGPUCanvas() does not exist. I see that the provider comes from app.GPUContextProvider() and the provider is used with gg.NewGPUCanvas() to get canvas which then is used to get canvas.Context(). But gg does not have a function called "NewGPUCanvas()" |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your efforts. There are still issues. This is regarding the gg_integration/main.go When I use the minimum versions as recommended in the comments in the code: It does not compile. I used the minimum versions because initially i used the latest versions and there were issues. The issues are:
Changing the clear background color seems to have no effect. On what platform are you running the application? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @amortaza, Thanks for the detailed report and your patience! Version RequirementsThe The earlier versions you tried (v0.13.3/v0.21.4 and v0.23.0/v0.15.3) predate the current integration architecture. The working example lives in: What Was Fixedv0.24.1 + v0.15.5 (released today) fix an alpha compositing bug that caused:
Root cause: mixed premultiplied/straight alpha conventions between gg's software renderer and gogpu's GPU pipeline. Both now use premultiplied alpha (industry standard). About Your Specific Issues
PlatformWe develop and test on Windows (Win32 backend). Linux (X11/Wayland) and macOS (Cocoa) are supported but less tested. Quick Startgit clone https://github.com/gogpu/gg.git
cd gg/examples/gogpu_integration
go run .Let us know if you still have issues with the latest versions! |
Beta Was this translation helpful? Give feedback.
-
|
I am using: There is a fault exception right where this call is made: |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the detailed crash report, @amortaza! Root CauseThe crash is in our premultiplied alpha pipeline - a new feature added in v0.15.4 (PR #77). The access violation ( The crash path: FixWe are eliminating the second pipeline entirely - instead of two separate GPU pipelines (one for premultiplied, one for standard alpha), we will use a single pipeline with a uniform-based switch. This avoids the pipeline creation that triggers the crash and is cleaner architecturally. The fix will be in the next gogpu release. We will post here when it's available. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @amortaza, The crash fix is available! Updated versions: What Was FixedNVIDIA crash ( The fix: eliminated the second pipeline entirely. Both alpha modes now go through a single pipeline with a uniform-based shader switch. The fix required changes across the entire stack: naga v0.11.0 (SPIR-V codegen fix) → wgpu v0.13.2 → gogpu v0.15.7 → gg v0.26.1. Earlier Issues — All FixedRegarding the problems you reported on Feb 5 (
How to Updatego get github.com/gogpu/gg@v0.26.1 github.com/gogpu/gogpu@v0.15.7
go mod tidyOr run the reference example: git clone https://github.com/gogpu/gg.git
cd gg/examples/gogpu_integration
go run .About BellinaChecked out go-bellina — the node-based If you wanted to use GoGPU as Bellina's HAL backend instead of Available today:
Not yet available (on our roadmap):
Zero CGO throughout — no MSYS2, no C compiler, One thing worth discussing: common UI primitives (geometry types, layout engines, event handling) that any Go UI framework needs. Rather than each project reinventing these, we could potentially unify shared building blocks in the ecosystem. If that's interesting, let's discuss it separately. Please let us know if v0.15.7 works on your RTX 2080! |
Beta Was this translation helpful? Give feedback.
-
|
Using the Rust backend there were NO crashes. The circles animated just fine. However, I expected this change on line 108 to make the background flash different colors, but its a solid dark color (not black). Doing something similar coloring for the center circle DOES make it flash different colors as expected. |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
Hi @amortaza, A quick update — we've shipped a significant amount of changes across the entire stack since your last test:
The To test:go get github.com/gogpu/gg@v0.28.1 github.com/gogpu/gogpu@v0.18.1
go mod tidy
go run .The reference example now also supports event-driven rendering — press Space to pause animation (GPU drops to 0%), press again to resume. Would be great to know if the Pure Go backend works on your RTX 2080 now! |
Beta Was this translation helpful? Give feedback.
gogpu/gg#79