简体   繁体   English

OpenGL ES 2:简单绘图需要顶点和片段着色器吗?

[英]OpenGL ES 2: Are vertex and fragment shaders necessary for simple drawing?

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. 在搜索最小的GL设置以进行绘图时(我匹配屏幕分辨率和我的iOS,但问题也适用于其他ES 2平台) ,我看到大多数示例都使用顶点和片段着色器,但不是全部。

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? 如果没有,在着色器方法上使用着色器是否有任何优势?

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. OpenGL ES 2.0与OpenGL ES 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. 使用着色器(2.0)或不使用着色器(1.x)的优势取决于应用程序的当前和长期功能,但1.x的固定功能管道很快就会成为过去。 The recently released OpenGL ES 3.0 specification is backward compatible with 2.0, but not 1.x. 最近发布的OpenGL ES 3.0规范向后兼容2.0,但不是1.x.

OpenGL ES 2.0 uses a programmable pipeline, so you must always declare a vertex and a fragment shader. OpenGL ES 2.0使用可编程管道,因此您必须始终声明顶点和片段着色器。 The simplest ones you can declare for geometry + color are: 您可以为几何+颜色声明的最简单的是:

// Vertex Shader

attribute vec3 position;

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

and: 和:

// Fragment Shader

uniform lowp vec3 color;

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

Source: Khronos Website & Docs 资料来源: Khronos网站和文档

"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.0规范的重大变化是不支持OpenGL固定功能转换和片段管道。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM