Kaynağa Gözat

add byte, short, int ushort uint formats (#28483)

Renaud Rohlinger 1 yıl önce
ebeveyn
işleme
0f91e50463

+ 23 - 0
examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js

@@ -117,6 +117,11 @@ class WebGLTextureUtils {
 			if ( glType === gl.FLOAT ) internalFormat = gl.R32F;
 			if ( glType === gl.HALF_FLOAT ) internalFormat = gl.R16F;
 			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8;
+			if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.R16;
+			if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.R32UI;
+			if ( glType === gl.BYTE ) internalFormat = gl.R8I;
+			if ( glType === gl.SHORT ) internalFormat = gl.R16I;
+			if ( glType === gl.INT ) internalFormat = gl.R32I;
 
 		}
 
@@ -136,6 +141,12 @@ class WebGLTextureUtils {
 			if ( glType === gl.FLOAT ) internalFormat = gl.RG32F;
 			if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RG16F;
 			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8;
+			if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RG16;
+			if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RG32UI;
+			if ( glType === gl.BYTE ) internalFormat = gl.RG8I;
+			if ( glType === gl.SHORT ) internalFormat = gl.RG16I;
+			if ( glType === gl.INT ) internalFormat = gl.RG32I;
+
 
 		}
 
@@ -144,6 +155,12 @@ class WebGLTextureUtils {
 			if ( glType === gl.FLOAT ) internalFormat = gl.RGB32F;
 			if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGB16F;
 			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGB8;
+			if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGB16;
+			if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGB32UI;
+			if ( glType === gl.BYTE ) internalFormat = gl.RGB8I;
+			if ( glType === gl.SHORT ) internalFormat = gl.RGB16I;
+			if ( glType === gl.INT ) internalFormat = gl.RGB32I;
+			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( colorSpace === SRGBColorSpace && forceLinearTransfer === false ) ? gl.SRGB8 : gl.RGB8;
 			if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
 			if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
 			if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
@@ -155,6 +172,12 @@ class WebGLTextureUtils {
 
 			if ( glType === gl.FLOAT ) internalFormat = gl.RGBA32F;
 			if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGBA16F;
+			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGBA8;
+			if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGBA16;
+			if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGBA32UI;
+			if ( glType === gl.BYTE ) internalFormat = gl.RGBA8I;
+			if ( glType === gl.SHORT ) internalFormat = gl.RGBA16I;
+			if ( glType === gl.INT ) internalFormat = gl.RGBA32I;
 			if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( colorSpace === SRGBColorSpace && forceLinearTransfer === false ) ? gl.SRGB8_ALPHA8 : gl.RGBA8;
 			if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4;
 			if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;

+ 60 - 1
examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js

@@ -3,7 +3,7 @@ import {
 } from './WebGPUConstants.js';
 
 import {
-	CubeTexture, Texture,
+	ByteType, ShortType, CubeTexture, Texture,
 	NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter,
 	RepeatWrapping, MirroredRepeatWrapping,
 	RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
@@ -913,6 +913,25 @@ export function getFormat( texture, device = null ) {
 
 				switch ( type ) {
 
+					case ByteType:
+						formatGPU = GPUTextureFormat.RGBA8Snorm;
+						break;
+
+					case ShortType:
+						formatGPU = GPUTextureFormat.RGBA16Sint;
+						break;
+
+					case UnsignedShortType:
+						formatGPU = GPUTextureFormat.RGBA16Uint;
+						break;
+					case UnsignedIntType:
+						formatGPU = GPUTextureFormat.RGBA32Uint;
+						break;
+
+					case IntType:
+						formatGPU = GPUTextureFormat.RGBA32Sint;
+						break;
+
 					case UnsignedByteType:
 						formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm;
 						break;
@@ -951,6 +970,26 @@ export function getFormat( texture, device = null ) {
 
 				switch ( type ) {
 
+					case ByteType:
+						formatGPU = GPUTextureFormat.R8Snorm;
+						break;
+
+					case ShortType:
+						formatGPU = GPUTextureFormat.R16Sint;
+						break;
+
+					case UnsignedShortType:
+						formatGPU = GPUTextureFormat.R16Uint;
+						break;
+
+					case UnsignedIntType:
+						formatGPU = GPUTextureFormat.R32Uint;
+						break;
+
+					case IntType:
+						formatGPU = GPUTextureFormat.R32Sint;
+						break;
+
 					case UnsignedByteType:
 						formatGPU = GPUTextureFormat.R8Unorm;
 						break;
@@ -974,6 +1013,26 @@ export function getFormat( texture, device = null ) {
 
 				switch ( type ) {
 
+					case ByteType:
+						formatGPU = GPUTextureFormat.RG8Snorm;
+						break;
+
+					case ShortType:
+						formatGPU = GPUTextureFormat.RG16Sint;
+						break;
+
+					case UnsignedShortType:
+						formatGPU = GPUTextureFormat.RG16Uint;
+						break;
+
+					case UnsignedIntType:
+						formatGPU = GPUTextureFormat.RG32Uint;
+						break;
+
+					case IntType:
+						formatGPU = GPUTextureFormat.RG32Sint;
+						break;
+
 					case UnsignedByteType:
 						formatGPU = GPUTextureFormat.RG8Unorm;
 						break;