mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
ebiten: Add a new shader function imageDstRegionOnTexture
Updates #1428
This commit is contained in:
parent
8d2a4ac917
commit
718273c2d7
@ -25,15 +25,19 @@ const (
|
|||||||
// Any shaders in Ebiten must have these uniform variables.
|
// Any shaders in Ebiten must have these uniform variables.
|
||||||
PreservedUniformVariablesNum = 1 + // the destination texture size
|
PreservedUniformVariablesNum = 1 + // the destination texture size
|
||||||
1 + // the texture sizes array
|
1 + // the texture sizes array
|
||||||
|
1 + // the texture destination region's origin
|
||||||
|
1 + // the texture destination region's size
|
||||||
1 + // the offsets array of the second and the following images
|
1 + // the offsets array of the second and the following images
|
||||||
1 + // the texture source region's origin
|
1 + // the texture source region's origin
|
||||||
1 // the texture source region's size
|
1 // the texture source region's size
|
||||||
|
|
||||||
DestinationTextureSizeUniformVariableIndex = 0
|
DestinationTextureSizeUniformVariableIndex = 0
|
||||||
TextureSizesUniformVariableIndex = 1
|
TextureSizesUniformVariableIndex = 1
|
||||||
TextureSourceOffsetsUniformVariableIndex = 2
|
TextureDestinationRegionOriginUniformVariableIndex = 2
|
||||||
TextureSourceRegionOriginUniformVariableIndex = 3
|
TextureDestinationRegionSizeUniformVariableIndex = 3
|
||||||
TextureSourceRegionSizeUniformVariableIndex = 4
|
TextureSourceOffsetsUniformVariableIndex = 4
|
||||||
|
TextureSourceRegionOriginUniformVariableIndex = 5
|
||||||
|
TextureSourceRegionSizeUniformVariableIndex = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -970,6 +970,14 @@ func (g *Graphics) DrawShader(dstID driver.ImageID, srcIDs [graphics.ShaderImage
|
|||||||
}
|
}
|
||||||
us[graphics.TextureSizesUniformVariableIndex] = usizes
|
us[graphics.TextureSizesUniformVariableIndex] = usizes
|
||||||
|
|
||||||
|
// Set the destination region's origin.
|
||||||
|
udorigin := []float32{float32(dstRegion.X) / float32(dw), float32(dstRegion.Y) / float32(dh)}
|
||||||
|
us[graphics.TextureDestinationRegionOriginUniformVariableIndex] = udorigin
|
||||||
|
|
||||||
|
// Set the destination region's size.
|
||||||
|
udsize := []float32{float32(dstRegion.Width) / float32(dw), float32(dstRegion.Height) / float32(dh)}
|
||||||
|
us[graphics.TextureDestinationRegionSizeUniformVariableIndex] = udsize
|
||||||
|
|
||||||
// Set the source offsets.
|
// Set the source offsets.
|
||||||
uoffsets := make([]float32, 2*len(offsets))
|
uoffsets := make([]float32, 2*len(offsets))
|
||||||
for i, offset := range offsets {
|
for i, offset := range offsets {
|
||||||
@ -979,8 +987,8 @@ func (g *Graphics) DrawShader(dstID driver.ImageID, srcIDs [graphics.ShaderImage
|
|||||||
us[graphics.TextureSourceOffsetsUniformVariableIndex] = uoffsets
|
us[graphics.TextureSourceOffsetsUniformVariableIndex] = uoffsets
|
||||||
|
|
||||||
// Set the source region's origin of texture0.
|
// Set the source region's origin of texture0.
|
||||||
uorigin := []float32{float32(srcRegion.X), float32(srcRegion.Y)}
|
usorigin := []float32{float32(srcRegion.X), float32(srcRegion.Y)}
|
||||||
us[graphics.TextureSourceRegionOriginUniformVariableIndex] = uorigin
|
us[graphics.TextureSourceRegionOriginUniformVariableIndex] = usorigin
|
||||||
|
|
||||||
// Set the source region's size of texture0.
|
// Set the source region's size of texture0.
|
||||||
ussize := []float32{float32(srcRegion.Width), float32(srcRegion.Height)}
|
ussize := []float32{float32(srcRegion.Width), float32(srcRegion.Height)}
|
||||||
|
@ -341,6 +341,21 @@ func (g *Graphics) DrawShader(dst driver.ImageID, srcs [graphics.ShaderImageNum]
|
|||||||
us[idx].value = sizes
|
us[idx].value = sizes
|
||||||
us[idx].typ = s.ir.Uniforms[idx]
|
us[idx].typ = s.ir.Uniforms[idx]
|
||||||
}
|
}
|
||||||
|
dw, dh := d.framebufferSize()
|
||||||
|
{
|
||||||
|
origin := []float32{float32(dstRegion.X) / float32(dw), float32(dstRegion.Y) / float32(dh)}
|
||||||
|
const idx = graphics.TextureDestinationRegionOriginUniformVariableIndex
|
||||||
|
us[idx].name = fmt.Sprintf("U%d", idx)
|
||||||
|
us[idx].value = origin
|
||||||
|
us[idx].typ = s.ir.Uniforms[idx]
|
||||||
|
}
|
||||||
|
{
|
||||||
|
size := []float32{float32(dstRegion.Width) / float32(dw), float32(dstRegion.Height) / float32(dh)}
|
||||||
|
const idx = graphics.TextureDestinationRegionSizeUniformVariableIndex
|
||||||
|
us[idx].name = fmt.Sprintf("U%d", idx)
|
||||||
|
us[idx].value = size
|
||||||
|
us[idx].typ = s.ir.Uniforms[idx]
|
||||||
|
}
|
||||||
{
|
{
|
||||||
voffsets := make([]float32, 2*len(offsets))
|
voffsets := make([]float32, 2*len(offsets))
|
||||||
for i, o := range offsets {
|
for i, o := range offsets {
|
||||||
|
14
shader.go
14
shader.go
@ -49,6 +49,20 @@ func imageSrcTextureSize() vec2 {
|
|||||||
return __textureSizes[0]
|
return __textureSizes[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The unit is the source texture's texel.
|
||||||
|
var __textureDestinationRegionOrigin vec2
|
||||||
|
|
||||||
|
// The unit is the source texture's texel.
|
||||||
|
var __textureDestinationRegionSize vec2
|
||||||
|
|
||||||
|
// imageDstRegionOnTexture returns the destination image's region (the origin and the size) on its texture.
|
||||||
|
// The unit is the source texture's texel.
|
||||||
|
//
|
||||||
|
// As an image is a part of internal texture, the image can be located at an arbitrary position on the texture.
|
||||||
|
func imageDstRegionOnTexture() (vec2, vec2) {
|
||||||
|
return __textureDestinationRegionOrigin, __textureDestinationRegionSize
|
||||||
|
}
|
||||||
|
|
||||||
// The unit is the source texture's texel.
|
// The unit is the source texture's texel.
|
||||||
var __textureSourceOffsets [%[2]d]vec2
|
var __textureSourceOffsets [%[2]d]vec2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user