Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/webgl_materials_texture_partialupdate.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

const data = new Uint8Array( width * height * 4 );
dataTexture = new THREE.DataTexture( data, width, height );
dataTexture.colorSpace = THREE.SRGBColorSpace;

//

Expand Down
1 change: 1 addition & 0 deletions examples/webgpu_textures_partialupdate.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

const data = new Uint8Array( width * height * 4 );
dataTexture = new THREE.DataTexture( data, width, height );
dataTexture.colorSpace = THREE.SRGBColorSpace;

//

Expand Down
6 changes: 3 additions & 3 deletions examples/webxr_vr_layers.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@

const glayer = xr.getBinding().getSubImage( quadLayerPlain, frame );
renderer.state.bindTexture( gl.TEXTURE_2D, glayer.colorTexture );
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
renderer.state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
gl.texSubImage2D( gl.TEXTURE_2D, 0,
( snellenConfig.textureSizePx - snellenConfig.widthPx ) / 2,
( snellenConfig.textureSizePx - snellenConfig.heightPx ) / 2,
Expand All @@ -415,7 +415,7 @@

const glayer = xr.getBinding().getSubImage( quadLayerMips, frame );
renderer.state.bindTexture( gl.TEXTURE_2D, glayer.colorTexture );
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
renderer.state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
gl.texSubImage2D( gl.TEXTURE_2D, 0,
( snellenConfig.textureSizePx - snellenConfig.widthPx ) / 2,
( snellenConfig.textureSizePx - snellenConfig.heightPx ) / 2,
Expand All @@ -430,7 +430,7 @@

const glayer = xr.getBinding().getSubImage( guiLayer, frame );
renderer.state.bindTexture( gl.TEXTURE_2D, glayer.colorTexture );
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
renderer.state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
const canvas = guiMesh.material.map.image;
gl.texSubImage2D( gl.TEXTURE_2D, 0, 0, 0, canvas.width, canvas.height, gl.RGBA, gl.UNSIGNED_BYTE, canvas );
guiLayer.needsUpdate = false;
Expand Down
38 changes: 19 additions & 19 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3289,22 +3289,22 @@ class WebGLRenderer {

state.activeTexture( _gl.TEXTURE0 ); // see #33153

_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
_gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
_gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
state.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );

// used for copying data from cpu
const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );

_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );
const currentUnpackImageHeight = state.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );
const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );
const currentUnpackSkipImages = state.getParameter( _gl.UNPACK_SKIP_IMAGES );

state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
state.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );

// set up the src texture
const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
Expand Down Expand Up @@ -3430,11 +3430,11 @@ class WebGLRenderer {
}

// reset values
_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );

// Generate mipmaps only when copying level 0
if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/nodes/NodeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ class NodeManager extends DataMap {

/**
* Triggers the call of `update()` methods
* for all nodes of the given compute node.
* for all nodes of the given render object.
*
* @param {RenderObject} renderObject - The render object.
*/
Expand Down
43 changes: 42 additions & 1 deletion src/renderers/webgl-fallback/utils/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WebGLState {
// documented for convenience reasons.

this.enabled = {};
this.parameters = {};
this.currentFlipSided = null;
this.currentCullFace = null;
this.currentProgram = null;
Expand Down Expand Up @@ -1291,7 +1292,6 @@ class WebGLState {

}


/**
* Unbinds the current bound texture.
*
Expand All @@ -1315,6 +1315,47 @@ class WebGLState {

}

/**
* Returns the value for the given parameter.
*
* @param {number} name - The paramter to get the value for.
* @return {any} The value for the given parameter.
*/
getParameter( name ) {

const { gl, parameters } = this;

if ( parameters[ name ] !== undefined ) {

return parameters[ name ];

} else {

return gl.getParameter( name );

}

}

/**
* Specifies a pixel storage mode.
*
* @param {number} name - The parameter to set.
* @param {any} value - A value to set the parameter to.
*/
pixelStorei( name, value ) {

const { gl, parameters } = this;

if ( parameters[ name ] !== value ) {

gl.pixelStorei( name, value );
parameters[ name ] = value;

}

}

}

export default WebGLState;
52 changes: 27 additions & 25 deletions src/renderers/webgl-fallback/utils/WebGLTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,16 @@ class WebGLTextureUtils {
setTextureParameters( textureType, texture ) {

const { gl, extensions, backend } = this;
const { state } = this.backend;

const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? gl.NONE : gl.BROWSER_DEFAULT_WEBGL;

gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
gl.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
state.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
state.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
state.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );

gl.texParameteri( textureType, gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
gl.texParameteri( textureType, gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
Expand Down Expand Up @@ -470,6 +471,7 @@ class WebGLTextureUtils {
copyBufferToTexture( buffer, texture ) {

const { gl, backend } = this;
const { state } = backend;

const { textureGPU, glTextureType, glFormat, glType } = backend.get( texture );

Expand All @@ -479,8 +481,8 @@ class WebGLTextureUtils {

backend.state.bindTexture( glTextureType, textureGPU );

gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );
state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );
state.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );
gl.texSubImage2D( glTextureType, 0, 0, 0, width, height, glFormat, glType, 0 );

gl.bindBuffer( gl.PIXEL_UNPACK_BUFFER, null );
Expand Down Expand Up @@ -832,22 +834,22 @@ class WebGLTextureUtils {

}

gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
state.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
state.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );

// used for copying data from cpu
const currentUnpackRowLen = gl.getParameter( gl.UNPACK_ROW_LENGTH );
const currentUnpackImageHeight = gl.getParameter( gl.UNPACK_IMAGE_HEIGHT );
const currentUnpackSkipPixels = gl.getParameter( gl.UNPACK_SKIP_PIXELS );
const currentUnpackSkipRows = gl.getParameter( gl.UNPACK_SKIP_ROWS );
const currentUnpackSkipImages = gl.getParameter( gl.UNPACK_SKIP_IMAGES );

gl.pixelStorei( gl.UNPACK_ROW_LENGTH, image.width );
gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, image.height );
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, minX );
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, minY );
gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, minZ );
const currentUnpackRowLen = state.getParameter( gl.UNPACK_ROW_LENGTH );
const currentUnpackImageHeight = state.getParameter( gl.UNPACK_IMAGE_HEIGHT );
const currentUnpackSkipPixels = state.getParameter( gl.UNPACK_SKIP_PIXELS );
const currentUnpackSkipRows = state.getParameter( gl.UNPACK_SKIP_ROWS );
const currentUnpackSkipImages = state.getParameter( gl.UNPACK_SKIP_IMAGES );

