OpenGL 3. + glsl兼容性一团糟吗? [英] OpenGL 3.+ glsl compatibility mess?

查看:271
本文介绍了OpenGL 3. + glsl兼容性一团糟吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我搜索了很多opengl 3. +教程,所有教程都包含着色器(GLSL 330核心).但是,我没有支持这些较新的GLSL实现的图形卡,或者我必须更新驱动程序,但仍然不确定我的卡是否本质上能够支持它.

So, I googled a lot of opengl 3.+ tutorials, all incorporating shaders (GLSL 330 core). I however do not have a graphics card supporting these newer GLSL implementations, either I have to update my driver but still I'm not sure if my card is intrinsically able to support it.

当前,我的openGL版本是3.1,我在Windows上使用C ++创建了具有向后兼容性的现代上下文.我的GLSL版本通过NVIDIA Cg编译器(完整定义)为1.30,而GLSL 1.30->版本130.

Currently my openGL version is 3.1, and I created on windows with C++ a modern context with backwards compatibility. My GLSL version is 1.30 via NVIDIA Cg compiler (full definition), and GLSL 1.30 -> version 130.

问题是:版本130完全基于旧版opengl管道,因为它包含诸如viewmatrix,modelmatrix等之类的东西.那么,当我在客户端应用程序中使用核心功能时,我应该如何使用它们(OpenGL 3 +)?

The problem is : version 130 is fully based on the legacy opengl pipeline, because it contains things like viewmatrix, modelmatrix, etc. Then how am I supposed to use them when I am using core functions in my client app (OpenGL 3+)?

这真是令人困惑,请举个具体的例子.

This is really confusing, give me concrete examples.

此外,我希望我的应用程序能够在大多数OpenGL实现中运行,那么您能告诉我旧版GLSL与现代GLSL之间的边界在哪里吗? GLSL 300是现代的GLSL,并且与OpenGL 3. +和较早的GLSL版本兼容吗?

Furthermore, I want my app to be able to run on most OpenGL implementations, then could you tell me where the border is between legacy GLSL and modern GLSL? Is GLSL 300 the modern GLSL, and is there a compatibilty with OpenGL 3.+ with older GLSL versions?

推荐答案

我会说OpenGL 3.1是现代OpenGL.

I would say OpenGL 3.1 is modern OpenGL.

任何支持OpenGL 3.1的硬件都能够支持OpenGL 3.3.驾驶员是否始终支持它是另一回事.更新显卡可能会使您升级到OpenGL 3.3.

Any hardware that supports OpenGL 3.1 is capable of supporting OpenGL 3.3. Whether the driver always support of it is another matter. Updating your graphics card will probably bump you up to OpenGL 3.3.

只是要清除此问题,OpenGL 3.1并不是旧版OpenGL.

Just to clear this up OpenGL 3.1 is not legacy OpenGL.

旧版OpenGL将是:

legacy OpenGL would be:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(90.0, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -5.0);

具有兼容上下文的OpenGL 3.1支持,但这并不意味着应该使用它.如果您正在开发支持OpenGL 3的硬件,则绝对不应该使用它.您可以通过请求核心上下文来禁用旧版功能.

Which OpenGL 3.1 with a compatibility context supports, but that doesn't mean it should be used. If you are developing for OpenGL 3 capable hardware you should most definitely not be using it. You can disable the legacy functionality by requesting a core context.

如果您使用着色器,那么您已经移走了旧式固定功能管道.因此GLSL 130不是旧版的:P.

if you are using shaders then you already moved away the legacy fixed function pipeline. So GLSL 130 is not legacy :P.

使用Intel CPU在Linux笔记本电脑上工作,最新的稳定驱动程序仅在OpenGL 3.1上运行(是的,OpenGL 3.3提交已经到位,但是我正在等待MESA 10;))让OpenGL 3.3教程在我的机器上运行而无需接触旧版OpenGL.

