Skip to main content

Overview

The texture system provides comprehensive support for loading textures from resources, creating procedural textures, managing cubemaps, and rendering to textures. It supports various filtering and wrapping modes for precise texture sampling control.

Texture Types

TextureType
enum
Defines the type and purpose of a texture:
  • Color - Standard color/albedo texture
  • Specular - Specular intensity map
  • Cubemap - Cubemap for skyboxes and reflections
  • Depth - Depth buffer texture
  • DepthCube - Cubemap depth texture
  • Normal - Normal map for surface detail
  • Parallax - Height map for parallax mapping
  • SSAONoise - Noise texture for SSAO
  • SSAO - Screen-space ambient occlusion texture
  • Metallic - Metallic property map (PBR)
  • Roughness - Roughness property map (PBR)
  • AO - Ambient occlusion map
  • HDR - High dynamic range texture

Texture Parameters

TextureWrappingMode

TextureWrappingMode
enum
Determines how textures are sampled when coordinates fall outside [0, 1]:
  • Repeat - Repeats the texture infinitely
  • MirroredRepeat - Alternates texture direction on every repeat
  • ClampToEdge - Clamps coordinates to the edge, stretching edge pixels
  • ClampToBorder - Uses a constant border color outside [0,1]

TextureFilteringMode

TextureFilteringMode
enum
Determines texture sampling quality:
  • Nearest - Picks the closest texel (pixelated look)
  • Linear - Linearly interpolates texels (smooth sampling)

TextureParameters

wrappingModeS
TextureWrappingMode
default:"Repeat"
Wrapping mode for the horizontal (S/U) axis
wrappingModeT
TextureWrappingMode
default:"Repeat"
Wrapping mode for the vertical (T/V) axis
minifyingFilter
TextureFilteringMode
default:"Linear"
Filter applied when the texture is minified (viewed from far away)
magnifyingFilter
TextureFilteringMode
default:"Linear"
Filter applied when the texture is magnified (viewed up close)

Texture Class

Creating Textures

Texture::fromResource
static Texture
Creates a texture from a resource.Parameters:
  • resource - The resource from which to create the texture
  • type - The type of texture to create (default: TextureType::Color)
  • params - Texture parameters for filtering and wrapping (default: {})
  • borderColor - Border color when using ClampToBorder wrapping (default: {0, 0, 0, 0})
Returns: Texture instance
Texture::fromResourceName
static Texture
Creates a texture from a resource name.Parameters:
  • resourceName - The target resource’s name
  • type - The type of texture to create (default: TextureType::Color)
  • params - Texture parameters (default: {})
  • borderColor - Border color (default: {0, 0, 0, 0})
Returns: Texture instance

Procedural Textures

Texture::createCheckerboard
static Texture
Creates a checkerboard pattern texture.Parameters:
  • width - Width of the texture in pixels
  • height - Height of the texture in pixels
  • checkSize - Size of each checker square
  • color1 - First checkerboard color
  • color2 - Second checkerboard color
  • params - Texture parameters (default: {})
  • borderColor - Border color (default: {0, 0, 0, 0})
Returns: Checkerboard texture
Texture::createDoubleCheckerboard
static Texture
Creates a double-scale checkerboard texture with three colors.Parameters:
  • width - Width of the texture
  • height - Height of the texture
  • checkSizeBig - Size of larger checker squares
  • checkSizeSmall - Size of smaller checker squares
  • color1 - First color
  • color2 - Second color
  • color3 - Third color
  • params - Texture parameters (default: {})
  • borderColor - Border color (default: {0, 0, 0, 0})
Returns: Double checkerboard texture
Texture::createTiledCheckerboard
static Texture
Creates a tiled checkerboard texture with multiple tile patterns.Parameters:
  • width - Width of the texture
  • height - Height of the texture
  • tiles - Vector of CheckerTile definitions
  • params - Texture parameters (default: {})
  • borderColor - Border color (default: {0, 0, 0, 0})
Returns: Tiled checkerboard texture
Texture::createRainStreak
static Texture
Creates a vertically stretched streak texture suited for rain particles.Parameters:
  • width - Width of the texture
  • height - Height of the texture
  • params - Texture parameters (default: {})
  • borderColor - Border color (default: {0, 0, 0, 0})
Returns: Rain streak texture

Properties

resource
Resource
Resource from which the texture was created. Empty for procedural textures.
creationData
TextureCreationData
Contains width, height, and channel information about the texture.
id
Id
OpenGL texture ID.
type
TextureType
default:"TextureType::Color"
The type of the texture.
borderColor
Color
default:"{0, 0, 0, 0}"
Border color used when wrapping mode is set to ClampToBorder.

