C#OpenGLua

It’s coming together slowly. Recently Kaffeeklatsch has been enhanced with Lua, which is used for key bindings and in several effects. For example, there is a “Custom” effect that simply runs a Lua script each frame. The script gets full access to OpenGL by default, but can access any loaded .NET classes. (This could be a security problem in the future, but it’s not a major concern right now.) Key bindings simply run a Lua script that is given access to the entire effect list, allowing bindings to do anything — manipulate properties and fields, and invoke methods. So a key binding can toggle multiple effects, change colors, you name it. You can also bind a different script to a key press and a key release, allowing for tap/hit effects.

Also available is an effect called SuperScope, which users of Winamp’s AVS will immediately recognize. The implementation uses Lua, and is almost completely compatible with Winamp’s implementation. With a little work, it will be 100% compatible. At first it was unbearably slow. More than 128 points with sync at 75hz (basically 128 * 75 = 9,600 points per second) would cause a significant drop in framerate. This was due to the implementation: the “point” script was compiled once per frame, and invoked n times by C#, the relevant global variables extracted, and the vertex drawn with OpenGL, through Tao. For each point. Whew.

I decided this needed to be fixed. The solution is not pretty, but it’s very effective. I moved the point loop into Lua, and wrote a small glue library in C that exposed glColor4d and glVertex2d to Lua, effectively bypassing a .NET-to-Lua call for every point — now only once per frame. I can now get up to 2,048 vertices, 75 times per second, before performance suffers.

A beta release may be coming soon. But first I need to find the source of a bug that manages to terminate mono with no stack trace after a few minutes of rendering.

Time bombs suck.