Working on my Linux Laptop with my Intel CPU where the latest stable drivers are only at OpenGL 3.1 (Yes OpenGL 3.3 commits are in place, but I'm waiting for MESA 10 ;) ) I have without much effort been able to get the OpenGL 3.3 Tutorials to run on my machine without touching legacy OpenGL.

关于OpenGL的一件奇妙的事情是您可以使用OpenGL扩展来扩展功能.即使您的硬件无法处理OpenGL 4.4,您仍然可以使用不需要OpenGL 4 HW的扩展程序以及更新的驱动程序!

One of the wonderful things about OpenGL is that you can extend the functionality with OpenGL extension. Even if your HW isn't capable of handling OpenGL 4.4 you can still use the extensions that doesn't require OpenGL 4 HW with updated drivers!

请参见 https://developer.nvidia.com/opengl-driver http://developer.amd.com/resources/documentation-articles/opengl-zone/,了解有关较旧硬件增加了哪些功能的信息,但是如果不确定,您只需在硬件上进行测试即可.

See https://developer.nvidia.com/opengl-driver and http://developer.amd.com/resources/documentation-articles/opengl-zone/ for info on what features are added to older HW, but if you are uncertain all you have to do is test it on your HW.

最后我要说传统OpenGL也有它的位置.

And I'll finish of by saying Legacy OpenGL also has it's place.

在我看来,传统OpenGL可能比现代OpenGL更容易学习,因为您不需要着色器和OpenGL缓冲区的知识即可绘制第一个三角形,但我认为您不应该在现代产品中使用它应用程序.

In my opinion legacy OpenGL might be easier to learn than modern OpenGL, since you don't need knowledge of shaders and OpenGL buffers to draw your first triangle, but I don't think you should be using it in a modern production application.

如果您需要对旧硬件的支持,则可能需要使用旧版OpenGL.即使是现代CPU也支持OpenGL 3,因此我对此不必担心太多.

If you need support for old hardware you might need to use an older OpenGL version. Even modern CPU's support OpenGL 3 so I would not worry about this to much.

我在 http://www.opengl-tutorial.org/的教程中对其进行了测试. .我不能像从教程中那样按原样放置转换后的代码,并且我没有权限在此处放置代码.

I tested it on the tutorials from http://www.opengl-tutorial.org/. I cannot put the code up I converted as most of it is as is from the tutorials and I don't have permission to put the code here.

他们作者谈论了OpenGL 3.1,但是由于他的上限是glsl 130(OpenGL 3.0),所以我要转换为3.0.

They author talked about OpenGL 3.1, but since he is capped at glsl 130 (OpenGL 3.0) I am converting to 3.0.

  1. 首先将上下文版本更改为OpenGL 3.0(只需更改 如果您使用的是教程,则将次要版本设置为0).如果您使用的是OpenGL 3.0,也不要将其设置为使用核心上下文,因为据我所知,ARB_compatibility仅可用于OpenGL 3.1.

  1. First of all change the context version to OpenGL 3.0 (Just change the minor version to 0 if your working from the tutorials). Also don't set it to use core context if your using OpenGL 3.0 since as far as I know ARB_compatibility is only available from OpenGL 3.1.

将着色器版本更改为

#version 130

  • 删除着色器中的所有布局绑定

  • Remove all layout binding in shaders

     layout(location = #) in vec2 #myVarName;
    

     in vec2 #myVarName;
    

  • 使用 glBindAttribLocation 来绑定布局按照指定(请参阅3)

  • Use glBindAttribLocation to bind the in layouts as they were specified (see 3)

    例如

    glBindAttribLocation(#myProgramName, #, "#myVarName");
    

  • 使用 glBindFragDataLocation 绑定输出布局按照指定(请参阅3)

  • Use glBindFragDataLocation to bind the out layout as they were specified (see 3)

    例如

    glBindFragDataLocation(#myProgramName, #, "#myVarName");
    

  • glFramebufferTexture在OpenGL 3.0中不起作用. (用于阴影贴图和延迟渲染等).相反,您需要使用 glFramebufferTexture2D . (它有一个额外的参数,但是文档就足够了)

  • glFramebufferTexture doesn't work in OpenGL 3.0. (Used for shadowmapping and deferred rendering etc.). Instead you need to use glFramebufferTexture2D. (It has a extra parameter, but the documentation is sufficient)

    这是tutorial16的屏幕截图(尽管我涵盖了大部分领域,并使用它进行了测试以查看是否全部必要)

    Here is screenshot of tutorial16 (I though this one covered the most areas and used this a test to see if that all that's needed)

    tutorial16 (在撰写本文时). FBO设置为不输出颜色,但是片段着色器仍会输出颜色值,从而导致段错误(通常尝试不写入任何内容).只需更改深度片段着色器以不输出任何内容即可对其进行修复. (不会在容忍度更高的驱动程序上产生段错误,但这不是您应该讨价还价的原因)

    There is a mistake in the source of tutorial16 (At the time of writing). The FBO is set to have no color output, but the fragment shader still outputs a color value, causing a segfault (Trying to write to nothing ussually does that). Simply changing the depth fragment shader to output nothing fixes it. (Doesn't produce segfault on more tolerant drivers, but that's not something you should bargain on)

    这篇关于OpenGL 3. + glsl兼容性一团糟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