Textures

OpenGL: https://www.khronos.org/opengl/wiki/Texture#Texture_Objects

Textures in OpenGL have three components to them:

  1. Storage
  2. Texture Parameters
  3. Sampling Parameters

WGPU's approach is very close to this, but they do the following:

  • Texture Storage and Texture Parameters are combined together into the wgpu::Texture and wgpu::TextureDescriptor objects.
  • Sampling Parameters and a Sampler object are dedicated to the wgpu::Sampler and wgpu::SamplerDescriptor
  • The best practice of using texture views to immutably get references to slices of the texture storage data is more closely adhered to with the wgpu::TextureView and wgpu::TextureViewDescriptor structs.

Texture Storage

OpenGL:

WGPU:

Texture Views

OpenGL:

WGPU:

In OpenGL, when a texture storage is created, immutable storage may be allocated. When objects are immutable, there can be many immutable borrows to the same location in memory. (Rust users should know this too well).

A texture view in OpenGL is a slice, read-only view into an existing immutable texture storage. It need not have the same size as the original texture, for example, it could reference only a portion of the texture or a subset of the mipmap levels.

Samplers

OpenGL:

WGPU: