Exemple #1
0
func (b *blitter) blitShape(ctx *context, shape shape, color gxui.Color, ds *drawState) {
	b.commitGlyphs(ctx)
	dipsToPixels := ctx.resolution.dipsToPixels()
	dw, dh := ctx.sizePixels.WH()
	mPos := math.CreateMat3(
		+2.0*dipsToPixels/float32(dw), 0, 0,
		0, -2.0*dipsToPixels/float32(dh), 0,
		-1.0+2.0*float32(ds.OriginPixels.X)/float32(dw),
		+1.0-2.0*float32(ds.OriginPixels.Y)/float32(dh), 1,
	)

	shape.draw(ctx, b.colorShader, uniformBindings{
		"mPos":  mPos,
		"Color": color,
	})

	if debugWireframePolygons {
		// glPolygonMode is not available in OpenGL ES/WebGL (since its implementation is very inefficient; a shame because it's useful for debugging).
		//gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
		shape.draw(ctx, b.colorShader, uniformBindings{
			"mPos":  mPos,
			"Color": gxui.Blue,
		})
		//gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
	}
	b.stats.drawCallCount++
}
Exemple #2
0
func (b *blitter) commitGlyphs(ctx *context) {
	tc := b.glyphBatch.GlyphPage
	if tc == nil {
		return
	}
	sw, sh := tc.sizePixels.WH()
	dw, dh := ctx.sizePixels.WH()

	mSrc := math.CreateMat3(
		1.0/float32(sw), 0, 0,
		0, 1.0/float32(sh), 0,
		0.0, 0.0, 1,
	)
	mDst := math.CreateMat3(
		+2.0/float32(dw), 0, 0,
		0, -2.0/float32(dh), 0,
		-1.0, +1.0, 1,
	)
	vb := newVertexBuffer(
		newVertexStream("aDst", stFloatVec2, b.glyphBatch.DstRects),
		newVertexStream("aSrc", stFloatVec2, b.glyphBatch.SrcRects),
		newVertexStream("aClp", stFloatVec4, b.glyphBatch.ClipRects),
		newVertexStream("aCol", stFloatVec4, b.glyphBatch.Colors),
	)
	ib := newIndexBuffer(ptUshort, b.glyphBatch.Indices)
	s := newShape(vb, ib, dmTriangles)
	gl.Disable(gl.SCISSOR_TEST)
	s.draw(ctx, b.fontShader, uniformBindings{
		"source": tc,
		"mDst":   mDst,
		"mSrc":   mSrc,
	})
	gl.Enable(gl.SCISSOR_TEST)
	s.release()
	b.glyphBatch.GlyphPage = nil
	b.glyphBatch.DstRects = b.glyphBatch.DstRects[:0]
	b.glyphBatch.SrcRects = b.glyphBatch.SrcRects[:0]
	b.glyphBatch.ClipRects = b.glyphBatch.ClipRects[:0]
	b.glyphBatch.Colors = b.glyphBatch.Colors[:0]
	b.glyphBatch.Indices = b.glyphBatch.Indices[:0]
	b.stats.drawCallCount++
}
Exemple #3
0
func (b *blitter) blit(ctx *context, tc *textureContext, srcRect, dstRect math.Rect, ds *drawState) {
	b.commitGlyphs(ctx)

	dstRect = dstRect.Offset(ds.OriginPixels)
	sw, sh := tc.sizePixels.WH()
	dw, dh := ctx.sizePixels.WH()

	var mUV math.Mat3
	if tc.flipY {
		mUV = math.CreateMat3(
			float32(srcRect.W())/float32(sw), 0, 0,
			0, -float32(srcRect.H())/float32(sh), 0,
			float32(srcRect.Min.X)/float32(sw),
			1.0-float32(srcRect.Min.Y)/float32(sh), 1,
		)
	} else {
		mUV = math.CreateMat3(
			float32(srcRect.W())/float32(sw), 0, 0,
			0, float32(srcRect.H())/float32(sh), 0,
			float32(srcRect.Min.X)/float32(sw),
			float32(srcRect.Min.Y)/float32(sh), 1,
		)
	}
	mPos := math.CreateMat3(
		+2.0*float32(dstRect.W())/float32(dw), 0, 0,
		0, -2.0*float32(dstRect.H())/float32(dh), 0,
		-1.0+2.0*float32(dstRect.Min.X)/float32(dw),
		+1.0-2.0*float32(dstRect.Min.Y)/float32(dh), 1,
	)
	if !tc.pma {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	}
	b.quad.draw(ctx, b.copyShader, uniformBindings{
		"source": tc,
		"mUV":    mUV,
		"mPos":   mPos,
	})
	if !tc.pma {
		gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
	}
	b.stats.drawCallCount++
}
Exemple #4
0
func (b *blitter) blitRect(ctx *context, dstRect math.Rect, color gxui.Color, ds *drawState) {
	b.commitGlyphs(ctx)
	dstRect = dstRect.Offset(ds.OriginPixels)
	dw, dh := ctx.sizePixels.WH()
	mPos := math.CreateMat3(
		+2.0*float32(dstRect.W())/float32(dw), 0, 0,
		0, -2.0*float32(dstRect.H())/float32(dh), 0,
		-1.0+2.0*float32(dstRect.Min.X)/float32(dw),
		+1.0-2.0*float32(dstRect.Min.Y)/float32(dh), 1,
	)

	b.quad.draw(ctx, b.colorShader, uniformBindings{
		"mPos":  mPos,
		"Color": color,
	})
	b.stats.drawCallCount++
}