Drawing graphics in C++ w/out APIs?

Started by
12 comments, last by Anthony Serrano 8 years, 6 months ago

In the interest of fairness I would like to point out that devices that use port-mapped i/o can't be accessed from pure C/C++ - that requires platform- and compiler-specific extensions.

Advertisement


Can you communicate directly with drivers and graphics card using C++?

Absolutely.

There's two layers: the OS layer and the userland layer.

You can examine the source code for both of these layers if you look at the open drivers for the Linux operating system. No magic. It's all just C code (likely compilable wit ha C++ compiler, because that's what C++ is all about).

At the lower (kernel) level, the GPU has a bunch of memory-mapped registers (ie. you read or write data at a specified memory location and it sets or gets values from hardware registers). A lot of GPUs have dual-ported memory (ie. they can read and write data from the CPU's main memory). There's often interrups as well: these are events triggerd by the hardware the need to be handled by the CPU, but are really just subroutines in the kernel driver. All drivers these days at least for the Linux kernel tend to be written in C and C only, for portability.

If you choose to write your own driver using C code, it's not going to be portable. That's the whole raison d'etre of an API like OpenGL: it hides all the ugly hairy and warty bits behind a thin layer of stretchy fabric so you can sleep at night.

Stephen M. Webb
Professional Free Software Developer

In the interest of fairness I would like to point out that devices that use port-mapped i/o can't be accessed from pure C/C++ - that requires platform- and compiler-specific extensions.

Fair point. The first by definition, and the second as a matter of C and C++ not defining port-mapped i/o in its abstract machine -- but still, I took OP's intent as "without intervening APIs or drivers; possibly bare-metal", not "100% standard C++: portable and cross-platform."

throw table_exception("(? ???)? ? ???");

In the interest of fairness I would like to point out that devices that use port-mapped i/o can't be accessed from pure C/C++ - that requires platform- and compiler-specific extensions.

Fair point. The first by definition, and the second as a matter of C and C++ not defining port-mapped i/o in its abstract machine -- but still, I took OP's intent as "without intervening APIs or drivers; possibly bare-metal", not "100% standard C++: portable and cross-platform."

I only brought it up for the sake of completeness anyway since port-based i/o is so rarely used nowadays.

This topic is closed to new replies.

Advertisement