Can I write graphics library from 0 with C++ like OpenGL and DirectX?

Started by
6 comments, last by hupsilardee 11 years, 11 months ago
Can I write my own graphics library from 0 with C++ like OpenGL and DirectX? Or are they Hardware supported and it's impossible to create new graphics library?
Advertisement
You *can* write your own 3D API, but unless you get a hardware vendor to write a driver for your API then it will be useless. In the case of D3D Microsoft provides some functionality in the base runtime library, but the real guts are in the driver which implements the D3D spec and actually communicates with the hardware. In the case of OpenGL there's only a spec, and pretty much everything is implemented by the hardware vendor.
Yeah, unless you write a custom driver for your specific card you won't be able to do anything, and trust me, getting detailed specifications for recent cards so you can write your own drivers is pretty much impossible (I've tried), and writing a driver in itself really is not something you'd want to do

I gets all your texture budgets!

In theory, Gallium3D would allow you to create your own drivers to support hardware acceleration for your own API on multiple operating systems and hardware.
It's important to realise here that neither OpenGL nor D3D are "graphics libraries". They don't actually implement graphics functionality themselves, that's implemented by the driver and hardware. What OpenGL and D3D provide is a means for your program to talk to the driver and hardware.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

you could for sure write a software-only version of your library, in the next step you could try to use opencl/cuda to get some hardware acceleration.
Tho, it's less fun than it sounds, most of the work would probably be writing some shader compiler (unless that's fun for you :D ).
Like everyone's said, technically, it is possible. You could figure out how your driver communicates with the DirectX or OpenGL and write your own API to handle the driver calls, but it's largely pointless, because it would be a MASSIVE project, and I can guarantee your code would be a worse library than either OpenGL or DirectX
I read a thread a long time ago about creating a custom graphics API with OpenCL. While this would no doubt work, it would not be as quick as the hardware implemented APIs, because some operations have dedicated hardware, like the texture samplers/filters. You would have to replicate these in OpenCL code, which would run on the general purpose cores and likely be slower.

This topic is closed to new replies.

Advertisement