Saturday, June 23, 2012

Simple Multitouch on Windows

Quickliy coded a dll (packaged as a Game Maker extension here, but can be used with any HWND) that gives a simple interface to multi touch handling on Windows.

All source files included.


Friday, June 15, 2012

NVIDIA GPU-accelerated Path / SVG Vector Graphics Rendering

This definitely needs attention:

(video with link without slides: http://www.youtube.com/watch?v=bCrohG6PJQE)
Try viewing for example this svg image in your browser - it'll definately kill it. This particular image renders at 35 FPS on my GPU (GTX 260) in NVIDIAs svg viewer which uses their quite new (June 2011) GL_NV_path_rendering OpenGL extension. Remarkable.
The GPU implementation doesn't implement the filters - blurring in this example - (neither does IE). I'll try to add these, I don't think they'll slow it down too much.

Read more at http://developer.nvidia.com/nv-path-rendering

Note: Many browsers claim to have GPU accelerated rendering, but this mostly only applies to the final composition of different elements (though some do have GPU text rendering).

Edit: After looking at the specification and some samples, I see that this is actually pretty complex: You can define various intermediate targets and in and outputs for filters. The easiest way to do this would of course be to render every step to a texture, then apply a shader that represents the predefined effect (one of just a handful) and repeat. However this can be optimized - e.g. a blur and offset pass can be done in one step. Applying such optimizations will require smart runtime shader compilation... let's see what we can do. It would also be interesting to implement the pathrendering with OpenGL and shaders in WebGL to provide an  alternative for the current browser's software svg rendering.

Edit 2: Not even browser/software svg renderer makers bothered to implement all of the specification, I couldn't find a browser or program that supports enable-background and renders this correctly (maybe OpenVG would):

Should look like this:

Another edit: Opera does! Looks like it's 100% compilant.

Tuesday, June 05, 2012

Some Java Bit Functions and easy syntax hightlighting of various languages in html

Use http://tohtml.com/ and http://bedaux.net/cpp2html/ for easy syntax highlighting in your blogger posts. (I tried this with that but it doesn't seem to work).

Now the Java stuff (easily portable to C, C++ and many other languages):


    // Returs bit a to b (> a). lsb is bit 0, msb is 63, is returned as String in normal order (msb first)
    public static String getBits(long n, int a, int b) {
        String bs="";
        for (int i = a; i <= b; i++)
            bs = (1 & (n >> i)) + bs;
        return bs;
    }

    // Calculates floored log2 by finding position of highest set bit. 
    // Ignores very highest bit of long (63rd).
    public static int log2(long n) {
        long m = 1L << 62; int i = 62;
        while ((n & m) == 0 && i > 0) {m = m >> 1; i--;}
        return i;
    }

    /**
     * Extracts the n-th b-bit number. E.g. extractBitDigit(0xff00, 8, 2) =0xff. Useful for e.g. Radixsort.
     */
    public static long extractBitDigit(long value, int b, int n) {
        long m = (
                ((1 << b) - 1) // Mask
                << (n*b) // move to n-th position
                );
        return  (m &
                value) // apply
                >> (n*b) // shift down
                ;

    }