Vertex Attributes - 官网上的文章
来源:互联网 发布:sql server 连接 编辑:程序博客网 时间:2024/06/06 00:51
原文地址:https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php
这是一篇openGL官方网站上的文章,比较清晰的讲述了Vertex Attributes的内容。
Vertex Attributes
Introduction
Vertex attributes are used to communicate from "outside" to the vertex shader. Unlike uniform variables, values are provided per vertex (and not globally for all vertices). There are built-in vertex attributes like the normal or the position, or you can specify your own vertex attribute like a tangent or another custom value. Attributes can't be defined in the fragment shader.
Attributes can be defined in the vertex shader using the "attribute" qualifier:
attribute float myAttrib;Vertex Shader Source Code
Built in Vertex Attributes
In many cases the built in vertex attributes are sufficent to use. In the C++ program you can use the regular OpenGL function to set vertex attribute values, for example glVertex3f for the position.
gl_VertexPosition (vec4)gl_NormalNormal (vec4)gl_ColorPrimary color of vertex (vec4)gl_MultiTexCoord0Texture coordinate of texture unit 0 (vec4)gl_MultiTexCoord1Texture coordinate of texture unit 1 (vec4)gl_MultiTexCoord2Texture coordinate of texture unit 2 (vec4)gl_MultiTexCoord3Texture coordinate of texture unit 3 (vec4)gl_MultiTexCoord4Texture coordinate of texture unit 4 (vec4)gl_MultiTexCoord5Texture coordinate of texture unit 5 (vec4)gl_MultiTexCoord6Texture coordinate of texture unit 6 (vec4)
gl_MultiTexCoord7Texture coordinate of texture unit 7 (vec4)gl_FogCoordFog Coord (float)Example: Built-in Vertex Attributes
This example uses the built in attributes gl_Vertex and gl_Color. The color value is used to translate the object (i.e. misuse of color) .
glBegin(GL_TRIANGLES) glVertex3f(0.0f, 0.0f, 0.0f); glColor3f(0.1,0.0,0.0); glVertex3f(1.0f, 0.0f, 0.0f); glColor3f(0.0,0.1,0.0); glVertex3f(1.0f, 1.0f, 0.0f); glColor3f(0.1,0.1,0.0);glEnd();C++ Source Code
void main(void){ vec4 a = gl_Vertex + gl_Color; gl_Position = gl_ModelViewProjectionMatrix * a;}Vertex Shader Source Code
void main (void) { gl_FragColor = vec4(0.0,0.0,1.0,1.0); }Fragment Shader Source Code
Custom Vertex Attributes
A custom, user-defined attribute can also be defined. The OpenGL function glBindAttribLocation associates the name of the variable with an index.
For example, glBindAttribLocation(ProgramObject, 10, "myAttrib") would bind the attribute "myAttrib" to index 10.
The maximum number of attribute locations is limited by the graphics hardware. You can retrieve the maximum supported number of vertex attributes with glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &n).
Setting attribute values can be done using glVertexAttrib function.
Unfortunately there are certain limitations when using this on NVidia Hardware. According to NVidia:
"GLSL attempts to eliminate aliasing of vertex attributes but this is integral to NVIDIA’s hardware approach and necessary for maintaining compatibility with existing OpenGL applications that NVIDIA customers rely on. NVIDIA’s GLSL implementation therefore does not allow built-in vertex attributes to collide with a generic vertex attributes that is assigned to a particular vertex attribute index with glBindAttribLocation. For example, you should not use gl_Normal (a built-in vertex attribute) and also use glBindAttribLocation to bind a generic vertex attribute named "whatever" to vertex attribute index 2 because gl_Normal aliases to index 2."
In other words, NVidia hardware indices are reserved for built-in attributes:
gl_Vertex0gl_Normal2gl_Color3gl_SecondaryColor4gl_FogCoord5gl_MultiTexCoord08gl_MultiTexCoord19gl_MultiTexCoord210gl_MultiTexCoord311gl_MultiTexCoord412gl_MultiTexCoord513gl_MultiTexCoord614gl_MultiTexCoord715Example Project
Download: GLSL_Attributes.zip (Visual Studio 8 Project)
(If you create a project/makefile for a different platform/compiler, please send it to: christen(at)clockworkcoders.com and I will put it here.)
- Vertex Attributes - 官网上的文章
- 引用网上的文章
- 网上的一段文章
- I. The Basics---Chapter 2----Vertex Attributes
- glBindAttribLocation GLSL,generic vertex attributes)
- 来自网上的C++文章
- 网上的一篇好文章
- 网上看到的一篇文章
- Maven网上的几篇好文章
- 在codeproject官网上一篇介绍wxWidgets的好文章
- OpenGL ES3.0 《学习笔记 六》 Vertex Attributes, Vertex Arrays, and Buffer Objects
- OpenGL ES2.0 Programming Guide - chapter 6:Vertex attributes, vertex array and buffer objects
- OpenGL ES3.0 《学习笔记 六》 Vertex Attributes, Vertex Arrays, and Buffer Objects
- @property (attributes) 迷惑的attributes
- 网上找的安装opendiameter的文章
- 网上找的Rxjava的好文章
- 谈谈网上的一些废话文章
- 网上找到的一篇java笔试文章
- Maven学习总结(2)—-使用Maven构建多模块项目
- Oracle接口开发之PL/SQL Gateway
- Asp清除html中style,javascript,css代码
- Android如何避免OOM总结
- 语言模型如何评估
- Vertex Attributes - 官网上的文章
- SQL中存储过程和自定义函数的区别
- python getattr获取对象属性
- 3分钟教会你用excel做多层饼图
- 简单实现MFC ListControl 点击列头排序
- 【Loadrunner】LR中监控ORACLE数据库常用计数器(如何自定义Oracle计数器)
- 短信开发(华为软件包)
- 黑马程序员—Java基础—IO流—字符流
- redis数据结构