<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Neil's Blog</title>
    <link>http://www.busydoingnothing.co.uk/blog/</link>
    <description>Neil's unimaginative blog</description>
    <language>en</language>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <generator>blosxom/2.1.2</generator>

  <item>
    <title>Cogl Shader Snippets</title>
    <pubDate>Wed, 07 Dec 2011 22:37:00 +0000</pubDate>
    <link>http://www.busydoingnothing.co.uk/blog/2011/12/07#cogl-shader-snippets</link>
    <category>/gnomable</category>
    <guid isPermaLink="false">http://www.busydoingnothing.co.uk/blog/gnomable/cogl-shader-snippets</guid>
    <description>
&lt;p&gt;
Cogl has been getting some love lately to move towards the 2.0 API
that will eventually replace the existing API. Now that Cogl has split
out from Clutter and it can be used as a standalone library we are
getting close to the goal of Cogl being a convenient replacement for
OpenGL. However one thing that until recently has been severely
lacking for Cogl to be a credible modern graphics library is good
support for shaders. Cogl has had a sort of shader support for a long
time but it has hardly been touched since the days when Cogl was just
a very thin wrapper over the GL API. Cogl has evolved a lot since then
so the previous shader support no longer fits with Cogl&apos;s design.
&lt;/p&gt;

&lt;p&gt;
We&apos;ve finally got around to improving this situation so there are now
a few changes in git master of Cogl to make this better. In 2.0 land,
instead of having to create a CoglProgram to replace the entire of
either the vertex or fragment pipeline you can now create
CoglSnippets. These can be inserted at specific hook points on a
CoglPipeline to either wrap around or completely replace a part of the
pipeline. For example, imagine we have a function in GLSL that can
take an input colour and convert it to black-and-white. If we wanted to
use this in Cogl we would previously have had to implement the entire
fragment pipeline. Usually this would mean having to create a sampler
uniform, update that uniform and writing the code to get a texel from
the sampler. If we wanted to use this shader in another situation
without texturing, for example when drawing a solid colour rectangle,
we would have to write another shader that includes the function
without the texturing.
&lt;/p&gt;

&lt;p&gt;
With the snippets API we can now create an object that just contains
the black-and-white conversion in a single line, like this:
&lt;/p&gt;

&lt;pre&gt;
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                            NULL,
                            &quot;cogl_color_out.rgb = &quot;
                            &quot;vec3 (length (cogl_color_out.rgb) / 1.732);&quot;);
&lt;/pre&gt;

&lt;p&gt;
Then we can attach that snippet to any CoglPipeline and Cogl will fill
in the rest of the code needed to make it work. It can be attached to
multiple pipelines, for example one with texturing and one without.
&lt;/p&gt;

&lt;p&gt;
The second feature that has landed recently is to be able to store
uniform values on a CoglPipeline. The idea behind the design of Cogl
is that you will store as much of the GL state as possible in a
CoglPipeline object and try to switch between these cached states
rather than redescribing the state to the graphics library every time
something is drawn. That way Cogl can minimise the state changes by
recognising the minimal set of differences between two pipelines. The
previous approach for uniforms - which was the same as OpenGL where
the uniform values are attached to the program object - doesn&apos;t match
well to this design. If you wanted to use a program multiple times
with different values then you would have to reset the values on the
program for every primitive.
&lt;/p&gt;

&lt;p&gt;
In Cogl master you can instead encapsulate these uniform values on the
pipeline and Cogl can efficiently recognise which uniforms are
different between two pipelines sharing the same program and avoid
flushing uniforms that haven&apos;t changed. For example, imagine this
snippet which just replaces the red component of the fragment colour
based on the value of a uniform:
&lt;/p&gt;

&lt;pre&gt;
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
                            &quot;uniform float red_value;&quot;,
                            &quot;cogl_color_out.r = red_value;&quot;);
pipeline = cogl_pipeline_new ();
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);
&lt;/pre&gt;

