GL_EXT_sparse_texture

Valid APIs

OpenGL ES 3.1+

Description

Recent advances in application complexity and a desire for higher resolutions have pushed texture sizes up considerably. Often, the amount of physical memory available to a graphics processor is a limiting factor in the performance of texture-heavy applications. Once the available physical memory is exhausted, paging may occur bringing performance down considerably - or worse, the application may fail. Nevertheless, the amount of address space available to the graphics processor has increased to the point where many gigabytes - or even terabytes of address space may be usable even though that amount of physical memory is not present.

This extension allows the separation of the graphics processor's address space (reservation) from the requirement that all textures must be physically backed (commitment). This exposes a limited form of virtualisation for textures. Use cases include sparse (or partially resident) textures, texture paging, on-demand and delayed loading of texture assets and application-controlled level of detail.

Registry Link

https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_sparse_texture.txt

Example

//generate texture with sparse storage 
glGenTextures(1, &tex); 
glActiveTexture(GL_TEXTURE0); 
glBindTexture(GL_TEXTURE_2D_ARRAY, tex); 
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); 
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SPARSE_EXT, GL_TRUE); 
glTexStorage3D(GL_TEXTURE_2D_ARRAY, levels, GL_RGBA8, size, size, 1); 
ivec3 pageSize; 
glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_X_EXT, 1, &pageSize.x); 
glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Y_EXT, 1, &pageSize.y); 
glGetInternalformativ(GL_TEXTURE_2D_ARRAY, GL_RGBA8, GL_VIRTUAL_PAGE_SIZE_Z_EXT, 1, &pageSize.z); 
//set page to commit 
glTexPageCommitmentEXT(GL_TEXTURE_2D_ARRAY, level, 
			  pageSize.x * i, pageSize.y * j, 0, // xoffset, yoffset, zoffset 
			  pageSize.x, pageSize.y, 1, // width, height, depth 
			  GL_TRUE); //do commit 
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, level, 
		 	pageSize.x * i, pageSize.y * j, 0, // xoffset, yoffset, zoffset 
		 	pageSize.x, pageSize.y, 1, // width, height, depth 
			 GL_RGBA, GL_UNSIGNED_BYTE, // format, type 
			 &page[0][0]); //ptr