|
1 | 1 | export type TextureData = ArrayBufferView | null; |
2 | 2 |
|
3 | | -type BaseTextureParams = { |
| 3 | +type MagFilter = "linear" | "nearest"; |
| 4 | +type MinFilter = "linear" | "nearest" | "linear-mipmap-linear" | "nearest-mipmap-linear"; |
| 5 | +type ColorSpace = "srgb" | "linear-rgb"; |
| 6 | +type WrappingMode = "clamp-to-edge" | "repeat" | "mirrored-repeat"; |
| 7 | + |
| 8 | +export type BaseTextureParams = { |
4 | 9 | /** |
5 | 10 | * @default "linear-mipmap-linear" if generateMipmaps is true, "linear" otherwise |
6 | 11 | */ |
@@ -37,6 +42,10 @@ type BaseTextureParams = { |
37 | 42 | * @default WebGL2RenderingContext.RGBA |
38 | 43 | */ |
39 | 44 | internalFormat?: number; |
| 45 | + /** |
| 46 | + * @default "linear-rgb" |
| 47 | + */ |
| 48 | + colorSpace?: ColorSpace; |
40 | 49 | /** |
41 | 50 | * @default WebGL2RenderingContext.RGBA |
42 | 51 | */ |
@@ -75,10 +84,6 @@ export type ImageTextureParams = BaseTextureParams & { |
75 | 84 |
|
76 | 85 | export type TextureParams = DataTextureParams | ImageTextureParams; |
77 | 86 |
|
78 | | -type MagFilter = "linear" | "nearest"; |
79 | | -type MinFilter = "linear" | "nearest" | "linear-mipmap-linear" | "nearest-mipmap-linear"; |
80 | | -type WrappingMode = "clamp-to-edge" | "repeat" | "mirrored-repeat"; |
81 | | - |
82 | 87 | const minFilterMap: Record<MinFilter, number> = { |
83 | 88 | linear: WebGL2RenderingContext.LINEAR, |
84 | 89 | nearest: WebGL2RenderingContext.NEAREST, |
@@ -118,8 +123,11 @@ export function fillTexture( |
118 | 123 | const { |
119 | 124 | level = 0, |
120 | 125 | flipY = true, |
121 | | - internalFormat = WebGL2RenderingContext.RGBA, |
122 | 126 | format = WebGL2RenderingContext.RGBA, |
| 127 | + colorSpace = "linear-rgb", |
| 128 | + internalFormat = colorSpace === "srgb" |
| 129 | + ? WebGL2RenderingContext.SRGB8_ALPHA8 |
| 130 | + : WebGL2RenderingContext.RGBA, |
123 | 131 | type = WebGL2RenderingContext.UNSIGNED_BYTE, |
124 | 132 | generateMipmaps = true, |
125 | 133 | anisotropy = navigator.hardwareConcurrency, // in most case between 4 and 12, depending on the hardware range |
|
0 commit comments