Cubemap

Cubemaps are used for skyboxes, environment mapping, and reflections.

Creating Cubemaps

Cubemap::fromResourceGroup
static Cubemap
Creates a cubemap from a resource group containing exactly six face images.Parameters:
  • resourceGroup - Resource group with six resources in order: +X, -X, +Y, -Y, +Z, -Z
Returns: Cubemap instance
Cubemap::fromColors
static Cubemap
Creates a cubemap from six solid colors.Parameters:
  • colors - Array of 6 colors for each cubemap face
  • size - Resolution of each face
Returns: Cubemap instance

Methods

updateWithColors
void
Updates the cubemap with new colors for each face.Parameters:
  • colors - Array of 6 colors

Properties

resources
array<Resource, 6>
Resources for the six cubemap faces in order: +X, -X, +Y, -Y, +Z, -Z
averageColor
Color
default:"Color::white()"
Average color sampled across cubemap faces for ambient approximations.
hasAverageColor
bool
default:"false"
Flag indicating whether averageColor contains sampled data.

RenderTarget

Render targets allow rendering scenes to textures for post-processing or use in materials.

Constructor

RenderTarget
constructor
Creates a new render target.Parameters:
  • window - The window in which the render target will be used
  • type - Type of render target (default: RenderTargetType::Scene)
  • resolution - Resolution in pixels (default: 1024)

RenderTargetType

RenderTargetType
enum
  • Scene - Standard scene render target
  • Multisampled - Anti-aliased render target
  • Shadow - Shadow map render target
  • CubeShadow - Cubemap shadow map
  • GBuffer - G-buffer for deferred rendering
  • SSAO - Screen-space ambient occlusion buffer
  • SSAOBlur - Blurred SSAO buffer

Methods

display
void
Displays the render target in the window.Parameters:
  • window - The window to display in
  • zindex - Z-index for display ordering (default: 0)
hide
void
Hides the render target from the window.
show
void
Shows the render target in the window.
bind
void
Binds this render target’s framebuffer for rendering.
bindCubemapFace
void
Binds a specific face of a cubemap render target.Parameters:
  • face - Face index (0-5: +X, -X, +Y, -Y, +Z, -Z)
unbind
void
Unbinds the framebuffer (binds the default framebuffer).
resolve
void
Resolves multisampled buffers to regular textures.
addEffect
void
Adds a post-processing effect to the render target.Parameters:
  • effect - The effect to add
getWidth
int
Returns the width of the render target in pixels.
getHeight
int
Returns the height of the render target in pixels.

Properties

texture
Texture
Primary output texture of the rendering process.
depthTexture
Texture
Depth information texture for depth-based effects.
brightTexture
Texture
Texture containing bright areas for bloom effects.
gPosition
Texture
G-buffer texture for world-space positions (deferred rendering).
gNormal
Texture
G-buffer texture for normals (deferred rendering).
gAlbedoSpec
Texture
G-buffer texture for albedo and specular intensity.
gMaterial
Texture
G-buffer texture for material properties.

Skybox

Skyboxes render cubemaps as scene backgrounds.

Creating Skyboxes

Skybox::create
static shared_ptr<Skybox>
Creates a skybox with a cubemap.Parameters:
  • cubemap - The cubemap texture to use
  • window - The window in which to display
Returns: Shared pointer to skybox

Methods

display
void
Displays the skybox in the window.Parameters:
  • window - The window to display in
hide
void
Hides the skybox from the window.
show
void
Shows the skybox in the window.

Properties

cubemap
Cubemap
The cubemap texture used for the skybox.

Example Usage

// Load a texture from a resource
Texture myTexture = Texture::fromResourceName("MyTextureResource", TextureType::Color);

// Create a checkerboard texture
Texture checkerTexture = Texture::createCheckerboard(512, 512, 32, Color::white(), Color::black());

// Create a tiled checkerboard texture
std::vector<CheckerTile> tiles = {
    {Color::red(), Color::black(), 64},
    {Color::green(), Color::black(), 32},
    {Color::blue(), Color::black(), 16}
};
Texture tiledTexture = Texture::createTiledCheckerboard(512, 512, tiles);

// Create a render target with post-processing
RenderTarget renderTarget(window, RenderTargetType::Scene, 1024);
renderTarget.addEffect(Blur::create(16.0f));
renderTarget.display(window, -1.0f);

// Create a skybox
Cubemap skyboxCubemap = Cubemap::fromResourceGroup(
    Workspace::get().getResourceGroup("SkyboxResources"));
Skybox skybox;
skybox.cubemap = skyboxCubemap;
skybox.display(window);

Build docs developers (and LLMs) love