automated snapshot
This commit is contained in:
118
sketch.go
118
sketch.go
@@ -9,9 +9,9 @@ type Sketch struct {
|
||||
sourceWidth int32
|
||||
sourceHeight int32
|
||||
cam *TextureCam
|
||||
layerTools map[string]LayerTools
|
||||
layerToolsOrdered []LayerTools
|
||||
composite rl.RenderTexture2D
|
||||
layerTools map[string]*LayerTools
|
||||
layerToolsOrdered []*LayerTools
|
||||
}
|
||||
|
||||
type TextureCam struct {
|
||||
@@ -19,6 +19,35 @@ type TextureCam struct {
|
||||
Zoom float32
|
||||
}
|
||||
|
||||
/** RenderCtx **/
|
||||
type RenderCtx struct {
|
||||
TargetBounds rl.Rectangle
|
||||
SourceWidth int32
|
||||
SourceHeight int32
|
||||
Time float64
|
||||
Ports map[string]float64
|
||||
}
|
||||
|
||||
type LayerTools struct {
|
||||
name string
|
||||
layer Layer
|
||||
texture rl.RenderTexture2D
|
||||
config *LayerConfig
|
||||
}
|
||||
|
||||
type LayerConfig struct {
|
||||
visible bool
|
||||
a uint8
|
||||
rVisible bool
|
||||
r uint8
|
||||
gVisible bool
|
||||
g uint8
|
||||
bVisible bool
|
||||
b uint8
|
||||
desaturate bool
|
||||
saturation float32
|
||||
kValue float32
|
||||
}
|
||||
|
||||
func NewSketch(sourceWidth, sourceHeight int32) Sketch {
|
||||
|
||||
@@ -32,8 +61,8 @@ func NewSketch(sourceWidth, sourceHeight int32) Sketch {
|
||||
return Sketch {
|
||||
sourceWidth: sourceWidth,
|
||||
sourceHeight: sourceHeight,
|
||||
layerTools: make(map[string]LayerTools),
|
||||
layerToolsOrdered: []LayerTools {},
|
||||
layerTools: make(map[string]*LayerTools),
|
||||
layerToolsOrdered: []*LayerTools {},
|
||||
composite: rl.LoadRenderTexture(sourceWidth, sourceHeight),
|
||||
cam: &camera,
|
||||
}
|
||||
@@ -41,25 +70,30 @@ func NewSketch(sourceWidth, sourceHeight int32) Sketch {
|
||||
|
||||
func (s *Sketch) CreateLayer(name string, layer Layer) {
|
||||
texture := rl.LoadRenderTexture(s.sourceWidth, s.sourceHeight)
|
||||
layerTools := LayerTools {
|
||||
name: name,
|
||||
texture: &texture,
|
||||
layer: layer,
|
||||
config: NewLayerConfig(),
|
||||
}
|
||||
s.layerToolsOrdered = append(s.layerToolsOrdered, layerTools)
|
||||
s.layerTools[name] = layerTools
|
||||
rl.GenTextureMipmaps(&texture.Texture)
|
||||
rl.SetTextureFilter(texture.Texture, rl.FilterTrilinear)
|
||||
config := NewLayerConfig()
|
||||
layerTools :=
|
||||
LayerTools {
|
||||
name: name,
|
||||
texture: texture,
|
||||
layer: layer,
|
||||
config: &config,
|
||||
}
|
||||
s.layerToolsOrdered = append(s.layerToolsOrdered, &layerTools)
|
||||
s.layerTools[name] = &layerTools
|
||||
}
|
||||
|
||||
func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
// render onto all layer textures
|
||||
for _, instance := range s.layerToolsOrdered {
|
||||
instance.layer.Update(ctx)
|
||||
layer := instance.layer
|
||||
layer.Update(ctx)
|
||||
if instance.layer.IsDirty() {
|
||||
rl.BeginTextureMode(*instance.texture)
|
||||
rl.BeginTextureMode(instance.texture)
|
||||
layer.Draw(ctx)
|
||||
rl.EndTextureMode()
|
||||
rl.GenTextureMipmaps(&instance.texture.Texture)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +118,23 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
|
||||
rl.BeginTextureMode(s.composite)
|
||||
rl.ClearBackground(rl.Black)
|
||||
for _, instance := range s.layerToolsOrdered {
|
||||
rl.DrawTexturePro(instance.texture.Texture, src, dst, rl.Vector2{}, 0, rl.White)
|
||||
config := instance.config
|
||||
if config.visible {
|
||||
var r uint8
|
||||
if config.rVisible {
|
||||
r = config.r
|
||||
}
|
||||
var g uint8
|
||||
if config.gVisible {
|
||||
g = config.g
|
||||
}
|
||||
var b uint8
|
||||
if config.bVisible {
|
||||
b = config.b
|
||||
}
|
||||
tint := rl.NewColor(r, g, b, config.a)
|
||||
rl.DrawTexturePro(instance.texture.Texture, src, dst, rl.Vector2{}, 0, tint)
|
||||
}
|
||||
}
|
||||
rl.EndTextureMode()
|
||||
|
||||
@@ -191,12 +241,6 @@ func (s *Sketch) Capture() *SketchCapture {
|
||||
}
|
||||
|
||||
|
||||
type LayerTools struct {
|
||||
name string
|
||||
layer Layer
|
||||
texture *rl.RenderTexture2D
|
||||
config LayerConfig
|
||||
}
|
||||
|
||||
func NewLayerConfig() LayerConfig {
|
||||
return LayerConfig {
|
||||
@@ -213,28 +257,6 @@ func NewLayerConfig() LayerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
type LayerConfig struct {
|
||||
|
||||
visible bool
|
||||
a uint8
|
||||
|
||||
rVisible bool
|
||||
r uint8
|
||||
|
||||
gVisible bool
|
||||
g uint8
|
||||
|
||||
|
||||
bVisible bool
|
||||
b uint8
|
||||
|
||||
|
||||
desaturate bool
|
||||
saturation float32
|
||||
|
||||
kValue float32
|
||||
}
|
||||
|
||||
/** Layer **/
|
||||
|
||||
type Layer interface {
|
||||
@@ -297,13 +319,3 @@ func (p Ports) Eval(t float64) map[string]float64 {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** RenderCtx **/
|
||||
|
||||
type RenderCtx struct {
|
||||
TargetBounds rl.Rectangle
|
||||
SourceWidth int32
|
||||
SourceHeight int32
|
||||
Time float64
|
||||
Ports map[string]float64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user