state.pixelStorei( gl.UNPACK_ROW_LENGTH, image.width );
state.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, image.height );
state.pixelStorei( gl.UNPACK_SKIP_PIXELS, minX );
state.pixelStorei( gl.UNPACK_SKIP_ROWS, minY );
state.pixelStorei( gl.UNPACK_SKIP_IMAGES, minZ );

// set up the src texture
const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture || dstTexture.isArrayTexture;
Expand Down Expand Up @@ -981,11 +983,11 @@ class WebGLTextureUtils {
}

// reset values
gl.pixelStorei( gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
state.pixelStorei( gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
state.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
state.pixelStorei( gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
state.pixelStorei( gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
state.pixelStorei( gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );

// Generate mipmaps only when copying level 0
if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
Expand Down
43 changes: 43 additions & 0 deletions src/renderers/webgl/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ function WebGLState( gl, extensions ) {
const uboProgramMap = new WeakMap();

let enabledCapabilities = {};
let parameters = {};

let currentBoundFramebuffers = {};
let currentDrawbuffers = new WeakMap();
Expand Down Expand Up @@ -1112,6 +1113,31 @@ function WebGLState( gl, extensions ) {

}

function getParameter( name ) {

if ( parameters[ name ] !== undefined ) {

return parameters[ name ];

} else {

return gl.getParameter( name );

}

}

function pixelStorei( name, value ) {

if ( parameters[ name ] !== value ) {

gl.pixelStorei( name, value );
parameters[ name ] = value;

}

}

//

function scissor( scissor ) {
Expand Down Expand Up @@ -1228,9 +1254,24 @@ function WebGLState( gl, extensions ) {
gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );

gl.pixelStorei( gl.PACK_ALIGNMENT, 4 );
gl.pixelStorei( gl.UNPACK_ALIGNMENT, 4 );
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );
gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL );
gl.pixelStorei( gl.PACK_ROW_LENGTH, 0 );
gl.pixelStorei( gl.PACK_SKIP_PIXELS, 0 );
gl.pixelStorei( gl.PACK_SKIP_ROWS, 0 );
gl.pixelStorei( gl.UNPACK_ROW_LENGTH, 0 );
gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, 0 );
gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, 0 );
gl.pixelStorei( gl.UNPACK_SKIP_ROWS, 0 );
gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, 0 );

// reset internals

enabledCapabilities = {};
parameters = {};

currentTextureSlot = null;
currentBoundTextures = {};
Expand Down Expand Up @@ -1304,6 +1345,8 @@ function WebGLState( gl, extensions ) {
compressedTexImage3D: compressedTexImage3D,
texImage2D: texImage2D,
texImage3D: texImage3D,
pixelStorei: pixelStorei,
getParameter: getParameter,

updateUBOMapping: updateUBOMapping,
uniformBlockBinding: uniformBlockBinding,
Expand Down
Loading
Loading