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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.31.1] - 2026-08-30

### Changed

- **`TextureRegionUpdater.UpdateRegion` — struct API** (#484) — replaced six positional int parameters with `image.Rectangle` + `ImageDataLayout` (WebGPU / Go stdlib idiom). Fixes silent parameter-swap bugs. Zero-value layout = offset 0, tight packed rows, region height.

## [0.31.0] - 2026-08-30

### Changed
Expand Down
33 changes: 21 additions & 12 deletions texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package gpucontext

import "image"

// Texture is the minimal interface for GPU textures.
// This interface enables type-safe cross-package texture handling
// without circular dependencies.
Expand Down Expand Up @@ -35,28 +37,35 @@ type TextureUpdater interface {
UpdateData(data []byte) error
}

// ImageDataLayout describes the memory layout of pixel data for region uploads.
// Mirrors W3C GPUTexelCopyBufferLayout at the application level.
type ImageDataLayout struct {
// BytesPerRow is the stride in bytes between consecutive rows in data.
// Zero means tightly packed rows (region width * bytesPerPixel).
BytesPerRow int
// RowsPerImage is the height of the source image in rows. Zero defaults to
// the region height (2D textures).
RowsPerImage int
// Offset is the byte offset into data where pixel data begins.
Offset int
}

// TextureRegionUpdater uploads a sub-rectangle of pixel data to the texture.
// Use for incremental rendering where only a small portion of the texture
// changes per frame (e.g., dirty region upload).
//
// Implementations:
// - gogpu.Texture implements TextureRegionUpdater
type TextureRegionUpdater interface {
// UpdateRegion uploads a sub-rectangle of pixel data to the texture.
// x, y is the top-left corner of the region in the texture.
// w, h is the size of the region.
// bytesPerRow is the stride in bytes between consecutive rows in data.
// Pass 0 for tightly packed rows (w * bytesPerPixel) — WebGPU
// ImageDataLayout.bytesPerRow semantics. This eliminates the need for
// callers to extractRegion-copy dirty bands from a full-frame buffer.
// UpdateRegion uploads pixel data to region using stdlib image.Rectangle
// coordinates (Min = top-left, Max = exclusive bottom-right).
//
// When bytesPerRow is 0, data must be exactly w * h * bytesPerPixel bytes.
// When bytesPerRow > 0, data must be at least
// bytesPerRow*(h-1) + w*bytesPerPixel bytes (last row need not be padded).
// layout describes source buffer stride and offset. Zero value means
// offset 0, tightly packed rows, single image (region height).
//
// Returns error if the region exceeds texture bounds, data size is invalid,
// bytesPerRow is too small, or the texture has been destroyed.
UpdateRegion(x, y, w, h, bytesPerRow int, data []byte) error
// layout stride is too small, or the texture has been destroyed.
UpdateRegion(region image.Rectangle, data []byte, layout ImageDataLayout) error
}

// TextureDrawer provides texture drawing capabilities for 2D rendering.
Expand Down
Loading