opengl 2.x vs 3.x

Started by
19 comments, last by andy_boy 14 years ago
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?)
Advertisement
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
[ my blog ]
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!
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.
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]
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.
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.

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

This topic is closed to new replies.

Advertisement