Sign in to follow this  
DracoLacertae

OpenGL opengl 2.x vs 3.x

Recommended Posts

DracoLacertae    518
What is everyone targeting nowadays? I'm just getting back into graphics programming after a long hiatus. Currently I have to target GL 2.x (because my computer is a bit old!), but am planning on getting a 3.x card sometime soon. I already have a lot of 2.x code that I may want to port to 3.x, and I would like to do so just using the core profile, and not depend on deprecated functionality. I have a couple questions about moving from 2.x to 3.x: 1. I know that the built-in named parameters ( such as the ones you populate with glNormalPointer, etc) go away , and I have to use the all-generic glVertexAttribPointer for everything. Can I also do this in 2.x? By that, I mean ONLY pass 'attribs' to my shaders and never use the built-in names like glNormalPointer? Or is it the case where in 2.x I must use the built-in attributes, and in 3.x I must-not use them? 2. I know in 3.x you loose all fixed-function vertex and pixel operations. I suppose I can replace any fixed-function rendering with simple shaders; does doing this on a 2.x have a large impact on performce? (By that I mean, take a OpenGL 2.x card that supports shaders, like the 6600. If you draw a mesh with the fixed function pipeline versus drawing a mesh with a pixel shader that does the same operations, do I take a performance hit using the shader? Would a card that has shader even HAVE a fixed function pipeline at all... doesn't the driver just emulate fixed function by using a 'default' shader?)

Share this post


Link to post
Share on other sites
arithma    226
I have recently started learning OpenGL ES 2.0
All the code from ES should be immediately portable to the non-ES version. In ES, there isn't a fixed function pipeline. So regardless of OGL 3, you can go without the fixed functions.

I am not sure about the performance of old cards, but in the new ones, the fixed function pipeline is translated internally (perhaps in the driver) into a shader much like the ones you write. Shouldn't affect performance with the later cards. I am not entirely sure with the older ones that were seeing a transition in architecture.

My 2 cents

Share this post


Link to post
Share on other sites
Aks9    1499
Quote:
Original post by DracoLacertae
1. I know that the built-in named parameters ( such as the ones you populate with glNormalPointer, etc) go away , and I have to use the all-generic glVertexAttribPointer for everything. Can I also do this in 2.x? By that, I mean ONLY pass 'attribs' to my shaders and never use the built-in names like glNormalPointer? Or is it the case where in 2.x I must use the built-in attributes, and in 3.x I must-not use them?

NO! You have to use built-in attributes (and uniforms) in GL 2.x.
On the other hand in GL 3.x, you can use built-in attributes as well as generic ones. On NVIDIA you can even mix-up them no matter what GLSL version you are using (of course, newer version support old ones, bit not vise versa).