&lt;p&gt;
Now if we want to frequently paint using this snippet with two
different values, we can create two pipelines like this:
&lt;/p&gt;

&lt;pre&gt;
pipeline1 = cogl_pipeline_copy (pipeline);
location = cogl_pipeline_get_uniform_location (pipeline, &quot;red_value&quot;);
cogl_pipeline_set_uniform_1f (pipeline1, location, 0.5f);

pipeline2 = cogl_pipeline_copy (pipeline);
location = cogl_pipeline_get_uniform_location (pipeline, &quot;red_value&quot;);
cogl_pipeline_set_uniform_1f (pipeline2, location, 0.8f);
&lt;/pre&gt;

&lt;p&gt;
Now we can draw with these two pipelines easily:
&lt;/p&gt;

&lt;pre&gt;
cogl_push_source (pipeline1);
cogl_rectangle (0, 0, 10, 10);
cogl_pop_source ();

cogl_push_source (pipeline2);
cogl_rectangle (10, 10, 20, 20);
cogl_pop_source ();
&lt;/pre&gt;

&lt;p&gt;
Cogl will quickly know that the two pipelines are using the same
program because they are copied from the same parent so it will only
flush the state for the new uniform value when switching between the
two.
&lt;/p&gt;

&lt;p&gt;
The third recent addition to Cogl related to shaders is support for
custom attributes. The API has already been in place for this for a
while from both CoglPrimitive and the now deprecated
CoglVertexBuffer. However it was never actually connected together
properly so no-one could use it. The custom attributes can be set by
just naming them when a CoglAttribute is created. Here is a short
example:
&lt;/p&gt;

&lt;pre&gt;
/* Create a pipeline with a snippet using a custom attribute. This
   will just replace the red component of the colour using a float */
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
                            &quot;attribute float redness;&quot;,
                            &quot;cogl_color_out.r = redness;&quot;);
pipeline = cogl_pipeline_new ();
cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet);

/* Create a primitive with two attributes. One will be our custom
   attribute and the other will be the normal position attribute */
static const float verts[] = { 0, 0, 0.0,
                               100, 0, 0.5,
                               50, 100, 1.0 };
CoglAttributeBuffer *buffer =
 cogl_attribute_buffer_new (sizeof (verts), verts);
CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (buffer,
                                    &quot;cogl_position_in&quot;,
                                    /* Stride */
                                    sizeof (float) * 3,
                                    /* Offset */
                                    0,
                                    /* n_components */
                                    2,
                                    COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[1] = cogl_attribute_new (buffer,
                                    &quot;redness&quot;,
                                    /* Stride */
                                    sizeof (float) * 3,
                                    /* Offset */
                                    sizeof (float) * 2,
                                    /* n_components */
                                    1,
                                    COGL_ATTRIBUTE_TYPE_FLOAT);
primitive =
  cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
                                      3, /* n_vertices */
                                      attributes,
                                      2 /* n_attributes */);
cogl_object_unref (attributes[0]);
cogl_object_unref (attributes[1]);
cogl_object_unref (buffer);

/* Now we can draw with this primitive and pipeline */
cogl_push_source (pipeline);
cogl_primitive_draw (primitive);
cogl_pop_source ();
&lt;/pre&gt;

&lt;p&gt;
I&apos;ve uploaded the current documentation to a &lt;a
href=&quot;http://www.busydoingnothing.co.uk/cogl-doc/cogl-2.0-experimental-Shader-snippets.html&quot;&gt;
temporary location&lt;/a&gt; if you want further details of the API. It&apos;s
all still experimental so we&apos;d very much welcome any testing and
feedback. The Cogl developers can be contacted on the new &lt;a
href=&quot;http://groups.google.com/group/cogl3d&quot;&gt;mailing list&lt;/a&gt; or at
#clutter on GIMPnet.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>gtk-im-extra</title>
    <pubDate>Thu, 17 Nov 2011 01:13:00 +0000</pubDate>
    <link>http://www.busydoingnothing.co.uk/blog/2011/11/17#gtk-im-extra</link>
    <category>/gnomable</category>
    <guid isPermaLink="false">http://www.busydoingnothing.co.uk/blog/gnomable/gtk-im-extra</guid>
    <description>
