evanw / lightgl.js

A lightweight WebGL library
MIT License
1.52k stars 146 forks source link

Switch gl_TexCoord to vec2 in vertex shader header #24

Closed jlfwong closed 8 years ago

jlfwong commented 8 years ago

I'm perhaps misunderstanding the code here, but it seems to me like gl_TexCoord should be a vec2, given mesh example code that looks like this:

mesh.coords = [[0, 0], [1, 0], [0, 1], [1, 1]];
evanw commented 8 years ago

I known what you're saying but gl_TexCoord is actually supposed to be a vec4. It's the same reason why gl_Vertex is a vec4 instead of a vec3. Sometimes you need all four values. When you pass smaller-sized vectors as vertex attribute values, the values for the missing fields are taken from the default value vec4(0, 0, 0, 1). The definition of gl_TexCoord (and gl_Vertex) can be found in the GLSL spec: https://www.opengl.org/registry/doc/GLSLangSpec.Full.1.10.59.pdf.

evanw commented 8 years ago

The behavior for default values isn't in the GLSL spec, but you can find it in the OpenGL spec: https://www.opengl.org/registry/doc/glspec30.20080811.pdf. That behavior is defined in section 2.7: Vertex Specification.

jlfwong commented 8 years ago

Gotcha :)