On Windows, how does OpenGL differ from DirectX?
Asked Answered
C

4

13

I don't have any hands on experience with graphics programming. I got this doubt when I was reading about graphics programming.

From what I understand, because Windows didn't offer DOS like direct hardware access, DirectX was created. That means DirectX is the only sure way to achieve direct(ish) hardware access. Am I wrong?

If I am not wrong, then OpenGL must be implemented either using DirectX itself or on top of DirectX.

So doesn't it mean that on Windows OpenGL is really DirectX?

Please note that my doubt is restricted to what the title says, exactly, and I am not interested why is one better than the other etc.

Charlton answered 10/9, 2011 at 14:42 Comment(0)
U
27

From what I understand, because Windows didn't offer DOS like direct hardware access, Direct X was created.

You're right that Windows didn't offer DOS like direct hardware access. In fact no operating system with memory protection does.

And yes, DirectX was created to offer a API for accelerated access to certain kinds of hardware. DirectX is a API for accelerated hardware access, not THE (one and only) one.

That means Direct X is the only sure way to achieve direct(ish) hardware access. Am I wrong?

You are wrong because nothing and nobody prevents you from implementing another track for accelerated hardware access. The pieces of software responsible for channeling access to hardware are called drivers. Drivers run in priviledged mode, which means, address space protection doesn't apply to them. That is, because drivers must be able to communicate with hardware.

Drivers communicate with regular programs, the so called User Space through APIs. APIs may be standardized, then may be tightly specified or they may be completely propritary.

DirectX is a specified API, the specification was written down by Microsoft.

OpenGL in a similar way is an API, but instead of having being specified by a single entity it's in some form standardized in collaboration of several contributors.

One example for a propriatary API was Glide by 3Dfx, which in large parts was inspired by OpenGL. In fact there is a compatibility wrapper called "minigl" implementing the subset of OpenGL required for the Half-Life 1 engine to work on 3Dfx/Glide systems.

The GPU vendors' driver developers follow the APIs' specifications, writing drivers for DirectX, OpenGL or some propriatary interface. Each of those APIs gives access to the driver and thus to the hardware. And there may be multiple APIs to a single resource. A driver may implement DirectX 3D, OpenGL and whatever else in parallel and provide them all to user space.

So no, OpenGL is not built on top of DirectX if shipping with a GPU driver. Windows Vista and above ship with a OpenGL-1.4 emulation built on top of DirectX, but that doesn't support shaders, vertex buffer objects and all the other whistles and bells. As soon as you install a GPU driver with OpenGL support, this completely replaces the OpenGL-1.4 emulation with an actual low-level implementation.

Uno answered 10/9, 2011 at 15:36 Comment(4)
+1 For providing an accurate answer in addition to the other not neccessarily incorrect but rather incomplete answers.Instruction
@Goz: Actually HL1 uses a heavily modified version of the Quake-1 engine. Major changes included switch from indexed color to RGB color mode to support dynamic illumination, support for multiple WAD texture containers with differing palettes references by a single map, complete overhaul of the sound system, new AI system (which integrates with the sound and illumination system – enter a dark room with cockroaches and turn on the lights, cockroaches will hide in dark corners) and a keyframe interpolation character animation system, that can act on individual body parts.Uno
Does this mean having installed DirectX driver I am able to call OpenGL functions without explicit GPU driver supporting OpenGL?Starks
@TurkhanBadalov: No. It means that you can make DirectX calls. In order to support OpenGL a driver of course must ship with a OpenGL implementation. However on the topic of APIs (i.e. DirectX, OpenGL, Vulkan, Metal, etc.) it always comes down to software. The hardware itself is agnostic about the APIs.Uno
H
5

DirectX is a layer to use the graphic card hardware functions. Since Windows Vista, the default OpenGL implementation (the one provided from Microsoft) uses DirectX, so OpenGL is really slow.

However, graphic card manufacturers provides drivers with OpenGL that directly use the graphic card without passing through DirectX; the performance should be the same. If you have an integrated graphic card with a poor driver, OpenGL may use DirectX.

Hygrometry answered 10/9, 2011 at 14:49 Comment(0)
Z
2

The problem is more that there was direct hardware access and no convenient abstract layer. Software vendors don't want to spend all their time writing support for each new card so they push Microsoft to implement the abstraction.

The choice was OpenGL or invent a new layer. Various reasons led to the latter.

Vista+ can convert OpenGL to DirectX, and conversely Wine can convert DirectX to OpenGL.

Zinciferous answered 10/9, 2011 at 14:55 Comment(2)
I don't understand the first sentence. How was the access possible, through 16 bit emulation mode?Charlton
@Charlton DirectX appeared with Windows 95, i.e. when there was limited memory protection. You often have mini-drivers such as MiniGLX.Zinciferous
M
2

No, both languages talk directly to the graphics card hardware through a driver written by the card manufacturer so both offer the same level of hardware access.

Windows support DirectX directly, it's part of the OS needed for pretty display effects - their support of OpenGL is rather more limited, they only support v1.1 (we are now on version 4) so to do anything useful you need to use some extra library (such as glew) or the graphics card makers OpenGL SDK.

In terms of capabilities. DirectX is carefully controlled by MSFT - so all DirectX systems should behave identically. OpenGL allows graphics card makers to add their own extentions, so they can produce higher performance by adding specific features to the hardware (at least in theory). OpenGL is also cross platform, so your Windows OpenGL code will run anywhere (in theory)

Mutualism answered 10/9, 2011 at 15:11 Comment(2)
"GLEW" is not an OpenGL extension. It's a library that makes it easier to use the OpenGL extensions provided by the GPU manufacturer. The last paragraph is totally biased and also baloney.Kaunas
GLEW is not an openGL ARB_EXT extention but it is an extention to the capabilities of openGL on windows. ps Just try and run an OpenGL program of any complexity on an Intel embedded graphics chipsetMutualism

© 2022 - 2024 — McMap. All rights reserved.