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)
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()
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)
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()
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)

View File

@ -52,7 +52,7 @@ func TestUnsyncedPixels(t *testing.T) {
// Flush unsynced pixel cache.
src := buffered.NewImage(16, 16, atlas.ImageTypeRegular)
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()
dr := 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
}
// float32Count returns the total float32 count for one element of the array buffer.
func (a *arrayBufferLayout) float32Count() int {
// totalBytes returns the size in bytes for one element of the array buffer.
func (a *arrayBufferLayout) totalBytes() int {
if a.total != 0 {
return a.total
}
t := 0
for _, p := range a.parts {
t += p.num
t += floatSizeInBytes * p.num
}
a.total = t
return a.total
@ -71,10 +71,10 @@ func (a *arrayBufferLayout) enable(context *context) {
for i := range a.parts {
context.ctx.EnableVertexAttribArray(uint32(i))
}
total := a.float32Count()
total := a.totalBytes()
offset := 0
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
}
}
@ -88,10 +88,7 @@ func (a *arrayBufferLayout) disable(context *context) {
}
// theArrayBufferLayout is the array buffer layout for Ebitengine.
var theArrayBufferLayout arrayBufferLayout
func init() {
theArrayBufferLayout = arrayBufferLayout{
var theArrayBufferLayout = arrayBufferLayout{
// Note that GL_MAX_VERTEX_ATTRIBS is at least 16.
parts: []arrayBufferLayoutPart{
{
@ -108,19 +105,11 @@ func init() {
},
},
}
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,
})
func init() {
vertexFloatCount := theArrayBufferLayout.totalBytes() / floatSizeInBytes
if graphics.VertexFloatCount != vertexFloatCount {
panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatCount, vertexFloatCount))
}
}