Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

texture vs texture2D in GLSL

Tags:

opengl

glsl

When sampling a 2D texture in GLSL (a uniform sampler2D), the texture function is used and the dimension is inferred from the sampler (2D in this case). This is the modern way of sampling a texture in the GLSL since 1.30 (GLSL Reference Pages). However you can also use the texture2D function.

Is the texture2D function deprecated and if so, will support for the texture2D function be removed (or has been removed) in some version of GLSL?

like image 530
Mortennobel Avatar asked Sep 06 '12 19:09

Mortennobel


People also ask

What is OpenGL texture?

A texture is an OpenGL Object that contains one or more images that all have the same image format. A texture can be used in two ways: it can be the source of a texture access from a Shader, or it can be used as a render target.

What is a sampler GLSL?

A sampler is a set of GLSL variable types. Variables of one of the sampler types must be uniforms or as function parameters. Each sampler in a program represents a single texture of a particular texture type. The type of the sampler corresponds to the type of the texture that can be used by that sampler.

What is gl_FragColor?

gl_FragColor is the principal variable that your fragment shader is designed to change. If your code does not assign a value to it then it is left undefined for the rest of the pipeline. gl_FragData is an array of data that can be used by the rest of the pipeline.

What language is GLSL?

The OpenGL Shading Language (GLSL) is the principal shading language for OpenGL. While, thanks to OpenGL Extensions, there are several shading languages available for use in OpenGL, GLSL (and SPIR-V) are supported directly by OpenGL without extensions. GLSL is a C-style language.


1 Answers

Yes, texture2D() is deprecated as of (at least) OpenGL 3.3; see page 99 of the 3.30 GLSL specification. It will continue to be supported in OpenGL compatibility profiles to avoid breaking existing code, but its usage in new code is strongly discouraged.

EDIT: The details are slightly different for OpenGL ES, but the end result is the same: texture2D() was deprecated and replaced by texture() in OpenGL ES 3.0; see section 8.8 of the 3.0 GLSL ES specification.

like image 191
postgoodism Avatar answered Oct 08 '22 04:10

postgoodism