&lt;p&gt;
Is anybody else using &lt;a
href=&quot;http://gtk-im-extra.sourceforge.net/&quot;&gt;gtk-im-extra&lt;/a&gt;? If so
you might be interested to know I&apos;ve made a &lt;a
href=&quot;http://git.busydoingnothing.co.uk/cgit.cgi/gtk-im-extra.git/&quot;&gt;git
repo&lt;/a&gt; (it&apos;s currently still in CVS!) and added some patches to make
it build with GTK+3. It would be really great if someone would get
this into a Fedora package so I don&apos;t have to keep building it.
&lt;/p&gt;

&lt;pre&gt;
 git clone git://git.busydoingnothing.co.uk/gtk-im-extra
&lt;/pre&gt;</description>
  </item>
  <item>
    <title>Esperantaj domajnnomoj</title>
    <pubDate>Thu, 29 Sep 2011 14:25:00 +0100</pubDate>
    <link>http://www.busydoingnothing.co.uk/blog/2011/09/29#esperantaj_domajnnomoj</link>
    <category></category>
    <guid isPermaLink="false">http://www.busydoingnothing.co.uk/blog/esperantaj_domajnnomoj</guid>
    <description>
&lt;p&gt;
Antaŭ ne longe mi tre volis registri domajnnomon kiu havas esperantajn
literojn. Mi ne scias kial sed mi simple volis. Tio eblas pro IDN
(internacigitaj domajnnomojn). Ekzemple, per tio ekzistas la
domajnnomon &lt;a href=&quot;http://müller.info/&quot;&gt;http://müller.info/&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Tamen estas problemo pri sekureco kun IDN. Ekzemple, oni povus
registri la adreson &lt;a
href=&quot;http://pаypаl.com/&quot;&gt;http://pаypаl.com/&lt;/a&gt;. La literoj ‘а’ en
tiu ligilo ne estas same kiel la latina litero ‘a’ kiun oni kutime
uzas en esperanto sed ĝi estas la rusa litero. Do ĝi estas tute alia
retejo ol la oficiala paypal.com sed ĝi aspektas same. La retumiloj
evitas tiun problemon per montri la adreson per alia aspekto kiu tute
ne estas konfuzebla. Ekzemple, en Firefox tiu ligilo aspektas kiel
“http://xn--pypl-53dc.com/” en la adresbreto.
&lt;/p&gt;

&lt;p&gt;
Firefox inkluzivas liston de supraj retregionoj al kiuj ĝi permesos
montri la internaciajn literojn. Ĝi ne inkluzivas adresojn ĉe .com ĉar
la organizo kiu estras tiun retregionon permesas ion ajn adreson do ĝi
estas tre malsekura. Aliaj organizoj permesas nur la literojn de
kelkaj lingvoj kaj malpermesas nomojn kiuj evidente estas trompaj. La
listo de nomoj kun tia bona organizo nun en Firefox estas: .ac, .ar,
.asia, .at, .biz, .br, .cat, .ch, .cl, .cn, .de, .dk, .es, .fi, .gr,
.hu, .il, .info, .io, .ir, .is, .jp, .kr, .li, .lt, .lu, .lv, .museum,
.no, .nz, .org, .pl, .pr, .se, .sh, .tel, .th, .tm, .tw, .ua kaj
.vn. La plejmulto el ili estas uzata por iu specifa lando kaj la
organizo nur akceptas la lingvon de tiu lando. Kaj ofte tiaj organizoj
eĉ ne permesas registrojn de homoj kiuj ne loĝas en tiuj landoj.
&lt;/p&gt;

