sampler1D not supported in nVidia GLSL?

守給你的承諾、 提交于 2019-12-23 09:18:33

问题


In the GLSL spec, and other sources about GLSL, sampler types are available in 3 dimensions: sampler1D, sampler2D, and sampler3D.

However when I try to compile GLSL programs using WebGL in Chrome (both regular, and also in Canary), sampler2D and sampler3D are accepted but sampler1D gives a syntax error. Code:

uniform sampler1D tex1;

Error:

FS ERROR: ERROR: 0:9: 'sampler1D' : syntax error 

This error occurs even if I give Canary the command line argument --use-gl=desktop.

I am running Chrome 12.0.742.68 beta-m, and Canary 13.0.782.1. The chipset I have is Nvidia Quadro NVS 160M.

Is it possible that Nvidia allows 2- and 3-dimensional texture samplers, but not 1D? I've tried searching for information to that effect, but have not found anything.


回答1:


No, your problem isn't related to "NVIDIA GLSL". WebGL is based on OpenGL ES 2.0, and OpenGL ES 2.0 doesn't have 1D textures, only 2D and 3D textures (as extensions), so you won't be able to use a sampler1D in WebGL.

Solution? Just use a 2D texture with a height of 1 with a sampler2D.

Note: If you use Desktop OpenGL (OpenGL >= 2.0), you will be able to use 1D textures and sampler1D's.




回答2:


An example of using a a OpenGL texture 2D object with a height of 1:

glTexStorage2D(GL_TEXTURE_2D, 8, GL_RGB8, 256, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 1, GL_RGB, GL_UNSIGNED_BYTE, palette);

And the corresponding call in GLSL, using a sampler2D object named "tex":

vec4 color = texture(tex, vec2(x, 1.0f));\n"


来源:https://stackoverflow.com/questions/6210080/sampler1d-not-supported-in-nvidia-glsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!