zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

graphics.go (2610B)


      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/graphics"
     21 	"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
     22 )
     23 
     24 type Region struct {
     25 	X      float32
     26 	Y      float32
     27 	Width  float32
     28 	Height float32
     29 }
     30 
     31 const (
     32 	InvalidImageID  = 0
     33 	InvalidShaderID = 0
     34 )
     35 
     36 type ColorM interface {
     37 	IsIdentity() bool
     38 	At(i, j int) float32
     39 	Elements(body *[16]float32, translate *[4]float32)
     40 }
     41 
     42 type Graphics interface {
     43 	Begin()
     44 	End()
     45 	SetTransparent(transparent bool)
     46 	SetVertices(vertices []float32, indices []uint16)
     47 	NewImage(width, height int) (Image, error)
     48 	NewScreenFramebufferImage(width, height int) (Image, error)
     49 	Initialize() error
     50 	SetVsyncEnabled(enabled bool)
     51 	SetFullscreen(fullscreen bool)
     52 	FramebufferYDirection() YDirection
     53 	NeedsRestoring() bool
     54 	NeedsClearingScreen() bool
     55 	IsGL() bool
     56 	HasHighPrecisionFloat() bool
     57 	MaxImageSize() int
     58 
     59 	NewShader(program *shaderir.Program) (Shader, error)
     60 
     61 	// DrawTriangles draws an image onto another image with the given parameters.
     62 	//
     63 	// uniforms represents a colletion of uniform variables. The values must be one of these types:
     64 	//
     65 	//   * float32
     66 	//   * []float32
     67 	DrawTriangles(dst ImageID, srcs [graphics.ShaderImageNum]ImageID, offsets [graphics.ShaderImageNum - 1][2]float32, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, colorM ColorM, filter Filter, address Address, dstRegion, srcRegion Region, uniforms []interface{}, evenOdd bool) error
     68 }
     69 
     70 // GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost.
     71 var GraphicsNotReady = errors.New("graphics not ready")
     72 
     73 type Image interface {
     74 	ID() ImageID
     75 	Dispose()
     76 	IsInvalidated() bool
     77 	Pixels() ([]byte, error)
     78 	ReplacePixels(args []*ReplacePixelsArgs)
     79 }
     80 
     81 type ImageID int
     82 
     83 type ReplacePixelsArgs struct {
     84 	Pixels []byte
     85 	X      int
     86 	Y      int
     87 	Width  int
     88 	Height int
     89 }
     90 
     91 type YDirection int
     92 
     93 const (
     94 	Upward YDirection = iota
     95 	Downward
     96 )
     97 
     98 type Shader interface {
     99 	ID() ShaderID
    100 	Dispose()
    101 }
    102 
    103 type ShaderID int