OpenGL ES 2:顶点和片段着色器是否需要简单绘制? [英] OpenGL ES 2: Are vertex and fragment shaders necessary for simple drawing?

查看:73
本文介绍了OpenGL ES 2:顶点和片段着色器是否需要简单绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用一些在运行时生成的几何图形并且仅使用纯色的绘图例程.在寻找最小的GL设置来绘制我的图形时(我与屏幕分辨率匹配,并且在iOS上,但该问题也适用于其他ES 2平台),我看到了大多数示例都使用顶点着色器和片段着色器,但不是全部.

I'm currently working on some drawing routines using geometry generated at runtime and only flat colored.  While searching for a minimal GL setup to do my drawing (I'm matching the screen resolution and on I'm iOS, but the question holds for other ES 2 platforms as well), I'm seeing that most examples use vertex and fragment shaders, but not all of them.

如果我不打算使用任何纹理或照明(只是直接进行颜色复制/混合),并且我不打算进行任何无法通过操纵视图进行的转换矩阵,我真的需要设置顶点和/或片段着色器吗?如果没有,使用着色器比无着色器方法有什么优势吗?

If I don't plan to use any textures or lighting (just direct color copying/blending) and I don't plan on doing any transformations that can't be done by manipulating the view matrix, do I really need to set up vertex and/or fragment shaders?  If not, is there any advantage to using shaders over a shader-less approach?

推荐答案

据我所知,是的,它们是必需的. OpenGL ES 2.0与OpenGL ES 1.x向后不兼容,两者之间的主要区别是自定义着色器.

As far as I know, yes, they are necessary. OpenGL ES 2.0 is not backward compatible with OpenGL ES 1.x and the main differences between the two are custom shaders.

使用着色器(2.0)或不使用着色器(1.x)的优势取决于应用程序的当前和长期功能,但是1.x的固定功能管道已迅速成为过去.最新发布的OpenGL ES 3.0规范向后兼容2.0,但不兼容1.x.

The advantage of using shaders (2.0) or not (1.x) depends on your application's current and long-term functionality, but the fixed-function pipeline of 1.x is quickly becoming a thing of the past. The recently released OpenGL ES 3.0 specification is backward compatible with 2.0, but not 1.x.

OpenGL ES 2.0使用可编程管线,因此您必须始终声明一个顶点和一个片段着色器.您可以为几何+颜色声明的最简单的是:

OpenGL ES 2.0 uses a programmable pipeline, so you must always declare a vertex and a fragment shader. The simplest ones you can declare for geometry + color are:

// Vertex Shader

attribute vec3 position;

void main(void)
{
     gl_Position = vec4(position, 1.0);
}

和:

// Fragment Shader

uniform lowp vec3 color;

void main(void)
{
     gl_FragColor = vec4(color, 1.0);
}

来源: Khronos网站&文件

" OpenGL ES 2.0规范中的重大变化是 OpenGL固定的函数转换和片段流水线不是 支持."

"The significant change in the OpenGL ES 2.0 specification is that the OpenGL fixed function transformation and fragment pipeline is not supported."

这篇关于OpenGL ES 2:顶点和片段着色器是否需要简单绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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