~eliasnaur/gio-patches

gio: gpu: UploadPixels interface v1 PROPOSED

~dejadeja9
~dejadeja9: 1
 gpu: UploadPixels interface

 2 files changed, 15 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/11391/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio] gpu: UploadPixels interface Export this patch

~dejadeja9
From: Deja Deja <dejadejade9@outlook.com>

---
 gpu/backend/backend.go |  2 ++
 gpu/gl/backend.go      | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gpu/backend/backend.go b/gpu/backend/backend.go
index 871eea4..922f95a 100644
--- a/gpu/backend/backend.go
+++ b/gpu/backend/backend.go
@@ -151,6 +151,7 @@ type Timer interface {

type Texture interface {
	Upload(img *image.RGBA)
	UploadPixels(pix []byte, width, height int)
	Release()
}

@@ -176,6 +177,7 @@ const (
const (
	TextureFormatSRGB TextureFormat = iota
	TextureFormatFloat
	TextureFormatLuminance
)

const (
diff --git a/gpu/gl/backend.go b/gpu/gl/backend.go
index 02037c3..d5cc2ea 100644
--- a/gpu/gl/backend.go
+++ b/gpu/gl/backend.go
@@ -29,6 +29,8 @@ type Backend struct {
	// Single channel alpha textures.
	alphaTriple textureTriple
	srgbaTriple textureTriple
	// Single channel luminace texture
	luminTriple textureTriple
}

// State tracking.
@@ -36,7 +38,7 @@ type glstate struct {
	// nattr is the current number of enabled vertex arrays.
	nattr    int
	prog     *gpuProgram
	texUnits [2]*gpuTexture
	texUnits [3]*gpuTexture
	layout   *gpuInputLayout
	buffer   bufferBinding
}
@@ -130,6 +132,8 @@ func NewBackend(f Functions) (*Backend, error) {
	if err != nil {
		return nil, err
	}
	luminanceTriple := textureTriple{LUMINANCE, Enum(LUMINANCE), UNSIGNED_BYTE}

	ubo := ver[0] >= 3 && gles
	b := &Backend{
		glver:       ver,
@@ -139,6 +143,7 @@ func NewBackend(f Functions) (*Backend, error) {
		floatTriple: floatTriple,
		alphaTriple: alphaTripleFor(ver),
		srgbaTriple: srgbaTriple,
		luminTriple: luminanceTriple,
	}
	if hasExtension(exts, "GL_EXT_disjoint_timer_query_webgl2") || hasExtension(exts, "GL_EXT_disjoint_timer_query") {
		b.feats.Features |= backend.FeatureTimers
@@ -221,6 +226,8 @@ func (b *Backend) NewTexture(format backend.TextureFormat, width, height int, mi
		tex.triple = b.floatTriple
	case backend.TextureFormatSRGB:
		tex.triple = b.srgbaTriple
	case backend.TextureFormatLuminance:
		tex.triple = b.luminTriple
	default:
		return nil, errors.New("unsupported texture format")
	}
@@ -717,6 +724,11 @@ func (t *gpuTexture) Upload(img *image.RGBA) {
	t.backend.funcs.TexImage2D(TEXTURE_2D, 0, t.triple.internalFormat, w, h, t.triple.format, t.triple.typ, pixels)
}

func (t *gpuTexture) UploadPixels(pix []byte, w, h int) {
	t.backend.BindTexture(0, t)
	t.backend.funcs.TexImage2D(TEXTURE_2D, 0, t.triple.internalFormat, w, h, t.triple.format, t.triple.typ, pix)
}

func (t *gpuTimer) Begin() {
	t.funcs.BeginQuery(TIME_ELAPSED_EXT, t.obj)
}
-- 
2.26.2