| 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux || darwin || windows |
| 6 | |
| 7 | package glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/ |
| 8 | |
| 9 | import ( |
| 10 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/" |
| 11 | "imagescip-go gomod github.com/golang/go/src go1.24.0 image/" |
| 12 | "runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/" |
| 13 | "syncscip-go gomod github.com/golang/go/src go1.24.0 sync/" |
| 14 | |
| 15 | "golang.org/x/mobile/event/sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/" |
| 16 | "golang.org/x/mobile/exp/f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/" |
| 17 | "golang.org/x/mobile/geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/" |
| 18 | "golang.org/x/mobile/glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/" |
| 19 | ) |
| 20 | |
| 21 | // Images maintains the shared state used by a set of *Image objects. |
| 22 | type Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images# struct { |
| 23 | glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context# |
| 24 | quadXYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadXY. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Bufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Buffer# |
| 25 | quadUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadUV. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Bufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Buffer# |
| 26 | programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Program# |
| 27 | posscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#pos. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Attribscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Attrib# |
| 28 | mvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mvp. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Uniformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Uniform# |
| 29 | uvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#uvp. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Uniformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Uniform# |
| 30 | inUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#inUV. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Attribscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Attrib# |
| 31 | textureSamplescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#textureSample. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Uniformscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Uniform# |
| 32 | |
| 33 | muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu. syncscip-go gomod github.com/golang/go/src go1.24.0 sync/.Mutexscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex# |
| 34 | activeImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#activeImages. int |
| 35 | } |
| 36 | |
| 37 | // NewImages creates an *Images. |
| 38 | func NewImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/NewImages().(glctx glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Contextscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#) *Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images# { |
| 39 | program, err := CreateProgramscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/CreateProgram().(glctx, vertexShaderscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/vertexShader., fragmentShaderscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/fragmentShader.) |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | |
| 44 | p := &Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#{ |
| 45 | glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx.: glctx, |
| 46 | quadXYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadXY.: glctx.CreateBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#CreateBuffer.(), |
| 47 | quadUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadUV.: glctx.CreateBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#CreateBuffer.(), |
| 48 | programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program.: program, |
| 49 | posscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#pos.: glctx.GetAttribLocationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#GetAttribLocation.(program, "pos"), |
| 50 | mvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mvp.: glctx.GetUniformLocationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#GetUniformLocation.(program, "mvp"), |
| 51 | uvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#uvp.: glctx.GetUniformLocationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#GetUniformLocation.(program, "uvp"), |
| 52 | inUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#inUV.: glctx.GetAttribLocationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#GetAttribLocation.(program, "inUV"), |
| 53 | textureSamplescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#textureSample.: glctx.GetUniformLocationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#GetUniformLocation.(program, "textureSample"), |
| 54 | } |
| 55 | |
| 56 | glctx.BindBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindBuffer.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., p.quadXYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadXY.) |
| 57 | glctx.BufferDatascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BufferData.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., quadXYCoordsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/quadXYCoords., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.STATIC_DRAWscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/STATIC_DRAW.) |
| 58 | glctx.BindBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindBuffer.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., p.quadUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadUV.) |
| 59 | glctx.BufferDatascip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BufferData.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., quadUVCoordsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/quadUVCoords., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.STATIC_DRAWscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/STATIC_DRAW.) |
| 60 | |
| 61 | return p |
| 62 | } |
| 63 | |
| 64 | // Release releases any held OpenGL resources. |
| 65 | // All *Image objects must be released first, or this function panics. |
| 66 | func (p *Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#) Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#Release().() { |
| 67 | if p.programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program. == (glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Program#{}) { |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | p.muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 72 | rem := p.activeImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#activeImages. |
| 73 | p.muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 74 | if rem > 0 { |
| 75 | panic("glutil.Images.Release called, but active *Image objects remain") |
| 76 | } |
| 77 | |
| 78 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..DeleteProgramscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DeleteProgram.(p.programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program.) |
| 79 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..DeleteBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DeleteBuffer.(p.quadXYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadXY.) |
| 80 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..DeleteBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DeleteBuffer.(p.quadUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadUV.) |
| 81 | |
| 82 | p.programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program. = glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Program#{} |
| 83 | } |
| 84 | |
| 85 | // Image bridges between an *image.RGBA and an OpenGL texture. |
| 86 | // |
| 87 | // The contents of the *image.RGBA can be uploaded as a texture and drawn as a |
| 88 | // 2D quad. |
| 89 | // |
| 90 | // The number of active Images must fit in the system's OpenGL texture limit. |
| 91 | // The typical use of an Image is as a texture atlas. |
| 92 | type Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image# struct { |
| 93 | RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA. *imagescip-go gomod github.com/golang/go/src go1.24.0 image/.RGBAscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA# |
| 94 | |
| 95 | gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex. glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Texturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Texture# |
| 96 | widthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#width. int |
| 97 | heightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#height. int |
| 98 | imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images. *Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images# |
| 99 | } |
| 100 | |
| 101 | // NewImage creates an Image of the given size. |
| 102 | // |
| 103 | // Both a host-memory *image.RGBA and a GL texture are created. |
| 104 | func (p *Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#) NewImagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#NewImage().(w, h int) *Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image# { |
| 105 | dx := roundToPower2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/roundToPower2().(w) |
| 106 | dy := roundToPower2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/roundToPower2().(h) |
| 107 | |
| 108 | // TODO(crawshaw): Using VertexAttribPointer we can pass texture |
| 109 | // data with a stride, which would let us use the exact number of |
| 110 | // pixels on the host instead of the rounded up power 2 size. |
| 111 | m := imagescip-go gomod github.com/golang/go/src go1.24.0 image/.NewRGBAscip-go gomod github.com/golang/go/src go1.24.0 image/NewRGBA().(imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(0, 0, dx, dy)) |
| 112 | |
| 113 | img := &Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#{ |
| 114 | RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA.: m.SubImagescip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#SubImage().(imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectscip-go gomod github.com/golang/go/src go1.24.0 image/Rect().(0, 0, w, h)).(*imagescip-go gomod github.com/golang/go/src go1.24.0 image/.RGBAscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#), |
| 115 | imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images.: p, |
| 116 | widthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#width.: dx, |
| 117 | heightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#height.: dy, |
| 118 | } |
| 119 | |
| 120 | p.muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 121 | p.activeImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#activeImages.++ |
| 122 | p.muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 123 | |
| 124 | img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex. = p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..CreateTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#CreateTexture.() |
| 125 | |
| 126 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..BindTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindTexture.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex.) |
| 127 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexImage2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexImage2D.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., 0, glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/RGBA., img.widthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#width., img.heightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#height., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/RGBA., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.UNSIGNED_BYTEscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/UNSIGNED_BYTE., nil) |
| 128 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexParameteriscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexParameteri.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_MAG_FILTERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_MAG_FILTER., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.LINEARscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/LINEAR.) |
| 129 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexParameteriscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexParameteri.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_MIN_FILTERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_MIN_FILTER., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.LINEARscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/LINEAR.) |
| 130 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexParameteriscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexParameteri.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_WRAP_Sscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_WRAP_S., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.CLAMP_TO_EDGEscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/CLAMP_TO_EDGE.) |
| 131 | p.glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexParameteriscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexParameteri.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_WRAP_Tscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_WRAP_T., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.CLAMP_TO_EDGEscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/CLAMP_TO_EDGE.) |
| 132 | |
| 133 | runtimescip-go gomod github.com/golang/go/src go1.24.0 runtime/.SetFinalizerscip-go gomod github.com/golang/go/src go1.24.0 runtime/SetFinalizer().(img, (*Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#).Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Release().) |
| 134 | return img |
| 135 | } |
| 136 | |
| 137 | func roundToPower2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/roundToPower2().(x int) int { |
| 138 | x2 := 1 |
| 139 | for x2 < x { |
| 140 | x2 *= 2 |
| 141 | } |
| 142 | return x2 |
| 143 | } |
| 144 | |
| 145 | // Upload copies the host image data to the GL device. |
| 146 | func (img *Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#) Uploadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Upload().() { |
| 147 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..BindTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindTexture.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex.) |
| 148 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..TexSubImage2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#TexSubImage2D.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., 0, 0, 0, img.widthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#width., img.heightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#height., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/RGBA., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.UNSIGNED_BYTEscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/UNSIGNED_BYTE., img.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Pixscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Pix.) |
| 149 | } |
| 150 | |
| 151 | // Release invalidates the Image and removes any underlying data structures. |
| 152 | // The Image cannot be used after being deleted. |
| 153 | func (img *Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#) Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Release().() { |
| 154 | if img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex. == (glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Texturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Texture#{}) { |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx..DeleteTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DeleteTexture.(img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex.) |
| 159 | img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex. = glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.Texturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Texture#{} |
| 160 | |
| 161 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Lockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Lock().() |
| 162 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..activeImagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#activeImages.-- |
| 163 | img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..muscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mu..Unlockscip-go gomod github.com/golang/go/src go1.24.0 sync/Mutex#Unlock().() |
| 164 | } |
| 165 | |
| 166 | // Draw draws the srcBounds part of the image onto a parallelogram, defined by |
| 167 | // three of its corners, in the current GL framebuffer. |
| 168 | func (img *Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#) Drawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Draw().(sz sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#, topLeft, topRight, bottomLeft geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/.Pointscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#, srcBounds imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectanglescip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#) { |
| 169 | glimage := img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images. |
| 170 | glctx := img.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#images..glctxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#glctx. |
| 171 | |
| 172 | glctx.BlendFuncscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BlendFunc.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ONEscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ONE., glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ONE_MINUS_SRC_ALPHAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ONE_MINUS_SRC_ALPHA.) |
| 173 | glctx.Enablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#Enable.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.BLENDscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/BLEND.) |
| 174 | |
| 175 | // TODO(crawshaw): Adjust viewport for the top bar on android? |
| 176 | glctx.UseProgramscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#UseProgram.(glimage.programscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#program.) |
| 177 | { |
| 178 | // We are drawing a parallelogram PQRS, defined by three of its |
| 179 | // corners, onto the entire GL framebuffer ABCD. The two quads may |
| 180 | // actually be equal, but in the general case, PQRS can be smaller, |
| 181 | // and PQRS is not necessarily axis-aligned. |
| 182 | // |
| 183 | // A +---------------+ B |
| 184 | // | P +-----+ Q | |
| 185 | // | | | | |
| 186 | // | S +-----+ R | |
| 187 | // D +---------------+ C |
| 188 | // |
| 189 | // There are two co-ordinate spaces: geom space and framebuffer space. |
| 190 | // In geom space, the ABCD rectangle is: |
| 191 | // |
| 192 | // (0, 0) (geom.Width, 0) |
| 193 | // (0, geom.Height) (geom.Width, geom.Height) |
| 194 | // |
| 195 | // and the PQRS quad is: |
| 196 | // |
| 197 | // (topLeft.X, topLeft.Y) (topRight.X, topRight.Y) |
| 198 | // (bottomLeft.X, bottomLeft.Y) (implicit, implicit) |
| 199 | // |
| 200 | // In framebuffer space, the ABCD rectangle is: |
| 201 | // |
| 202 | // (-1, +1) (+1, +1) |
| 203 | // (-1, -1) (+1, -1) |
| 204 | // |
| 205 | // First of all, convert from geom space to framebuffer space. For |
| 206 | // later convenience, we divide everything by 2 here: px2 is half of |
| 207 | // the P.X co-ordinate (in framebuffer space). |
| 208 | px2 := -0.5 + float32(topLeft.Xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#X./sz.WidthPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPt.) |
| 209 | py2 := +0.5 - float32(topLeft.Yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#Y./sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt.) |
| 210 | qx2 := -0.5 + float32(topRight.Xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#X./sz.WidthPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPt.) |
| 211 | qy2 := +0.5 - float32(topRight.Yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#Y./sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt.) |
| 212 | sx2 := -0.5 + float32(bottomLeft.Xscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#X./sz.WidthPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPt.) |
| 213 | sy2 := +0.5 - float32(bottomLeft.Yscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#Y./sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt.) |
| 214 | // Next, solve for the affine transformation matrix |
| 215 | // [ a00 a01 a02 ] |
| 216 | // a = [ a10 a11 a12 ] |
| 217 | // [ 0 0 1 ] |
| 218 | // that maps A to P: |
| 219 | // a × [ -1 +1 1 ]' = [ 2*px2 2*py2 1 ]' |
| 220 | // and likewise maps B to Q and D to S. Solving those three constraints |
| 221 | // implies that C maps to R, since affine transformations keep parallel |
| 222 | // lines parallel. This gives 6 equations in 6 unknowns: |
| 223 | // -a00 + a01 + a02 = 2*px2 |
| 224 | // -a10 + a11 + a12 = 2*py2 |
| 225 | // +a00 + a01 + a02 = 2*qx2 |
| 226 | // +a10 + a11 + a12 = 2*qy2 |
| 227 | // -a00 - a01 + a02 = 2*sx2 |
| 228 | // -a10 - a11 + a12 = 2*sy2 |
| 229 | // which gives: |
| 230 | // a00 = (2*qx2 - 2*px2) / 2 = qx2 - px2 |
| 231 | // and similarly for the other elements of a. |
| 232 | writeAffinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/writeAffine().(glctx, glimage.mvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#mvp., &f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{{ |
| 233 | qx2 - px2, |
| 234 | px2 - sx2, |
| 235 | qx2 + sx2, |
| 236 | }, { |
| 237 | qy2 - py2, |
| 238 | py2 - sy2, |
| 239 | qy2 + sy2, |
| 240 | }}) |
| 241 | } |
| 242 | |
| 243 | { |
| 244 | // Mapping texture co-ordinates is similar, except that in texture |
| 245 | // space, the ABCD rectangle is: |
| 246 | // |
| 247 | // (0,0) (1,0) |
| 248 | // (0,1) (1,1) |
| 249 | // |
| 250 | // and the PQRS quad is always axis-aligned. First of all, convert |
| 251 | // from pixel space to texture space. |
| 252 | w := float32(img.widthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#width.) |
| 253 | h := float32(img.heightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#height.) |
| 254 | px := float32(srcBounds.Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Xscip-go gomod github.com/golang/go/src go1.24.0 image/Point#X.-img.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Rectscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Rect..Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Xscip-go gomod github.com/golang/go/src go1.24.0 image/Point#X.) / w |
| 255 | py := float32(srcBounds.Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Yscip-go gomod github.com/golang/go/src go1.24.0 image/Point#Y.-img.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Rectscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Rect..Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Yscip-go gomod github.com/golang/go/src go1.24.0 image/Point#Y.) / h |
| 256 | qx := float32(srcBounds.Maxscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Max..Xscip-go gomod github.com/golang/go/src go1.24.0 image/Point#X.-img.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Rectscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Rect..Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Xscip-go gomod github.com/golang/go/src go1.24.0 image/Point#X.) / w |
| 257 | sy := float32(srcBounds.Maxscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Max..Yscip-go gomod github.com/golang/go/src go1.24.0 image/Point#Y.-img.RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Rectscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Rect..Minscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Min..Yscip-go gomod github.com/golang/go/src go1.24.0 image/Point#Y.) / h |
| 258 | // Due to axis alignment, qy = py and sx = px. |
| 259 | // |
| 260 | // The simultaneous equations are: |
| 261 | // 0 + 0 + a02 = px |
| 262 | // 0 + 0 + a12 = py |
| 263 | // a00 + 0 + a02 = qx |
| 264 | // a10 + 0 + a12 = qy = py |
| 265 | // 0 + a01 + a02 = sx = px |
| 266 | // 0 + a11 + a12 = sy |
| 267 | writeAffinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/writeAffine().(glctx, glimage.uvpscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#uvp., &f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Affinescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Affine#{{ |
| 268 | qx - px, |
| 269 | 0, |
| 270 | px, |
| 271 | }, { |
| 272 | 0, |
| 273 | sy - py, |
| 274 | py, |
| 275 | }}) |
| 276 | } |
| 277 | |
| 278 | glctx.ActiveTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#ActiveTexture.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE0scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE0.) |
| 279 | glctx.BindTexturescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindTexture.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TEXTURE_2Dscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TEXTURE_2D., img.gltexscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#gltex.) |
| 280 | glctx.Uniform1iscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#Uniform1i.(glimage.textureSamplescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#textureSample., 0) |
| 281 | |
| 282 | glctx.BindBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindBuffer.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., glimage.quadXYscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadXY.) |
| 283 | glctx.EnableVertexAttribArrayscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#EnableVertexAttribArray.(glimage.posscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#pos.) |
| 284 | glctx.VertexAttribPointerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#VertexAttribPointer.(glimage.posscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#pos., 2, glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.FLOATscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/FLOAT., false, 0, 0) |
| 285 | |
| 286 | glctx.BindBufferscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#BindBuffer.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.ARRAY_BUFFERscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/ARRAY_BUFFER., glimage.quadUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#quadUV.) |
| 287 | glctx.EnableVertexAttribArrayscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#EnableVertexAttribArray.(glimage.inUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#inUV.) |
| 288 | glctx.VertexAttribPointerscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#VertexAttribPointer.(glimage.inUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#inUV., 2, glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.FLOATscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/FLOAT., false, 0, 0) |
| 289 | |
| 290 | glctx.DrawArraysscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DrawArrays.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.TRIANGLE_STRIPscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/TRIANGLE_STRIP., 0, 4) |
| 291 | |
| 292 | glctx.DisableVertexAttribArrayscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DisableVertexAttribArray.(glimage.posscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#pos.) |
| 293 | glctx.DisableVertexAttribArrayscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#DisableVertexAttribArray.(glimage.inUVscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#inUV.) |
| 294 | |
| 295 | glctx.Disablescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/Context#Disable.(glscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/.BLENDscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/gl`/BLEND.) |
| 296 | } |
| 297 | |
| 298 | var quadXYCoordsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/quadXYCoords. = f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Bytesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Bytes().(binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/LittleEndian., |
| 299 | -1, +1, // top left |
| 300 | +1, +1, // top right |
| 301 | -1, -1, // bottom left |
| 302 | +1, -1, // bottom right |
| 303 | ) |
| 304 | |
| 305 | var quadUVCoordsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/quadUVCoords. = f32scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/.Bytesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/f32`/Bytes().(binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.LittleEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/LittleEndian., |
| 306 | 0, 0, // top left |
| 307 | 1, 0, // top right |
| 308 | 0, 1, // bottom left |
| 309 | 1, 1, // bottom right |
| 310 | ) |
| 311 | |
| 312 | const vertexShaderscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/vertexShader. = `#version 100 |
| 313 | uniform mat3 mvp; |
| 314 | uniform mat3 uvp; |
| 315 | attribute vec3 pos; |
| 316 | attribute vec2 inUV; |
| 317 | varying vec2 UV; |
| 318 | void main() { |
| 319 | vec3 p = pos; |
| 320 | p.z = 1.0; |
| 321 | gl_Position = vec4(mvp * p, 1); |
| 322 | UV = (uvp * vec3(inUV, 1)).xy; |
| 323 | } |
| 324 | ` |
| 325 | |
| 326 | const fragmentShaderscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/fragmentShader. = `#version 100 |
| 327 | precision mediump float; |
| 328 | varying vec2 UV; |
| 329 | uniform sampler2D textureSample; |
| 330 | void main(){ |
| 331 | gl_FragColor = texture2D(textureSample, UV); |
| 332 | } |
| 333 | ` |