sampler1D not supported in nVidia GLSL?
Asked Answered
H

2

8

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.

Heartrending answered 2/6, 2011 at 3:33 Comment(0)
R
11

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.

Ribeiro answered 2/6, 2011 at 19:32 Comment(4)
Sure enough, you're right. For others who are interested, the GLSL ES 2.0 spec is here: khronos.org/registry/gles/specs/2.0/… This shows that both sampler1D and sampler3D are keywords "reserved for future use. Using them will result in an error."Heartrending
2D textures are square, so one with a height of 1 also has a width of 1. You need a 2DRect texture which, like 1D textures, are available in desktop GL but not in GLES without an extensionDeckert
@Chris No, a 2D texture need not be square, at least if NPOT textures are supported, I think. There is no reason to use a rectangle texture. Although I don't know if ES handles this different from desktop.Sterilize
@ChristianRau NPOT textures are always supported in OpenGL ES 2.0, although mipmapping and border wrap options are reduced. Quoting from the Gold Book (OpenGL ES 2.0 Programming Guide), "... for npot textures, the wrap mode can only be GL_CLAMP_TO_EDGE and the minification filter can only be GL_NEAREST or GL_LINEAR (in other words, not mipmapped). The extension GL_OES_texture_npot relaxes these restrictions and allows wrap modes of GL_REPEAT and GL_MIRRORED_REPEAT and also allows npot textures to be mipmapped with the full set of minification filters."Chirrup
E
1

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"
Evie answered 7/12, 2018 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.