partiallydisassembled.net

pyglet CSS improvements

2007-01-05 13:01:07

This week has mostly been rewriting/refactoring the layout code. Mostly this was due to me not correctly understanding CSS when I started implementing it, and some of it was because I got better ideas on how to do things. As a result of having the code match the specification more closely in terms of structure, it became far simpler to work with, and several new CSS features (borders, backgrounds) were added quite quickly and easily. Today I finished this refactoring of existing code by moving the Font/Glyph interaction with layout from Box into Frame. This will make properties like :first-line possible, and much of the layout calculation becomes simplified. I also suspect that this will simplify incremental changes to documents (though no work has started on that yet). As expected, layout is now 2-5 times slower (though box creation is faster, but that's not very interesting), but drawing is 1.5-2 times faster (due to the reduced depth of the document tree). While I like fast layout, in reality I think it's a low priority for a games-oriented toolkit.

pyglet gets CSS

2006-12-27 00:02:11

Some of it, anyway. r322 gives classes for parsing XML/XHTML + CSS 2.1 and rendering, including backgrounds and borders. Only the bare minimum is implemented so far: block and inline display elements; but dare I say the hard bit's done? I'll finish off the text attributes (line-height, text-indent, font-weight, font-style, ...) in the next couple of days, then look into float, absolute and relative displays. Parsing CSS feels slow (haven't measured it), could be improved with a hand-crafted scanner (I'm using Plex at the moment). Many parts of the grammar could be inlined to reduce function-call (of which there will be many) overhead. Layout (reflowing after resizing) is pretty quick on my desktop, and perfectly acceptable on my iBook. There's not much that can be done to speed it up. For pyglet, this will really only need to be done during content updates (I don't imagine many people using resizable windows), and incremental updates could be implemented. Display is very fast... between 35 and 75 FPS for the Frog King text (1400 words) without any optimisations. I plan to improve on this a lot, by flattening the render structure and partitioning it for view culling.

pyglet.org goes live

2006-12-18 16:01:22

The rumours are true, here's the link: pyglet.org. Thanks to Richard for providing the hosting and drawing the buttons and the cube.

pyglet: Mesa and image regressions

2006-12-09 12:44:47

Mesa rendering works now. The problem was to do with not setting a colormap on the window--indirect rendering needs to have a compatible colormap with the GLX visual. I would never have worked this out myself... extensive Googling found a thread with a similar problem on another program, Clutter, which ended with the maintainer posting "there's a fix in the trunk now". A carefully crafted svn diff on that date found exactly the patch I needed to apply to pyglet :-) A nice Gentooism that helped debug is: eselect opengl set xorg-x11 which swaps in the Mesa software rendering driver. Later I can eselect opengl set nvidia to return to the proprietary driver, all without rebooting. Test cases can now save images of themselves which are stored in a regressions directory; the next time the test runs instead of having to ask the user if it looks correct, they simply match the on-screen image with the regression image. Some tests (image.*) can use the same regression images across platforms, while others (text.*) will have to be kept separate due to inherent (desirable) rendering differences.

anthony baxter writes:

I can't remember right now - what was the suggestion you had for trying to make the ATI blob driver work with pyglet? Right now, everything fails - for instance, glGetString(GL_EXTENSIONS) (or GL_VENDOR) returns None.

Alex writes:

Make sure you have created a GL context before you call any GL functions. This should work:: from pyglet.window import * from pyglet.GL.VERSION_1_1 import * w = Window() print glGetString(GL_VENDOR)

anthony baxter writes:

It's the Window() call that's the problem: >>> from pyglet.window import * >>> from pyglet.GL.VERSION_1_1 import * >>> w = Window() Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/anthony/src/py/pyglet/pyglet/window/__init__.py", line 777, in __init__ self.switch_to() File "pyglet/window/xlib/__init__.py", line 472, in switch_to pyglet.GL.info.set_context() File "/home/anthony/src/py/pyglet/pyglet/GL/info.py", line 34, in set_context _extensions = glGetString(GL_EXTENSIONS).split() AttributeError: 'NoneType' object has no attribute 'split'

anthony baxter writes:

Damn. Try that again: <pre> from pyglet.window import * from pyglet.GL.VERSION_1_1 import * w = Window() Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/anthony/src/py/pyglet/pyglet/window/__init__.py", line 777, in __init__ self.switch_to() File "pyglet/window/xlib/__init__.py", line 472, in switch_to pyglet.GL.info.set_context() File "/home/anthony/src/py/pyglet/pyglet/GL/info.py", line 34, in set_context _extensions = glGetString(GL_EXTENSIONS).split() AttributeError: 'NoneType' object has no attribute 'split' </pre>

Alex writes:

That says to me that the context isn't being created. See pyglet/window/__init__.py line 470: check that the return value is non-zero. Above that, check that self._glx_window and self._glx_context are non-None. You could also check the return value of glXGetCurrentContext() (should be non-None after setting it).

anthony baxter writes:

Ok, it's the glXCreateWindow() call that's failing. It returns 0. All the args to it are non-null, and after the failing call, a call to glGetError() also returns 0.

Alex writes:

glGetError won't help you... it also needs a GL context, which is still unset. glXCreateWindow is probably failing because of a mismatch in config/visual attributes. This was essentially the problem with Mesa rendering (I'm assuming you are using the latest trunk that includes that fix). It is worth comparing the results of glxinfo -v with:: from pyglet.window import * f = get_factory() print f.get_matching_configs() # returns a list of XlibGLConfig instances This will be a long dump... email me off-blog perhaps? By default the first config in this list is used, but you can override with:: f.set_config(config) # where config is an XlibGLConfig

Laptop: addition

2006-12-07 21:33:45

The flicker, interferency, frozen, supernova problem is apparently the same old logic board problem that plagues all iBooks of my vintage (I remember checking serial numbers some time ago and falling outside the range, which has evidently been updated since). The replacement program is over now, but Apple have given me the part for free ($1500 value!) because they feel sorry for my having to have the same part replaced only 4.5 months ago (as far as I know, that never actually happened). So, what is old will be new again ;-)
login