Comments (1)
For those who also have a similar concern, here is the conclusion I come to:
infering the data type for attribute from shader code is simply NOT possible
I tried:
attribute ivec4 a_color;
varying ivec4 v_color;
and the shader fail to compile
Error compiling shader '[object WebGLShader]':ERROR: 0:5: 'attribute' : cannot be bool or int
ERROR: 0:6: 'varying' : cannot be bool or int
Actually
The attribute qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4. Attribute variables cannot be declared as arrays or structures.
However, when we specify the layout of the buffer, integer or byte is a legal option:
gl.vertexAttribPointer(a_positionLoc, positionNumComponents, gl.UNSIGNED_BYTE, false, 0, 0);
It seems that the gl engine converts all data types in the buffer to float somehow, which does not make much sense to me, maybe for the sake of hardware performance, I do not know
So, there is NO WAY to infer the individual data type in the buffer memory layout from the shader code, however, there is STILL something we can improve, we can infer the numComponents
from shader! All the possible data type is listed below:
float, vec2, vec3, vec4, mat2, mat3, and mat4.
We can definitely infer numComponents
However, as mentioned in the article
Why don't we look at the attributes on the shader program to figure out the number of components? That's because it's common to supply 3 components (x, y, z) from a buffer but use a vec4 in the shader. For attributes WebGL will set w = 1 automatically. But that means we can't easily know the user's intent since what they declared in their shader might not match the number of components they provide.
So, inferring numComponents is also not possible!
from webgl-fundamentals.
Related Issues (20)
- Suggestion: How about to use unit square instead of unit quad? HOT 4
- Is the example lost? HOT 3
- Is it modulo or module? HOT 1
- WebGL Using 2 or More Textures (wrong order of calls) HOT 6
- Explanation error HOT 1
- Skinning inverse world matrix HOT 1
- possible bug in m3.js HOT 1
- another bug in m3.js HOT 3
- error in textures example code HOT 2
- [SUGGESTION] Point Sprites HOT 4
- data-textures: Mention (data in texture)=(data supplied)/255?
- webgl-state-diagram use-2-programs does not work HOT 6
- Broken links HOT 1
- webgl state diagram : draw on cube
- webgl-state-diagram: extraneous column heading in vertex array HOT 2
- Broken link in Load Obj HOT 1
- webgl-how-it-works.html: some poor rounding, one wrong number
- webgl-image-processing: images don't actually have to be same-origin
- Camera tutorial requirements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webgl-fundamentals.