@@ -17,21 +17,62 @@ import * as constants from '../core/constants';
17
17
* will provide the GL context for this new p5.Texture
18
18
* @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData } [obj] the
19
19
* object containing the image data to store in the texture.
20
+ * @param {Object } [settings] optional A javascript object containing texture
21
+ * settings.
22
+ * @param {Number } [settings.format] optional The internal color component
23
+ * format for the texture. Possible values for format include gl.RGBA,
24
+ * gl.RGB, gl.ALPHA, gl.LUMINANCE, gl.LUMINANCE_ALPHA. Defaults to gl.RBGA
25
+ * @param {Number } [settings.minFilter] optional The texture minification
26
+ * filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults
27
+ * to gl.LINEAR. Note, Mipmaps are not implemented in p5.
28
+ * @param {Number } [settings.magFilter] optional The texture magnification
29
+ * filter setting. Possible values are gl.NEAREST or gl.LINEAR. Defaults
30
+ * to gl.LINEAR. Note, Mipmaps are not implemented in p5.
31
+ * @param {Number } [settings.wrapS] optional The texture wrap settings for
32
+ * the s coordinate, or x axis. Possible values are gl.CLAMP_TO_EDGE,
33
+ * gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available
34
+ * when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE
35
+ * @param {Number } [settings.wrapT] optional The texture wrap settings for
36
+ * the t coordinate, or y axis. Possible values are gl.CLAMP_TO_EDGE,
37
+ * gl.REPEAT, and gl.MIRRORED_REPEAT. The mirror settings are only available
38
+ * when using a power of two sized texture. Defaults to gl.CLAMP_TO_EDGE
39
+ * @param {Number } [settings.dataType] optional The data type of the texel
40
+ * data. Possible values are gl.UNSIGNED_BYTE or gl.FLOAT. There are more
41
+ * formats that are not implemented in p5. Defaults to gl.UNSIGNED_BYTE.
20
42
*/
21
- p5 . Texture = function ( renderer , obj ) {
43
+ p5 . Texture = function ( renderer , obj , settings ) {
22
44
this . _renderer = renderer ;
23
45
24
46
const gl = this . _renderer . GL ;
25
47
48
+ settings = settings || { } ;
49
+
50
+ if ( settings . dataType === gl . FLOAT ) {
51
+ const ext = gl . getExtension ( 'OES_texture_float' ) ;
52
+ if ( ! ext ) {
53
+ console . log (
54
+ "Oh no, your device doesn't support floating point textures!"
55
+ ) ;
56
+ }
57
+
58
+ const linear = gl . getExtension ( 'OES_texture_float_linear' ) ;
59
+ if ( ! linear ) {
60
+ console . log (
61
+ "Ack! Your device doesn't support linear filtering for floating point textures"
62
+ ) ;
63
+ }
64
+ }
65
+
26
66
this . src = obj ;
27
67
this . glTex = undefined ;
28
68
this . glTarget = gl . TEXTURE_2D ;
29
- this . glFormat = gl . RGBA ;
69
+ this . glFormat = settings . format || gl . RGBA ;
30
70
this . mipmaps = false ;
31
- this . glMinFilter = gl . LINEAR ;
32
- this . glMagFilter = gl . LINEAR ;
33
- this . glWrapS = gl . CLAMP_TO_EDGE ;
34
- this . glWrapT = gl . CLAMP_TO_EDGE ;
71
+ this . glMinFilter = settings . minFilter || gl . LINEAR ;
72
+ this . glMagFilter = settings . magFilter || gl . LINEAR ;
73
+ this . glWrapS = settings . wrapS || gl . CLAMP_TO_EDGE ;
74
+ this . glWrapT = settings . wrapT || gl . CLAMP_TO_EDGE ;
75
+ this . glDataType = settings . dataType || gl . UNSIGNED_BYTE ;
35
76
36
77
// used to determine if this texture might need constant updating
37
78
// because it is a video or gif.
@@ -110,7 +151,7 @@ p5.Texture.prototype.init = function(data) {
110
151
1 ,
111
152
0 ,
112
153
this . glFormat ,
113
- gl . UNSIGNED_BYTE ,
154
+ this . glDataType ,
114
155
tmpdata
115
156
) ;
116
157
} else {
@@ -120,7 +161,7 @@ p5.Texture.prototype.init = function(data) {
120
161
0 ,
121
162
this . glFormat ,
122
163
this . glFormat ,
123
- gl . UNSIGNED_BYTE ,
164
+ this . glDataType ,
124
165
data
125
166
) ;
126
167
}
@@ -211,7 +252,7 @@ p5.Texture.prototype.update = function() {
211
252
0 ,
212
253
this . glFormat ,
213
254
this . glFormat ,
214
- gl . UNSIGNED_BYTE ,
255
+ this . glDataType ,
215
256
textureData
216
257
) ;
217
258
}
0 commit comments