Saturday, January 10, 2009

Exams and system calls

I have got my GRE comping up on 27th. It's really keeping me away from my crazy shaders. I wanted to get into system call level programming earlier, as I find it to be a powerful tool. I looked at the mmap system call first and found it to be very nice.

The GLSL examples I have looked at usually define a read from file function which stat's a file for it's size, allocates memory reads and passes the char * to compiler. Better still, just stat the file to get it's size, mmap those many bytes and then, just pass the mmap-ed pointer to the compiler!

PPM images lend themselves to even better use. Just open the file, read the header info and close it. Then, mmap the file at the offset such that the header is read off and use the size from prior header read, and voila, you can stream the texture to the GPU from hard disk asynchronously. Other texture loading libraries typically require you to allocate memory temporarily while they read the files. This way, we get rid of memory bugs, (which can get nasty BTW) and this is something we can do easily in the background, ideal use for multi-threading. And it's simple too, as they it requires no inter-thread I/O.

I know PPM images are too big to be practically used, but hey, OpenGL needs images in that format, and we will give it in that format. Compressed textures, we'll look into, but later.

No comments: