ebiten/internal/graphicsdriver/compositemode.go

89 lines
2.7 KiB
Go
Raw Normal View History

2018-10-28 12:42:57 +01:00
// Copyright 2018 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package graphicsdriver
2018-10-28 12:42:57 +01:00
2019-02-07 09:19:24 +01:00
import (
"fmt"
)
2018-10-28 12:42:57 +01:00
type CompositeMode int
const (
CompositeModeUnknown CompositeMode = iota - 1
CompositeModeSourceOver // This value must be 0 (= initial value)
2018-10-28 12:42:57 +01:00
CompositeModeClear
CompositeModeCopy
CompositeModeDestination
CompositeModeDestinationOver
CompositeModeSourceIn
CompositeModeDestinationIn
CompositeModeSourceOut
CompositeModeDestinationOut
CompositeModeSourceAtop
CompositeModeDestinationAtop
CompositeModeXor
CompositeModeLighter
CompositeModeMultiply
2018-11-12 16:00:10 +01:00
CompositeModeMax = CompositeModeMultiply
2018-10-28 12:42:57 +01:00
)
type BlendFactor int
2018-10-28 12:42:57 +01:00
const (
BlendFactorZero BlendFactor = iota
BlendFactorOne
BlendFactorSourceAlpha
BlendFactorDestinationAlpha
BlendFactorOneMinusSourceAlpha
BlendFactorOneMinusDestinationAlpha
BlendFactorDestinationColor
2018-10-28 12:42:57 +01:00
)
func (c CompositeMode) BlendFactors() (src BlendFactor, dst BlendFactor) {
2018-10-28 12:42:57 +01:00
switch c {
case CompositeModeSourceOver:
return BlendFactorOne, BlendFactorOneMinusSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeClear:
return BlendFactorZero, BlendFactorZero
2018-10-28 12:42:57 +01:00
case CompositeModeCopy:
return BlendFactorOne, BlendFactorZero
2018-10-28 12:42:57 +01:00
case CompositeModeDestination:
return BlendFactorZero, BlendFactorOne
2018-10-28 12:42:57 +01:00
case CompositeModeDestinationOver:
return BlendFactorOneMinusDestinationAlpha, BlendFactorOne
2018-10-28 12:42:57 +01:00
case CompositeModeSourceIn:
return BlendFactorDestinationAlpha, BlendFactorZero
2018-10-28 12:42:57 +01:00
case CompositeModeDestinationIn:
return BlendFactorZero, BlendFactorSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeSourceOut:
return BlendFactorOneMinusDestinationAlpha, BlendFactorZero
2018-10-28 12:42:57 +01:00
case CompositeModeDestinationOut:
return BlendFactorZero, BlendFactorOneMinusSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeSourceAtop:
return BlendFactorDestinationAlpha, BlendFactorOneMinusSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeDestinationAtop:
return BlendFactorOneMinusDestinationAlpha, BlendFactorSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeXor:
return BlendFactorOneMinusDestinationAlpha, BlendFactorOneMinusSourceAlpha
2018-10-28 12:42:57 +01:00
case CompositeModeLighter:
return BlendFactorOne, BlendFactorOne
case CompositeModeMultiply:
return BlendFactorDestinationColor, BlendFactorZero
2018-10-28 12:42:57 +01:00
default:
panic(fmt.Sprintf("graphicsdriver: invalid composite mode: %d", c))
2018-10-28 12:42:57 +01:00
}
}