&lt;p&gt;
Interesa escepto estas &lt;a
href=&quot;http://www.nic.io/IO-IDN-Policy.pdf&quot;&gt;.io&lt;/a&gt;. Tiu nomo apartenas
al la Brita Hindoceana Teritorio sed ĝi permesas registrojn de iu
ajn. Plej interesa estas ke ili specife permesas esperantajn literojn!
Ekzemple estus amuze registri &lt;a
href=&quot;http://suŝ.io/&quot;&gt;http://suŝ.io/&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Verŝajne la plej utila por esperantio el tiuj retregiono estus
.org. Tamen &lt;a href=&quot;http://www.pir.org/why/global/idn&quot;&gt;la organizo
por tio&lt;/a&gt; ne permesas esperantajn literojn. La nuraj lingvoj kiujn
ili akceptas estas la dana, germana, hungara, islanda, korea, latvia,
litovia, pola, hispana, sveda kaj ĉina. Do mia peto al la esperanta
komuno estas ke ni kune petu al .org ke ili permesu esperantajn
literojn. Eble iu esperanta organizo kiel UEA aŭ E@I povos fari
oficialan leteron al ili? Ĉu iu havas proponon por helpi tion?
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Gemelo</title>
    <pubDate>Mon, 11 Jul 2011 07:50:00 +0100</pubDate>
    <link>http://www.busydoingnothing.co.uk/blog/2011/07/11#gemelo</link>
    <category>/gnomable</category>
    <guid isPermaLink="false">http://www.busydoingnothing.co.uk/blog/gnomable/gemelo</guid>
    <description>
&lt;p&gt;
This year I have been taking French lessons in the evenings and it&apos;s
given me the language learning bug. The tricky part so far has been
finding people to practice the language with. As I am still too
chicken to speak to real people, I thought it might be fun to try
something like &lt;a href=&quot;http://omegle.com/&quot;&gt;Omegle&lt;/a&gt; which lets you
talk to random strangers. There is a sleazy &lt;a
href=&quot;http://roulettechat.fr&quot;&gt;French equivalent&lt;/a&gt; but most of the
conversations go like this:
&lt;/p&gt;

