Compare commits

..

No commits in common. "435c8b75ebc001f3d1afda243bbe68ba3cfe38d1" and "b6ab7a10c1f57218499ced930a881ef1738af946" have entirely different histories.

3 changed files with 28 additions and 39 deletions

View File

@ -345,7 +345,7 @@ func (i *Image) ensureIsolatedFromSource(backends []*backend) {
w, h := float32(i.width), float32(i.height) w, h := float32(i.width), float32(i.height)
vs := make([]float32, 4*graphics.VertexFloatCount) vs := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, w, h, 0, 0, w, h, 1, 1, 1, 1) graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphics.QuadIndices() is := graphics.QuadIndices()
dr := image.Rect(0, 0, i.width, i.height) dr := image.Rect(0, 0, i.width, i.height)
@ -376,7 +376,7 @@ func (i *Image) putOnSourceBackend() {
w, h := float32(i.width), float32(i.height) w, h := float32(i.width), float32(i.height)
vs := make([]float32, 4*graphics.VertexFloatCount) vs := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, w, h, 0, 0, w, h, 1, 1, 1, 1) graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphics.QuadIndices() is := graphics.QuadIndices()
dr := image.Rect(0, 0, i.width, i.height) dr := image.Rect(0, 0, i.width, i.height)
newI.drawTriangles([graphics.ShaderSrcImageCount]*Image{i}, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillRuleFillAll) newI.drawTriangles([graphics.ShaderSrcImageCount]*Image{i}, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillRuleFillAll)

View File

@ -52,7 +52,7 @@ func TestUnsyncedPixels(t *testing.T) {
// Flush unsynced pixel cache. // Flush unsynced pixel cache.
src := buffered.NewImage(16, 16, atlas.ImageTypeRegular) src := buffered.NewImage(16, 16, atlas.ImageTypeRegular)
vs := make([]float32, 4*graphics.VertexFloatCount) vs := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, 16, 16, 0, 0, 16, 16, 1, 1, 1, 1) graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, 16, 16, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphics.QuadIndices() is := graphics.QuadIndices()
dr := image.Rect(0, 0, 16, 16) dr := image.Rect(0, 0, 16, 16)
sr := [graphics.ShaderSrcImageCount]image.Rectangle{image.Rect(0, 0, 16, 16)} sr := [graphics.ShaderSrcImageCount]image.Rectangle{image.Rect(0, 0, 16, 16)}

View File

@ -53,14 +53,14 @@ func (a *arrayBufferLayout) names() []string {
return ns return ns
} }
// float32Count returns the total float32 count for one element of the array buffer. // totalBytes returns the size in bytes for one element of the array buffer.
func (a *arrayBufferLayout) float32Count() int { func (a *arrayBufferLayout) totalBytes() int {
if a.total != 0 { if a.total != 0 {
return a.total return a.total
} }
t := 0 t := 0
for _, p := range a.parts { for _, p := range a.parts {
t += p.num t += floatSizeInBytes * p.num
} }
a.total = t a.total = t
return a.total return a.total
@ -71,10 +71,10 @@ func (a *arrayBufferLayout) enable(context *context) {
for i := range a.parts { for i := range a.parts {
context.ctx.EnableVertexAttribArray(uint32(i)) context.ctx.EnableVertexAttribArray(uint32(i))
} }
total := a.float32Count() total := a.totalBytes()
offset := 0 offset := 0
for i, p := range a.parts { for i, p := range a.parts {
context.ctx.VertexAttribPointer(uint32(i), int32(p.num), gl.FLOAT, false, int32(floatSizeInBytes*total), offset) context.ctx.VertexAttribPointer(uint32(i), int32(p.num), gl.FLOAT, false, int32(total), offset)
offset += floatSizeInBytes * p.num offset += floatSizeInBytes * p.num
} }
} }
@ -88,39 +88,28 @@ func (a *arrayBufferLayout) disable(context *context) {
} }
// theArrayBufferLayout is the array buffer layout for Ebitengine. // theArrayBufferLayout is the array buffer layout for Ebitengine.
var theArrayBufferLayout arrayBufferLayout var theArrayBufferLayout = arrayBufferLayout{
// Note that GL_MAX_VERTEX_ATTRIBS is at least 16.
parts: []arrayBufferLayoutPart{
{
name: "A0",
num: 2,
},
{
name: "A1",
num: 2,
},
{
name: "A2",
num: 4,
},
},
}
func init() { func init() {
theArrayBufferLayout = arrayBufferLayout{ vertexFloatCount := theArrayBufferLayout.totalBytes() / floatSizeInBytes
// Note that GL_MAX_VERTEX_ATTRIBS is at least 16. if graphics.VertexFloatCount != vertexFloatCount {
parts: []arrayBufferLayoutPart{ panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatCount, vertexFloatCount))
{
name: "A0",
num: 2,
},
{
name: "A1",
num: 2,
},
{
name: "A2",
num: 4,
},
},
}
n := theArrayBufferLayout.float32Count()
if n > graphics.VertexFloatCount {
panic("opengl: the array buffer layout is too large")
}
if n < graphics.VertexFloatCount {
d := graphics.VertexFloatCount - n
if d > 4 {
panic("opengl: the array buffer layout is too small")
}
theArrayBufferLayout.parts = append(theArrayBufferLayout.parts, arrayBufferLayoutPart{
name: "A3",
num: d,
})
} }
} }