mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
internal/buffer, internal/mipmap: remove Shader
This commit is contained in:
parent
19ee79e2cb
commit
da979a3ab2
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
@ -121,7 +120,7 @@ func (i *Image) writePixelsImpl(pix []byte, region image.Rectangle) {
|
|||||||
// DrawTriangles draws the src image with the given vertices.
|
// DrawTriangles draws the src image with the given vertices.
|
||||||
//
|
//
|
||||||
// Copying vertices and indices is the caller's responsibility.
|
// Copying vertices and indices is the caller's responsibility.
|
||||||
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool) {
|
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *atlas.Shader, uniforms []uint32, evenOdd bool) {
|
||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
if i == src {
|
if i == src {
|
||||||
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
panic("buffered: Image.DrawTriangles: source images must be different from the receiver")
|
||||||
@ -145,7 +144,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
|
|||||||
i.drawTrianglesImpl(srcs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, evenOdd)
|
i.drawTrianglesImpl(srcs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, evenOdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) drawTrianglesImpl(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool) {
|
func (i *Image) drawTrianglesImpl(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *atlas.Shader, uniforms []uint32, evenOdd bool) {
|
||||||
var imgs [graphics.ShaderImageCount]*atlas.Image
|
var imgs [graphics.ShaderImageCount]*atlas.Image
|
||||||
for i, img := range srcs {
|
for i, img := range srcs {
|
||||||
if img == nil {
|
if img == nil {
|
||||||
@ -154,25 +153,5 @@ func (i *Image) drawTrianglesImpl(srcs [graphics.ShaderImageCount]*Image, vertic
|
|||||||
imgs[i] = img.img
|
imgs[i] = img.img
|
||||||
}
|
}
|
||||||
|
|
||||||
i.img.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, evenOdd)
|
i.img.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, evenOdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Shader struct {
|
|
||||||
shader *atlas.Shader
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewShader(ir *shaderir.Program) *Shader {
|
|
||||||
return &Shader{
|
|
||||||
shader: atlas.NewShader(ir),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Shader) MarkDisposed() {
|
|
||||||
s.shader.MarkDisposed()
|
|
||||||
s.shader = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
NearestFilterShader = &Shader{shader: atlas.NearestFilterShader}
|
|
||||||
LinearFilterShader = &Shader{shader: atlas.LinearFilterShader}
|
|
||||||
)
|
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func canUseMipmap(imageType atlas.ImageType) bool {
|
func canUseMipmap(imageType atlas.ImageType) bool {
|
||||||
@ -66,7 +65,7 @@ func (m *Mipmap) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byt
|
|||||||
return m.orig.ReadPixels(graphicsDriver, pixels, region)
|
return m.orig.ReadPixels(graphicsDriver, pixels, region)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool, canSkipMipmap bool) {
|
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *atlas.Shader, uniforms []uint32, evenOdd bool, canSkipMipmap bool) {
|
||||||
if len(indices) == 0 {
|
if len(indices) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -124,7 +123,7 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices
|
|||||||
imgs[i] = src.orig
|
imgs[i] = src.orig
|
||||||
}
|
}
|
||||||
|
|
||||||
m.orig.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.shader, uniforms, evenOdd)
|
m.orig.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader, uniforms, evenOdd)
|
||||||
m.disposeMipmaps()
|
m.disposeMipmaps()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,12 +149,12 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
|
|
||||||
var src *buffered.Image
|
var src *buffered.Image
|
||||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||||
shader := NearestFilterShader
|
shader := atlas.NearestFilterShader
|
||||||
switch {
|
switch {
|
||||||
case level == 1:
|
case level == 1:
|
||||||
src = m.orig
|
src = m.orig
|
||||||
graphics.QuadVertices(vs, 0, 0, float32(m.width), float32(m.height), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
graphics.QuadVertices(vs, 0, 0, float32(m.width), float32(m.height), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||||
shader = LinearFilterShader
|
shader = atlas.LinearFilterShader
|
||||||
case level > 1:
|
case level > 1:
|
||||||
src = m.level(level - 1)
|
src = m.level(level - 1)
|
||||||
if src == nil {
|
if src == nil {
|
||||||
@ -165,7 +164,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
w := sizeForLevel(m.width, level-1)
|
w := sizeForLevel(m.width, level-1)
|
||||||
h := sizeForLevel(m.height, level-1)
|
h := sizeForLevel(m.height, level-1)
|
||||||
graphics.QuadVertices(vs, 0, 0, float32(w), float32(h), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
graphics.QuadVertices(vs, 0, 0, float32(w), float32(h), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||||
shader = LinearFilterShader
|
shader = atlas.LinearFilterShader
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("mipmap: invalid level: %d", level))
|
panic(fmt.Sprintf("mipmap: invalid level: %d", level))
|
||||||
}
|
}
|
||||||
@ -188,7 +187,7 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
s := buffered.NewImage(w2, h2, m.imageType)
|
s := buffered.NewImage(w2, h2, m.imageType)
|
||||||
|
|
||||||
dstRegion := image.Rect(0, 0, w2, h2)
|
dstRegion := image.Rect(0, 0, w2, h2)
|
||||||
s.DrawTriangles([graphics.ShaderImageCount]*buffered.Image{src}, vs, is, graphicsdriver.BlendCopy, dstRegion, [graphics.ShaderImageCount]image.Rectangle{}, shader.shader, nil, false)
|
s.DrawTriangles([graphics.ShaderImageCount]*buffered.Image{src}, vs, is, graphicsdriver.BlendCopy, dstRegion, [graphics.ShaderImageCount]image.Rectangle{}, shader, nil, false)
|
||||||
m.setImg(level, s)
|
m.setImg(level, s)
|
||||||
|
|
||||||
return m.imgs[level]
|
return m.imgs[level]
|
||||||
@ -277,23 +276,3 @@ func pow2(power int) float32 {
|
|||||||
x := 1
|
x := 1
|
||||||
return float32(x << uint(power))
|
return float32(x << uint(power))
|
||||||
}
|
}
|
||||||
|
|
||||||
type Shader struct {
|
|
||||||
shader *buffered.Shader
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewShader(ir *shaderir.Program) *Shader {
|
|
||||||
return &Shader{
|
|
||||||
shader: buffered.NewShader(ir),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Shader) MarkDisposed() {
|
|
||||||
s.shader.MarkDisposed()
|
|
||||||
s.shader = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
NearestFilterShader = &Shader{shader: buffered.NearestFilterShader}
|
|
||||||
LinearFilterShader = &Shader{shader: buffered.LinearFilterShader}
|
|
||||||
)
|
|
||||||
|
@ -24,12 +24,11 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/mipmap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
NearestFilterShader = &Shader{shader: mipmap.NearestFilterShader}
|
NearestFilterShader = &Shader{shader: atlas.NearestFilterShader}
|
||||||
LinearFilterShader = &Shader{shader: mipmap.LinearFilterShader}
|
LinearFilterShader = &Shader{shader: atlas.LinearFilterShader}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Game interface {
|
type Game interface {
|
||||||
|
@ -19,13 +19,13 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/mipmap"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Shader struct {
|
type Shader struct {
|
||||||
shader *mipmap.Shader
|
shader *atlas.Shader
|
||||||
|
|
||||||
uniformNames []string
|
uniformNames []string
|
||||||
uniformTypes []shaderir.Type
|
uniformTypes []shaderir.Type
|
||||||
@ -34,7 +34,7 @@ type Shader struct {
|
|||||||
|
|
||||||
func NewShader(ir *shaderir.Program) *Shader {
|
func NewShader(ir *shaderir.Program) *Shader {
|
||||||
return &Shader{
|
return &Shader{
|
||||||
shader: mipmap.NewShader(ir),
|
shader: atlas.NewShader(ir),
|
||||||
uniformNames: ir.UniformNames[graphics.PreservedUniformVariablesCount:],
|
uniformNames: ir.UniformNames[graphics.PreservedUniformVariablesCount:],
|
||||||
uniformTypes: ir.Uniforms[graphics.PreservedUniformVariablesCount:],
|
uniformTypes: ir.Uniforms[graphics.PreservedUniformVariablesCount:],
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user