graphics.go (2662B)
1 // Copyright 2018 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package driver 16 17 import ( 18 "errors" 19 20 "github.com/hajimehoshi/ebiten/v2/internal/affine" 21 "github.com/hajimehoshi/ebiten/v2/internal/graphics" 22 "github.com/hajimehoshi/ebiten/v2/internal/shaderir" 23 "github.com/hajimehoshi/ebiten/v2/internal/thread" 24 ) 25 26 type Region struct { 27 X float32 28 Y float32 29 Width float32 30 Height float32 31 } 32 33 type Graphics interface { 34 SetThread(thread *thread.Thread) 35 Begin() 36 End() 37 SetTransparent(transparent bool) 38 SetVertices(vertices []float32, indices []uint16) 39 NewImage(width, height int) (Image, error) 40 NewScreenFramebufferImage(width, height int) (Image, error) 41 Reset() error 42 SetVsyncEnabled(enabled bool) 43 FramebufferYDirection() YDirection 44 NeedsRestoring() bool 45 IsGL() bool 46 HasHighPrecisionFloat() bool 47 MaxImageSize() int 48 InvalidImageID() ImageID 49 50 NewShader(program *shaderir.Program) (Shader, error) 51 52 // Draw draws an image onto another image. 53 // 54 // TODO: Merge this into DrawShader. 55 Draw(dst, src ImageID, indexLen int, indexOffset int, mode CompositeMode, colorM *affine.ColorM, filter Filter, address Address, sourceRegion Region) error 56 57 // DrawShader draws the shader. 58 // 59 // uniforms represents a colletion of uniform variables. The values must be one of these types: 60 // 61 // * float32 62 // * []float32 63 DrawShader(dst ImageID, srcs [graphics.ShaderImageNum]ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, sourceRegion Region, mode CompositeMode, uniforms []interface{}) error 64 } 65 66 // GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost. 67 var GraphicsNotReady = errors.New("graphics not ready") 68 69 type Image interface { 70 ID() ImageID 71 Dispose() 72 IsInvalidated() bool 73 Pixels() ([]byte, error) 74 ReplacePixels(args []*ReplacePixelsArgs) 75 } 76 77 type ImageID int 78 79 type ReplacePixelsArgs struct { 80 Pixels []byte 81 X int 82 Y int 83 Width int 84 Height int 85 } 86 87 type YDirection int 88 89 const ( 90 Upward YDirection = iota 91 Downward 92 ) 93 94 type Shader interface { 95 ID() ShaderID 96 Dispose() 97 } 98 99 type ShaderID int