1

I am writing an x86 os and a question popped into my mind: If I would want to create a simple opengl game in my os, would I be able to do that without reinventing opengl? SO what I am asking is, is opengl included in e.g. the nvideo drivers, or is it located in the gpu firmware? If it would be in the gpu, i could simple port/create a opengl wrapper right?

Can someone elaborate on this?

Thanks

  • GPU, software or OS? Yes to all. The hardware accelerates OpenGL operations, which can be performed by hardware or software. The OS is responsible for managing the screen to OpenGL relationship (context); loading and managing the OpenGL driver(s). Suggest you read some history of graphics programming and development. – Richard Critten Jan 15 '18 at 17:43
  • [OpenGL](https://www.opengl.org/) is a standard like C++. It specifies which functionalities must exist and how they work in order to be called OpenGL compatible. If you want to implement OpenGL you would need to look through the standard and just do it. Ideally though you would port existing drivers that do most implementations by telling the graphics card to do it. – nwp Jan 15 '18 at 17:43
  • Well, where would i find nvidea or amd drivers? Arent they closed source? And, thus, opengl is just a way of letting a gpu draw a 3d world(just like directx is)or is opengl a program loaded to the gpu and that then loads a 3d world? –  Jan 15 '18 at 17:51
  • 1
    With a lot of effort you might be able to port one of the open source drivers (such as Nouveau). With a lot more effort you could probably get a closed source driver to work too. – user253751 Jan 15 '18 at 21:24

2 Answers2

3

OpenGL is the API of the GPU driver. Taking nVidia as an example, they release closed source drivers for supported operating systems. There are also open source drivers (the nouveou project) that try to reverse engineer the nVidia graphics cards and implement an open source driver for them. The same is also true for other vendors to some extent.

So considering your scenario, you should either implement an ABI compatibility layer in your OS with a widely supported OS so that you could run the closed-source drivers, or port the open-source community drivers to your OS.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
2

The GPU hardware executes specific code. Some of this code is programmable, which means that you write special code that runs inside the GPU card.

The instructions to pass this special code (shaders in OpenGL parlance) and the data they handle are the graphics API (OpenGL, DirectX). There are also more instructions for the GPU, they are also handled by the API.

This API lives in the graphics card driver.

First, an app asks the OS to provide the function pointers to the API commands. These pointers are retrieved from the driver. Then the app use these pointers to comunicate with the GPU (via driver).
Two details: Retriving pointers is not needed in MAC, they provide them as any C++ instruction. This is also true in Windows, but just for OpenGL 1.1

The drivers for Windows and Mac are propietary software.
In Linux nVidia, AMD and Intel provide their drivers (but mostly as closed source). Also in Linux, there are open source drivers, which some developers wrote on their own.

Finally, There is a software inplementation of the OpenGL API done by Mesa. Mesa also is one of those that writes open source drivers for Linux.

Ripi2
  • 7,031
  • 1
  • 17
  • 33