Quote:
Original post by DracoLacertae
2. I know in 3.x you loose all fixed-function vertex and pixel operations. I suppose I can replace any fixed-function rendering with simple shaders; does doing this on a 2.x have a large impact on performce? (By that I mean, take a OpenGL 2.x card that supports shaders, like the 6600. If you draw a mesh with the fixed function pipeline versus drawing a mesh with a pixel shader that does the same operations, do I take a performance hit using the shader? Would a card that has shader even HAVE a fixed function pipeline at all... doesn't the driver just emulate fixed function by using a 'default' shader?)

Yes, you can implement fixed functionality with shaders (in fact, it is the way the things are going under the hood), but it will be probably slower if you do it on your own. Or in the best case as slow as the fixed functionality!

Share this post


Link to post
Share on other sites
bubu LV    1436
Quote:
Original post by DracoLacertae
1. I know that the built-in named parameters ( such as the ones you populate with glNormalPointer, etc) go away , and I have to use the all-generic glVertexAttribPointer for everything. Can I also do this in 2.x? By that, I mean ONLY pass 'attribs' to my shaders and never use the built-in names like glNormalPointer? Or is it the case where in 2.x I must use the built-in attributes, and in 3.x I must-not use them?

Yes, you can manually bind vertex attribs in 2.x and not use built-in attribs. For example - I was doing this all the time, so porting my GLSL shaders to 3.x was peace of cake!

Quote:
2. I know in 3.x you loose all fixed-function vertex and pixel operations. I suppose I can replace any fixed-function rendering with simple shaders; does doing this on a 2.x have a large impact on performce?

It depends. Sometimes you will have impact on performance, sometims not. If you are not careful and do some stupid things in shaders then you can have significant performance loss. But if you are smart with your code you can even get better performance with shaders even on GF 5x cards.

Share this post


Link to post
Share on other sites
Aks9    1499
bubu LV, do you really know what you are talking about? How GLSL 1.1 can be aware of generic attributes? It is meaningless! And, there is NO WAY to implement shaders better than drivers' developers!

P.S. After all, maybe my posts about OpenGL performance issues are not so useless. [cool]

Share this post


Link to post
Share on other sites
bubu LV    1436
Aks9: he is talking about passing built-in/custom attributes to his GLSL shaders, no about how to pass custom attributes to GL fixed functionality rendering. And using only custom attributes instead of builtin attribs in GL 2.x is possible.

About implementing shader effecively that fixed functionality - I don't say it is possible in every case, but in some specific cases it is. For example Nvidia GLSL compiler allows to use half floating point format instead of full floating point precision.

Share this post


Link to post
Share on other sites
diablos_blade    257
Quote:
Original post by Aks9
How GLSL 1.1 can be aware of generic attributes? It is meaningless!


Generic vertex attributes have been available since the origional ARB extension, and were certainly a part of GLSL 1.1. (from what I can tell anyway, the 1.2 spec mentions "attribute" as a keyword and makes no mention of a change since 1.1)

So there is no reason not to use glVertexAttribPointer rather than the built in types, and I'd recomend it if you wish to maintain compatability with GL 3/4 and the more recent versions of GLSL.

GLSL 1.30 seems to have been the last revision of GLSL before the release of OpenGL 3.0. So I'd recomend using that if you can, most of the built in attributes/uniforms are depricated in the specification, so it's alot closer to the newer versions.

Share this post


Link to post
Share on other sites
DracoLacertae    518
Thanks. I'll definitely start switching from built-in named attributes to generic attributes.

I currently think it makes sense to target 2.x more than 3.x, just because I think a lot of people out there don't have 3.x capable cards. (including me!) I'm not planning on switching completely to 3.x core profile for a while, but I just wanted to be able to keep certain things in mind when I code for 2.x so that when I do decide to make the switch, everything will be a lot easier.

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Aks9
How GLSL 1.1 can be aware of generic attributes? It is meaningless!

As others said, GLSL 1.1 is perfectly usable with generic attributes. It is actually the recommended way to pass vertex data to any version of GLSL. Generic vertex attributes were introduced with the first ASM vertex shaders, before GLSL even existed.

Quote:
Original post by Aks9
And, there is NO WAY to implement shaders better than drivers' developers!

That is incorrect. The fixed function pipeline imposes a very rigid framework of operation, and a shader implementation has to replicate this strictly for backwards compatibility. Since modern GPUs work very differently from the old FFP ones, it sometimes takes a surprising amount of shader operations to simulate the behaviour of certain parts of the FFP. If you write your own shaders, then these restrictions do not apply to you. As an example, FFP vertex lighting is done in eye space, which is often very inconvenient. In your own shaders you can select any other coordinate frame, and potentially reduce the amount of coordsys transforms needed.

Quote:
Original post by Aks9
bubu LV, do you really know what you are talking about?

The irony...

Share this post


Link to post
Share on other sites
Aks9    1499
I'm sorry, guys!
I have to apologize for hard words. [oh]

Quote:
THE OPENGL SHADING LANGUAGE v1.10 rev 59. pg.42.

Some OpenGL operations still continue to occur in fixed functionality in between the vertex processor and the fragment processor. Other OpenGL operations continue to occur in fixed functionality after the fragment processor. Shaders communicate with the fixed functionality of OpenGL through the use of built-in variables.


I admit that generic attributes exist in GLSL 1.1, after all. But still claim that implementing the same thing in shaders (as it is in fixed functionality) cannot be faster. It is totally different thing if you skip to implement something in your custom shaders.

Share this post


Link to post
Share on other sites
HuntsMan    368
Quote:
Original post by Aks9
But still claim that implementing the same thing in shaders (as it is in fixed functionality) cannot be faster. It is totally different thing if you skip to implement something in your custom shaders.


Most (if not all) modern cards don't have a fixed function. The driver implements the fixed function through shaders. So, your claim is nonsense :).

Share this post


Link to post
Share on other sites
Aks9    1499
Quote:
Original post by HuntsMan
Most (if not all) modern cards don't have a fixed function. The driver implements the fixed function through shaders. So, your claim is nonsense :).


Exactly! And those are default shaders set by the drivers. If you can compete with driver developers in shaders tuning, than I admire you! [cool]

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Aks9
Exactly! And those are default shaders set by the drivers. If you can compete with driver developers in shaders tuning, than I admire you! [cool]

Depends. Some time ago, the performance of ATIs FFP simulation was abysmal, for example. You could reimplement the whole FFP in the most naive way imaginable, and it would still be twice as fast as the vendor supplied one. This is changed with the new AMD drivers of course, but better optimizations are always thinkable. Keep in mind that high speed support for the FFP is rapidly dropping in priority for the GPU manufacturers. It just has to work for the legacy CAD folks, but top-most performance is not required, as everybody else has moved on to shaders.

That said, reimplementing the FFP with shaders yourself is obviously nonsense from a practical point of view.

Share this post


Link to post
Share on other sites
Aks9    1499
Quote:
Original post by Yann L
Depends. Some time ago, the performance of ATIs FFP simulation was abysmal, for example. You could reimplement the whole FFP in the most naive way imaginable, and it would still be twice as fast as the vendor supplied one. This is changed with the new AMD drivers of course, but better optimizations are always thinkable.

I haven't had an opportunity to program for AMD/ATI, but my shaders on NVIDIA hardware can be only few percents faster than standard fixed functionality. And it is a case only if I skip the full implementation (of lighting, for example).

Quote:
Original post by Yann L
Keep in mind that high speed support for the FFP is rapidly dropping in priority for the GPU manufacturers. It just has to work for the legacy CAD folks, but top-most performance is not required, as everybody else has moved on to shaders.

Can you point out some resource for that statement? I thought the same way, but the current situation strongly confutes it. I have carried out many experiments with GL 3.2 Core profile and so far observe no speed up at all in any aspect of code execution. I would be glad if it wasn't true, but so far it is.

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Aks9
I haven't had an opportunity to program for AMD/ATI, but my shaders on NVIDIA hardware can be only few percents faster than standard fixed functionality. And it is a case only if I skip the full implementation (of lighting, for example).

You mean that your simplified shaders are only marginally faster than the full FFP ? That is impossible, since on all modern HW, FFP vertex and fragment processing are entirely implemented as shaders (except for the parts that are still FF, like blending). You are doing something wrong. Either you are writing highly unoptimized shaders, or, and this is more likely, you are profiling incorrectly.

Quote:
Original post by Aks9
Can you point out some resource for that statement. I thought the same way, but the current situation strongly confute it. I have carried out many experiments with GL 3.2 Core profile and so far observe no speed up at all in any aspect of code execution. I would be glad if it wasn't true, but so far it is.

There is no FFP in 3.2 core profile. Are you comparing 3.2 core shaders with 2.x FFP ? In that case, see above. You are doing something wrong. Probably profiling.

Share this post


Link to post
Share on other sites
Aks9    1499
You are probably right again.

Shaders are not unoptimized. In fact they are pretty simple. Just the per-vertex lighting, and modulate texturing. No conditional branching, no multipassing, no invariances, no loops... nothing that can slowdown them.

But I have to admit that my application is pretty complex. Although all VBOs are static, there can be from few hundreds up to 65K VBOs. To suppress CPU L2 cache pollution I'm using bindless extensions. Of course, the bindless is not the problem, I have just mentioned it to emphasize that the test was not a single triangle application. But you are probably right that the bottleneck exists and it is neither in vertex nor in fragment shader.

Can you suggest any profiler that can be used to find the bottleneck? gDEBugger is probably one of them, and I'll try to dig it out...

Thank you!

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Aks9
But you are probably right that the bottleneck exists and it is neither in vertex nor in fragment shader.

Correct. If the performance difference between two very different shaders is very small, then something is wrong. Usually it means, as you said, that the bottleneck is somewhere else, and that the shaders cannot be profiled unless they are artificially made the bottleneck (or with access to GPU internal perf counters, see below).

Quote:
Original post by Aks9
Can you suggest any profiler that can be used to find the bottleneck? gDEBugger is probably one of them, and I'll try to dig it out...

Yes gDebugger, together with NVPerfkit and instrumented drivers.

Share this post


Link to post
Share on other sites
Prune    224
Quote:
Original post by Aks9
Exactly! And those are default shaders set by the drivers. If you can compete with driver developers in shaders tuning, than I admire you!

This is ridiculous. I'll give you an example in the CPU world where an end user writes assembly for functions such as memcpy and so on that beats those written by Intel/Microsoft: http://www.agner.org/optimize/#asmlib Click on Manual, page 3, Table 1.5 and especially note the memcpy on unaligned operands performance difference between implementations, it is quite significant.
Analogously, I can quite easily believe that even shader functionality might be better optimized by a good programmer than the driver writers!

Share this post


Link to post
Share on other sites
Aks9    1499
Quote:
Original post by Prune
... I'll give you an example in the CPU world where an end user writes assembly for functions such as memcpy and so on that beats those written by Intel/Microsoft: http://www.agner.org/optimize/#asmlib Click on Manual, page 3, Table 1.5 and especially note the memcpy on unaligned operands performance difference between implementations, it is quite significant...

I'm glad that there are such enthusiasts and experts. [smile]

But writing fixed functionality shaders for a whole world of users still use it is a completely different thing than optimizing a memory copying. I don't say that it is impossible but that it is not likely for most of programmers.

Thank you for a useful link!

Share this post


Link to post
Share on other sites
Promit    13246
You can use strictly generic attributes in GL 2.x, however the NVIDIA driver will not allow you to mix them with the built-ins, which they've given static bindings. As long as you commit to all generics and don't try to cheat you'll be fine.

Share this post


Link to post
Share on other sites
andy_boy    100
Quote:
Original post by arithma
I have recently started learning OpenGL ES 2.0
All the code from ES should be immediately portable to the non-ES version. In ES, there isn't a fixed function pipeline. So regardless of OGL 3, you can go without the fixed functions.


So if I learn ES 2.0, it would de facto be a write once run every where scenario.

Excellent!! description of your image

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now