-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTexture.js
More file actions
95 lines (88 loc) · 3.2 KB
/
Texture.js
File metadata and controls
95 lines (88 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
import Elm.Kernel.Utils exposing (Tuple2)
import Elm.Kernel.Scheduler exposing (binding, succeed, fail)
import WebGL.Texture as Texture exposing (LoadError, SizeError)
*/
// eslint-disable-next-line no-unused-vars
var _Texture_load = F6(function (magnify, mininify, horizontalWrap, verticalWrap, flipY, url) {
var isMipmap = mininify !== 9728 && mininify !== 9729;
return __Scheduler_binding(function (callback) {
var img = new Image();
function createTexture(gl) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magnify);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, mininify);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, horizontalWrap);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, verticalWrap);
if (isMipmap) {
gl.generateMipmap(gl.TEXTURE_2D);
}
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
}
img.onload = function () {
var width = img.width;
var height = img.height;
var widthPowerOfTwo = (width & (width - 1)) === 0;
var heightPowerOfTwo = (height & (height - 1)) === 0;
var isSizeValid = (widthPowerOfTwo && heightPowerOfTwo) || (
!isMipmap
&& horizontalWrap === 33071 // clamp to edge
&& verticalWrap === 33071
);
if (isSizeValid) {
callback(__Scheduler_succeed({
$: __0_TEXTURE,
__$createTexture: createTexture,
__width: width,
__height: height
}));
} else {
callback(__Scheduler_fail(A2(
__Texture_SizeError,
width,
height
)));
}
};
img.onerror = function () {
callback(__Scheduler_fail(__Texture_LoadError));
};
if (url.slice(0, 5) !== 'data:') {
img.crossOrigin = 'Anonymous';
}
img.src = url;
});
});
// eslint-disable-next-line no-unused-vars
var _Texture_size = function (texture) {
return __Utils_Tuple2(texture.__width, texture.__height);
};
//Texture Loading from Bytes
// eslint-disable-next-line no-unused-vars
var _Texture_loadBytes = F9(function (magnify, mininify, horizontalWrap, verticalWrap, flipY, width, height, pixelFormat, bytes) {
function createTexture(gl) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
gl.texImage2D(gl.TEXTURE_2D, 0, pixelFormat, width, height, 0, pixelFormat, gl.UNSIGNED_BYTE, new Uint8Array(bytes.buffer));
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magnify);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, mininify);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, horizontalWrap);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, verticalWrap);
if (mininify !== 9728 && mininify !== 9729) {
gl.generateMipmap(gl.TEXTURE_2D);
}
gl.bindTexture(gl.TEXTURE_2D, null);
return texture;
}
return {
$: __0_TEXTURE,
__$createTexture: createTexture,
__width: width,
__height: height
};
});