• Advertisement
Sign in to follow this  

OpenGL opengl 2.x vs 3.x

This topic is 2891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By LifeArtist
      Good Evening,
      I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
      First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
      I am really stucked right now because of the fundamental question:
      Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
      If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on. 
      In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
      Should I treat those debug objects as entities/components?
      For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
      Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
      Regards,
      LifeArtist
    • By QQemka
      Hello. I am coding a small thingy in my spare time. All i want to achieve is to load a heightmap (as the lowest possible walking terrain), some static meshes (elements of the environment) and a dynamic character (meaning i can move, collide with heightmap/static meshes and hold a varying item in a hand ). Got a bunch of questions, or rather problems i can't find solution to myself. Nearly all are deal with graphics/gpu, not the coding part. My c++ is on high enough level.
      Let's go:
      Heightmap - i obviously want it to be textured, size is hardcoded to 256x256 squares. I can't have one huge texture stretched over entire terrain cause every pixel would be enormous. Thats why i decided to use 2 specified textures. First will be a tileset consisting of 16 square tiles (u v range from 0 to 0.25 for first tile and so on) and second a 256x256 buffer with 0-15 value representing index of the tile from tileset for every heigtmap square. Problem is, how do i blend the edges nicely and make some computationally cheap changes so its not obvious there are only 16 tiles? Is it possible to generate such terrain with some existing program?
      Collisions - i want to use bounding sphere and aabb. But should i store them for a model or entity instance? Meaning i have 20 same trees spawned using the same tree model, but every entity got its own transformation (position, scale etc). Storing collision component per instance grats faster access + is precalculated and transformed (takes additional memory, but who cares?), so i stick with this, right? What should i do if object is dynamically rotated? The aabb is no longer aligned and calculating per vertex min/max everytime object rotates/scales is pretty expensive, right?
      Drawing aabb - problem similar to above (storing aabb data per instance or model). This time in my opinion per model is enough since every instance also does not have own vertex buffer but uses the shared one (so 20 trees share reference to one tree model). So rendering aabb is about taking the model's aabb, transforming with instance matrix and voila. What about aabb vertex buffer (this is more of a cosmetic question, just curious, bumped onto it in time of writing this). Is it better to make it as 8 points and index buffer (12 lines), or only 2 vertices with min/max x/y/z and having the shaders dynamically generate 6 other vertices and draw the box? Or maybe there should be just ONE 1x1x1 cube box template moved/scaled per entity?
      What if one model got a diffuse texture and a normal map, and other has only diffuse? Should i pass some bool flag to shader with that info, or just assume that my game supports only diffuse maps without fancy stuff?
      There were several more but i forgot/solved them at time of writing
      Thanks in advance
    • By RenanRR
      Hi All,
      I'm reading the tutorials from learnOpengl site (nice site) and I'm having a question on the camera (https://learnopengl.com/Getting-started/Camera).
      I always saw the camera being manipulated with the lookat, but in tutorial I saw the camera being changed through the MVP arrays, which do not seem to be camera, but rather the scene that changes:
      Vertex Shader:
      #version 330 core layout (location = 0) in vec3 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { gl_Position = projection * view * model * vec4(aPos, 1.0f); TexCoord = vec2(aTexCoord.x, aTexCoord.y); } then, the matrix manipulated:
      ..... glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f); ourShader.setMat4("projection", projection); .... glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp); ourShader.setMat4("view", view); .... model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); ourShader.setMat4("model", model);  
      So, some doubts:
      - Why use it like that?
      - Is it okay to manipulate the camera that way?
      -in this way, are not the vertex's positions that changes instead of the camera?
      - I need to pass MVP to all shaders of object in my scenes ?
       
      What it seems, is that the camera stands still and the scenery that changes...
      it's right?
       
       
      Thank you
       
    • By dpadam450
      Sampling a floating point texture where the alpha channel holds 4-bytes of packed data into the float. I don't know how to cast the raw memory to treat it as an integer so I can perform bit-shifting operations.

      int rgbValue = int(textureSample.w);//4 bytes of data packed as color
      // algorithm might not be correct and endianness might need switching.
      vec3 extractedData = vec3(  rgbValue & 0xFF000000,  (rgbValue << 8) & 0xFF000000, (rgbValue << 16) & 0xFF000000);
      extractedData /= 255.0f;
    • By Devashish Khandelwal
      While writing a simple renderer using OpenGL, I faced an issue with the glGetUniformLocation function. For some reason, the location is coming to be -1.
      Anyone has any idea .. what should I do?
  • Advertisement