WebGL和HTML着色器类型 [英] WebGL and HTML shader-type
问题描述
我使用以下代码在HTML文件中声明我的GLSL ES着色器程序:
<script id="shader-fs" type="x-shader/x-fragment">..shader-code..</script>
在学习WebGL 示例中可以看到
.一切正常,但是我不明白为什么我应该使用script标签的type属性.我想知道在哪里指定了"x-shader/x-fragment"值. W3C,Khronos Group或浏览器开发人员是谁?有谁能够帮我?谢谢你.
没有官方组织指定将GLSL代码放在类型为"x-shader/x-fragment"
的<script>
标记内.
将GLSL代码放在该<script>
标记内的唯一原因是,教程作者认为,如果他将GLSL代码放在<script>
标记内而不是普通字符串内,则其代码会更干净.
但是,由于WebGL将GLSL代码作为字符串值接收,因此在将其传递给WebGL之前,作者不得不编写一个名为getShader(gl, id)
的帮助器函数以从页面中获取脚本标记并将其转换为javascript字符串. /p>
作者选择类型值"x-shader/x-fragment"
的原因是因为"x-shader/x-fragment"
不是浏览器已知的脚本类型,因此浏览器可以安全地忽略它.
I declare my GLSL ES shader program within a HTML file, using this code:
<script id="shader-fs" type="x-shader/x-fragment">..shader-code..</script>
as seen in the learning WebGL examples. Everything works fine, but I dont understand why I should use the type attribute of the script tag. I want to know where the "x-shader/x-fragment" value is specified. Who does that.. the W3C, the Khronos Group or the browser developers? Can anybody help me? Tahnk you.
There is no official organization who specified that GLSL code should be put within a <script>
tag of type "x-shader/x-fragment"
.
The only reason the GLSL code is placed within that <script>
tag is because the tutorial writer decided his code would be cleaner if he placed the GLSL code within a <script>
tag rather than a normal string.
However since WebGL takes in GLSL code as a string value, the author had to write a helper function called getShader(gl, id)
to grab the script tag from the page and convert it into a javascript string, before passing it to WebGL.
The reason the author chose a type value of "x-shader/x-fragment"
is because "x-shader/x-fragment"
is not a known script type by the browser and thus would be safely ignored by the browser.
这篇关于WebGL和HTML着色器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!