DGL
https://delphigl.com/forum/

OpenGL vs DirectX - 2D Rendering.
https://delphigl.com/forum/viewtopic.php?f=19&t=9747
Seite 1 von 1

Autor:  Stucuk [ Di Feb 15, 2011 09:26 ]
Betreff des Beitrags:  OpenGL vs DirectX - 2D Rendering.

What makes DirectX way faster at 2D rendering than OpenGL? Based on my rubbish understanding of Direct X, all you do is update some buffers which are effectively just textures. Couldn't you just have one large image in OpenGL which would be the same as the Primary Buffer in DirectX, each frame where there is a change you would modify a "Local" version of the texture and then submit that to the graphics card to update the large image at the end of the frame(And then render it to the screen)?

Or would the act of uploading a large image to the graphics card each time something changed take too long?

Autor:  Coolcat [ Di Feb 15, 2011 10:32 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Zitat:
Couldn't you just have one large image in OpenGL which would be the same as the Primary Buffer in DirectX

That's the framebuffer?

When using single buffering and you don't call glClear in the following frame, then image remains in the framebuffer. You just have to render your local changes into the framebuffer.
When using double buffering you have two buffers, which are swapped all the time. This is faster when you clear the buffer anyway each frame. If you don't clear the buffer you have the image of the frame before the last frame in the buffer.

You setup the use of single/double buffering when creating your OpenGL context.

Autor:  Stucuk [ Di Feb 15, 2011 11:02 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

I know the difference between Single and Double buffers, that has nothing to do with my question.

When you render in 2D on Direct X you are literally modifying a buffer:

Code:
LockSurf(IDDS,0,0,Width,Height,LockedData,LockedPitch); //Lock the Buffer and get its data

DoSomething(LockedData);// Modify the buffer (LockedData)

IDDS.Unlock(LockedData); //Send LockedData back to DirectX

Supposedly DirectX is far faster than OpenGL at rendering in 2D. But im asking why we can't just do the same thing in OpenGL and get similer speeds. Where you basically just use an OpenGL Texture and modify it just as you would modify DirectX's Primary Buffer if you used DirectX.

Code:
//We wouldn't need to get the texture data from OpenGL as we would store it locally.

DoSomething(LockedData);

UpdateTexture(SomeValue,LockedData);

RenderTexture(SomeValue);

Autor:  Coolcat [ Di Feb 15, 2011 11:17 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

You should show your OpenGL code. Maybe you are doing something not the correct way. There should be no real performance difference between DirectX and OpenGL.

For example:
If you use glTexImage2D to upload your new texture data you will always cause the graphics hardware to allocate new memory and create a new texture. You should always use glTexSubImage2D when modifying an existing texture, even if you replace the whole texture.

There are more things like that.

Autor:  igel457 [ Di Feb 15, 2011 11:52 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

The problem is, that you're looking at DirectDraw (IDDS = IDirectDrawSurface) - and DirectDraw cannot be compared to OpenGL: DirectDraw is a framework for directly accessing framebuffer memory on windows, OpenGL is a cross platform library for 3D graphics.

What you could compare is Direct3D and OpenGL. Or DirectDraw and DGA. Or DirectDraw and the SDL-Framebuffer extension. But your comparison makes no sense at all, thats like asking, why OpenGL performs that bad in playing audio compared to DirectX.

I hope that solves your question,
Andreas

Autor:  Stucuk [ Di Feb 15, 2011 12:08 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Coolcat hat geschrieben:
You should show your OpenGL code.

I don't have OpenGL Code.... Im going on what i have heard about the speed difference in rendering 2D as OpenGL doesn't have any 2D rendering optimisations since it renders everything in 3D.
Coolcat hat geschrieben:
For example:
If you use glTexImage2D to upload your new texture data you will always cause the graphics hardware to allocate new memory and create a new texture. You should always use glTexSubImage2D when modifying an existing texture, even if you replace the whole texture.

There are more things like that.

Never knew that, nice tip.

@igel457: Err, i know its DirectDraw. DirectX is an ambiguous term. I know that OpenGL is for 3D Graphics. I know that OpenGL can't actualy do 2D Graphics even though everyone calls it 2D Graphics. You can compare DirectDraw to OpenGL when both are rendering 2D Scenes as the visual output is the same.

Lets try again:

From what i have heard, DirectDraw can do 2D related stuff faster than OpenGL can do 2D Looking 3D Stuff. What i was wondering is why OpenGL people can't just fake what DirectDraw does and get simmiler speeds for rendering complex 2D scenes.

Autor:  Coolcat [ Di Feb 15, 2011 12:34 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Zitat:
From what i have heard,

That sounds like a really reliable source of information....

Zitat:
What i was wondering is why OpenGL people can't just fake what DirectDraw does and get simmiler speeds for rendering complex 2D scenes.

DirectDraw is fully 2D. You can modify a scene by just copying pixels into memory. When using OpenGL you render triangles...apply matrices, shaders and stuff like that. As igel457 said, it's a 3D API. However, when doing it correctly (*) OpenGL should be even faster than DirectDraw, since current graphics hardware is optimized for 3D.

(*) "correctly" means for example not using fixed function pipeline or the immediate mode. A few tips can be found here.

Autor:  Stucuk [ Di Feb 15, 2011 12:52 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

So your saying that rendering 2D Quads for everything should(TM) be faster than doing the same scene using DirectDraw? Ultimately id like to replace Original War's Ingame rendering with OpenGL, but if its going to lower the FPS then its not a great idea(There are still some users with older hardware).

Coolcat hat geschrieben:
Zitat:
From what i have heard,

That sounds like a really reliable source of information....

Well i don't want to learn DirectX so i can make a comparable test case in both API's, so i can only go on what other people tell me.

Autor:  igel457 [ Di Feb 15, 2011 13:08 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Yes, drawing 3D-Quads for everything is a lot faster than using DirectDraw (for the same purpose). That's what my 2D-Library Andorra 2D does, which either uses Direct3D or OpenGL (the website is currently down as SF updated their hosting service).

Just one example: I used the DirectDraw-Wrapper DelphiX in one game and got around 20-30 FPS. The very same code with Andorra 2D ran at 250 FPS without doing any further optimizations.

Autor:  Coolcat [ Di Feb 15, 2011 13:25 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Zitat:
So your saying that rendering 2D Quads for everything should(TM) be faster than doing the same scene using DirectDraw?

Its faster in case where you can do things in hardware which where not possible in DirectDraw and therefore would have to be done in software otherwise. For example blending or multi-texturing might be faster in OpenGL. Same goes for image rotation or particle effects. However, I'm not familiar with DirectDraw and I don't know what's done on hardware and what is software. In any case the overhead due to rendering triangles instead of just copying should be minimal on OpenGL 2.x+ hardware.

Why do you have to use OpenGL? There are other APIs which are intended for hardware accelerated 2D rendering, e.g. SDL (*). This should also work on old hardware and you will get a speed comparable to DirectDraw.


Edit: (*) or Andorra 2D of course :wink:

Autor:  Stucuk [ Di Feb 15, 2011 14:52 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Coolcat hat geschrieben:
Why do you have to use OpenGL?

Because i already am planning on making Original War's Menu's use an OpenGL GUI System i have been developing. Current Plan is to just replace the Menu's in Original War which would mean having both an OpenGL and a Direct X Window, where id switch between the two depending on if the user is in the Main Menu's or the actual game. So fully removing Direct X would be a nice longer term goal (And would allow my GUI system to be used in the game part as well as the menus).

Doesn't SDL just use OpenGL?

Autor:  Coolcat [ Mi Feb 16, 2011 08:56 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Zitat:
Doesn't SDL just use OpenGL?

You can use SDL to create an OpenGL or DirectX context, but it does also support hardware accelerate 2D graphics on its own.
Zitat:
This API supports the following features:
* single pixel points
* single pixel lines
* filled rectangles
* texture images
The primitives may be drawn in opaque, blended, or additive modes.

The texture images may be drawn in opaque, blended, or additive modes. They can have an additional color tint or alpha modulation applied to them, and may also be stretched with linear interpolation.

This API is designed to accelerate simple 2D operations. You may want more functionality such as rotation and particle effects and in that case you should use SDL's OpenGL/Direct3D support or one of the many good 3D engines.

Autor:  TAK2004 [ Mi Feb 16, 2011 11:36 ]
Betreff des Beitrags:  Re: OpenGL vs DirectX - 2D Rendering.

Since Windows Vista, the desktop system use D3D to render everything on AERO.
You get a window which contain a singe or double buffer. You can activate DoubleBuffer for every Window, to reduce the gpu usage.
The drawing Operations run over d3d.
MS use some patented technology to boost the rendering.
The moste important one is the rendering of bezier curve with fragment shader.
You only need 2 triangle to draw a perfect antialiased bezier curve in no time.
This will be used to draw round border and true type fonts on Vertex base with cheap hardware.

If you use the same technologies then you can also get the same performance with opengl.
Yes you need VBO, FBO, GLSL and yes you will fall in a performance pit if you don't use them.
Only repaint on changes else draw the front buffer.
Don't use triangle teselation or Geometry Shader to draw curves.
Use the Scissor function(cutting fonts, child components which else draw outside the parent) and draw your UI from child to root(reduce the overdraw) and not from root to child.
Avoid textures and use generated shaders for blend effects and some basic pattern.

The Windows UI use up to 7 Layer for a component like a button.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/