&lt;b&gt;Partenaire&lt;/b&gt; : bonsoir&lt;br&gt;
&lt;b&gt;Vous&lt;/b&gt; : bonsoir&lt;br&gt;
&lt;b&gt;Partenaire&lt;/b&gt; : h ou f&lt;br&gt;
&lt;b&gt;Vous&lt;/b&gt; : je suis un homme&lt;br&gt;
&lt;i&gt;Votre partenaire a mis fin à la conversation ;-(&lt;/i&gt;&lt;br&gt;

&lt;p&gt;
I was thinking it would be fun to make a similar website but that is
specifically designed for language learning so that people can expect
beginners of the languages to use the service too. Some quick hacking
later and &lt;a href=&quot;http://gemelo.org/&quot;&gt;Gemelo&lt;/a&gt; is born. It is
basically working but it&apos;s currently quite ugly and it only supports
three languages. It hardly gets any traffic at the moment so it is
unlikely that you&apos;ll find someone to talk to there unless you ask a
friend to join at the same time.
&lt;/p&gt;

&lt;p&gt;
The server is written as a custom HTTP server in C using GLib. I know
that sounds a bit silly considering there are many existing libraries
to a web service, but I really wanted to make each connection as
light-weight as possible so that it could potentially handle 1000s of
simultaneous connections. It is using a single thread model with epoll
instead of the glib main context so that it scales by the amount of
traffic instead of the amount of connections.
&lt;/p&gt;

&lt;p&gt;
The code is all &lt;a
href=&quot;http://git.busydoingnothing.co.uk/cgit.cgi/gemelo.git/&quot;&gt;available
in Git&lt;/a&gt;. So far I haven&apos;t been able to drum up much interest in the
project so it might turn out to be a stupid idea. However if anyone
wants to contribute it would be much appreciated, particularly if
someone wants to make it look pretty or translate it to more
languages. Also the code might be useful to someone as a base
lightweight HTTP server for something else.
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Embedded linked lists</title>
    <pubDate>Thu, 16 Jun 2011 18:19:00 +0100</pubDate>
    <link>http://www.busydoingnothing.co.uk/blog/2011/06/16#embedded-linked-list</link>
    <category>/gnomable</category>
    <guid isPermaLink="false">http://www.busydoingnothing.co.uk/blog/gnomable/embedded-linked-list</guid>
    <description>
&lt;p&gt;
GLib already has a pretty cool linked list implementation that
everyone knows very well. It works by slice allocating small list
nodes that each contain a void* pointer to some other data
structure. This is convenient to use and it works well. However there
are some situations where the implementation of the thing being listed
is very closely tied to some list that is referring to it. For
example, in the GdkWindow struct there is this:
&lt;/p&gt;

&lt;pre&gt;
 struct _GdkWindow
 {
   /* ... */

   GdkWindow *parent;

   /* ... */

   GList *children;
 };
&lt;/pre&gt;

&lt;p&gt;
In this case the idea of listing the child windows of a window is
intrinsic to the implementation of a GdkWindow. The implementation
itself owns the list. Almost every GdkWindow belongs to a list of
children so there is almost always this extra list node being
allocated in addition to the GdkWindow struct. A window can only ever
have one parent so it will only ever belong to one of these lists. If
we know we&apos;re always going to allocate a list node for the window, why
don&apos;t we just put the list node directly in the struct? Then we have
something like this:
&lt;/p&gt;

&lt;pre&gt;
 struct _GdkWindow
 {
   /* ... */

   GdkWindow *parent;

   GdkWindow *next_sibling;
   GdkWindow *prev_sibling;

   GdkWindow *first_child;
 };
&lt;/pre&gt;

&lt;p&gt;
This is starting to look much more like a DOM style tree
structure. The major benefit of this is now if we want to know the
siblings of a window we can just directly look at the pointers in its
data structure. When the sibling pointers are stored in a separate
GList allocation there is no simple way to get a pointer to the list
node so we can&apos;t easily determine the siblings. This is an annoying
problem for implementing g_list_remove because it needs to iterate the
entire list to find the node that corresponds to the data pointer. For
something like GdkWindow this is not good because it frequently uses
g_list_remove to reorganise the window list for example in
gdk_window_raise.
&lt;/p&gt;

&lt;p&gt;
The downside of embedding the prev/next pointers directly is that you
can no longer use the nice GList API to manipulate the list and
instead you have to update the pointers manually. This can be quite
fiddly and it can be easy to forget to update one of the prev pointers
which can sometimes cause hidden confusing bugs.
&lt;/p&gt;

&lt;p&gt;
I think it would make sense to have something in GLib itself to help
applications use this embedded list approach so that we don&apos;t have to
have home-grown implementations spread all over Gnome. I&apos;ve opened a
bug about this here:
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://bugzilla.gnome.org/show_bug.cgi?id=652587&quot;&gt;
  https://bugzilla.gnome.org/show_bug.cgi?id=652587
 &lt;/a&gt;

&lt;p&gt;
I have two suggestions. One is to steal the embedded list
implementation from the FreeBSD kernel. This is implemented as a short
series of macros in a single header. It makes it very convenient to
code in terms of the pointers to the objects themselves rather than
having to pass the list node pointers to the list API. The second
suggestion is to add some extra functions to the g_list_* API to make
it convenient to directly add GList nodes inline to another
struct. The downside of this is that the data pointer in the node is
then redundant but it may be a better fit for the existing style of
GLib API.
&lt;/p&gt;

&lt;p&gt;
The bug so far doesn&apos;t seem to be getting much traction. I know
however that a fair few Gnome projects are already using their own
embedded list implementations so I&apos;m sure there must be others
interested in this idea. Please help and comment on the bug if you are
interested! Thanks.
&lt;/p&gt;</description>
  </item>
  </channel>
</rss>

