Sign in to follow this  
DracoLacertae

OpenGL opengl 2.x vs 3.x

Recommended Posts

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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  

  • Announcements

  • Forum Statistics

    • Total Topics
      628368
    • Total Posts
      2982293
  • Similar Content

    • By test opty
      Hi all,
       
      I'm starting OpenGL using a tut on the Web. But at this point I would like to know the primitives needed for creating a window using OpenGL. So on Windows and using MS VS 2017, what is the simplest code required to render a window with the title of "First Rectangle", please?
       
       
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
  • Popular Now