A Technical Post on Acorn 4.2
  • Apparently I'm turning this forum into a personal dev journal of sorts. I guess that works.

    Acorn 4.2 is out, and I thought it might be fun to talk about a couple of interesting things that were put into Acorn, but from the implementation side (aka, this is going to be a technical post).

    #### OpenGL Stuff

    All the pixels are now going through OpenGL. This involved having the main canvas class subclass NSOpenGLView, tweaking the Core Image Contexts that everything renders through, updating how all the Core Graphics calls happen (since Acorn no longer has a CGContext to draw to), and then fixing all the bugs that showed up.

    Mixing the CG calls into everything wasn't too hard, but it was a lot of work making everything fit into the new way of drawing. I ended up taking some sample Apple code and hacking it up quite a bit to make it do what I want as a proof of concept. I then shared it with the world up here:
    https://github.com/ccgus/FMMicroPaintPlus

    (Trivia: Acorn now does a hybrid of hardware accelerated graphics with cpu contexts. I'll have more to talk about this at a later day… hopefully.)

    Even though I'm much more comfortable with OpenGL these days, I still consider myself very wet behind the ears when it comes to it. Getting everything drawing correctly, and making it happen fast at the same time was a bit of a challenge. This was especially true when it came to drawing to Retina displays.

    You'd think it would just automatically work- but it seems that even though Core Image is happy to render through OpenGL, it really has a mind of its own.

    I tried a couple of ways to get rendering to happen correctly with retina - one technique was to draw to an IOSurface first, and then blit that to whatever OpenGL was currently drawing to. In theory, this meant I could also do things asynchronously as well- but the extra compositing was a cost I didn't want to deal with at the time. Maybe at a later date if it makes sense?

    In the end, I ended up using glViewport to make a surface to draw to big enough to encompass everything showing in the window. And just doubled that up if it's on a retina display. Seems obvious, but getting CI to play with it nicely was a bit work- mostly tweaking settings here and there till you hit the magic numbers.

    #### New Text Rendering

    One of the causalities of going OpenGL was that the normal drawing hierarchy was thrown out the window (which was why I had to make the CG surface stuff mentioned above). This also meant that text views wouldn't draw correctly when you edited a text field.

    In the past when you started editing some text, Acorn would make a field editor for you, which was then owned by the window - and it would handle the drawing. This is also why when you were zoomed in on an image the the point where you'd see blocky text, and then you began editing it, that it would then turn super smooth. The text wasn't actually drawing inside the canvas - it was drawing over it.

    Well that bit is gone. Now Acorn draws the text through the canvas, so it can go up through the GL pipeline correctly. The upshot of this is that if you have gradients on text, or layer styles set - those are visible while you are editing your text! This is pretty cool, and something I've been wanting to do for a looong time, but didn't have a good enough reason to do this.

    (Someone is going to mention "hey- why didn't you make your canvas layer backed?". That was a whole other can of worms…)

    #### Radial Gradient Blur

    The new "Radial Gradient Blur" filter is a new way to add depth of focus to an image. Sort of.

    Here's how it works.
    1) Take the layer and blur it.
    2) Take a black and white radial gradient, which will be used as a mask.
    3) Blend the blurred image on top of the original image, using the the radial gradient as a mask.

    Tada - fancy depth of focus / blurring. Here's a little image that explains it visually:

    http://gusmueller.com/stuff/how_radial_graident_blur_works.jpeg

    Anyway, those are a couple of my favorite technical things that showed up in Acorn 4.2.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID