Skip to content

Commit

Permalink
Small cleanup of the internal dirty flags for the Texture properties (#…
Browse files Browse the repository at this point in the history
…6885)

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Aug 19, 2024
1 parent 4819239 commit e5030bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
11 changes: 11 additions & 0 deletions src/platform/graphics/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,17 @@ export const DISPLAYFORMAT_LDR_SRGB = 'ldr_srgb';
*/
export const DISPLAYFORMAT_HDR = 'hdr';

// internal flags of the texture properties
export const TEXPROPERTY_MIN_FILTER = 1;
export const TEXPROPERTY_MAG_FILTER = 2;
export const TEXPROPERTY_ADDRESS_U = 4;
export const TEXPROPERTY_ADDRESS_V = 8;
export const TEXPROPERTY_ADDRESS_W = 16;
export const TEXPROPERTY_COMPARE_ON_READ = 32;
export const TEXPROPERTY_COMPARE_FUNC = 64;
export const TEXPROPERTY_ANISOTROPY = 128;
export const TEXPROPERTY_ALL = 255; // 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128

// indices of commonly used bind groups, sorted from the least commonly changing to avoid internal rebinding
export const BINDGROUP_VIEW = 0; // view bind group, textures, samplers and uniforms
export const BINDGROUP_MESH = 1; // mesh bind group - textures and samplers
Expand Down
33 changes: 13 additions & 20 deletions src/platform/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
TEXTUREPROJECTION_NONE, TEXTUREPROJECTION_CUBE,
TEXTURETYPE_DEFAULT, TEXTURETYPE_RGBM, TEXTURETYPE_RGBE, TEXTURETYPE_RGBP,
isIntegerPixelFormat, FILTER_NEAREST, TEXTURELOCK_NONE, TEXTURELOCK_READ,
requiresManualGamma
TEXPROPERTY_MIN_FILTER, TEXPROPERTY_MAG_FILTER, TEXPROPERTY_ADDRESS_U, TEXPROPERTY_ADDRESS_V,
TEXPROPERTY_ADDRESS_W, TEXPROPERTY_COMPARE_ON_READ, TEXPROPERTY_COMPARE_FUNC, TEXPROPERTY_ANISOTROPY,
TEXPROPERTY_ALL, requiresManualGamma

} from './constants.js';
import { TextureUtils } from './texture-utils.js';

Expand All @@ -23,16 +26,6 @@ import { TextureUtils } from './texture-utils.js';

let id = 0;

const PROPERTY_MIN_FILTER = 1;
const PROPERTY_MAG_FILTER = 2;
const PROPERTY_ADDRESS_U = 4;
const PROPERTY_ADDRESS_V = 8;
const PROPERTY_ADDRESS_W = 16;
const PROPERTY_COMPARE_ON_READ = 32;
const PROPERTY_COMPARE_FUNC = 64;
const PROPERTY_ANISOTROPY = 128;
const PROPERTY_ALL = 255; // 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128

