The Raspberry Pi (RPi) is a low-cost Linux computer developed with the intention of improving the background of students entering university computer science courses by giving them a good, cheap environment in which to play. And it does! In fact, Ive got a bunch of colleagues at work, well into middle age, who have leapt upon it to play with. So far their kids havent found out, though....
Introduction
The RPi is a small, single-board computer developed originally for the purpose of teaching computer science in schools. It uses a system on a chip (SoC) and is characterized by a small form factor, low power, not much RAM, limited inputs and outputs, and disk storage provided either by an SD card or by external storage using a USB port.
There is a growing ecosystem of such computers, and sites such as Element14 Single Board Computers Line Card ( https://www.element14.com/community/docs/DOC-55875?ICID=sbc-featured-products ) and Wikipedia ( http://en.wikipedia.org/wiki/Single-board_computer ) list many of them.
Now this doesnt seem very exciting, but nevertheless the RPi has captured the imagination (and the pockets!), with more than ten million sold. In fact, Amazon lists more than 1,000 books related to the RPi.
So, what is it? Well, it is a single-board computer, about the size of a credit card. There are a series of models beginning with the Raspberry Pi 1 released in 2012 to the Model 3 Model B released in 2016 and the Pi Zero.
The Model B has 512 MB RAM, two USB ports, and an Ethernet port. It has HDMI and analog audio and video outputs. The RPi FAQ states that the models currently available are the Pi 2 Model B, the Pi 3 Model B, the Pi Zero, and the Pi 1 Model B+ and A+. The following is from the FAQ at www.raspberrypi.org/faqs :
The Model A+ is the low-cost variant of the Raspberry Pi. It has 256 MB RAM, one USB port, 40 GPIO pins, and no Ethernet port. The Model B+ is the final revision of the original Raspberry Pi. It has 512 MB RAM (twice as much as the A+), four USB ports, 40 GPIO pins, and an Ethernet port. In February 2015, it was superseded by the Pi 2 Model B, the second generation of the Raspberry Pi. The Pi 2 shares many specs with the Pi 1 B+, but it uses a 900 MHz quad-core ARM Cortex-A7 CPU and has 1 GB RAM. The Pi 2 is completely compatible with first-generation boards and is the model we recommend for use in schools, due to its flexibility for the learner. The Pi 3 Model B was launched in February 2016; it uses a 1.2 GHz 64-bit quad-core ARM Cortex-A53 CPU, has 1 GB RAM, integrated 802.11n wireless LAN, and Bluetooth 4.1. Finally, the Pi Zero is half the size of a Model A+, with a 1 GHz single-core CPU and 512 MB RAM, and mini-HDMI and USB On-the-Go ports.
Figure shows what the RPi looks like graphically, and Figure 1-2 shows what it looks like in real life.
Figure 1-1.
Raspberry Pi Model 3B ( https://www.element14.com/community )
For its target audience, this is a wonderful computer. Its price point means that if it breaks, well, you just get another one. It runs a full-blown Linux system (the RPi 3B can run a very stripped down version IoT version of Windows) and can be used in a huge variety of situations (including as an array of RPis to build a supercomputer or hooked up to sensors as a participant in the Internet of Things). But if you want to use a single RPi for heavy-duty computation, well, it sucks. The following is from Wikipedia:
On the CPU level the performance of the RPi 2 is similar to a 300 MHz Pentium II of 19971999. The RPi 3 is substantially better but still not a world-shaker.
The GPU, on the other hand, is quite reasonable. The following is from the RPi FAQ:
The GPU is capable of 1 Gpixel/s, 1.5 Gtexel/s, or 24 GFLOPs of general-purpose compute and features a bunch of texture filtering and DMA infrastructure.
The GPU provides Open GL ES 2.0, hardware-accelerated OpenVG, and 1080p30 H.264 high-profile encode and decode.
Now this isnt top-of-the-range GPU performance. A review of the NVidia GTX 980 gave 72 gigapixels per second, but then that single graphics card is ten times the cost of the whole RPi!
From the point of view of this book, an important factor is that while the CPU has changed in the different models, the GPU has remained the same. That means programs written to the GPU will run unchanged across all the different models.
A number of Linux images are available from the Raspberry Pi site, and others are being developed elsewhere. I use the Debian-based Raspbian image, which essentially comes in two forms: with or without a GUI. It doesnt matter which one you use since in this book you will write directly to the GPU and bypass any running window system.
ELinux.org maintains a list of RPi distributions. There are many standard Linux distros included, such as Fedora, Debian, Arch, SUSE, Gentoo, and others. The RPi has gained traction as a media center based on the XBMC media center, and this is represented by distros such as OSMC (formerly Raspbmc) and OpenElec.
It doesnt really matter which distro you use or even whether you use the X Window System or a command line. You will be bypassing those for this book.
There dont seem to be any books that go into detail about the Broadcom VideoCore GPU used on the RPi, besides several tutorials and a set of examples from Broadcom. I bumped into a need to do this kind of programming while trying to turn the RPi into a karaoke machine: with the CPU busting its gut rendering MIDI files, there was nothing left for showing images such as karaoke lyrics except for the GPU, and nothing really to tell me how to do it.
This book scratches my itch. Since Ive had to learn a lot about RPi GPU programming , I might as well share it. Lets be honest: much of this is about sharing the pain. What started as a side issue turned into a full-blown project of its own, and this stuff is hard .
I will cover OpenGL ES, OpenMAX, and OpenVG. Along the way I will cover some Dispmanx. A version of the full OpenGL has just been released in beta, but this book will not cover that.
If you cant program in C, then go away. If you cant do concurrent programming using threads, then you will probably get glassy-eyed at various points. You need to be able to read formal specifications and pay attention to all the finicky details or your application wont work. And you will need to spend a lot of time experimenting and working through unexplained features, buggy behavior, and not-yet-implemented core elements. Get used to staring at your screen in a totally bemused fashion, with a debugger running and the specification open on one side and a half-dozen web sites open on the other. Ive found that a good bottle of red wine helps, not with the programming but for handling the frustration!