OpenGL SL和OpenGL ES 2.0 SL之间的区别 [英] Difference between OpenGL SL and OpenGL ES 2.0 SL

查看:284
本文介绍了OpenGL SL和OpenGL ES 2.0 SL之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为Android编写基于opengl的应用程序.

I need to write opengl-based application for Android.

OpenGL SL和OpenGL ES 2.0 SL之间以及OpenGL和OpenGL ES之间是否有很大的区别?如果我使用一些与普通OpenGL有关的书籍而不是与OpenGL ES有关的书籍来学习OpenGL和GLSL,这会很有用吗?

Is there a big difference between OpenGL SL and OpenGL ES 2.0 SL and between OpenGL and OpenGL ES and will it be useful if I learn OpenGL and GLSL using some books related to general OpenGL, not to OpenGL ES?

推荐答案

桌面环境中的GLSL与OpenGL ES 2.0中的GLSL之间存在一些巨大差异.

There are some huge differences between GLSL on a desktop environment and GLSL in OpenGL ES 2.0.

  • 主要区别在于将精度引入整数和浮点类型.需要实现以在顶点着色器(低/中/高)中为三个不同的精度级别和在片段着色器(低/中)中为两个提供不同的精度级别.一个实现可以有选择地支持片段着色器中的高精度,这可以在编译时通过测试GL_FRAGMENT_PRECISION_HIGH的预处理器定义是否存在来确定.

  • The primary difference would be the introduction of precision to integer and floating-point types. Implementations are required to give you three different precision levels in vertex shaders (low / med / high) and two in fragment shaders (low / med). An implementation may optionally support high precision in fragment shaders, and this can be determined at compile-time by testing whether a pre-processor definition for GL_FRAGMENT_PRECISION_HIGH exists or not.

第一个发布的桌面GLSL规范.对应于#version 110(如果没有#version,则GLSL编译器应假定这是为着色器编写的版本)GLSL ES以#version 100开头,并且在许多方面,语法大致上等同于GLSL 在桌面上.您必须对顶点着色器输入/输出和片段着色器输入使用旧的attributevarying变量声明,而不要使用桌面GLSL(> = 130)定义的inout.

Where the first published desktop GLSL spec. corresponds to #version 110 (and GLSL compilers are supposed to assume this is the version a shader was written for if no #version is present) GLSL ES begins with #version 100 and in many respects the syntax is roughly equivalent to GLSL #version 120 on the desktop. You have to use the old attribute and varying variable declarations for vertex shader input/output and fragment shader input instead of in and out as defined by desktop GLSL (>= 130).

顶点纹理查找是OpenGL ES 2.0中的一项可选功能,您需要特别注意GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS的值(如果您的实现不支持,则为0).

Vertex texture lookups are an optional feature in OpenGL ES 2.0, and you need to pay special attention to the value of GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS (it will be 0 if your implementation does not support them).

与台式机GLSL相比,GLSL ES中所需的制服和顶点属性的数量非常有限. GLSL ES只需要8个顶点属性和128个vec4制服,而桌面GLSL分别需要16个和256个.

The number of uniforms and vertex attributes required in GLSL ES are extremely limited compared to desktop GLSL. GLSL ES only requires 8 vertex attributes and 128 vec4 uniforms as opposed to desktop GLSL which requires 16 and 256 respectively.

GLSL ES(100)仅需要2个绘制缓冲区(片段着色器输出),而台式机GLSL需要8个.

GLSL ES (100) only requires 2 draw buffers (fragment shader outputs) where as desktop GLSL requires 8.

在GLSL ES中,关于可以和不能用于索引数组的规则更加严格.最低的实现要求是,您可能无法使用循环计数器作为GLSL ES中片段着色器中统一数组的索引.

Rules for what can and cannot be used to index arrays are more strict in GLSL ES. The minimum implementation requirements are such that you may not be able to use a loop counter as an index into a uniform array in a fragment shader in GLSL ES.

最后,尽管桌面GLSL着色器可能面向兼容性配置文件上下文,因此支持gl_FrontColorgl_ModelViewMatrix之类的东西OpenGL ES 2.0消除了OpenGL 3.2中已弃用的OpenGL所有功能(以及多边形等其他东西)填充模式).因此,编写用于重用固定功能顶点指针,矩阵等的任何着色器都不能直接移植到OpenGL ES 2.0.

Last, while a desktop GLSL shader may target a compatibility profile context and thus support things like gl_FrontColor and gl_ModelViewMatrix OpenGL ES 2.0 eliminates all of the features OpenGL deemed deprecated in OpenGL 3.2 (plus a few more things like polygon fill mode). So any shader that was written to reuse fixed-function vertex pointers, matrices, etc. cannot be ported directly to OpenGL ES 2.0.

还有很多不同之处,但这应该可以帮助您入门.如果您确实想要更完整的列表,则可能应该参考 GLSL的正式规范150 +(OpenGL 3.2)和 GLSL ES 100 (OpenGL ES 2.0).两种语言规范的末尾都有一个小节(标题为内置常量),概述了实现的最低要求,熟悉这些最低要求是一个好主意.如果您使用为桌面GLSL编写的着色器并尝试进行移植,则通常会遇到GLES中的硬件/实现限制.

There are a lot more differences, but this should get you started. If you really want a more thorough list you should probably consult the formal specifications for GLSL 150+ (OpenGL 3.2) and GLSL ES 100 (OpenGL ES 2.0). There is a sub-section at the end of both language specifications (titled Built-in Constants) that outlines implementation minimum requirements, and it is a good idea to familiarize yourself with these. If you take a shader written for desktop GLSL and attempt to port it you will often run into hardware/implementation limitations in GLES.

这篇关于OpenGL SL和OpenGL ES 2.0 SL之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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