/**
* A texture is a container for texel data that can be utilized in a fragment shader. Typically,
* the texel data represents an image that is mapped over geometry.
Expand Down Expand Up @@ -427,7 +420,7 @@ class Texture {
Debug.warn('Texture#minFilter: minFilter property cannot be changed on an integer texture, will remain FILTER_NEAREST', this);
} else {
this._minFilter = v;
this.propertyChanged(PROPERTY_MIN_FILTER);
this.propertyChanged(TEXPROPERTY_MIN_FILTER);
}
}
}
Expand Down Expand Up @@ -455,7 +448,7 @@ class Texture {
Debug.warn('Texture#magFilter: magFilter property cannot be changed on an integer texture, will remain FILTER_NEAREST', this);
} else {
this._magFilter = v;
this.propertyChanged(PROPERTY_MAG_FILTER);
this.propertyChanged(TEXPROPERTY_MAG_FILTER);
}
}
}
Expand All @@ -481,7 +474,7 @@ class Texture {
set addressU(v) {
if (this._addressU !== v) {
this._addressU = v;
this.propertyChanged(PROPERTY_ADDRESS_U);
this.propertyChanged(TEXPROPERTY_ADDRESS_U);
}
}

Expand All @@ -506,7 +499,7 @@ class Texture {
set addressV(v) {
if (this._addressV !== v) {
this._addressV = v;
this.propertyChanged(PROPERTY_ADDRESS_V);
this.propertyChanged(TEXPROPERTY_ADDRESS_V);
}
}

Expand Down Expand Up @@ -535,7 +528,7 @@ class Texture {
}
if (addressW !== this._addressW) {
this._addressW = addressW;
this.propertyChanged(PROPERTY_ADDRESS_W);
this.propertyChanged(TEXPROPERTY_ADDRESS_W);
}
}

Expand All @@ -558,7 +551,7 @@ class Texture {
set compareOnRead(v) {
if (this._compareOnRead !== v) {
this._compareOnRead = v;
this.propertyChanged(PROPERTY_COMPARE_ON_READ);
this.propertyChanged(TEXPROPERTY_COMPARE_ON_READ);
}
}

Expand Down Expand Up @@ -586,7 +579,7 @@ class Texture {
set compareFunc(v) {
if (this._compareFunc !== v) {
this._compareFunc = v;
this.propertyChanged(PROPERTY_COMPARE_FUNC);
this.propertyChanged(TEXPROPERTY_COMPARE_FUNC);
}
}

Expand All @@ -608,7 +601,7 @@ class Texture {
set anisotropy(v) {
if (this._anisotropy !== v) {
this._anisotropy = v;
this.propertyChanged(PROPERTY_ANISOTROPY);
this.propertyChanged(TEXPROPERTY_ANISOTROPY);
}
}

Expand Down Expand Up @@ -826,7 +819,7 @@ class Texture {
this._needsMipmapsUpload = this._mipmaps;
this._mipmapsUploaded = false;

this.propertyChanged(PROPERTY_ALL);
this.propertyChanged(TEXPROPERTY_ALL);
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
UNIFORMTYPE_IVEC4ARRAY, UNIFORMTYPE_BVEC4ARRAY, UNIFORMTYPE_UVEC4ARRAY, UNIFORMTYPE_MAT4ARRAY,
semanticToLocation, getPixelFormatArrayType,
UNIFORMTYPE_TEXTURE2D_ARRAY,
DEVICETYPE_WEBGL2
DEVICETYPE_WEBGL2,
TEXPROPERTY_MIN_FILTER, TEXPROPERTY_MAG_FILTER, TEXPROPERTY_ADDRESS_U, TEXPROPERTY_ADDRESS_V,
TEXPROPERTY_ADDRESS_W, TEXPROPERTY_COMPARE_ON_READ, TEXPROPERTY_COMPARE_FUNC, TEXPROPERTY_ANISOTROPY
} from '../constants.js';
import { GraphicsDevice } from '../graphics-device.js';
import { RenderTarget } from '../render-target.js';
Expand Down Expand Up @@ -1494,7 +1496,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
const flags = texture.impl.dirtyParameterFlags;
const target = texture.impl._glTarget;

if (flags & 1) {
if (flags & TEXPROPERTY_MIN_FILTER) {
let filter = texture._minFilter;
if (!texture._mipmaps || (texture._compressed && texture._levels.length === 1)) {
if (filter === FILTER_NEAREST_MIPMAP_NEAREST || filter === FILTER_NEAREST_MIPMAP_LINEAR) {
Expand All @@ -1505,25 +1507,25 @@ class WebglGraphicsDevice extends GraphicsDevice {
}
gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, this.glFilter[filter]);
}
if (flags & 2) {
if (flags & TEXPROPERTY_MAG_FILTER) {
gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, this.glFilter[texture._magFilter]);
}
if (flags & 4) {
if (flags & TEXPROPERTY_ADDRESS_U) {
gl.texParameteri(target, gl.TEXTURE_WRAP_S, this.glAddress[texture._addressU]);
}
if (flags & 8) {
if (flags & TEXPROPERTY_ADDRESS_V) {
gl.texParameteri(target, gl.TEXTURE_WRAP_T, this.glAddress[texture._addressV]);
}
if (flags & 16) {
if (flags & TEXPROPERTY_ADDRESS_W) {
gl.texParameteri(target, gl.TEXTURE_WRAP_R, this.glAddress[texture._addressW]);
}
if (flags & 32) {
if (flags & TEXPROPERTY_COMPARE_ON_READ) {
gl.texParameteri(target, gl.TEXTURE_COMPARE_MODE, texture._compareOnRead ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
}
if (flags & 64) {
if (flags & TEXPROPERTY_COMPARE_FUNC) {
gl.texParameteri(target, gl.TEXTURE_COMPARE_FUNC, this.glComparison[texture._compareFunc]);
}
if (flags & 128) {
if (flags & TEXPROPERTY_ANISOTROPY) {
const ext = this.extTextureFilterAnisotropic;
if (ext) {
gl.texParameterf(target, ext.TEXTURE_MAX_ANISOTROPY_EXT, math.clamp(Math.round(texture._anisotropy), 1, this.maxAnisotropy));
Expand Down

0 comments on commit e5030bf

Please sign in to comment.