Applecorn
Applecorn copied to clipboard
Implement proper clipping of graphics at screen edges [MODE 2, HGR]
FDraw does not behave well when one passes out-of-range coordinates.
OpenLogo and ACTLogo both have very messed up displays, which I think is a consequence of the improper clipping method.
Need an efficient way to do this.
We can do better in SHR mode, where we have 100% control over all the code.
Have implemented extremely stupid clipping in SHR mode - it checks each point is within the window before plotting it. Performance sucks less than one might imagine. I have yet to find a clever algorithm (Cohen Sutherland etc.) that doesn't require accurate division.
So, a simple optimization to the el stupido clipping algorithm occurred to me. Not sure how much it improves things. The basic method I am using is to check every single point is within the graphics window (which is four 16 bit comparisons, in 16 bit native mode.) However, it seems better to check the bounds of each point when it is first submitted to the graphics subsystem via PLOT (MOVE, DRAW are shortcuts into PLOT with appropriate options ... it is all PLOT really). Then for lines, we can short-circuit the point-by-point within bounds check if both end points were within the window (which I would expect is almost always the case, in the real world.) It is still inefficient in that if any part of the line needs to be clipped, it looks at every point still, and maybe that can be improved with something a bit more Cohen Sutherland-ish. but this is a start, and probably makes the average case faster.
I implemented this simple optimization idea but it didn't help with performance appreciably so I reverted it.
I also tested the impact of the boundary checking of every single point ... and found it to be about 5% at most, for lines which are within the region (so the test always passes.) So it may not be worth making too much effort here. Perhaps it is 'good enough.'
The clipping still has some flaws. This: MOVE 500,500:DRAW 500,1600:DRAW 1600,500:DRAW 500,500 should draw a triangle where half of it is missing off the screen. Instead it clamps the cords to the screen edge and draws a triangle fully within the screen, instead of clipping to the screen edge. Looking at the code it's going to take a bit of thought to work it out. In the meantime, I'll upload a test program to test for correct functionality.
Gaffaw! The clipping is definitely dodgy! https://mdfs.net/Software/BBCBasic/Apple/img/demo13.gif
LOL!
There is no clipping in MODE 2
. Try MODE 0
or MODE 1
.
In general MODE 2
is pretty rubbish, and we rely on an external library which makes it harder to fix.
MODE 0
and MODE 1
are all my code, which at least means I understand it :)
Also VDU 24
is not implemented at all in MODE 2
. (It's implemented for for modes 0 and 1.)
On 22-01-2023 17:50, Bobbi Webber-Manners wrote:
There is no clipping in MODE 2. Try MODE 0 or MODE 1. In general MODE 2 is pretty rubbish, and we rely on an external library which makes it harder to fix.
Yes, I was looking at the code last Christmas (as in 13 months ago!).
MODE 0 and MODE 1 are all my code, which at least means I understand it :)
I haven't looked at it in enough detail to understand it. I was reading through it yesterday and got lost. ;)
-- J.G.Harston - @.*** - mdfs.net/jgh
The clipping in MODE 0
/ MODE 1
is very simple minded. I don't do Cohen Sutherland or anything clever ... simply check every point is within the window when I plot it. You would think this would be very slow (and in fairness, my line drawing is not super fast) but I found that removing the bounds check on each point plotted made little difference. (If I was going to speed things up I think special cases for horiz and vertical lines would be more effective.)