Commit Graph

24 Commits

Author SHA1 Message Date
Seebs ee5d49dbd3 Push: Don't convert pixel.RGBA to pixel.RGBA
Because that's expensive, even in the case where the conversion
is trivial. Use type assertion first. Reduces runtime cost of
imdraw.Push from ~15.3% to 8.4%, so not-quite-50% of runtime
cost of pushing points.

If you were setting imd.Color to Color objects that aren't RGBA
every single point, not much help. But if you set it and then
draw a bunch of points, this will be a big win.
2017-06-10 17:56:15 -05:00
Seebs daedc45ea9 Improve normal calculations
Soooo. It turns out that the bunch of smallish (~4-5% of runtime)
loads associated with Len(), Unit(), Rotated(), and so on... Were
actually more like 15% or more of computational effort. I first
figured this out by creating:

	func (u Vec) Normal(v Vec) Vec

which gives you a vector normal to u->v. That consumed a lot
of CPU time, and was followed by .Unit().Scaled(imd.thickness / 2),
which consumed a bit more CPU time.

After some poking, and in the interests of avoiding UI cruft,
the final selection is
	func (u Vec) Normal() Vec

This returns the vector rotated 90 degrees, which turns out to
be the most common problem.
2017-06-10 17:55:16 -05:00
Seebs 678da34fc3 Slightly clean up normal calculations
We never actually need the "normal" value; it's an extra calculation
we didn't need, because ijNormal is the same value early on. It's
totally possible that we could further simplify this; there's a lot
of time going into the normal computations.
2017-06-10 10:47:22 -05:00
faiface c0766504e3 minor, mostly stylistic, changes 2017-06-09 18:13:05 +02:00
Seebs c6e7a83467 Reduce copying in fillPolygon
A slice of points means copying every point into the slice, then
copying every point's data from the slice to TrianglesData. An
array of indicies lets the compiler make better choices.
2017-06-09 10:37:47 -05:00
Seebs b6533006e7 smaller imdraw optimizations
For polyline, don't compute each normal twice; when we're going through a line,
the "next" normal for segment N is always the "previous" normal for segment
N+1, and we can compute fewer of them.
2017-06-09 10:37:47 -05:00
Seebs 9d1fc5bd1f use point pool
For internal operations (anything using getAndClearPoints), there's a
pretty good chance that the operation will repeatedly invoke something
like fillPolygon(), meaning that it needs to push "a few" points
and then invoke something that uses those points.

So, we add a slice for containing spare slices of points, and on the
way out of each such function, shove the current imd.points (as used
inside that function) onto a stack, and set imd.points to [0:0] of
the thing it was called with.

Performance goes from 11-13fps to 17-18fps on my test case.
2017-06-09 10:37:47 -05:00
faiface fcfeb200b6 replace complex128 Vec with a struct 2017-05-21 19:25:06 +02:00
faiface 022f25895a change IMDraw properties to fields 2017-05-18 23:50:45 +02:00
faiface b333cd2e0b IMDraw: change default point color to (1, 1, 1, 1) (was (0, 0, 0, 0)) 2017-05-06 22:57:55 +02:00
faiface 663727731c remove commented code 2017-04-21 16:43:56 +02:00
faiface ac61175aea fix drawing non-closed lines in IMDraw 2017-04-21 01:17:29 +02:00
faiface fc2a7a8afc simplify code in IMDraw 2017-04-16 00:59:07 +02:00
faiface 9d48c4a828 add IMDraw.Rectangle 2017-04-16 00:01:43 +02:00
faiface f0303c27af immediate-like-mode -> immediate-mode-like 2017-04-13 17:44:28 +02:00
faiface 7939b1fdb7 add imdraw package doc comment 2017-04-13 17:41:38 +02:00
faiface b2819732fc clarify IMDraw.Draw doc 2017-04-12 16:03:36 +02:00
faiface 3e65588e00 adopt RGB and Alpha 2017-04-10 17:25:56 +02:00
faiface f4916a4272 replace NRGBA to RGBA because Porter-Duff (!!!) 2017-04-09 22:00:26 +02:00
faiface 379b4df667 adopt new ToNRGBA function 2017-03-23 23:07:49 +01:00
faiface fb8424cd32 add support for one point lines in imdraw 2017-03-23 19:38:53 +01:00
faiface 4619398b9e fix 0 vector len + fix imdraw polyline 2017-03-23 19:15:06 +01:00
faiface 0585b0af8c improve imdraw doc 2017-03-22 18:53:25 +01:00
faiface 5e698c63f0 move IMDraw to separate package 2017-03-21 11:33:11 +01:00