webruby 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/webruby.rb +0 -4
- data/lib/webruby/app.rb +4 -0
- data/lib/webruby/rake/files.rake +2 -1
- data/lib/webruby/rake/mruby.rake +1 -1
- data/modules/emscripten/AUTHORS +1 -0
- data/modules/emscripten/ChangeLog +34 -1
- data/modules/emscripten/cmake/Platform/Emscripten.cmake +30 -9
- data/modules/emscripten/emcc +61 -28
- data/modules/emscripten/emrun +15 -11
- data/modules/emscripten/emscripten.py +3 -0
- data/modules/emscripten/src/closure-externs.js +110 -0
- data/modules/emscripten/src/intertyper.js +1 -1
- data/modules/emscripten/src/jsifier.js +7 -21
- data/modules/emscripten/src/library.js +2 -1
- data/modules/emscripten/src/library_browser.js +16 -5
- data/modules/emscripten/src/library_fs.js +3 -1
- data/modules/emscripten/src/library_gl.js +691 -591
- data/modules/emscripten/src/library_glut.js +2 -0
- data/modules/emscripten/src/library_sdl.js +29 -5
- data/modules/emscripten/src/library_uuid.js +140 -0
- data/modules/emscripten/src/modules.js +1 -1
- data/modules/emscripten/src/parseTools.js +29 -19
- data/modules/emscripten/src/postamble.js +3 -4
- data/modules/emscripten/src/preamble.js +17 -1
- data/modules/emscripten/src/relooper/Relooper.cpp +8 -8
- data/modules/emscripten/src/relooper/Relooper.h +5 -5
- data/modules/emscripten/src/relooper/test.txt +2 -2
- data/modules/emscripten/src/runtime.js +1 -1
- data/modules/emscripten/src/settings.js +3 -0
- data/modules/emscripten/src/struct_info.json +12 -0
- data/modules/emscripten/system/include/uuid/uuid.h +35 -0
- data/modules/emscripten/tools/js-optimizer.js +191 -142
- data/modules/emscripten/tools/js_optimizer.py +3 -29
- data/modules/emscripten/tools/shared.py +43 -6
- data/modules/mruby/include/mruby/value.h +3 -2
- data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +5 -9
- data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +3 -5
- data/modules/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +0 -3
- data/modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +0 -1
- data/modules/mruby/mrbgems/mruby-random/src/mt19937ar.c +0 -1
- data/modules/mruby/mrbgems/mruby-range-ext/src/range.c +2 -6
- data/modules/mruby/mrbgems/mruby-sprintf/src/sprintf.c +0 -4
- data/modules/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +22 -0
- data/modules/mruby/mrbgems/mruby-string-ext/src/string.c +2 -2
- data/modules/mruby/mrbgems/mruby-string-ext/test/string.rb +21 -2
- data/modules/mruby/mrbgems/mruby-string-utf8/mrbgem.rake +4 -0
- data/modules/mruby/mrbgems/mruby-string-utf8/src/string.c +297 -0
- data/modules/mruby/mrbgems/mruby-string-utf8/test/string.rb +27 -0
- data/modules/mruby/mrbgems/mruby-struct/src/struct.c +0 -1
- data/modules/mruby/mrblib/init_mrblib.c +0 -3
- data/modules/mruby/src/array.c +22 -8
- data/modules/mruby/src/backtrace.c +12 -9
- data/modules/mruby/src/class.c +3 -3
- data/modules/mruby/src/codegen.c +17 -5
- data/modules/mruby/src/dump.c +5 -6
- data/modules/mruby/src/error.c +0 -2
- data/modules/mruby/src/etc.c +0 -2
- data/modules/mruby/src/gc.c +4 -8
- data/modules/mruby/src/load.c +1 -6
- data/modules/mruby/src/numeric.c +0 -6
- data/modules/mruby/src/object.c +3 -5
- data/modules/mruby/src/parse.y +37 -38
- data/modules/mruby/src/proc.c +8 -1
- data/modules/mruby/src/range.c +3 -7
- data/modules/mruby/src/state.c +0 -1
- data/modules/mruby/src/string.c +2 -17
- data/modules/mruby/src/symbol.c +0 -1
- data/modules/mruby/src/variable.c +3 -22
- data/modules/mruby/src/vm.c +9 -8
- data/modules/mruby/tasks/mrbgem_spec.rake +13 -5
- data/modules/mruby/tasks/mrbgems_test.rake +3 -3
- data/modules/mruby/tasks/mruby_build_commands.rake +2 -2
- data/modules/mruby/tasks/mruby_build_gem.rake +3 -3
- data/modules/mruby/test/init_mrbtest.c +0 -3
- data/modules/mruby/test/t/array.rb +12 -1
- data/modules/mruby/test/t/class.rb +67 -0
- data/modules/mruby/test/t/exception.rb +12 -0
- data/modules/mruby/test/t/kernel.rb +75 -1
- data/modules/mruby/test/t/syntax.rb +115 -0
- data/scripts/gen_require.rb +12 -1
- metadata +8 -2
|
@@ -241,7 +241,7 @@ function intertyper(lines, sidePass, baseLineNums) {
|
|
|
241
241
|
if (mainPass && /^}.*/.test(line)) {
|
|
242
242
|
inFunction = false;
|
|
243
243
|
if (mainPass) {
|
|
244
|
-
var func = funcHeaderHandler({ tokens: tokenize(currFunctionLines[0]
|
|
244
|
+
var func = funcHeaderHandler({ tokens: tokenize(currFunctionLines[0]) });
|
|
245
245
|
|
|
246
246
|
if (SKIP_STACK_IN_SMALL && /emscripten_autodebug/.exec(func.ident)) {
|
|
247
247
|
warnOnce('Disabling SKIP_STACK_IN_SMALL because we are apparently processing autodebugger data');
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// Handy sets
|
|
7
7
|
|
|
8
8
|
var STRUCT_LIST = set('struct', 'list');
|
|
9
|
-
var UNDERSCORE_OPENPARENS = set('_', '(');
|
|
10
9
|
var RELOOP_IGNORED_LASTS = set('return', 'unreachable', 'resume');
|
|
11
10
|
|
|
12
11
|
var addedLibraryItems = {};
|
|
@@ -19,7 +18,7 @@ var INDENTATION = ' ';
|
|
|
19
18
|
var functionStubSigs = {};
|
|
20
19
|
|
|
21
20
|
// JSifier
|
|
22
|
-
function JSify(data, functionsOnly
|
|
21
|
+
function JSify(data, functionsOnly) {
|
|
23
22
|
//B.start('jsifier');
|
|
24
23
|
var mainPass = !functionsOnly;
|
|
25
24
|
|
|
@@ -96,19 +95,6 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
96
95
|
|
|
97
96
|
// Functions
|
|
98
97
|
|
|
99
|
-
Functions.currExternalFunctions = !mainPass ? givenFunctions.currExternalFunctions : {};
|
|
100
|
-
|
|
101
|
-
data.functionStubs.forEach(function(func) {
|
|
102
|
-
// Don't overwrite stubs that have more info.
|
|
103
|
-
if (!Functions.currExternalFunctions.hasOwnProperty(func.ident) ||
|
|
104
|
-
!Functions.currExternalFunctions[func.ident].numParams === undefined) {
|
|
105
|
-
Functions.currExternalFunctions[func.ident] = {
|
|
106
|
-
hasVarArgs: func.hasVarArgs,
|
|
107
|
-
numParams: func.params && func.params.length
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
98
|
if (phase == 'funcs') { // || phase == 'pre') { // pre has function shells, just to defined implementedFunctions
|
|
113
99
|
var MAX_BATCH_FUNC_LINES = 1000;
|
|
114
100
|
while (data.unparsedFunctions.length > 0) {
|
|
@@ -123,7 +109,7 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
123
109
|
dprint('unparsedFunctions','====================\n// Processing function batch of ' + currBaseLineNums.length +
|
|
124
110
|
' functions, ' + currFuncLines.length + ' lines, functions left: ' + data.unparsedFunctions.length);
|
|
125
111
|
if (DEBUG_MEMORY) MemoryDebugger.tick('pre-func');
|
|
126
|
-
JSify(analyzer(intertyper(currFuncLines, true, currBaseLineNums), true), true
|
|
112
|
+
JSify(analyzer(intertyper(currFuncLines, true, currBaseLineNums), true), true);
|
|
127
113
|
if (DEBUG_MEMORY) MemoryDebugger.tick('post-func');
|
|
128
114
|
}
|
|
129
115
|
currFuncLines = currBaseLineNums = null; // Do not hold on to anything from inside that loop (JS function scoping..)
|
|
@@ -639,8 +625,8 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
639
625
|
}
|
|
640
626
|
}
|
|
641
627
|
|
|
642
|
-
if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */';
|
|
643
628
|
if (!ASM_JS) {
|
|
629
|
+
if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */';
|
|
644
630
|
func.JS += INDENTATION + 'var label=0;\n';
|
|
645
631
|
}
|
|
646
632
|
|
|
@@ -892,8 +878,8 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
892
878
|
function makeAssign(item) {
|
|
893
879
|
var valueJS = item.JS;
|
|
894
880
|
item.JS = '';
|
|
895
|
-
if (CLOSURE_ANNOTATIONS) item.JS += '/** @type {number} */ ';
|
|
896
881
|
if (!ASM_JS || item.intertype != 'alloca' || item.funcData.variables[item.assignTo].impl == VAR_EMULATED) { // asm only needs non-allocas
|
|
882
|
+
if (CLOSURE_ANNOTATIONS) item.JS += '/** @type {number} */ ';
|
|
897
883
|
item.JS += ((ASM_JS || item.overrideSSA) ? '' : 'var ') + toNiceIdent(item.assignTo);
|
|
898
884
|
}
|
|
899
885
|
var value = parseNumerical(valueJS);
|
|
@@ -1810,7 +1796,7 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
1810
1796
|
}
|
|
1811
1797
|
});
|
|
1812
1798
|
}
|
|
1813
|
-
JSify(globalsData, true
|
|
1799
|
+
JSify(globalsData, true);
|
|
1814
1800
|
globalsData = null;
|
|
1815
1801
|
data.unparsedGlobalss = null;
|
|
1816
1802
|
|
|
@@ -1824,7 +1810,7 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
1824
1810
|
print('staticSealed = true; // seal the static portion of memory\n');
|
|
1825
1811
|
print('STACK_MAX = STACK_BASE + ' + TOTAL_STACK + ';\n');
|
|
1826
1812
|
print('DYNAMIC_BASE = DYNAMICTOP = Runtime.alignMemory(STACK_MAX);\n');
|
|
1827
|
-
print('assert(DYNAMIC_BASE < TOTAL_MEMORY
|
|
1813
|
+
print('assert(DYNAMIC_BASE < TOTAL_MEMORY, "TOTAL_MEMORY not big enough for stack");\n');
|
|
1828
1814
|
}
|
|
1829
1815
|
|
|
1830
1816
|
if (asmLibraryFunctions.length > 0) {
|
|
@@ -1885,7 +1871,7 @@ function JSify(data, functionsOnly, givenFunctions) {
|
|
|
1885
1871
|
print('// Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included');
|
|
1886
1872
|
print('var i64Math = null;');
|
|
1887
1873
|
}
|
|
1888
|
-
if (Types.usesSIMD) {
|
|
1874
|
+
if (Types.usesSIMD || SIMD) {
|
|
1889
1875
|
print(read('simd.js'));
|
|
1890
1876
|
}
|
|
1891
1877
|
|
|
@@ -8858,7 +8858,8 @@ LibraryManager.library = {
|
|
|
8858
8858
|
}
|
|
8859
8859
|
}
|
|
8860
8860
|
str += ')';
|
|
8861
|
-
|
|
8861
|
+
var caller = args.callee.caller;
|
|
8862
|
+
args = caller ? caller.arguments : [];
|
|
8862
8863
|
if (first)
|
|
8863
8864
|
str = '';
|
|
8864
8865
|
return [args, funcname, str];
|
|
@@ -319,7 +319,7 @@ mergeInto(LibraryManager.library, {
|
|
|
319
319
|
}, false);
|
|
320
320
|
}
|
|
321
321
|
if (setInModule) {
|
|
322
|
-
Module.ctx = ctx;
|
|
322
|
+
GLctx = Module.ctx = ctx;
|
|
323
323
|
Module.useWebGL = useWebGL;
|
|
324
324
|
Browser.moduleContextCreatedCallbacks.forEach(function(callback) { callback() });
|
|
325
325
|
Browser.init();
|
|
@@ -478,19 +478,30 @@ mergeInto(LibraryManager.library, {
|
|
|
478
478
|
// in the coordinates.
|
|
479
479
|
var rect = Module["canvas"].getBoundingClientRect();
|
|
480
480
|
var x, y;
|
|
481
|
+
|
|
482
|
+
// Neither .scrollX or .pageXOffset are defined in a spec, but
|
|
483
|
+
// we prefer .scrollX because it is currently in a spec draft.
|
|
484
|
+
// (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
|
|
485
|
+
var scrollX = ((typeof window.scrollX !== 'undefined') ? window.scrollX : window.pageXOffset);
|
|
486
|
+
var scrollY = ((typeof window.scrollY !== 'undefined') ? window.scrollY : window.pageYOffset);
|
|
487
|
+
#if ASSERTIONS
|
|
488
|
+
// If this assert lands, it's likely because the browser doesn't support scrollX or pageXOffset
|
|
489
|
+
// and we have no viable fallback.
|
|
490
|
+
assert((typeof scrollX !== 'undefined') && (typeof scrollY !== 'undefined'), 'Unable to retrieve scroll position, mouse positions likely broken.');
|
|
491
|
+
#endif
|
|
481
492
|
if (event.type == 'touchstart' ||
|
|
482
493
|
event.type == 'touchend' ||
|
|
483
494
|
event.type == 'touchmove') {
|
|
484
495
|
var t = event.touches.item(0);
|
|
485
496
|
if (t) {
|
|
486
|
-
x = t.pageX - (
|
|
487
|
-
y = t.pageY - (
|
|
497
|
+
x = t.pageX - (scrollX + rect.left);
|
|
498
|
+
y = t.pageY - (scrollY + rect.top);
|
|
488
499
|
} else {
|
|
489
500
|
return;
|
|
490
501
|
}
|
|
491
502
|
} else {
|
|
492
|
-
x = event.pageX - (
|
|
493
|
-
y = event.pageY - (
|
|
503
|
+
x = event.pageX - (scrollX + rect.left);
|
|
504
|
+
y = event.pageY - (scrollY + rect.top);
|
|
494
505
|
}
|
|
495
506
|
|
|
496
507
|
// the canvas might be CSS-scaled compared to its backbuffer;
|
|
@@ -1102,7 +1102,9 @@ mergeInto(LibraryManager.library, {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
}
|
|
1104
1104
|
this.message = ERRNO_MESSAGES[errno];
|
|
1105
|
-
|
|
1105
|
+
#if ASSERTIONS
|
|
1106
|
+
if (this.stack) this.stack = demangleAll(this.stack);
|
|
1107
|
+
#endif
|
|
1106
1108
|
};
|
|
1107
1109
|
FS.ErrnoError.prototype = new Error();
|
|
1108
1110
|
FS.ErrnoError.prototype.constructor = FS.ErrnoError;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
var LibraryGL = {
|
|
7
|
-
$GL__postset: 'GL.init()',
|
|
7
|
+
$GL__postset: 'var GLctx; GL.init()',
|
|
8
8
|
$GL: {
|
|
9
9
|
#if GL_DEBUG
|
|
10
10
|
debug: true,
|
|
@@ -22,9 +22,13 @@ var LibraryGL = {
|
|
|
22
22
|
|
|
23
23
|
#if FULL_ES2
|
|
24
24
|
clientBuffers: [],
|
|
25
|
+
currArrayBuffer: 0,
|
|
26
|
+
currElementArrayBuffer: 0,
|
|
25
27
|
#endif
|
|
28
|
+
#if LEGACY_GL_EMULATION
|
|
26
29
|
currArrayBuffer: 0,
|
|
27
30
|
currElementArrayBuffer: 0,
|
|
31
|
+
#endif
|
|
28
32
|
|
|
29
33
|
byteSizeByTypeRoot: 0x1400, // GL_BYTE
|
|
30
34
|
byteSizeByType: [
|
|
@@ -96,14 +100,14 @@ var LibraryGL = {
|
|
|
96
100
|
}
|
|
97
101
|
if (size != last) {
|
|
98
102
|
curr++;
|
|
99
|
-
GL.tempVertexBuffers[curr] =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
GL.tempIndexBuffers[curr] =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
GL.tempVertexBuffers[curr] = GLctx.createBuffer();
|
|
104
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, GL.tempVertexBuffers[curr]);
|
|
105
|
+
GLctx.bufferData(GLctx.ARRAY_BUFFER, size, GLctx.DYNAMIC_DRAW);
|
|
106
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, null);
|
|
107
|
+
GL.tempIndexBuffers[curr] = GLctx.createBuffer();
|
|
108
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, GL.tempIndexBuffers[curr]);
|
|
109
|
+
GLctx.bufferData(GLctx.ELEMENT_ARRAY_BUFFER, size, GLctx.DYNAMIC_DRAW);
|
|
110
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, null);
|
|
107
111
|
last = size;
|
|
108
112
|
}
|
|
109
113
|
GL.tempBufferIndexLookup[i] = curr;
|
|
@@ -111,8 +115,8 @@ var LibraryGL = {
|
|
|
111
115
|
|
|
112
116
|
if (quads) {
|
|
113
117
|
// GL_QUAD indexes can be precalculated
|
|
114
|
-
GL.tempQuadIndexBuffer =
|
|
115
|
-
|
|
118
|
+
GL.tempQuadIndexBuffer = GLctx.createBuffer();
|
|
119
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, GL.tempQuadIndexBuffer);
|
|
116
120
|
var numIndexes = GL.MAX_TEMP_BUFFER_SIZE >> 1;
|
|
117
121
|
var quadIndexes = new Uint16Array(numIndexes);
|
|
118
122
|
var i = 0, v = 0;
|
|
@@ -131,8 +135,8 @@ var LibraryGL = {
|
|
|
131
135
|
if (i >= numIndexes) break;
|
|
132
136
|
v += 4;
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
GLctx.bufferData(GLctx.ELEMENT_ARRAY_BUFFER, quadIndexes, GLctx.STATIC_DRAW);
|
|
139
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, null);
|
|
136
140
|
}
|
|
137
141
|
},
|
|
138
142
|
|
|
@@ -182,13 +186,13 @@ var LibraryGL = {
|
|
|
182
186
|
source += frag;
|
|
183
187
|
}
|
|
184
188
|
// Let's see if we need to enable the standard derivatives extension
|
|
185
|
-
type =
|
|
189
|
+
type = GLctx.getShaderParameter(GL.shaders[shader], 0x8B4F /* GL_SHADER_TYPE */);
|
|
186
190
|
if (type == 0x8B30 /* GL_FRAGMENT_SHADER */) {
|
|
187
191
|
if (GL.findToken(source, "dFdx") ||
|
|
188
192
|
GL.findToken(source, "dFdy") ||
|
|
189
193
|
GL.findToken(source, "fwidth")) {
|
|
190
194
|
source = "#extension GL_OES_standard_derivatives : enable\n" + source;
|
|
191
|
-
var extension =
|
|
195
|
+
var extension = GLctx.getExtension("OES_standard_derivatives");
|
|
192
196
|
#if GL_DEBUG
|
|
193
197
|
if (!extension) {
|
|
194
198
|
Module.printErr("Shader attempts to use the standard derivatives extension which is not available.");
|
|
@@ -240,7 +244,7 @@ var LibraryGL = {
|
|
|
240
244
|
case 0x86A2: // GL_NUM_COMPRESSED_TEXTURE_FORMATS
|
|
241
245
|
// WebGL doesn't have GL_NUM_COMPRESSED_TEXTURE_FORMATS (it's obsolete since GL_COMPRESSED_TEXTURE_FORMATS returns a JS array that can be queried for length),
|
|
242
246
|
// so implement it ourselves to allow C++ GLES2 code get the length.
|
|
243
|
-
var formats =
|
|
247
|
+
var formats = GLctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/);
|
|
244
248
|
ret = formats.length;
|
|
245
249
|
break;
|
|
246
250
|
case 0x8B9A: // GL_IMPLEMENTATION_COLOR_READ_TYPE
|
|
@@ -252,7 +256,7 @@ var LibraryGL = {
|
|
|
252
256
|
}
|
|
253
257
|
|
|
254
258
|
if (ret === undefined) {
|
|
255
|
-
var result =
|
|
259
|
+
var result = GLctx.getParameter(name_);
|
|
256
260
|
switch (typeof(result)) {
|
|
257
261
|
case "number":
|
|
258
262
|
ret = result;
|
|
@@ -268,11 +272,27 @@ var LibraryGL = {
|
|
|
268
272
|
return;
|
|
269
273
|
case "object":
|
|
270
274
|
if (result === null) {
|
|
271
|
-
|
|
275
|
+
// null is a valid result for some (e.g., which buffer is bound - perhaps nothing is bound), but otherwise
|
|
276
|
+
// can mean an invalid name_, which we need to report as an error
|
|
277
|
+
switch(name_) {
|
|
278
|
+
case 0x8894: // ARRAY_BUFFER_BINDING
|
|
279
|
+
case 0x8B8D: // CURRENT_PROGRAM
|
|
280
|
+
case 0x8895: // ELEMENT_ARRAY_BUFFER_BINDING
|
|
281
|
+
case 0x8CA6: // FRAMEBUFFER_BINDING
|
|
282
|
+
case 0x8CA7: // RENDERBUFFER_BINDING
|
|
283
|
+
case 0x8069: // TEXTURE_BINDING_2D
|
|
284
|
+
case 0x8514: { // TEXTURE_BINDING_CUBE_MAP
|
|
285
|
+
ret = 0;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
default: {
|
|
289
|
+
GL.recordError(0x0500); // GL_INVALID_ENUM
|
|
272
290
|
#if GL_ASSERTIONS
|
|
273
|
-
|
|
291
|
+
Module.printErr('GL_INVALID_ENUM in glGet' + type + 'v(' + name_ + ') and it returns null!');
|
|
274
292
|
#endif
|
|
275
|
-
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
276
296
|
} else if (result instanceof Float32Array ||
|
|
277
297
|
result instanceof Uint32Array ||
|
|
278
298
|
result instanceof Int32Array ||
|
|
@@ -375,7 +395,7 @@ var LibraryGL = {
|
|
|
375
395
|
default:
|
|
376
396
|
throw 'Invalid format (' + format + ')';
|
|
377
397
|
}
|
|
378
|
-
internalFormat =
|
|
398
|
+
internalFormat = GLctx.RGBA;
|
|
379
399
|
break;
|
|
380
400
|
default:
|
|
381
401
|
throw 'Invalid type (' + type + ')';
|
|
@@ -401,13 +421,13 @@ var LibraryGL = {
|
|
|
401
421
|
enableVertexAttribArray: function enableVertexAttribArray(index) {
|
|
402
422
|
if (!GL.enabledClientAttribIndices[index]) {
|
|
403
423
|
GL.enabledClientAttribIndices[index] = true;
|
|
404
|
-
|
|
424
|
+
GLctx.enableVertexAttribArray(index);
|
|
405
425
|
}
|
|
406
426
|
},
|
|
407
427
|
disableVertexAttribArray: function disableVertexAttribArray(index) {
|
|
408
428
|
if (GL.enabledClientAttribIndices[index]) {
|
|
409
429
|
GL.enabledClientAttribIndices[index] = false;
|
|
410
|
-
|
|
430
|
+
GLctx.disableVertexAttribArray(index);
|
|
411
431
|
}
|
|
412
432
|
},
|
|
413
433
|
#endif
|
|
@@ -446,20 +466,20 @@ var LibraryGL = {
|
|
|
446
466
|
buf = GL.tempVertexBuffers[index++];
|
|
447
467
|
} while (used.indexOf(buf) >= 0);
|
|
448
468
|
used.push(buf);
|
|
449
|
-
|
|
450
|
-
|
|
469
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, buf);
|
|
470
|
+
GLctx.bufferSubData(GLctx.ARRAY_BUFFER,
|
|
451
471
|
0,
|
|
452
472
|
HEAPU8.subarray(cb.ptr, cb.ptr + size));
|
|
453
473
|
#if GL_ASSERTIONS
|
|
454
474
|
GL.validateVertexAttribPointer(cb.size, cb.type, cb.stride, 0);
|
|
455
475
|
#endif
|
|
456
|
-
|
|
476
|
+
GLctx.vertexAttribPointer(i, cb.size, cb.type, cb.normalized, cb.stride, 0);
|
|
457
477
|
}
|
|
458
478
|
},
|
|
459
479
|
|
|
460
480
|
postDrawHandleClientVertexAttribBindings: function postDrawHandleClientVertexAttribBindings() {
|
|
461
481
|
if (GL.resetBufferBinding) {
|
|
462
|
-
|
|
482
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, GL.buffers[GL.currArrayBuffer]);
|
|
463
483
|
}
|
|
464
484
|
},
|
|
465
485
|
#endif
|
|
@@ -528,7 +548,7 @@ var LibraryGL = {
|
|
|
528
548
|
GL.miniTempBufferViews[i] = GL.miniTempBuffer.subarray(0, i+1);
|
|
529
549
|
}
|
|
530
550
|
|
|
531
|
-
GL.maxVertexAttribs =
|
|
551
|
+
GL.maxVertexAttribs = GLctx.getParameter(GLctx.MAX_VERTEX_ATTRIBS);
|
|
532
552
|
#if FULL_ES2
|
|
533
553
|
for (var i = 0; i < GL.maxVertexAttribs; i++) {
|
|
534
554
|
GL.clientBuffers[i] = { enabled: false, clientside: false, size: 0, type: 0, normalized: 0, stride: 0, ptr: 0 };
|
|
@@ -538,15 +558,18 @@ var LibraryGL = {
|
|
|
538
558
|
#endif
|
|
539
559
|
|
|
540
560
|
// Detect the presence of a few extensions manually, this GL interop layer itself will need to know if they exist.
|
|
541
|
-
GL.compressionExt =
|
|
542
|
-
|
|
543
|
-
|
|
561
|
+
GL.compressionExt = GLctx.getExtension('WEBGL_compressed_texture_s3tc') ||
|
|
562
|
+
GLctx.getExtension('MOZ_WEBGL_compressed_texture_s3tc') ||
|
|
563
|
+
GLctx.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
|
|
544
564
|
|
|
545
|
-
GL.anisotropicExt =
|
|
546
|
-
|
|
547
|
-
|
|
565
|
+
GL.anisotropicExt = GLctx.getExtension('EXT_texture_filter_anisotropic') ||
|
|
566
|
+
GLctx.getExtension('MOZ_EXT_texture_filter_anisotropic') ||
|
|
567
|
+
GLctx.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
|
|
548
568
|
|
|
549
|
-
GL.floatExt =
|
|
569
|
+
GL.floatExt = GLctx.getExtension('OES_texture_float');
|
|
570
|
+
|
|
571
|
+
// Extension available from Firefox 26 and Google Chrome 30
|
|
572
|
+
GL.instancedArraysExt = GLctx.getExtension('ANGLE_instanced_arrays');
|
|
550
573
|
|
|
551
574
|
// These are the 'safe' feature-enabling extensions that don't add any performance impact related to e.g. debugging, and
|
|
552
575
|
// should be enabled by default so that client GLES2/GL code will not need to go through extra hoops to get its stuff working.
|
|
@@ -570,11 +593,11 @@ var LibraryGL = {
|
|
|
570
593
|
return false;
|
|
571
594
|
}
|
|
572
595
|
|
|
573
|
-
var extensions =
|
|
596
|
+
var extensions = GLctx.getSupportedExtensions();
|
|
574
597
|
for(var e in extensions) {
|
|
575
598
|
var ext = extensions[e].replace('MOZ_', '').replace('WEBKIT_', '');
|
|
576
599
|
if (automaticallyEnabledExtensions.indexOf(ext) != -1) {
|
|
577
|
-
|
|
600
|
+
GLctx.getExtension(ext); // Calling .getExtension enables that extension permanently, no need to store the return value to be enabled.
|
|
578
601
|
}
|
|
579
602
|
}
|
|
580
603
|
},
|
|
@@ -601,9 +624,9 @@ var LibraryGL = {
|
|
|
601
624
|
var utable = ptable.uniforms;
|
|
602
625
|
// A program's uniform table maps the string name of an uniform to an integer location of that uniform.
|
|
603
626
|
// The global GL.uniforms map maps integer locations to WebGLUniformLocations.
|
|
604
|
-
var numUniforms =
|
|
627
|
+
var numUniforms = GLctx.getProgramParameter(p, GLctx.ACTIVE_UNIFORMS);
|
|
605
628
|
for (var i = 0; i < numUniforms; ++i) {
|
|
606
|
-
var u =
|
|
629
|
+
var u = GLctx.getActiveUniform(p, i);
|
|
607
630
|
|
|
608
631
|
var name = u.name;
|
|
609
632
|
ptable.maxUniformLength = Math.max(ptable.maxUniformLength, name.length+1);
|
|
@@ -617,14 +640,14 @@ var LibraryGL = {
|
|
|
617
640
|
// Optimize memory usage slightly: If we have an array of uniforms, e.g. 'vec3 colors[3];', then
|
|
618
641
|
// only store the string 'colors' in utable, and 'colors[0]', 'colors[1]' and 'colors[2]' will be parsed as 'colors'+i.
|
|
619
642
|
// Note that for the GL.uniforms table, we still need to fetch the all WebGLUniformLocations for all the indices.
|
|
620
|
-
var loc =
|
|
643
|
+
var loc = GLctx.getUniformLocation(p, name);
|
|
621
644
|
var id = GL.getNewId(GL.uniforms);
|
|
622
645
|
utable[name] = [u.size, id];
|
|
623
646
|
GL.uniforms[id] = loc;
|
|
624
647
|
|
|
625
648
|
for (var j = 1; j < u.size; ++j) {
|
|
626
649
|
var n = name + '['+j+']';
|
|
627
|
-
loc =
|
|
650
|
+
loc = GLctx.getUniformLocation(p, n);
|
|
628
651
|
id = GL.getNewId(GL.uniforms);
|
|
629
652
|
|
|
630
653
|
GL.uniforms[id] = loc;
|
|
@@ -640,7 +663,7 @@ var LibraryGL = {
|
|
|
640
663
|
} else if (pname == 0x0cf5 /* GL_UNPACK_ALIGNMENT */) {
|
|
641
664
|
GL.unpackAlignment = param;
|
|
642
665
|
}
|
|
643
|
-
|
|
666
|
+
GLctx.pixelStorei(pname, param);
|
|
644
667
|
},
|
|
645
668
|
|
|
646
669
|
glGetString__sig: 'ii',
|
|
@@ -651,10 +674,10 @@ var LibraryGL = {
|
|
|
651
674
|
case 0x1F00 /* GL_VENDOR */:
|
|
652
675
|
case 0x1F01 /* GL_RENDERER */:
|
|
653
676
|
case 0x1F02 /* GL_VERSION */:
|
|
654
|
-
ret = allocate(intArrayFromString(
|
|
677
|
+
ret = allocate(intArrayFromString(GLctx.getParameter(name_)), 'i8', ALLOC_NORMAL);
|
|
655
678
|
break;
|
|
656
679
|
case 0x1F03 /* GL_EXTENSIONS */:
|
|
657
|
-
var exts =
|
|
680
|
+
var exts = GLctx.getSupportedExtensions();
|
|
658
681
|
var gl_exts = [];
|
|
659
682
|
for (i in exts) {
|
|
660
683
|
gl_exts.push(exts[i]);
|
|
@@ -695,7 +718,7 @@ var LibraryGL = {
|
|
|
695
718
|
glGenTextures: function(n, textures) {
|
|
696
719
|
for (var i = 0; i < n; i++) {
|
|
697
720
|
var id = GL.getNewId(GL.textures);
|
|
698
|
-
var texture =
|
|
721
|
+
var texture = GLctx.createTexture();
|
|
699
722
|
texture.name = id;
|
|
700
723
|
GL.textures[id] = texture;
|
|
701
724
|
{{{ makeSetValue('textures', 'i*4', 'id', 'i32') }}};
|
|
@@ -707,7 +730,7 @@ var LibraryGL = {
|
|
|
707
730
|
for (var i = 0; i < n; i++) {
|
|
708
731
|
var id = {{{ makeGetValue('textures', 'i*4', 'i32') }}};
|
|
709
732
|
var texture = GL.textures[id];
|
|
710
|
-
|
|
733
|
+
GLctx.deleteTexture(texture);
|
|
711
734
|
texture.name = 0;
|
|
712
735
|
GL.textures[id] = null;
|
|
713
736
|
}
|
|
@@ -723,7 +746,8 @@ var LibraryGL = {
|
|
|
723
746
|
} else {
|
|
724
747
|
data = null;
|
|
725
748
|
}
|
|
726
|
-
|
|
749
|
+
// N.b. using array notation explicitly to not confuse Closure minification.
|
|
750
|
+
GLctx['compressedTexImage2D'](target, level, internalFormat, width, height, border, data);
|
|
727
751
|
},
|
|
728
752
|
|
|
729
753
|
glCompressedTexSubImage2D__sig: 'viiiiiiiii',
|
|
@@ -736,7 +760,7 @@ var LibraryGL = {
|
|
|
736
760
|
} else {
|
|
737
761
|
data = null;
|
|
738
762
|
}
|
|
739
|
-
|
|
763
|
+
CLctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, data);
|
|
740
764
|
},
|
|
741
765
|
|
|
742
766
|
glTexImage2D__sig: 'viiiiiiiii',
|
|
@@ -748,7 +772,7 @@ var LibraryGL = {
|
|
|
748
772
|
} else {
|
|
749
773
|
pixels = null;
|
|
750
774
|
}
|
|
751
|
-
|
|
775
|
+
GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
|
|
752
776
|
},
|
|
753
777
|
|
|
754
778
|
glTexSubImage2D__sig: 'viiiiiiiii',
|
|
@@ -759,7 +783,7 @@ var LibraryGL = {
|
|
|
759
783
|
} else {
|
|
760
784
|
pixels = null;
|
|
761
785
|
}
|
|
762
|
-
|
|
786
|
+
GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
|
763
787
|
},
|
|
764
788
|
|
|
765
789
|
glReadPixels__sig: 'viiiiiii',
|
|
@@ -783,7 +807,7 @@ var LibraryGL = {
|
|
|
783
807
|
return;
|
|
784
808
|
}
|
|
785
809
|
var totalSize = width*height*sizePerPixel;
|
|
786
|
-
|
|
810
|
+
GLctx.readPixels(x, y, width, height, format, type, HEAPU8.subarray(pixels, pixels + totalSize));
|
|
787
811
|
},
|
|
788
812
|
|
|
789
813
|
glBindTexture__sig: 'vii',
|
|
@@ -791,7 +815,7 @@ var LibraryGL = {
|
|
|
791
815
|
#if GL_ASSERTIONS
|
|
792
816
|
GL.validateGLObjectID(GL.textures, texture, 'glBindTexture', 'texture');
|
|
793
817
|
#endif
|
|
794
|
-
|
|
818
|
+
GLctx.bindTexture(target, texture ? GL.textures[texture] : null);
|
|
795
819
|
},
|
|
796
820
|
|
|
797
821
|
glGetTexParameterfv__sig: 'viii',
|
|
@@ -807,27 +831,27 @@ var LibraryGL = {
|
|
|
807
831
|
glTexParameterfv__sig: 'viii',
|
|
808
832
|
glTexParameterfv: function(target, pname, params) {
|
|
809
833
|
var param = {{{ makeGetValue('params', '0', 'float') }}};
|
|
810
|
-
|
|
834
|
+
GLctx.texParameterf(target, pname, param);
|
|
811
835
|
},
|
|
812
836
|
|
|
813
837
|
glTexParameteriv__sig: 'viii',
|
|
814
838
|
glTexParameteriv: function(target, pname, params) {
|
|
815
839
|
var param = {{{ makeGetValue('params', '0', 'i32') }}};
|
|
816
|
-
|
|
840
|
+
GLctx.texParameteri(target, pname, param);
|
|
817
841
|
},
|
|
818
842
|
|
|
819
843
|
glIsTexture__sig: 'ii',
|
|
820
844
|
glIsTexture: function(texture) {
|
|
821
845
|
var texture = GL.textures[texture];
|
|
822
846
|
if (!texture) return 0;
|
|
823
|
-
return
|
|
847
|
+
return GLctx.isTexture(texture);
|
|
824
848
|
},
|
|
825
849
|
|
|
826
850
|
glGenBuffers__sig: 'vii',
|
|
827
851
|
glGenBuffers: function(n, buffers) {
|
|
828
852
|
for (var i = 0; i < n; i++) {
|
|
829
853
|
var id = GL.getNewId(GL.buffers);
|
|
830
|
-
var buffer =
|
|
854
|
+
var buffer = GLctx.createBuffer();
|
|
831
855
|
buffer.name = id;
|
|
832
856
|
GL.buffers[id] = buffer;
|
|
833
857
|
{{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}};
|
|
@@ -844,7 +868,7 @@ var LibraryGL = {
|
|
|
844
868
|
// correspond to existing buffer objects."
|
|
845
869
|
if (!buffer) continue;
|
|
846
870
|
|
|
847
|
-
|
|
871
|
+
GLctx.deleteBuffer(buffer);
|
|
848
872
|
buffer.name = 0;
|
|
849
873
|
GL.buffers[id] = null;
|
|
850
874
|
|
|
@@ -855,7 +879,7 @@ var LibraryGL = {
|
|
|
855
879
|
|
|
856
880
|
glGetBufferParameteriv__sig: 'viii',
|
|
857
881
|
glGetBufferParameteriv: function(target, value, data) {
|
|
858
|
-
{{{ makeSetValue('data', '0', '
|
|
882
|
+
{{{ makeSetValue('data', '0', 'GLctx.getBufferParameter(target, value)', 'i32') }}};
|
|
859
883
|
},
|
|
860
884
|
|
|
861
885
|
glBufferData__sig: 'viiii',
|
|
@@ -874,26 +898,26 @@ var LibraryGL = {
|
|
|
874
898
|
usage = 0x88E8; // GL_DYNAMIC_DRAW
|
|
875
899
|
break;
|
|
876
900
|
}
|
|
877
|
-
|
|
901
|
+
GLctx.bufferData(target, HEAPU8.subarray(data, data+size), usage);
|
|
878
902
|
},
|
|
879
903
|
|
|
880
904
|
glBufferSubData__sig: 'viiii',
|
|
881
905
|
glBufferSubData: function(target, offset, size, data) {
|
|
882
|
-
|
|
906
|
+
GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size));
|
|
883
907
|
},
|
|
884
908
|
|
|
885
909
|
glIsBuffer__sig: 'ii',
|
|
886
910
|
glIsBuffer: function(buffer) {
|
|
887
911
|
var b = GL.buffers[buffer];
|
|
888
912
|
if (!b) return 0;
|
|
889
|
-
return
|
|
913
|
+
return GLctx.isBuffer(b);
|
|
890
914
|
},
|
|
891
915
|
|
|
892
916
|
glGenRenderbuffers__sig: 'vii',
|
|
893
917
|
glGenRenderbuffers: function(n, renderbuffers) {
|
|
894
918
|
for (var i = 0; i < n; i++) {
|
|
895
919
|
var id = GL.getNewId(GL.renderbuffers);
|
|
896
|
-
var renderbuffer =
|
|
920
|
+
var renderbuffer = GLctx.createRenderbuffer();
|
|
897
921
|
renderbuffer.name = id;
|
|
898
922
|
GL.renderbuffers[id] = renderbuffer;
|
|
899
923
|
{{{ makeSetValue('renderbuffers', 'i*4', 'id', 'i32') }}};
|
|
@@ -905,7 +929,7 @@ var LibraryGL = {
|
|
|
905
929
|
for (var i = 0; i < n; i++) {
|
|
906
930
|
var id = {{{ makeGetValue('renderbuffers', 'i*4', 'i32') }}};
|
|
907
931
|
var renderbuffer = GL.renderbuffers[id];
|
|
908
|
-
|
|
932
|
+
GLctx.deleteRenderbuffer(renderbuffer);
|
|
909
933
|
renderbuffer.name = 0;
|
|
910
934
|
GL.renderbuffers[id] = null;
|
|
911
935
|
}
|
|
@@ -916,19 +940,19 @@ var LibraryGL = {
|
|
|
916
940
|
#if GL_ASSERTIONS
|
|
917
941
|
GL.validateGLObjectID(GL.renderbuffers, renderbuffer, 'glBindRenderbuffer', 'renderbuffer');
|
|
918
942
|
#endif
|
|
919
|
-
|
|
943
|
+
GLctx.bindRenderbuffer(target, renderbuffer ? GL.renderbuffers[renderbuffer] : null);
|
|
920
944
|
},
|
|
921
945
|
|
|
922
946
|
glGetRenderbufferParameteriv__sig: 'viii',
|
|
923
947
|
glGetRenderbufferParameteriv: function(target, pname, params) {
|
|
924
|
-
{{{ makeSetValue('params', '0', '
|
|
948
|
+
{{{ makeSetValue('params', '0', 'GLctx.getRenderbufferParameter(target, pname)', 'i32') }}};
|
|
925
949
|
},
|
|
926
950
|
|
|
927
951
|
glIsRenderbuffer__sig: 'ii',
|
|
928
952
|
glIsRenderbuffer: function(renderbuffer) {
|
|
929
953
|
var rb = GL.renderbuffers[renderbuffer];
|
|
930
954
|
if (!rb) return 0;
|
|
931
|
-
return
|
|
955
|
+
return GLctx.isRenderbuffer(rb);
|
|
932
956
|
},
|
|
933
957
|
|
|
934
958
|
glGetUniformfv__sig: 'viii',
|
|
@@ -937,7 +961,7 @@ var LibraryGL = {
|
|
|
937
961
|
GL.validateGLObjectID(GL.programs, program, 'glGetUniformfv', 'program');
|
|
938
962
|
GL.validateGLObjectID(GL.uniforms, location, 'glGetUniformfv', 'location');
|
|
939
963
|
#endif
|
|
940
|
-
var data =
|
|
964
|
+
var data = GLctx.getUniform(GL.programs[program], GL.uniforms[location]);
|
|
941
965
|
if (typeof data == 'number') {
|
|
942
966
|
{{{ makeSetValue('params', '0', 'data', 'float') }}};
|
|
943
967
|
} else {
|
|
@@ -953,7 +977,7 @@ var LibraryGL = {
|
|
|
953
977
|
GL.validateGLObjectID(GL.programs, program, 'glGetUniformiv', 'program');
|
|
954
978
|
GL.validateGLObjectID(GL.uniforms, location, 'glGetUniformiv', 'location');
|
|
955
979
|
#endif
|
|
956
|
-
var data =
|
|
980
|
+
var data = GLctx.getUniform(GL.programs[program], GL.uniforms[location]);
|
|
957
981
|
if (typeof data == 'number' || typeof data == 'boolean') {
|
|
958
982
|
{{{ makeSetValue('params', '0', 'data', 'i32') }}};
|
|
959
983
|
} else {
|
|
@@ -1004,7 +1028,7 @@ var LibraryGL = {
|
|
|
1004
1028
|
Module.printErr("glGetVertexAttribfv on client-side array: not supported, bad data returned");
|
|
1005
1029
|
}
|
|
1006
1030
|
#endif
|
|
1007
|
-
var data =
|
|
1031
|
+
var data = GLctx.getVertexAttrib(index, pname);
|
|
1008
1032
|
if (typeof data == 'number') {
|
|
1009
1033
|
{{{ makeSetValue('params', '0', 'data', 'float') }}};
|
|
1010
1034
|
} else {
|
|
@@ -1021,7 +1045,7 @@ var LibraryGL = {
|
|
|
1021
1045
|
Module.printErr("glGetVertexAttribiv on client-side array: not supported, bad data returned");
|
|
1022
1046
|
}
|
|
1023
1047
|
#endif
|
|
1024
|
-
var data =
|
|
1048
|
+
var data = GLctx.getVertexAttrib(index, pname);
|
|
1025
1049
|
if (typeof data == 'number' || typeof data == 'boolean') {
|
|
1026
1050
|
{{{ makeSetValue('params', '0', 'data', 'i32') }}};
|
|
1027
1051
|
} else {
|
|
@@ -1038,7 +1062,7 @@ var LibraryGL = {
|
|
|
1038
1062
|
Module.printErr("glGetVertexAttribPointer on client-side array: not supported, bad data returned");
|
|
1039
1063
|
}
|
|
1040
1064
|
#endif
|
|
1041
|
-
{{{ makeSetValue('pointer', '0', '
|
|
1065
|
+
{{{ makeSetValue('pointer', '0', 'GLctx.getVertexAttribOffset(index, pname)', 'i32') }}};
|
|
1042
1066
|
},
|
|
1043
1067
|
|
|
1044
1068
|
glGetActiveUniform__sig: 'viiiiiii',
|
|
@@ -1047,7 +1071,7 @@ var LibraryGL = {
|
|
|
1047
1071
|
GL.validateGLObjectID(GL.programs, program, 'glGetActiveUniform', 'program');
|
|
1048
1072
|
#endif
|
|
1049
1073
|
program = GL.programs[program];
|
|
1050
|
-
var info =
|
|
1074
|
+
var info = GLctx.getActiveUniform(program, index);
|
|
1051
1075
|
|
|
1052
1076
|
var infoname = info.name.slice(0, Math.max(0, bufSize - 1));
|
|
1053
1077
|
writeStringToMemory(infoname, name);
|
|
@@ -1069,7 +1093,7 @@ var LibraryGL = {
|
|
|
1069
1093
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform1f', 'location');
|
|
1070
1094
|
#endif
|
|
1071
1095
|
location = GL.uniforms[location];
|
|
1072
|
-
|
|
1096
|
+
GLctx.uniform1f(location, v0);
|
|
1073
1097
|
},
|
|
1074
1098
|
|
|
1075
1099
|
glUniform2f__sig: 'viff',
|
|
@@ -1078,7 +1102,7 @@ var LibraryGL = {
|
|
|
1078
1102
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform2f', 'location');
|
|
1079
1103
|
#endif
|
|
1080
1104
|
location = GL.uniforms[location];
|
|
1081
|
-
|
|
1105
|
+
GLctx.uniform2f(location, v0, v1);
|
|
1082
1106
|
},
|
|
1083
1107
|
|
|
1084
1108
|
glUniform3f__sig: 'vifff',
|
|
@@ -1087,7 +1111,7 @@ var LibraryGL = {
|
|
|
1087
1111
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform3f', 'location');
|
|
1088
1112
|
#endif
|
|
1089
1113
|
location = GL.uniforms[location];
|
|
1090
|
-
|
|
1114
|
+
GLctx.uniform3f(location, v0, v1, v2);
|
|
1091
1115
|
},
|
|
1092
1116
|
|
|
1093
1117
|
glUniform4f__sig: 'viffff',
|
|
@@ -1096,7 +1120,7 @@ var LibraryGL = {
|
|
|
1096
1120
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform4f', 'location');
|
|
1097
1121
|
#endif
|
|
1098
1122
|
location = GL.uniforms[location];
|
|
1099
|
-
|
|
1123
|
+
GLctx.uniform4f(location, v0, v1, v2, v3);
|
|
1100
1124
|
},
|
|
1101
1125
|
|
|
1102
1126
|
glUniform1i__sig: 'vii',
|
|
@@ -1105,7 +1129,7 @@ var LibraryGL = {
|
|
|
1105
1129
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform1i', 'location');
|
|
1106
1130
|
#endif
|
|
1107
1131
|
location = GL.uniforms[location];
|
|
1108
|
-
|
|
1132
|
+
GLctx.uniform1i(location, v0);
|
|
1109
1133
|
},
|
|
1110
1134
|
|
|
1111
1135
|
glUniform2i__sig: 'viii',
|
|
@@ -1114,7 +1138,7 @@ var LibraryGL = {
|
|
|
1114
1138
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform2i', 'location');
|
|
1115
1139
|
#endif
|
|
1116
1140
|
location = GL.uniforms[location];
|
|
1117
|
-
|
|
1141
|
+
GLctx.uniform2i(location, v0, v1);
|
|
1118
1142
|
},
|
|
1119
1143
|
|
|
1120
1144
|
glUniform3i__sig: 'viiii',
|
|
@@ -1123,7 +1147,7 @@ var LibraryGL = {
|
|
|
1123
1147
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform3i', 'location');
|
|
1124
1148
|
#endif
|
|
1125
1149
|
location = GL.uniforms[location];
|
|
1126
|
-
|
|
1150
|
+
GLctx.uniform3i(location, v0, v1, v2);
|
|
1127
1151
|
},
|
|
1128
1152
|
|
|
1129
1153
|
glUniform4i__sig: 'viiiii',
|
|
@@ -1132,7 +1156,7 @@ var LibraryGL = {
|
|
|
1132
1156
|
GL.validateGLObjectID(GL.uniforms, location, 'glUniform4i', 'location');
|
|
1133
1157
|
#endif
|
|
1134
1158
|
location = GL.uniforms[location];
|
|
1135
|
-
|
|
1159
|
+
GLctx.uniform4i(location, v0, v1, v2, v3);
|
|
1136
1160
|
},
|
|
1137
1161
|
|
|
1138
1162
|
glUniform1iv__sig: 'viii',
|
|
@@ -1142,7 +1166,7 @@ var LibraryGL = {
|
|
|
1142
1166
|
#endif
|
|
1143
1167
|
location = GL.uniforms[location];
|
|
1144
1168
|
value = {{{ makeHEAPView('32', 'value', 'value+count*4') }}};
|
|
1145
|
-
|
|
1169
|
+
GLctx.uniform1iv(location, value);
|
|
1146
1170
|
},
|
|
1147
1171
|
|
|
1148
1172
|
glUniform2iv__sig: 'viii',
|
|
@@ -1153,7 +1177,7 @@ var LibraryGL = {
|
|
|
1153
1177
|
location = GL.uniforms[location];
|
|
1154
1178
|
count *= 2;
|
|
1155
1179
|
value = {{{ makeHEAPView('32', 'value', 'value+count*4') }}};
|
|
1156
|
-
|
|
1180
|
+
GLctx.uniform2iv(location, value);
|
|
1157
1181
|
},
|
|
1158
1182
|
|
|
1159
1183
|
glUniform3iv__sig: 'viii',
|
|
@@ -1164,7 +1188,7 @@ var LibraryGL = {
|
|
|
1164
1188
|
location = GL.uniforms[location];
|
|
1165
1189
|
count *= 3;
|
|
1166
1190
|
value = {{{ makeHEAPView('32', 'value', 'value+count*4') }}};
|
|
1167
|
-
|
|
1191
|
+
GLctx.uniform3iv(location, value);
|
|
1168
1192
|
},
|
|
1169
1193
|
|
|
1170
1194
|
glUniform4iv__sig: 'viii',
|
|
@@ -1175,7 +1199,7 @@ var LibraryGL = {
|
|
|
1175
1199
|
location = GL.uniforms[location];
|
|
1176
1200
|
count *= 4;
|
|
1177
1201
|
value = {{{ makeHEAPView('32', 'value', 'value+count*4') }}};
|
|
1178
|
-
|
|
1202
|
+
GLctx.uniform4iv(location, value);
|
|
1179
1203
|
},
|
|
1180
1204
|
|
|
1181
1205
|
glUniform1fv__sig: 'viii',
|
|
@@ -1192,7 +1216,7 @@ var LibraryGL = {
|
|
|
1192
1216
|
} else {
|
|
1193
1217
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*4') }}};
|
|
1194
1218
|
}
|
|
1195
|
-
|
|
1219
|
+
GLctx.uniform1fv(location, view);
|
|
1196
1220
|
},
|
|
1197
1221
|
|
|
1198
1222
|
glUniform2fv__sig: 'viii',
|
|
@@ -1210,7 +1234,7 @@ var LibraryGL = {
|
|
|
1210
1234
|
} else {
|
|
1211
1235
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*8') }}};
|
|
1212
1236
|
}
|
|
1213
|
-
|
|
1237
|
+
GLctx.uniform2fv(location, view);
|
|
1214
1238
|
},
|
|
1215
1239
|
|
|
1216
1240
|
glUniform3fv__sig: 'viii',
|
|
@@ -1229,7 +1253,7 @@ var LibraryGL = {
|
|
|
1229
1253
|
} else {
|
|
1230
1254
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*12') }}};
|
|
1231
1255
|
}
|
|
1232
|
-
|
|
1256
|
+
GLctx.uniform3fv(location, view);
|
|
1233
1257
|
},
|
|
1234
1258
|
|
|
1235
1259
|
glUniform4fv__sig: 'viii',
|
|
@@ -1249,7 +1273,7 @@ var LibraryGL = {
|
|
|
1249
1273
|
} else {
|
|
1250
1274
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*16') }}};
|
|
1251
1275
|
}
|
|
1252
|
-
|
|
1276
|
+
GLctx.uniform4fv(location, view);
|
|
1253
1277
|
},
|
|
1254
1278
|
|
|
1255
1279
|
glUniformMatrix2fv__sig: 'viiii',
|
|
@@ -1268,7 +1292,7 @@ var LibraryGL = {
|
|
|
1268
1292
|
} else {
|
|
1269
1293
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*16') }}};
|
|
1270
1294
|
}
|
|
1271
|
-
|
|
1295
|
+
GLctx.uniformMatrix2fv(location, transpose, view);
|
|
1272
1296
|
},
|
|
1273
1297
|
|
|
1274
1298
|
glUniformMatrix3fv__sig: 'viiii',
|
|
@@ -1287,7 +1311,7 @@ var LibraryGL = {
|
|
|
1287
1311
|
} else {
|
|
1288
1312
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*36') }}};
|
|
1289
1313
|
}
|
|
1290
|
-
|
|
1314
|
+
GLctx.uniformMatrix3fv(location, transpose, view);
|
|
1291
1315
|
},
|
|
1292
1316
|
|
|
1293
1317
|
glUniformMatrix4fv__sig: 'viiii',
|
|
@@ -1306,7 +1330,7 @@ var LibraryGL = {
|
|
|
1306
1330
|
} else {
|
|
1307
1331
|
view = {{{ makeHEAPView('F32', 'value', 'value+count*64') }}};
|
|
1308
1332
|
}
|
|
1309
|
-
|
|
1333
|
+
GLctx.uniformMatrix4fv(location, transpose, view);
|
|
1310
1334
|
},
|
|
1311
1335
|
|
|
1312
1336
|
glBindBuffer__sig: 'vii',
|
|
@@ -1316,44 +1340,53 @@ var LibraryGL = {
|
|
|
1316
1340
|
#endif
|
|
1317
1341
|
var bufferObj = buffer ? GL.buffers[buffer] : null;
|
|
1318
1342
|
|
|
1319
|
-
|
|
1343
|
+
#if FULL_ES2
|
|
1344
|
+
if (target == GLctx.ARRAY_BUFFER) {
|
|
1320
1345
|
GL.currArrayBuffer = buffer;
|
|
1321
|
-
} else if (target ==
|
|
1346
|
+
} else if (target == GLctx.ELEMENT_ARRAY_BUFFER) {
|
|
1347
|
+
GL.currElementArrayBuffer = buffer;
|
|
1348
|
+
}
|
|
1349
|
+
#endif
|
|
1350
|
+
#if LEGACY_GL_EMULATION
|
|
1351
|
+
if (target == GLctx.ARRAY_BUFFER) {
|
|
1352
|
+
GLImmediate.lastArrayBuffer = GL.currArrayBuffer = buffer;
|
|
1353
|
+
} else if (target == GLctx.ELEMENT_ARRAY_BUFFER) {
|
|
1322
1354
|
GL.currElementArrayBuffer = buffer;
|
|
1323
1355
|
}
|
|
1356
|
+
#endif
|
|
1324
1357
|
|
|
1325
|
-
|
|
1358
|
+
GLctx.bindBuffer(target, bufferObj);
|
|
1326
1359
|
},
|
|
1327
1360
|
|
|
1328
1361
|
glVertexAttrib1fv__sig: 'vii',
|
|
1329
1362
|
glVertexAttrib1fv: function(index, v) {
|
|
1330
1363
|
v = {{{ makeHEAPView('F32', 'v', 'v+' + (1*4)) }}};
|
|
1331
|
-
|
|
1364
|
+
GLctx.vertexAttrib1fv(index, v);
|
|
1332
1365
|
},
|
|
1333
1366
|
|
|
1334
1367
|
glVertexAttrib2fv__sig: 'vii',
|
|
1335
1368
|
glVertexAttrib2fv: function(index, v) {
|
|
1336
1369
|
v = {{{ makeHEAPView('F32', 'v', 'v+' + (2*4)) }}};
|
|
1337
|
-
|
|
1370
|
+
GLctx.vertexAttrib2fv(index, v);
|
|
1338
1371
|
},
|
|
1339
1372
|
|
|
1340
1373
|
glVertexAttrib3fv__sig: 'vii',
|
|
1341
1374
|
glVertexAttrib3fv: function(index, v) {
|
|
1342
1375
|
v = {{{ makeHEAPView('F32', 'v', 'v+' + (3*4)) }}};
|
|
1343
|
-
|
|
1376
|
+
GLctx.vertexAttrib3fv(index, v);
|
|
1344
1377
|
},
|
|
1345
1378
|
|
|
1346
1379
|
glVertexAttrib4fv__sig: 'vii',
|
|
1347
1380
|
glVertexAttrib4fv: function(index, v) {
|
|
1348
1381
|
v = {{{ makeHEAPView('F32', 'v', 'v+' + (4*4)) }}};
|
|
1349
|
-
|
|
1382
|
+
GLctx.vertexAttrib4fv(index, v);
|
|
1350
1383
|
},
|
|
1351
1384
|
|
|
1352
1385
|
glGetAttribLocation__sig: 'vii',
|
|
1353
1386
|
glGetAttribLocation: function(program, name) {
|
|
1354
1387
|
program = GL.programs[program];
|
|
1355
1388
|
name = Pointer_stringify(name);
|
|
1356
|
-
return
|
|
1389
|
+
return GLctx.getAttribLocation(program, name);
|
|
1357
1390
|
},
|
|
1358
1391
|
|
|
1359
1392
|
glGetActiveAttrib__sig: 'viiiiiii',
|
|
@@ -1362,7 +1395,7 @@ var LibraryGL = {
|
|
|
1362
1395
|
GL.validateGLObjectID(GL.programs, program, 'glGetActiveAttrib', 'program');
|
|
1363
1396
|
#endif
|
|
1364
1397
|
program = GL.programs[program];
|
|
1365
|
-
var info =
|
|
1398
|
+
var info = GLctx.getActiveAttrib(program, index);
|
|
1366
1399
|
|
|
1367
1400
|
var infoname = info.name.slice(0, Math.max(0, bufSize - 1));
|
|
1368
1401
|
writeStringToMemory(infoname, name);
|
|
@@ -1381,13 +1414,13 @@ var LibraryGL = {
|
|
|
1381
1414
|
glCreateShader__sig: 'ii',
|
|
1382
1415
|
glCreateShader: function(shaderType) {
|
|
1383
1416
|
var id = GL.getNewId(GL.shaders);
|
|
1384
|
-
GL.shaders[id] =
|
|
1417
|
+
GL.shaders[id] = GLctx.createShader(shaderType);
|
|
1385
1418
|
return id;
|
|
1386
1419
|
},
|
|
1387
1420
|
|
|
1388
1421
|
glDeleteShader__sig: 'vi',
|
|
1389
1422
|
glDeleteShader: function(shader) {
|
|
1390
|
-
|
|
1423
|
+
GLctx.deleteShader(GL.shaders[shader]);
|
|
1391
1424
|
GL.shaders[shader] = null;
|
|
1392
1425
|
},
|
|
1393
1426
|
|
|
@@ -1396,7 +1429,7 @@ var LibraryGL = {
|
|
|
1396
1429
|
#if GL_ASSERTIONS
|
|
1397
1430
|
GL.validateGLObjectID(GL.programs, program, 'glGetAttachedShaders', 'program');
|
|
1398
1431
|
#endif
|
|
1399
|
-
var result =
|
|
1432
|
+
var result = GLctx.getAttachedShaders(GL.programs[program]);
|
|
1400
1433
|
var len = result.length;
|
|
1401
1434
|
if (len > maxCount) {
|
|
1402
1435
|
len = maxCount;
|
|
@@ -1417,7 +1450,7 @@ var LibraryGL = {
|
|
|
1417
1450
|
GL.validateGLObjectID(GL.shaders, shader, 'glShaderSource', 'shader');
|
|
1418
1451
|
#endif
|
|
1419
1452
|
var source = GL.getSource(shader, count, string, length);
|
|
1420
|
-
|
|
1453
|
+
GLctx.shaderSource(GL.shaders[shader], source);
|
|
1421
1454
|
},
|
|
1422
1455
|
|
|
1423
1456
|
glGetShaderSource__sig: 'viiii',
|
|
@@ -1425,7 +1458,7 @@ var LibraryGL = {
|
|
|
1425
1458
|
#if GL_ASSERTIONS
|
|
1426
1459
|
GL.validateGLObjectID(GL.shaders, shader, 'glGetShaderSource', 'shader');
|
|
1427
1460
|
#endif
|
|
1428
|
-
var result =
|
|
1461
|
+
var result = GLctx.getShaderSource(GL.shaders[shader]);
|
|
1429
1462
|
result = result.slice(0, Math.max(0, bufSize - 1));
|
|
1430
1463
|
writeStringToMemory(result, source);
|
|
1431
1464
|
if (length) {
|
|
@@ -1438,7 +1471,7 @@ var LibraryGL = {
|
|
|
1438
1471
|
#if GL_ASSERTIONS
|
|
1439
1472
|
GL.validateGLObjectID(GL.shaders, shader, 'glCompileShader', 'shader');
|
|
1440
1473
|
#endif
|
|
1441
|
-
|
|
1474
|
+
GLctx.compileShader(GL.shaders[shader]);
|
|
1442
1475
|
},
|
|
1443
1476
|
|
|
1444
1477
|
glGetShaderInfoLog__sig: 'viiii',
|
|
@@ -1446,7 +1479,7 @@ var LibraryGL = {
|
|
|
1446
1479
|
#if GL_ASSERTIONS
|
|
1447
1480
|
GL.validateGLObjectID(GL.shaders, shader, 'glGetShaderInfoLog', 'shader');
|
|
1448
1481
|
#endif
|
|
1449
|
-
var log =
|
|
1482
|
+
var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
|
|
1450
1483
|
// Work around a bug in Chromium which causes getShaderInfoLog to return null
|
|
1451
1484
|
if (!log) {
|
|
1452
1485
|
log = "";
|
|
@@ -1464,9 +1497,9 @@ var LibraryGL = {
|
|
|
1464
1497
|
GL.validateGLObjectID(GL.shaders, shader, 'glGetShaderiv', 'shader');
|
|
1465
1498
|
#endif
|
|
1466
1499
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
1467
|
-
{{{ makeSetValue('p', '0', '
|
|
1500
|
+
{{{ makeSetValue('p', '0', 'GLctx.getShaderInfoLog(GL.shaders[shader]).length + 1', 'i32') }}};
|
|
1468
1501
|
} else {
|
|
1469
|
-
{{{ makeSetValue('p', '0', '
|
|
1502
|
+
{{{ makeSetValue('p', '0', 'GLctx.getShaderParameter(GL.shaders[shader], pname)', 'i32') }}};
|
|
1470
1503
|
}
|
|
1471
1504
|
},
|
|
1472
1505
|
|
|
@@ -1476,7 +1509,7 @@ var LibraryGL = {
|
|
|
1476
1509
|
GL.validateGLObjectID(GL.programs, program, 'glGetProgramiv', 'program');
|
|
1477
1510
|
#endif
|
|
1478
1511
|
if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
|
|
1479
|
-
{{{ makeSetValue('p', '0', '
|
|
1512
|
+
{{{ makeSetValue('p', '0', 'GLctx.getProgramInfoLog(GL.programs[program]).length + 1', 'i32') }}};
|
|
1480
1513
|
} else if (pname == 0x8B87 /* GL_ACTIVE_UNIFORM_MAX_LENGTH */) {
|
|
1481
1514
|
var ptable = GL.programInfos[program];
|
|
1482
1515
|
if (ptable) {
|
|
@@ -1498,10 +1531,10 @@ var LibraryGL = {
|
|
|
1498
1531
|
if (ptable) {
|
|
1499
1532
|
if (ptable.maxAttributeLength == -1) {
|
|
1500
1533
|
var program = GL.programs[program];
|
|
1501
|
-
var numAttribs =
|
|
1534
|
+
var numAttribs = GLctx.getProgramParameter(program, GLctx.ACTIVE_ATTRIBUTES);
|
|
1502
1535
|
ptable.maxAttributeLength = 0; // Spec says if there are no active attribs, 0 must be returned.
|
|
1503
1536
|
for(var i = 0; i < numAttribs; ++i) {
|
|
1504
|
-
var activeAttrib =
|
|
1537
|
+
var activeAttrib = GLctx.getActiveAttrib(program, i);
|
|
1505
1538
|
ptable.maxAttributeLength = Math.max(ptable.maxAttributeLength, activeAttrib.name.length+1);
|
|
1506
1539
|
}
|
|
1507
1540
|
}
|
|
@@ -1519,7 +1552,7 @@ var LibraryGL = {
|
|
|
1519
1552
|
GL.recordError(0x0501 /* GL_INVALID_VALUE */);
|
|
1520
1553
|
}
|
|
1521
1554
|
} else {
|
|
1522
|
-
{{{ makeSetValue('p', '0', '
|
|
1555
|
+
{{{ makeSetValue('p', '0', 'GLctx.getProgramParameter(GL.programs[program], pname)', 'i32') }}};
|
|
1523
1556
|
}
|
|
1524
1557
|
},
|
|
1525
1558
|
|
|
@@ -1527,13 +1560,13 @@ var LibraryGL = {
|
|
|
1527
1560
|
glIsShader: function(shader) {
|
|
1528
1561
|
var s = GL.shaders[shader];
|
|
1529
1562
|
if (!s) return 0;
|
|
1530
|
-
return
|
|
1563
|
+
return GLctx.isShader(s);
|
|
1531
1564
|
},
|
|
1532
1565
|
|
|
1533
1566
|
glCreateProgram__sig: 'i',
|
|
1534
1567
|
glCreateProgram: function() {
|
|
1535
1568
|
var id = GL.getNewId(GL.programs);
|
|
1536
|
-
var program =
|
|
1569
|
+
var program = GLctx.createProgram();
|
|
1537
1570
|
program.name = id;
|
|
1538
1571
|
GL.programs[id] = program;
|
|
1539
1572
|
return id;
|
|
@@ -1542,7 +1575,7 @@ var LibraryGL = {
|
|
|
1542
1575
|
glDeleteProgram__sig: 'vi',
|
|
1543
1576
|
glDeleteProgram: function(program) {
|
|
1544
1577
|
var program = GL.programs[program];
|
|
1545
|
-
|
|
1578
|
+
GLctx.deleteProgram(program);
|
|
1546
1579
|
program.name = 0;
|
|
1547
1580
|
GL.programs[program] = null;
|
|
1548
1581
|
GL.programInfos[program] = null;
|
|
@@ -1554,7 +1587,7 @@ var LibraryGL = {
|
|
|
1554
1587
|
GL.validateGLObjectID(GL.programs, program, 'glAttachShader', 'program');
|
|
1555
1588
|
GL.validateGLObjectID(GL.shaders, shader, 'glAttachShader', 'shader');
|
|
1556
1589
|
#endif
|
|
1557
|
-
|
|
1590
|
+
GLctx.attachShader(GL.programs[program],
|
|
1558
1591
|
GL.shaders[shader]);
|
|
1559
1592
|
},
|
|
1560
1593
|
|
|
@@ -1564,12 +1597,12 @@ var LibraryGL = {
|
|
|
1564
1597
|
GL.validateGLObjectID(GL.programs, program, 'glDetachShader', 'program');
|
|
1565
1598
|
GL.validateGLObjectID(GL.shaders, shader, 'glDetachShader', 'shader');
|
|
1566
1599
|
#endif
|
|
1567
|
-
|
|
1600
|
+
GLctx.detachShader(GL.programs[program],
|
|
1568
1601
|
GL.shaders[shader]);
|
|
1569
1602
|
},
|
|
1570
1603
|
|
|
1571
1604
|
glGetShaderPrecisionFormat: function(shaderType, precisionType, range, precision) {
|
|
1572
|
-
var result =
|
|
1605
|
+
var result = GLctx.getShaderPrecisionFormat(shaderType, precisionType);
|
|
1573
1606
|
{{{ makeSetValue('range', '0', 'result.rangeMin', 'i32') }}};
|
|
1574
1607
|
{{{ makeSetValue('range', '4', 'result.rangeMax', 'i32') }}};
|
|
1575
1608
|
{{{ makeSetValue('precision', '0', 'result.precision', 'i32') }}};
|
|
@@ -1580,7 +1613,7 @@ var LibraryGL = {
|
|
|
1580
1613
|
#if GL_ASSERTIONS
|
|
1581
1614
|
GL.validateGLObjectID(GL.programs, program, 'glLinkProgram', 'program');
|
|
1582
1615
|
#endif
|
|
1583
|
-
|
|
1616
|
+
GLctx.linkProgram(GL.programs[program]);
|
|
1584
1617
|
GL.programInfos[program] = null; // uniforms no longer keep the same names after linking
|
|
1585
1618
|
GL.populateUniformTable(program);
|
|
1586
1619
|
},
|
|
@@ -1590,7 +1623,7 @@ var LibraryGL = {
|
|
|
1590
1623
|
#if GL_ASSERTIONS
|
|
1591
1624
|
GL.validateGLObjectID(GL.programs, program, 'glGetProgramInfoLog', 'program');
|
|
1592
1625
|
#endif
|
|
1593
|
-
var log =
|
|
1626
|
+
var log = GLctx.getProgramInfoLog(GL.programs[program]);
|
|
1594
1627
|
// Work around a bug in Chromium which causes getProgramInfoLog to return null
|
|
1595
1628
|
if (!log) {
|
|
1596
1629
|
log = "";
|
|
@@ -1607,7 +1640,7 @@ var LibraryGL = {
|
|
|
1607
1640
|
#if GL_ASSERTIONS
|
|
1608
1641
|
GL.validateGLObjectID(GL.programs, program, 'glUseProgram', 'program');
|
|
1609
1642
|
#endif
|
|
1610
|
-
|
|
1643
|
+
GLctx.useProgram(program ? GL.programs[program] : null);
|
|
1611
1644
|
},
|
|
1612
1645
|
|
|
1613
1646
|
glValidateProgram__sig: 'vi',
|
|
@@ -1615,14 +1648,14 @@ var LibraryGL = {
|
|
|
1615
1648
|
#if GL_ASSERTIONS
|
|
1616
1649
|
GL.validateGLObjectID(GL.programs, program, 'glValidateProgram', 'program');
|
|
1617
1650
|
#endif
|
|
1618
|
-
|
|
1651
|
+
GLctx.validateProgram(GL.programs[program]);
|
|
1619
1652
|
},
|
|
1620
1653
|
|
|
1621
1654
|
glIsProgram__sig: 'ii',
|
|
1622
1655
|
glIsProgram: function(program) {
|
|
1623
1656
|
var program = GL.programs[program];
|
|
1624
1657
|
if (!program) return 0;
|
|
1625
|
-
return
|
|
1658
|
+
return GLctx.isProgram(program);
|
|
1626
1659
|
},
|
|
1627
1660
|
|
|
1628
1661
|
glBindAttribLocation__sig: 'viii',
|
|
@@ -1631,7 +1664,7 @@ var LibraryGL = {
|
|
|
1631
1664
|
GL.validateGLObjectID(GL.programs, program, 'glBindAttribLocation', 'program');
|
|
1632
1665
|
#endif
|
|
1633
1666
|
name = Pointer_stringify(name);
|
|
1634
|
-
|
|
1667
|
+
GLctx.bindAttribLocation(GL.programs[program], index, name);
|
|
1635
1668
|
},
|
|
1636
1669
|
|
|
1637
1670
|
glBindFramebuffer__sig: 'vii',
|
|
@@ -1639,14 +1672,14 @@ var LibraryGL = {
|
|
|
1639
1672
|
#if GL_ASSERTIONS
|
|
1640
1673
|
GL.validateGLObjectID(GL.framebuffers, framebuffer, 'glBindFramebuffer', 'framebuffer');
|
|
1641
1674
|
#endif
|
|
1642
|
-
|
|
1675
|
+
GLctx.bindFramebuffer(target, framebuffer ? GL.framebuffers[framebuffer] : null);
|
|
1643
1676
|
},
|
|
1644
1677
|
|
|
1645
1678
|
glGenFramebuffers__sig: 'vii',
|
|
1646
1679
|
glGenFramebuffers: function(n, ids) {
|
|
1647
1680
|
for (var i = 0; i < n; ++i) {
|
|
1648
1681
|
var id = GL.getNewId(GL.framebuffers);
|
|
1649
|
-
var framebuffer =
|
|
1682
|
+
var framebuffer = GLctx.createFramebuffer();
|
|
1650
1683
|
framebuffer.name = id;
|
|
1651
1684
|
GL.framebuffers[id] = framebuffer;
|
|
1652
1685
|
{{{ makeSetValue('ids', 'i*4', 'id', 'i32') }}};
|
|
@@ -1658,7 +1691,7 @@ var LibraryGL = {
|
|
|
1658
1691
|
for (var i = 0; i < n; ++i) {
|
|
1659
1692
|
var id = {{{ makeGetValue('framebuffers', 'i*4', 'i32') }}};
|
|
1660
1693
|
var framebuffer = GL.framebuffers[id];
|
|
1661
|
-
|
|
1694
|
+
GLctx.deleteFramebuffer(framebuffer);
|
|
1662
1695
|
framebuffer.name = 0;
|
|
1663
1696
|
GL.framebuffers[id] = null;
|
|
1664
1697
|
}
|
|
@@ -1669,7 +1702,7 @@ var LibraryGL = {
|
|
|
1669
1702
|
#if GL_ASSERTIONS
|
|
1670
1703
|
GL.validateGLObjectID(GL.renderbuffers, renderbuffer, 'glFramebufferRenderbuffer', 'renderbuffer');
|
|
1671
1704
|
#endif
|
|
1672
|
-
|
|
1705
|
+
GLctx.framebufferRenderbuffer(target, attachment, renderbuffertarget,
|
|
1673
1706
|
GL.renderbuffers[renderbuffer]);
|
|
1674
1707
|
},
|
|
1675
1708
|
|
|
@@ -1678,21 +1711,21 @@ var LibraryGL = {
|
|
|
1678
1711
|
#if GL_ASSERTIONS
|
|
1679
1712
|
GL.validateGLObjectID(GL.textures, texture, 'glFramebufferTexture2D', 'texture');
|
|
1680
1713
|
#endif
|
|
1681
|
-
|
|
1714
|
+
GLctx.framebufferTexture2D(target, attachment, textarget,
|
|
1682
1715
|
GL.textures[texture], level);
|
|
1683
1716
|
},
|
|
1684
1717
|
|
|
1685
1718
|
glGetFramebufferAttachmentParameteriv__sig: 'viiii',
|
|
1686
1719
|
glGetFramebufferAttachmentParameteriv: function(target, attachment, pname, params) {
|
|
1687
|
-
var result =
|
|
1688
|
-
{{{ makeSetValue('params', '0', '
|
|
1720
|
+
var result = GLctx.getFramebufferAttachmentParameter(target, attachment, pname);
|
|
1721
|
+
{{{ makeSetValue('params', '0', 'result', 'i32') }}};
|
|
1689
1722
|
},
|
|
1690
1723
|
|
|
1691
1724
|
glIsFramebuffer__sig: 'ii',
|
|
1692
1725
|
glIsFramebuffer: function(framebuffer) {
|
|
1693
1726
|
var fb = GL.framebuffers[framebuffer];
|
|
1694
1727
|
if (!fb) return 0;
|
|
1695
|
-
return
|
|
1728
|
+
return GLctx.isFramebuffer(fb);
|
|
1696
1729
|
},
|
|
1697
1730
|
|
|
1698
1731
|
#if LEGACY_GL_EMULATION
|
|
@@ -1756,9 +1789,12 @@ var LibraryGL = {
|
|
|
1756
1789
|
_glEnable = function _glEnable(cap) {
|
|
1757
1790
|
// Clean up the renderer on any change to the rendering state. The optimization of
|
|
1758
1791
|
// skipping renderer setup is aimed at the case of multiple glDraw* right after each other
|
|
1759
|
-
if (
|
|
1792
|
+
if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup();
|
|
1760
1793
|
if (cap == 0x0B60 /* GL_FOG */) {
|
|
1761
|
-
GLEmulation.fogEnabled
|
|
1794
|
+
if (GLEmulation.fogEnabled != true) {
|
|
1795
|
+
GLImmediate.currentRenderer = null; // Fog parameter is part of the FFP shader state, we must re-lookup the renderer to use.
|
|
1796
|
+
GLEmulation.fogEnabled = true;
|
|
1797
|
+
}
|
|
1762
1798
|
return;
|
|
1763
1799
|
} else if (cap == 0x0de1 /* GL_TEXTURE_2D */) {
|
|
1764
1800
|
// XXX not according to spec, and not in desktop GL, but works in some GLES1.x apparently, so support
|
|
@@ -1776,9 +1812,12 @@ var LibraryGL = {
|
|
|
1776
1812
|
|
|
1777
1813
|
var glDisable = _glDisable;
|
|
1778
1814
|
_glDisable = function _glDisable(cap) {
|
|
1779
|
-
if (
|
|
1815
|
+
if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup();
|
|
1780
1816
|
if (cap == 0x0B60 /* GL_FOG */) {
|
|
1781
|
-
GLEmulation.fogEnabled
|
|
1817
|
+
if (GLEmulation.fogEnabled != false) {
|
|
1818
|
+
GLImmediate.currentRenderer = null; // Fog parameter is part of the FFP shader state, we must re-lookup the renderer to use.
|
|
1819
|
+
GLEmulation.fogEnabled = false;
|
|
1820
|
+
}
|
|
1782
1821
|
return;
|
|
1783
1822
|
} else if (cap == 0x0de1 /* GL_TEXTURE_2D */) {
|
|
1784
1823
|
// XXX not according to spec, and not in desktop GL, but works in some GLES1.x apparently, so support
|
|
@@ -1799,14 +1838,14 @@ var LibraryGL = {
|
|
|
1799
1838
|
} else if (!(cap in validCapabilities)) {
|
|
1800
1839
|
return 0;
|
|
1801
1840
|
}
|
|
1802
|
-
return
|
|
1841
|
+
return GLctx.isEnabled(cap);
|
|
1803
1842
|
};
|
|
1804
1843
|
|
|
1805
1844
|
var glGetBooleanv = _glGetBooleanv;
|
|
1806
1845
|
_glGetBooleanv = function _glGetBooleanv(pname, p) {
|
|
1807
1846
|
var attrib = GLEmulation.getAttributeFromCapability(pname);
|
|
1808
1847
|
if (attrib !== null) {
|
|
1809
|
-
var result =
|
|
1848
|
+
var result = GLImmediate.enabledClientAttributes[attrib];
|
|
1810
1849
|
{{{ makeSetValue('p', '0', 'result === true ? 1 : 0', 'i8') }}};
|
|
1811
1850
|
return;
|
|
1812
1851
|
}
|
|
@@ -1816,23 +1855,23 @@ var LibraryGL = {
|
|
|
1816
1855
|
var glGetIntegerv = _glGetIntegerv;
|
|
1817
1856
|
_glGetIntegerv = function _glGetIntegerv(pname, params) {
|
|
1818
1857
|
switch (pname) {
|
|
1819
|
-
case 0x84E2: pname =
|
|
1858
|
+
case 0x84E2: pname = GLctx.MAX_TEXTURE_IMAGE_UNITS /* fake it */; break; // GL_MAX_TEXTURE_UNITS
|
|
1820
1859
|
case 0x8B4A: { // GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB
|
|
1821
|
-
var result =
|
|
1860
|
+
var result = GLctx.getParameter(GLctx.MAX_VERTEX_UNIFORM_VECTORS);
|
|
1822
1861
|
{{{ makeSetValue('params', '0', 'result*4', 'i32') }}}; // GLES gives num of 4-element vectors, GL wants individual components, so multiply
|
|
1823
1862
|
return;
|
|
1824
1863
|
}
|
|
1825
1864
|
case 0x8B49: { // GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB
|
|
1826
|
-
var result =
|
|
1865
|
+
var result = GLctx.getParameter(GLctx.MAX_FRAGMENT_UNIFORM_VECTORS);
|
|
1827
1866
|
{{{ makeSetValue('params', '0', 'result*4', 'i32') }}}; // GLES gives num of 4-element vectors, GL wants individual components, so multiply
|
|
1828
1867
|
return;
|
|
1829
1868
|
}
|
|
1830
1869
|
case 0x8B4B: { // GL_MAX_VARYING_FLOATS_ARB
|
|
1831
|
-
var result =
|
|
1870
|
+
var result = GLctx.getParameter(GLctx.MAX_VARYING_VECTORS);
|
|
1832
1871
|
{{{ makeSetValue('params', '0', 'result*4', 'i32') }}}; // GLES gives num of 4-element vectors, GL wants individual components, so multiply
|
|
1833
1872
|
return;
|
|
1834
1873
|
}
|
|
1835
|
-
case 0x8871: pname =
|
|
1874
|
+
case 0x8871: pname = GLctx.MAX_COMBINED_TEXTURE_IMAGE_UNITS /* close enough */; break; // GL_MAX_TEXTURE_COORDS
|
|
1836
1875
|
case 0x807A: { // GL_VERTEX_ARRAY_SIZE
|
|
1837
1876
|
var attribute = GLImmediate.clientAttributes[GLImmediate.VERTEX];
|
|
1838
1877
|
{{{ makeSetValue('params', '0', 'attribute ? attribute.size : 0', 'i32') }}};
|
|
@@ -1887,7 +1926,7 @@ var LibraryGL = {
|
|
|
1887
1926
|
if (GL.stringCache[name_]) return GL.stringCache[name_];
|
|
1888
1927
|
switch(name_) {
|
|
1889
1928
|
case 0x1F03 /* GL_EXTENSIONS */: // Add various extensions that we can support
|
|
1890
|
-
var ret = allocate(intArrayFromString(
|
|
1929
|
+
var ret = allocate(intArrayFromString(GLctx.getSupportedExtensions().join(' ') +
|
|
1891
1930
|
' GL_EXT_texture_env_combine GL_ARB_texture_env_crossbar GL_ATI_texture_env_combine3 GL_NV_texture_env_combine4 GL_EXT_texture_env_dot3 GL_ARB_multitexture GL_ARB_vertex_buffer_object GL_EXT_framebuffer_object GL_ARB_vertex_program GL_ARB_fragment_program GL_ARB_shading_language_100 GL_ARB_shader_objects GL_ARB_vertex_shader GL_ARB_fragment_shader GL_ARB_texture_cube_map GL_EXT_draw_range_elements' +
|
|
1892
1931
|
(GL.compressionExt ? ' GL_ARB_texture_compression GL_EXT_texture_compression_s3tc' : '') +
|
|
1893
1932
|
(GL.anisotropicExt ? ' GL_EXT_texture_filter_anisotropic' : '')
|
|
@@ -1916,6 +1955,13 @@ var LibraryGL = {
|
|
|
1916
1955
|
return id;
|
|
1917
1956
|
};
|
|
1918
1957
|
|
|
1958
|
+
function ensurePrecision(source) {
|
|
1959
|
+
if (!/precision +(low|medium|high)p +float *;/.test(source)) {
|
|
1960
|
+
source = 'precision mediump float;\n' + source;
|
|
1961
|
+
}
|
|
1962
|
+
return source;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1919
1965
|
var glShaderSource = _glShaderSource;
|
|
1920
1966
|
_glShaderSource = function _glShaderSource(shader, count, string, length) {
|
|
1921
1967
|
var source = GL.getSource(shader, count, string, length);
|
|
@@ -1925,7 +1971,7 @@ var LibraryGL = {
|
|
|
1925
1971
|
#endif
|
|
1926
1972
|
// XXX We add attributes and uniforms to shaders. The program can ask for the # of them, and see the
|
|
1927
1973
|
// ones we generated, potentially confusing it? Perhaps we should hide them.
|
|
1928
|
-
if (GL.shaderInfos[shader].type ==
|
|
1974
|
+
if (GL.shaderInfos[shader].type == GLctx.VERTEX_SHADER) {
|
|
1929
1975
|
// Replace ftransform() with explicit project/modelview transforms, and add position and matrix info.
|
|
1930
1976
|
var has_pm = source.search(/u_projection/) >= 0;
|
|
1931
1977
|
var has_mm = source.search(/u_modelView/) >= 0;
|
|
@@ -1953,7 +1999,7 @@ var LibraryGL = {
|
|
|
1953
1999
|
if (need_mm && !has_mm) source = 'uniform mat4 u_modelView; \n' + source;
|
|
1954
2000
|
if (need_pm && !has_pm) source = 'uniform mat4 u_projection; \n' + source;
|
|
1955
2001
|
GL.shaderInfos[shader].ftransform = need_pm || need_mm || need_pv; // we will need to provide the fixed function stuff as attributes and uniforms
|
|
1956
|
-
for (var i = 0; i <
|
|
2002
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
1957
2003
|
// XXX To handle both regular texture mapping and cube mapping, we use vec4 for tex coordinates.
|
|
1958
2004
|
var old = source;
|
|
1959
2005
|
var need_vtc = source.search('v_texCoord' + i) == -1;
|
|
@@ -1989,8 +2035,9 @@ var LibraryGL = {
|
|
|
1989
2035
|
source = 'varying float v_fogFragCoord; \n' +
|
|
1990
2036
|
source.replace(/gl_FogFragCoord/g, 'v_fogFragCoord');
|
|
1991
2037
|
}
|
|
2038
|
+
source = ensurePrecision(source);
|
|
1992
2039
|
} else { // Fragment shader
|
|
1993
|
-
for (var i = 0; i <
|
|
2040
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
1994
2041
|
var old = source;
|
|
1995
2042
|
source = source.replace(new RegExp('gl_TexCoord\\[' + i + '\\]', 'g'), 'v_texCoord' + i);
|
|
1996
2043
|
if (source != old) {
|
|
@@ -2020,21 +2067,21 @@ var LibraryGL = {
|
|
|
2020
2067
|
source = 'varying float v_fogFragCoord; \n' +
|
|
2021
2068
|
source.replace(/gl_FogFragCoord/g, 'v_fogFragCoord');
|
|
2022
2069
|
}
|
|
2023
|
-
source =
|
|
2070
|
+
source = ensurePrecision(source);
|
|
2024
2071
|
}
|
|
2025
2072
|
#if GL_DEBUG
|
|
2026
2073
|
GL.shaderSources[shader] = source;
|
|
2027
2074
|
console.log("glShaderSource: Output: \n" + source);
|
|
2028
2075
|
#endif
|
|
2029
|
-
|
|
2076
|
+
GLctx.shaderSource(GL.shaders[shader], source);
|
|
2030
2077
|
};
|
|
2031
2078
|
|
|
2032
2079
|
var glCompileShader = _glCompileShader;
|
|
2033
2080
|
_glCompileShader = function _glCompileShader(shader) {
|
|
2034
|
-
|
|
2081
|
+
GLctx.compileShader(GL.shaders[shader]);
|
|
2035
2082
|
#if GL_DEBUG
|
|
2036
|
-
if (!
|
|
2037
|
-
Module.printErr('Failed to compile shader: ' +
|
|
2083
|
+
if (!GLctx.getShaderParameter(GL.shaders[shader], GLctx.COMPILE_STATUS)) {
|
|
2084
|
+
Module.printErr('Failed to compile shader: ' + GLctx.getShaderInfoLog(GL.shaders[shader]));
|
|
2038
2085
|
Module.printErr('Info: ' + JSON.stringify(GL.shaderInfos[shader]));
|
|
2039
2086
|
Module.printErr('Original source: ' + GL.shaderOriginalSources[shader]);
|
|
2040
2087
|
Module.printErr('Source: ' + GL.shaderSources[shader]);
|
|
@@ -2077,16 +2124,20 @@ var LibraryGL = {
|
|
|
2077
2124
|
}
|
|
2078
2125
|
#endif
|
|
2079
2126
|
if (GL.currProgram != program) {
|
|
2080
|
-
|
|
2127
|
+
GLImmediate.currentRenderer = null; // This changes the FFP emulation shader program, need to recompute that.
|
|
2081
2128
|
GL.currProgram = program;
|
|
2129
|
+
GLImmediate.fixedFunctionProgram = 0;
|
|
2130
|
+
glUseProgram(program);
|
|
2082
2131
|
}
|
|
2083
|
-
glUseProgram(program);
|
|
2084
2132
|
}
|
|
2085
2133
|
|
|
2086
2134
|
var glDeleteProgram = _glDeleteProgram;
|
|
2087
2135
|
_glDeleteProgram = function _glDeleteProgram(program) {
|
|
2088
2136
|
glDeleteProgram(program);
|
|
2089
|
-
if (program == GL.currProgram)
|
|
2137
|
+
if (program == GL.currProgram) {
|
|
2138
|
+
GLImmediate.currentRenderer = null; // This changes the FFP emulation shader program, need to recompute that.
|
|
2139
|
+
GL.currProgram = 0;
|
|
2140
|
+
}
|
|
2090
2141
|
};
|
|
2091
2142
|
|
|
2092
2143
|
// If attribute 0 was not bound, bind it to 0 for WebGL performance reasons. Track if 0 is free for that.
|
|
@@ -2099,7 +2150,7 @@ var LibraryGL = {
|
|
|
2099
2150
|
var glLinkProgram = _glLinkProgram;
|
|
2100
2151
|
_glLinkProgram = function _glLinkProgram(program) {
|
|
2101
2152
|
if (!(program in zeroUsedPrograms)) {
|
|
2102
|
-
|
|
2153
|
+
GLctx.bindAttribLocation(GL.programs[program], 0, 'a_position');
|
|
2103
2154
|
}
|
|
2104
2155
|
glLinkProgram(program);
|
|
2105
2156
|
};
|
|
@@ -2107,14 +2158,14 @@ var LibraryGL = {
|
|
|
2107
2158
|
var glBindBuffer = _glBindBuffer;
|
|
2108
2159
|
_glBindBuffer = function _glBindBuffer(target, buffer) {
|
|
2109
2160
|
glBindBuffer(target, buffer);
|
|
2110
|
-
if (target ==
|
|
2161
|
+
if (target == GLctx.ARRAY_BUFFER) {
|
|
2111
2162
|
if (GLEmulation.currentVao) {
|
|
2112
2163
|
#if ASSERTIONS
|
|
2113
2164
|
assert(GLEmulation.currentVao.arrayBuffer == buffer || GLEmulation.currentVao.arrayBuffer == 0 || buffer == 0, 'TODO: support for multiple array buffers in vao');
|
|
2114
2165
|
#endif
|
|
2115
2166
|
GLEmulation.currentVao.arrayBuffer = buffer;
|
|
2116
2167
|
}
|
|
2117
|
-
} else if (target ==
|
|
2168
|
+
} else if (target == GLctx.ELEMENT_ARRAY_BUFFER) {
|
|
2118
2169
|
if (GLEmulation.currentVao) GLEmulation.currentVao.elementArrayBuffer = buffer;
|
|
2119
2170
|
}
|
|
2120
2171
|
};
|
|
@@ -2122,11 +2173,11 @@ var LibraryGL = {
|
|
|
2122
2173
|
var glGetFloatv = _glGetFloatv;
|
|
2123
2174
|
_glGetFloatv = function _glGetFloatv(pname, params) {
|
|
2124
2175
|
if (pname == 0x0BA6) { // GL_MODELVIEW_MATRIX
|
|
2125
|
-
HEAPF32.set(
|
|
2176
|
+
HEAPF32.set(GLImmediate.matrix[0/*m*/], params >> 2);
|
|
2126
2177
|
} else if (pname == 0x0BA7) { // GL_PROJECTION_MATRIX
|
|
2127
|
-
HEAPF32.set(
|
|
2178
|
+
HEAPF32.set(GLImmediate.matrix[1/*p*/], params >> 2);
|
|
2128
2179
|
} else if (pname == 0x0BA8) { // GL_TEXTURE_MATRIX
|
|
2129
|
-
HEAPF32.set(
|
|
2180
|
+
HEAPF32.set(GLImmediate.matrix[2/*t*/ + GLImmediate.clientActiveTexture], params >> 2);
|
|
2130
2181
|
} else if (pname == 0x0B66) { // GL_FOG_COLOR
|
|
2131
2182
|
HEAPF32.set(GLEmulation.fogColor, params >> 2);
|
|
2132
2183
|
} else if (pname == 0x0B63) { // GL_FOG_START
|
|
@@ -2182,13 +2233,13 @@ var LibraryGL = {
|
|
|
2182
2233
|
#endif
|
|
2183
2234
|
// Fall through:
|
|
2184
2235
|
case 0x8078: // GL_TEXTURE_COORD_ARRAY
|
|
2185
|
-
attrib =
|
|
2236
|
+
attrib = GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture; break;
|
|
2186
2237
|
case 0x8074: // GL_VERTEX_ARRAY
|
|
2187
|
-
attrib =
|
|
2238
|
+
attrib = GLImmediate.VERTEX; break;
|
|
2188
2239
|
case 0x8075: // GL_NORMAL_ARRAY
|
|
2189
|
-
attrib =
|
|
2240
|
+
attrib = GLImmediate.NORMAL; break;
|
|
2190
2241
|
case 0x8076: // GL_COLOR_ARRAY
|
|
2191
|
-
attrib =
|
|
2242
|
+
attrib = GLImmediate.COLOR; break;
|
|
2192
2243
|
}
|
|
2193
2244
|
return attrib;
|
|
2194
2245
|
},
|
|
@@ -2212,16 +2263,16 @@ var LibraryGL = {
|
|
|
2212
2263
|
glGetObjectParameteriv: function(id, type, result) {
|
|
2213
2264
|
if (GL.programs[id]) {
|
|
2214
2265
|
if (type == 0x8B84) { // GL_OBJECT_INFO_LOG_LENGTH_ARB
|
|
2215
|
-
{{{ makeSetValue('result', '0', '
|
|
2266
|
+
{{{ makeSetValue('result', '0', 'GLctx.getProgramInfoLog(GL.programs[id]).length', 'i32') }}};
|
|
2216
2267
|
return;
|
|
2217
2268
|
}
|
|
2218
2269
|
_glGetProgramiv(id, type, result);
|
|
2219
2270
|
} else if (GL.shaders[id]) {
|
|
2220
2271
|
if (type == 0x8B84) { // GL_OBJECT_INFO_LOG_LENGTH_ARB
|
|
2221
|
-
{{{ makeSetValue('result', '0', '
|
|
2272
|
+
{{{ makeSetValue('result', '0', 'GLctx.getShaderInfoLog(GL.shaders[id]).length', 'i32') }}};
|
|
2222
2273
|
return;
|
|
2223
2274
|
} else if (type == 0x8B88) { // GL_OBJECT_SHADER_SOURCE_LENGTH_ARB
|
|
2224
|
-
{{{ makeSetValue('result', '0', '
|
|
2275
|
+
{{{ makeSetValue('result', '0', 'GLctx.getShaderSource(GL.shaders[id]).length', 'i32') }}};
|
|
2225
2276
|
return;
|
|
2226
2277
|
}
|
|
2227
2278
|
_glGetShaderiv(id, type, result);
|
|
@@ -2271,7 +2322,7 @@ var LibraryGL = {
|
|
|
2271
2322
|
|
|
2272
2323
|
// See comment in GLEmulation.init()
|
|
2273
2324
|
#if FULL_ES2 == 0
|
|
2274
|
-
$GLImmediate__postset: '
|
|
2325
|
+
$GLImmediate__postset: 'GLImmediate.setupFuncs(); Browser.moduleContextCreatedCallbacks.push(function() { GLImmediate.init() });',
|
|
2275
2326
|
#endif
|
|
2276
2327
|
$GLImmediate__deps: ['$Browser', '$GL', '$GLEmulation'],
|
|
2277
2328
|
$GLImmediate: {
|
|
@@ -2689,7 +2740,7 @@ var LibraryGL = {
|
|
|
2689
2740
|
}
|
|
2690
2741
|
this.invalidateKey = function() {
|
|
2691
2742
|
this.key0 = -1; // The key of this texture unit must be recomputed when rendering the next time.
|
|
2692
|
-
|
|
2743
|
+
GLImmediate.currentRenderer = null; // The currently used renderer must be re-evaluated at next render.
|
|
2693
2744
|
}
|
|
2694
2745
|
this.traverseState = function(keyView) {
|
|
2695
2746
|
if (this.key0 == -1) {
|
|
@@ -3060,25 +3111,25 @@ var LibraryGL = {
|
|
|
3060
3111
|
switch (cap) {
|
|
3061
3112
|
case GL_TEXTURE_1D:
|
|
3062
3113
|
if (!cur.enabled_tex1D) {
|
|
3063
|
-
|
|
3114
|
+
GLImmediate.currentRenderer = null; // Renderer state changed, and must be recreated or looked up again.
|
|
3064
3115
|
cur.enabled_tex1D = true;
|
|
3065
3116
|
}
|
|
3066
3117
|
break;
|
|
3067
3118
|
case GL_TEXTURE_2D:
|
|
3068
3119
|
if (!cur.enabled_tex2D) {
|
|
3069
|
-
|
|
3120
|
+
GLImmediate.currentRenderer = null;
|
|
3070
3121
|
cur.enabled_tex2D = true;
|
|
3071
3122
|
}
|
|
3072
3123
|
break;
|
|
3073
3124
|
case GL_TEXTURE_3D:
|
|
3074
3125
|
if (!cur.enabled_tex3D) {
|
|
3075
|
-
|
|
3126
|
+
GLImmediate.currentRenderer = null;
|
|
3076
3127
|
cur.enabled_tex3D = true;
|
|
3077
3128
|
}
|
|
3078
3129
|
break;
|
|
3079
3130
|
case GL_TEXTURE_CUBE_MAP:
|
|
3080
3131
|
if (!cur.enabled_texCube) {
|
|
3081
|
-
|
|
3132
|
+
GLImmediate.currentRenderer = null;
|
|
3082
3133
|
cur.enabled_texCube = true;
|
|
3083
3134
|
}
|
|
3084
3135
|
break;
|
|
@@ -3090,25 +3141,25 @@ var LibraryGL = {
|
|
|
3090
3141
|
switch (cap) {
|
|
3091
3142
|
case GL_TEXTURE_1D:
|
|
3092
3143
|
if (cur.enabled_tex1D) {
|
|
3093
|
-
|
|
3144
|
+
GLImmediate.currentRenderer = null; // Renderer state changed, and must be recreated or looked up again.
|
|
3094
3145
|
cur.enabled_tex1D = false;
|
|
3095
3146
|
}
|
|
3096
3147
|
break;
|
|
3097
3148
|
case GL_TEXTURE_2D:
|
|
3098
3149
|
if (cur.enabled_tex2D) {
|
|
3099
|
-
|
|
3150
|
+
GLImmediate.currentRenderer = null;
|
|
3100
3151
|
cur.enabled_tex2D = false;
|
|
3101
3152
|
}
|
|
3102
3153
|
break;
|
|
3103
3154
|
case GL_TEXTURE_3D:
|
|
3104
3155
|
if (cur.enabled_tex3D) {
|
|
3105
|
-
|
|
3156
|
+
GLImmediate.currentRenderer = null;
|
|
3106
3157
|
cur.enabled_tex3D = false;
|
|
3107
3158
|
}
|
|
3108
3159
|
break;
|
|
3109
3160
|
case GL_TEXTURE_CUBE_MAP:
|
|
3110
3161
|
if (cur.enabled_texCube) {
|
|
3111
|
-
|
|
3162
|
+
GLImmediate.currentRenderer = null;
|
|
3112
3163
|
cur.enabled_texCube = false;
|
|
3113
3164
|
}
|
|
3114
3165
|
break;
|
|
@@ -3298,9 +3349,9 @@ var LibraryGL = {
|
|
|
3298
3349
|
lastStride: -1, // ""
|
|
3299
3350
|
|
|
3300
3351
|
// The following data structures are used for OpenGL Immediate Mode matrix routines.
|
|
3301
|
-
matrix:
|
|
3302
|
-
matrixStack:
|
|
3303
|
-
currentMatrix:
|
|
3352
|
+
matrix: [],
|
|
3353
|
+
matrixStack: [],
|
|
3354
|
+
currentMatrix: 0, // 0: modelview, 1: projection, 2+i, texture matrix i.
|
|
3304
3355
|
tempMatrix: null,
|
|
3305
3356
|
matricesModified: false,
|
|
3306
3357
|
useTextureMatrix: false,
|
|
@@ -3325,11 +3376,11 @@ var LibraryGL = {
|
|
|
3325
3376
|
fixedFunctionProgram: null,
|
|
3326
3377
|
|
|
3327
3378
|
setClientAttribute: function setClientAttribute(name, size, type, stride, pointer) {
|
|
3328
|
-
var attrib =
|
|
3379
|
+
var attrib = GLImmediate.clientAttributes[name];
|
|
3329
3380
|
if (!attrib) {
|
|
3330
3381
|
for (var i = 0; i <= name; i++) { // keep flat
|
|
3331
|
-
if (!
|
|
3332
|
-
|
|
3382
|
+
if (!GLImmediate.clientAttributes[i]) {
|
|
3383
|
+
GLImmediate.clientAttributes[i] = {
|
|
3333
3384
|
name: name,
|
|
3334
3385
|
size: size,
|
|
3335
3386
|
type: type,
|
|
@@ -3347,42 +3398,42 @@ var LibraryGL = {
|
|
|
3347
3398
|
attrib.pointer = pointer;
|
|
3348
3399
|
attrib.offset = 0;
|
|
3349
3400
|
}
|
|
3350
|
-
|
|
3401
|
+
GLImmediate.modifiedClientAttributes = true;
|
|
3351
3402
|
},
|
|
3352
3403
|
|
|
3353
3404
|
// Renderers
|
|
3354
3405
|
addRendererComponent: function addRendererComponent(name, size, type) {
|
|
3355
|
-
if (!
|
|
3356
|
-
|
|
3406
|
+
if (!GLImmediate.rendererComponents[name]) {
|
|
3407
|
+
GLImmediate.rendererComponents[name] = 1;
|
|
3357
3408
|
#if ASSERTIONS
|
|
3358
|
-
if (
|
|
3409
|
+
if (GLImmediate.enabledClientAttributes[name]) {
|
|
3359
3410
|
console.log("Warning: glTexCoord used after EnableClientState for TEXTURE_COORD_ARRAY for TEXTURE0. Disabling TEXTURE_COORD_ARRAY...");
|
|
3360
3411
|
}
|
|
3361
3412
|
#endif
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3413
|
+
GLImmediate.enabledClientAttributes[name] = true;
|
|
3414
|
+
GLImmediate.setClientAttribute(name, size, type, 0, GLImmediate.rendererComponentPointer);
|
|
3415
|
+
GLImmediate.rendererComponentPointer += size * GL.byteSizeByType[type - GL.byteSizeByTypeRoot];
|
|
3365
3416
|
} else {
|
|
3366
|
-
|
|
3417
|
+
GLImmediate.rendererComponents[name]++;
|
|
3367
3418
|
}
|
|
3368
3419
|
},
|
|
3369
3420
|
|
|
3370
3421
|
disableBeginEndClientAttributes: function disableBeginEndClientAttributes() {
|
|
3371
|
-
for (var i = 0; i <
|
|
3372
|
-
if (
|
|
3422
|
+
for (var i = 0; i < GLImmediate.NUM_ATTRIBUTES; i++) {
|
|
3423
|
+
if (GLImmediate.rendererComponents[i]) GLImmediate.enabledClientAttributes[i] = false;
|
|
3373
3424
|
}
|
|
3374
3425
|
},
|
|
3375
3426
|
|
|
3376
3427
|
getRenderer: function getRenderer() {
|
|
3377
3428
|
// If no FFP state has changed that would have forced to re-evaluate which FFP emulation shader to use,
|
|
3378
3429
|
// we have the currently used renderer in cache, and can immediately return that.
|
|
3379
|
-
if (
|
|
3380
|
-
return
|
|
3430
|
+
if (GLImmediate.currentRenderer) {
|
|
3431
|
+
return GLImmediate.currentRenderer;
|
|
3381
3432
|
}
|
|
3382
3433
|
// return a renderer object given the liveClientAttributes
|
|
3383
3434
|
// we maintain a cache of renderers, optimized to not generate garbage
|
|
3384
|
-
var attributes =
|
|
3385
|
-
var cacheMap =
|
|
3435
|
+
var attributes = GLImmediate.liveClientAttributes;
|
|
3436
|
+
var cacheMap = GLImmediate.rendererCache;
|
|
3386
3437
|
var temp;
|
|
3387
3438
|
var keyView = cacheMap.getStaticKeyView().reset();
|
|
3388
3439
|
|
|
@@ -3413,7 +3464,7 @@ var LibraryGL = {
|
|
|
3413
3464
|
// By cur program:
|
|
3414
3465
|
keyView.next(GL.currProgram);
|
|
3415
3466
|
if (!GL.currProgram) {
|
|
3416
|
-
|
|
3467
|
+
GLImmediate.TexEnvJIT.traverseState(keyView);
|
|
3417
3468
|
}
|
|
3418
3469
|
|
|
3419
3470
|
// If we don't already have it, create it.
|
|
@@ -3422,26 +3473,26 @@ var LibraryGL = {
|
|
|
3422
3473
|
#if GL_DEBUG
|
|
3423
3474
|
Module.printErr('generating renderer for ' + JSON.stringify(attributes));
|
|
3424
3475
|
#endif
|
|
3425
|
-
renderer =
|
|
3426
|
-
|
|
3476
|
+
renderer = GLImmediate.createRenderer();
|
|
3477
|
+
GLImmediate.currentRenderer = renderer;
|
|
3427
3478
|
keyView.set(renderer);
|
|
3428
3479
|
return renderer;
|
|
3429
3480
|
}
|
|
3430
|
-
|
|
3481
|
+
GLImmediate.currentRenderer = renderer; // Cache the currently used renderer, so later lookups without state changes can get this fast.
|
|
3431
3482
|
return renderer;
|
|
3432
3483
|
},
|
|
3433
3484
|
|
|
3434
3485
|
createRenderer: function createRenderer(renderer) {
|
|
3435
3486
|
var useCurrProgram = !!GL.currProgram;
|
|
3436
3487
|
var hasTextures = false;
|
|
3437
|
-
for (var i = 0; i <
|
|
3438
|
-
var texAttribName =
|
|
3439
|
-
if (!
|
|
3488
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3489
|
+
var texAttribName = GLImmediate.TEXTURE0 + i;
|
|
3490
|
+
if (!GLImmediate.enabledClientAttributes[texAttribName])
|
|
3440
3491
|
continue;
|
|
3441
3492
|
|
|
3442
3493
|
#if ASSERTIONS
|
|
3443
3494
|
if (!useCurrProgram) {
|
|
3444
|
-
if (
|
|
3495
|
+
if (GLImmediate.TexEnvJIT.getTexUnitType(i) == 0) {
|
|
3445
3496
|
Runtime.warnOnce("GL_TEXTURE" + i + " coords are supplied, but that texture unit is disabled in the fixed-function pipeline.");
|
|
3446
3497
|
}
|
|
3447
3498
|
}
|
|
@@ -3457,10 +3508,10 @@ var LibraryGL = {
|
|
|
3457
3508
|
var aTexCoordPrefix = 'a_texCoord';
|
|
3458
3509
|
var vTexCoordPrefix = 'v_texCoord';
|
|
3459
3510
|
var vPrimColor = 'v_color';
|
|
3460
|
-
var uTexMatrixPrefix =
|
|
3511
|
+
var uTexMatrixPrefix = GLImmediate.useTextureMatrix ? 'u_textureMatrix' : null;
|
|
3461
3512
|
|
|
3462
3513
|
if (useCurrProgram) {
|
|
3463
|
-
if (GL.shaderInfos[GL.programShaders[GL.currProgram][0]].type ==
|
|
3514
|
+
if (GL.shaderInfos[GL.programShaders[GL.currProgram][0]].type == GLctx.VERTEX_SHADER) {
|
|
3464
3515
|
this.vertexShader = GL.shaders[GL.programShaders[GL.currProgram][0]];
|
|
3465
3516
|
this.fragmentShader = GL.shaders[GL.programShaders[GL.currProgram][1]];
|
|
3466
3517
|
} else {
|
|
@@ -3491,14 +3542,14 @@ var LibraryGL = {
|
|
|
3491
3542
|
}
|
|
3492
3543
|
}
|
|
3493
3544
|
|
|
3494
|
-
|
|
3495
|
-
var fsTexEnvPass =
|
|
3545
|
+
GLImmediate.TexEnvJIT.setGLSLVars(uTexUnitPrefix, vTexCoordPrefix, vPrimColor, uTexMatrixPrefix);
|
|
3546
|
+
var fsTexEnvPass = GLImmediate.TexEnvJIT.genAllPassLines('gl_FragColor', 2);
|
|
3496
3547
|
|
|
3497
3548
|
var texUnitAttribList = '';
|
|
3498
3549
|
var texUnitVaryingList = '';
|
|
3499
3550
|
var texUnitUniformList = '';
|
|
3500
3551
|
var vsTexCoordInits = '';
|
|
3501
|
-
this.usedTexUnitList =
|
|
3552
|
+
this.usedTexUnitList = GLImmediate.TexEnvJIT.getUsedTexUnitList();
|
|
3502
3553
|
for (var i = 0; i < this.usedTexUnitList.length; i++) {
|
|
3503
3554
|
var texUnit = this.usedTexUnitList[i];
|
|
3504
3555
|
texUnitAttribList += 'attribute vec4 ' + aTexCoordPrefix + texUnit + ';\n';
|
|
@@ -3506,7 +3557,7 @@ var LibraryGL = {
|
|
|
3506
3557
|
texUnitUniformList += 'uniform sampler2D ' + uTexUnitPrefix + texUnit + ';\n';
|
|
3507
3558
|
vsTexCoordInits += ' ' + vTexCoordPrefix + texUnit + ' = ' + aTexCoordPrefix + texUnit + ';\n';
|
|
3508
3559
|
|
|
3509
|
-
if (
|
|
3560
|
+
if (GLImmediate.useTextureMatrix) {
|
|
3510
3561
|
texUnitUniformList += 'uniform mat4 ' + uTexMatrixPrefix + texUnit + ';\n';
|
|
3511
3562
|
}
|
|
3512
3563
|
}
|
|
@@ -3536,9 +3587,9 @@ var LibraryGL = {
|
|
|
3536
3587
|
''
|
|
3537
3588
|
].join('\n').replace(/\n\n+/g, '\n');
|
|
3538
3589
|
|
|
3539
|
-
this.vertexShader =
|
|
3540
|
-
|
|
3541
|
-
|
|
3590
|
+
this.vertexShader = GLctx.createShader(GLctx.VERTEX_SHADER);
|
|
3591
|
+
GLctx.shaderSource(this.vertexShader, vsSource);
|
|
3592
|
+
GLctx.compileShader(this.vertexShader);
|
|
3542
3593
|
|
|
3543
3594
|
var fogHeaderIfNeeded = null;
|
|
3544
3595
|
if (GLEmulation.fogEnabled) {
|
|
@@ -3577,85 +3628,85 @@ var LibraryGL = {
|
|
|
3577
3628
|
''
|
|
3578
3629
|
].join("\n").replace(/\n\n+/g, '\n');
|
|
3579
3630
|
|
|
3580
|
-
this.fragmentShader =
|
|
3581
|
-
|
|
3582
|
-
|
|
3631
|
+
this.fragmentShader = GLctx.createShader(GLctx.FRAGMENT_SHADER);
|
|
3632
|
+
GLctx.shaderSource(this.fragmentShader, fsSource);
|
|
3633
|
+
GLctx.compileShader(this.fragmentShader);
|
|
3583
3634
|
|
|
3584
|
-
this.program =
|
|
3585
|
-
|
|
3586
|
-
|
|
3635
|
+
this.program = GLctx.createProgram();
|
|
3636
|
+
GLctx.attachShader(this.program, this.vertexShader);
|
|
3637
|
+
GLctx.attachShader(this.program, this.fragmentShader);
|
|
3587
3638
|
|
|
3588
3639
|
// As optimization, bind all attributes to prespecified locations, so that the FFP emulation
|
|
3589
3640
|
// code can submit attributes to any generated FFP shader without having to examine each shader in turn.
|
|
3590
3641
|
// These prespecified locations are only assumed if GL_FFP_ONLY is specified, since user could also create their
|
|
3591
3642
|
// own shaders that didn't have attributes in the same locations.
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
for (var i = 0; i <
|
|
3596
|
-
|
|
3597
|
-
|
|
3643
|
+
GLctx.bindAttribLocation(this.program, GLImmediate.VERTEX, 'a_position');
|
|
3644
|
+
GLctx.bindAttribLocation(this.program, GLImmediate.COLOR, 'a_color');
|
|
3645
|
+
GLctx.bindAttribLocation(this.program, GLImmediate.NORMAL, 'a_normal');
|
|
3646
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3647
|
+
GLctx.bindAttribLocation(this.program, GLImmediate.TEXTURE0 + i, 'a_texCoord'+i);
|
|
3648
|
+
GLctx.bindAttribLocation(this.program, GLImmediate.TEXTURE0 + i, aTexCoordPrefix+i);
|
|
3598
3649
|
}
|
|
3599
|
-
|
|
3650
|
+
GLctx.linkProgram(this.program);
|
|
3600
3651
|
}
|
|
3601
3652
|
|
|
3602
|
-
// Stores
|
|
3653
|
+
// Stores an array that remembers which matrix uniforms are up-to-date in this FFP renderer, so they don't need to be resubmitted
|
|
3603
3654
|
// each time we render with this program.
|
|
3604
|
-
this.textureMatrixVersion =
|
|
3655
|
+
this.textureMatrixVersion = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
|
|
3605
3656
|
|
|
3606
|
-
this.positionLocation =
|
|
3657
|
+
this.positionLocation = GLctx.getAttribLocation(this.program, 'a_position');
|
|
3607
3658
|
|
|
3608
3659
|
this.texCoordLocations = [];
|
|
3609
3660
|
|
|
3610
|
-
for (var i = 0; i <
|
|
3611
|
-
if (!
|
|
3661
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3662
|
+
if (!GLImmediate.enabledClientAttributes[GLImmediate.TEXTURE0 + i]) {
|
|
3612
3663
|
this.texCoordLocations[i] = -1;
|
|
3613
3664
|
continue;
|
|
3614
3665
|
}
|
|
3615
3666
|
|
|
3616
3667
|
if (useCurrProgram) {
|
|
3617
|
-
this.texCoordLocations[i] =
|
|
3668
|
+
this.texCoordLocations[i] = GLctx.getAttribLocation(this.program, 'a_texCoord' + i);
|
|
3618
3669
|
} else {
|
|
3619
|
-
this.texCoordLocations[i] =
|
|
3670
|
+
this.texCoordLocations[i] = GLctx.getAttribLocation(this.program, aTexCoordPrefix + i);
|
|
3620
3671
|
}
|
|
3621
3672
|
}
|
|
3622
3673
|
|
|
3623
3674
|
if (!useCurrProgram) {
|
|
3624
3675
|
// Temporarily switch to the program so we can set our sampler uniforms early.
|
|
3625
|
-
var prevBoundProg =
|
|
3626
|
-
|
|
3676
|
+
var prevBoundProg = GLctx.getParameter(GLctx.CURRENT_PROGRAM);
|
|
3677
|
+
GLctx.useProgram(this.program);
|
|
3627
3678
|
{
|
|
3628
3679
|
for (var i = 0; i < this.usedTexUnitList.length; i++) {
|
|
3629
3680
|
var texUnitID = this.usedTexUnitList[i];
|
|
3630
|
-
var texSamplerLoc =
|
|
3631
|
-
|
|
3681
|
+
var texSamplerLoc = GLctx.getUniformLocation(this.program, uTexUnitPrefix + texUnitID);
|
|
3682
|
+
GLctx.uniform1i(texSamplerLoc, texUnitID);
|
|
3632
3683
|
}
|
|
3633
3684
|
}
|
|
3634
|
-
|
|
3685
|
+
GLctx.useProgram(prevBoundProg);
|
|
3635
3686
|
}
|
|
3636
3687
|
|
|
3637
3688
|
this.textureMatrixLocations = [];
|
|
3638
|
-
for (var i = 0; i <
|
|
3639
|
-
this.textureMatrixLocations[i] =
|
|
3689
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3690
|
+
this.textureMatrixLocations[i] = GLctx.getUniformLocation(this.program, 'u_textureMatrix' + i);
|
|
3640
3691
|
}
|
|
3641
|
-
this.colorLocation =
|
|
3642
|
-
this.normalLocation =
|
|
3692
|
+
this.colorLocation = GLctx.getAttribLocation(this.program, 'a_color');
|
|
3693
|
+
this.normalLocation = GLctx.getAttribLocation(this.program, 'a_normal');
|
|
3643
3694
|
|
|
3644
|
-
this.modelViewLocation =
|
|
3645
|
-
this.projectionLocation =
|
|
3695
|
+
this.modelViewLocation = GLctx.getUniformLocation(this.program, 'u_modelView');
|
|
3696
|
+
this.projectionLocation = GLctx.getUniformLocation(this.program, 'u_projection');
|
|
3646
3697
|
|
|
3647
3698
|
this.hasTextures = hasTextures;
|
|
3648
|
-
this.hasNormal =
|
|
3649
|
-
|
|
3699
|
+
this.hasNormal = GLImmediate.enabledClientAttributes[GLImmediate.NORMAL] &&
|
|
3700
|
+
GLImmediate.clientAttributes[GLImmediate.NORMAL].size > 0 &&
|
|
3650
3701
|
this.normalLocation >= 0;
|
|
3651
3702
|
this.hasColor = (this.colorLocation === 0) || this.colorLocation > 0;
|
|
3652
3703
|
|
|
3653
|
-
this.floatType =
|
|
3704
|
+
this.floatType = GLctx.FLOAT; // minor optimization
|
|
3654
3705
|
|
|
3655
|
-
this.fogColorLocation =
|
|
3656
|
-
this.fogEndLocation =
|
|
3657
|
-
this.fogScaleLocation =
|
|
3658
|
-
this.fogDensityLocation =
|
|
3706
|
+
this.fogColorLocation = GLctx.getUniformLocation(this.program, 'u_fogColor');
|
|
3707
|
+
this.fogEndLocation = GLctx.getUniformLocation(this.program, 'u_fogEnd');
|
|
3708
|
+
this.fogScaleLocation = GLctx.getUniformLocation(this.program, 'u_fogScale');
|
|
3709
|
+
this.fogDensityLocation = GLctx.getUniformLocation(this.program, 'u_fogDensity');
|
|
3659
3710
|
this.hasFog = !!(this.fogColorLocation || this.fogEndLocation ||
|
|
3660
3711
|
this.fogScaleLocation || this.fogDensityLocation);
|
|
3661
3712
|
},
|
|
@@ -3664,8 +3715,8 @@ var LibraryGL = {
|
|
|
3664
3715
|
// Calculate the array buffer
|
|
3665
3716
|
var arrayBuffer;
|
|
3666
3717
|
if (!GL.currArrayBuffer) {
|
|
3667
|
-
var start =
|
|
3668
|
-
var end =
|
|
3718
|
+
var start = GLImmediate.firstVertex*GLImmediate.stride;
|
|
3719
|
+
var end = GLImmediate.lastVertex*GLImmediate.stride;
|
|
3669
3720
|
#if ASSERTIONS
|
|
3670
3721
|
assert(end <= GL.MAX_TEMP_BUFFER_SIZE, 'too much vertex data');
|
|
3671
3722
|
#endif
|
|
@@ -3679,177 +3730,176 @@ var LibraryGL = {
|
|
|
3679
3730
|
// If the array buffer is unchanged and the renderer as well, then we can avoid all the work here
|
|
3680
3731
|
// XXX We use some heuristics here, and this may not work in all cases. Try disabling GL_UNSAFE_OPTS if you
|
|
3681
3732
|
// have odd glitches
|
|
3682
|
-
var lastRenderer =
|
|
3733
|
+
var lastRenderer = GLImmediate.lastRenderer;
|
|
3683
3734
|
var canSkip = this == lastRenderer &&
|
|
3684
|
-
arrayBuffer ==
|
|
3685
|
-
(GL.currProgram || this.program) ==
|
|
3686
|
-
|
|
3687
|
-
!
|
|
3735
|
+
arrayBuffer == GLImmediate.lastArrayBuffer &&
|
|
3736
|
+
(GL.currProgram || this.program) == GLImmediate.lastProgram &&
|
|
3737
|
+
GLImmediate.stride == GLImmediate.lastStride &&
|
|
3738
|
+
!GLImmediate.matricesModified;
|
|
3688
3739
|
if (!canSkip && lastRenderer) lastRenderer.cleanup();
|
|
3689
3740
|
#endif
|
|
3690
3741
|
if (!GL.currArrayBuffer) {
|
|
3691
3742
|
// Bind the array buffer and upload data after cleaning up the previous renderer
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, arrayBuffer);
|
|
3697
|
-
#if GL_UNSAFE_OPTS
|
|
3743
|
+
|
|
3744
|
+
if (arrayBuffer != GLImmediate.lastArrayBuffer) {
|
|
3745
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, arrayBuffer);
|
|
3746
|
+
GLImmediate.lastArrayBuffer = arrayBuffer;
|
|
3698
3747
|
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3748
|
+
|
|
3749
|
+
GLctx.bufferSubData(GLctx.ARRAY_BUFFER, start, GLImmediate.vertexData.subarray(start >> 2, end >> 2));
|
|
3701
3750
|
}
|
|
3702
3751
|
#if GL_UNSAFE_OPTS
|
|
3703
3752
|
if (canSkip) return;
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
GL.immediate.matricesModified = false;
|
|
3753
|
+
GLImmediate.lastRenderer = this;
|
|
3754
|
+
GLImmediate.lastProgram = GL.currProgram || this.program;
|
|
3755
|
+
GLImmediate.lastStride == GLImmediate.stride;
|
|
3756
|
+
GLImmediate.matricesModified = false;
|
|
3709
3757
|
#endif
|
|
3710
3758
|
|
|
3711
3759
|
if (!GL.currProgram) {
|
|
3712
|
-
|
|
3713
|
-
|
|
3760
|
+
if (GLImmediate.fixedFunctionProgram != this.program) {
|
|
3761
|
+
GLctx.useProgram(this.program);
|
|
3762
|
+
GLImmediate.fixedFunctionProgram = this.program;
|
|
3763
|
+
}
|
|
3714
3764
|
}
|
|
3715
3765
|
|
|
3716
|
-
if (this.modelViewLocation && this.modelViewMatrixVersion !=
|
|
3717
|
-
this.modelViewMatrixVersion =
|
|
3718
|
-
|
|
3766
|
+
if (this.modelViewLocation && this.modelViewMatrixVersion != GLImmediate.matrixVersion[0/*m*/]) {
|
|
3767
|
+
this.modelViewMatrixVersion = GLImmediate.matrixVersion[0/*m*/];
|
|
3768
|
+
GLctx.uniformMatrix4fv(this.modelViewLocation, false, GLImmediate.matrix[0/*m*/]);
|
|
3719
3769
|
}
|
|
3720
|
-
if (this.projectionLocation && this.projectionMatrixVersion !=
|
|
3721
|
-
this.projectionMatrixVersion =
|
|
3722
|
-
|
|
3770
|
+
if (this.projectionLocation && this.projectionMatrixVersion != GLImmediate.matrixVersion[1/*p*/]) {
|
|
3771
|
+
this.projectionMatrixVersion = GLImmediate.matrixVersion[1/*p*/];
|
|
3772
|
+
GLctx.uniformMatrix4fv(this.projectionLocation, false, GLImmediate.matrix[1/*p*/]);
|
|
3723
3773
|
}
|
|
3724
3774
|
|
|
3725
|
-
var clientAttributes =
|
|
3726
|
-
var posAttr = clientAttributes[
|
|
3775
|
+
var clientAttributes = GLImmediate.clientAttributes;
|
|
3776
|
+
var posAttr = clientAttributes[GLImmediate.VERTEX];
|
|
3727
3777
|
|
|
3728
3778
|
#if GL_ASSERTIONS
|
|
3729
|
-
GL.validateVertexAttribPointer(posAttr.size, posAttr.type,
|
|
3779
|
+
GL.validateVertexAttribPointer(posAttr.size, posAttr.type, GLImmediate.stride, clientAttributes[GLImmediate.VERTEX].offset);
|
|
3730
3780
|
#endif
|
|
3731
3781
|
|
|
3732
3782
|
#if GL_FFP_ONLY
|
|
3733
3783
|
if (!GL.currArrayBuffer) {
|
|
3734
|
-
|
|
3735
|
-
GL.enableVertexAttribArray(
|
|
3784
|
+
GLctx.vertexAttribPointer(GLImmediate.VERTEX, posAttr.size, posAttr.type, false, GLImmediate.stride, posAttr.offset);
|
|
3785
|
+
GL.enableVertexAttribArray(GLImmediate.VERTEX);
|
|
3736
3786
|
if (this.hasNormal) {
|
|
3737
|
-
var normalAttr = clientAttributes[
|
|
3738
|
-
|
|
3739
|
-
GL.enableVertexAttribArray(
|
|
3787
|
+
var normalAttr = clientAttributes[GLImmediate.NORMAL];
|
|
3788
|
+
GLctx.vertexAttribPointer(GLImmediate.NORMAL, normalAttr.size, normalAttr.type, true, GLImmediate.stride, normalAttr.offset);
|
|
3789
|
+
GL.enableVertexAttribArray(GLImmediate.NORMAL);
|
|
3740
3790
|
}
|
|
3741
3791
|
}
|
|
3742
3792
|
#else
|
|
3743
|
-
|
|
3744
|
-
|
|
3793
|
+
GLctx.vertexAttribPointer(this.positionLocation, posAttr.size, posAttr.type, false, GLImmediate.stride, posAttr.offset);
|
|
3794
|
+
GLctx.enableVertexAttribArray(this.positionLocation);
|
|
3745
3795
|
if (this.hasNormal) {
|
|
3746
|
-
var normalAttr = clientAttributes[
|
|
3796
|
+
var normalAttr = clientAttributes[GLImmediate.NORMAL];
|
|
3747
3797
|
#if GL_ASSERTIONS
|
|
3748
|
-
GL.validateVertexAttribPointer(normalAttr.size, normalAttr.type,
|
|
3798
|
+
GL.validateVertexAttribPointer(normalAttr.size, normalAttr.type, GLImmediate.stride, normalAttr.offset);
|
|
3749
3799
|
#endif
|
|
3750
|
-
|
|
3751
|
-
|
|
3800
|
+
GLctx.vertexAttribPointer(this.normalLocation, normalAttr.size, normalAttr.type, true, GLImmediate.stride, normalAttr.offset);
|
|
3801
|
+
GLctx.enableVertexAttribArray(this.normalLocation);
|
|
3752
3802
|
}
|
|
3753
3803
|
#endif
|
|
3754
3804
|
if (this.hasTextures) {
|
|
3755
|
-
for (var i = 0; i <
|
|
3805
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3756
3806
|
#if GL_FFP_ONLY
|
|
3757
3807
|
if (!GL.currArrayBuffer) {
|
|
3758
|
-
var attribLoc =
|
|
3808
|
+
var attribLoc = GLImmediate.TEXTURE0+i;
|
|
3759
3809
|
var texAttr = clientAttributes[attribLoc];
|
|
3760
3810
|
if (texAttr.size) {
|
|
3761
|
-
|
|
3811
|
+
GLctx.vertexAttribPointer(attribLoc, texAttr.size, texAttr.type, false, GLImmediate.stride, texAttr.offset);
|
|
3762
3812
|
GL.enableVertexAttribArray(attribLoc);
|
|
3763
3813
|
} else {
|
|
3764
3814
|
// These two might be dangerous, but let's try them.
|
|
3765
|
-
|
|
3815
|
+
GLctx.vertexAttrib4f(attribLoc, 0, 0, 0, 1);
|
|
3766
3816
|
GL.disableVertexAttribArray(attribLoc);
|
|
3767
3817
|
}
|
|
3768
3818
|
}
|
|
3769
3819
|
#else
|
|
3770
3820
|
var attribLoc = this.texCoordLocations[i];
|
|
3771
3821
|
if (attribLoc === undefined || attribLoc < 0) continue;
|
|
3772
|
-
var texAttr = clientAttributes[
|
|
3822
|
+
var texAttr = clientAttributes[GLImmediate.TEXTURE0+i];
|
|
3773
3823
|
|
|
3774
3824
|
if (texAttr.size) {
|
|
3775
3825
|
#if GL_ASSERTIONS
|
|
3776
|
-
GL.validateVertexAttribPointer(texAttr.size, texAttr.type,
|
|
3826
|
+
GL.validateVertexAttribPointer(texAttr.size, texAttr.type, GLImmediate.stride, texAttr.offset);
|
|
3777
3827
|
#endif
|
|
3778
|
-
|
|
3779
|
-
|
|
3828
|
+
GLctx.vertexAttribPointer(attribLoc, texAttr.size, texAttr.type, false, GLImmediate.stride, texAttr.offset);
|
|
3829
|
+
GLctx.enableVertexAttribArray(attribLoc);
|
|
3780
3830
|
} else {
|
|
3781
3831
|
// These two might be dangerous, but let's try them.
|
|
3782
|
-
|
|
3783
|
-
|
|
3832
|
+
GLctx.vertexAttrib4f(attribLoc, 0, 0, 0, 1);
|
|
3833
|
+
GLctx.disableVertexAttribArray(attribLoc);
|
|
3784
3834
|
}
|
|
3785
3835
|
#endif
|
|
3786
|
-
var t =
|
|
3787
|
-
if (this.textureMatrixLocations[i] && this.textureMatrixVersion[t] !=
|
|
3788
|
-
this.textureMatrixVersion[t] =
|
|
3789
|
-
|
|
3836
|
+
var t = 2/*t*/+i;
|
|
3837
|
+
if (this.textureMatrixLocations[i] && this.textureMatrixVersion[t] != GLImmediate.matrixVersion[t]) { // XXX might we need this even without the condition we are currently in?
|
|
3838
|
+
this.textureMatrixVersion[t] = GLImmediate.matrixVersion[t];
|
|
3839
|
+
GLctx.uniformMatrix4fv(this.textureMatrixLocations[i], false, GLImmediate.matrix[t]);
|
|
3790
3840
|
}
|
|
3791
3841
|
}
|
|
3792
3842
|
}
|
|
3793
|
-
if (
|
|
3794
|
-
var colorAttr = clientAttributes[
|
|
3843
|
+
if (GLImmediate.enabledClientAttributes[GLImmediate.COLOR]) {
|
|
3844
|
+
var colorAttr = clientAttributes[GLImmediate.COLOR];
|
|
3795
3845
|
#if GL_ASSERTIONS
|
|
3796
|
-
GL.validateVertexAttribPointer(colorAttr.size, colorAttr.type,
|
|
3846
|
+
GL.validateVertexAttribPointer(colorAttr.size, colorAttr.type, GLImmediate.stride, colorAttr.offset);
|
|
3797
3847
|
#endif
|
|
3798
3848
|
#if GL_FFP_ONLY
|
|
3799
3849
|
if (!GL.currArrayBuffer) {
|
|
3800
|
-
|
|
3801
|
-
GL.enableVertexAttribArray(
|
|
3850
|
+
GLctx.vertexAttribPointer(GLImmediate.COLOR, colorAttr.size, colorAttr.type, true, GLImmediate.stride, colorAttr.offset);
|
|
3851
|
+
GL.enableVertexAttribArray(GLImmediate.COLOR);
|
|
3802
3852
|
}
|
|
3803
3853
|
#else
|
|
3804
|
-
|
|
3805
|
-
|
|
3854
|
+
GLctx.vertexAttribPointer(this.colorLocation, colorAttr.size, colorAttr.type, true, GLImmediate.stride, colorAttr.offset);
|
|
3855
|
+
GLctx.enableVertexAttribArray(this.colorLocation);
|
|
3806
3856
|
#endif
|
|
3807
3857
|
} else if (this.hasColor) {
|
|
3808
3858
|
#if GL_FFP_ONLY
|
|
3809
|
-
GL.disableVertexAttribArray(
|
|
3810
|
-
|
|
3859
|
+
GL.disableVertexAttribArray(GLImmediate.COLOR);
|
|
3860
|
+
GLctx.vertexAttrib4fv(GLImmediate.COLOR, GLImmediate.clientColor);
|
|
3811
3861
|
#else
|
|
3812
|
-
|
|
3813
|
-
|
|
3862
|
+
GLctx.disableVertexAttribArray(this.colorLocation);
|
|
3863
|
+
GLctx.vertexAttrib4fv(this.colorLocation, GLImmediate.clientColor);
|
|
3814
3864
|
#endif
|
|
3815
3865
|
}
|
|
3816
3866
|
if (this.hasFog) {
|
|
3817
|
-
if (this.fogColorLocation)
|
|
3818
|
-
if (this.fogEndLocation)
|
|
3819
|
-
if (this.fogScaleLocation)
|
|
3820
|
-
if (this.fogDensityLocation)
|
|
3867
|
+
if (this.fogColorLocation) GLctx.uniform4fv(this.fogColorLocation, GLEmulation.fogColor);
|
|
3868
|
+
if (this.fogEndLocation) GLctx.uniform1f(this.fogEndLocation, GLEmulation.fogEnd);
|
|
3869
|
+
if (this.fogScaleLocation) GLctx.uniform1f(this.fogScaleLocation, 1/(GLEmulation.fogEnd - GLEmulation.fogStart));
|
|
3870
|
+
if (this.fogDensityLocation) GLctx.uniform1f(this.fogDensityLocation, GLEmulation.fogDensity);
|
|
3821
3871
|
}
|
|
3822
3872
|
},
|
|
3823
3873
|
|
|
3824
3874
|
cleanup: function cleanup() {
|
|
3825
3875
|
#if !GL_FFP_ONLY
|
|
3826
|
-
|
|
3876
|
+
GLctx.disableVertexAttribArray(this.positionLocation);
|
|
3827
3877
|
if (this.hasTextures) {
|
|
3828
|
-
for (var i = 0; i <
|
|
3829
|
-
if (
|
|
3830
|
-
|
|
3878
|
+
for (var i = 0; i < GLImmediate.MAX_TEXTURES; i++) {
|
|
3879
|
+
if (GLImmediate.enabledClientAttributes[GLImmediate.TEXTURE0+i] && this.texCoordLocations[i] >= 0) {
|
|
3880
|
+
GLctx.disableVertexAttribArray(this.texCoordLocations[i]);
|
|
3831
3881
|
}
|
|
3832
3882
|
}
|
|
3833
3883
|
}
|
|
3834
3884
|
if (this.hasColor) {
|
|
3835
|
-
|
|
3885
|
+
GLctx.disableVertexAttribArray(this.colorLocation);
|
|
3836
3886
|
}
|
|
3837
3887
|
if (this.hasNormal) {
|
|
3838
|
-
|
|
3888
|
+
GLctx.disableVertexAttribArray(this.normalLocation);
|
|
3839
3889
|
}
|
|
3840
3890
|
if (!GL.currProgram) {
|
|
3841
|
-
|
|
3891
|
+
GLctx.useProgram(null);
|
|
3842
3892
|
}
|
|
3843
3893
|
if (!GL.currArrayBuffer) {
|
|
3844
|
-
|
|
3894
|
+
GLctx.bindBuffer(GLctx.ARRAY_BUFFER, null);
|
|
3895
|
+
GLImmediate.lastArrayBuffer = null;
|
|
3845
3896
|
}
|
|
3846
3897
|
|
|
3847
3898
|
#if GL_UNSAFE_OPTS
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
GL.immediate.lastProgram = null;
|
|
3899
|
+
GLImmediate.lastRenderer = null;
|
|
3900
|
+
GLImmediate.lastProgram = null;
|
|
3851
3901
|
#endif
|
|
3852
|
-
|
|
3902
|
+
GLImmediate.matricesModified = true;
|
|
3853
3903
|
#endif
|
|
3854
3904
|
}
|
|
3855
3905
|
};
|
|
@@ -3862,53 +3912,53 @@ var LibraryGL = {
|
|
|
3862
3912
|
// attributes enabled, and we use webgl-friendly modes (no GL_QUADS), then no need
|
|
3863
3913
|
// for emulation
|
|
3864
3914
|
_glDrawArrays = function _glDrawArrays(mode, first, count) {
|
|
3865
|
-
if (
|
|
3866
|
-
|
|
3915
|
+
if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6) {
|
|
3916
|
+
GLctx.drawArrays(mode, first, count);
|
|
3867
3917
|
return;
|
|
3868
3918
|
}
|
|
3869
|
-
|
|
3870
|
-
|
|
3919
|
+
GLImmediate.prepareClientAttributes(count, false);
|
|
3920
|
+
GLImmediate.mode = mode;
|
|
3871
3921
|
if (!GL.currArrayBuffer) {
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3922
|
+
GLImmediate.vertexData = {{{ makeHEAPView('F32', 'GLImmediate.vertexPointer', 'GLImmediate.vertexPointer + (first+count)*GLImmediate.stride') }}}; // XXX assuming float
|
|
3923
|
+
GLImmediate.firstVertex = first;
|
|
3924
|
+
GLImmediate.lastVertex = first + count;
|
|
3875
3925
|
}
|
|
3876
|
-
|
|
3877
|
-
|
|
3926
|
+
GLImmediate.flush(null, first);
|
|
3927
|
+
GLImmediate.mode = -1;
|
|
3878
3928
|
};
|
|
3879
3929
|
|
|
3880
3930
|
_glDrawElements = function _glDrawElements(mode, count, type, indices, start, end) { // start, end are given if we come from glDrawRangeElements
|
|
3881
|
-
if (
|
|
3882
|
-
|
|
3931
|
+
if (GLImmediate.totalEnabledClientAttributes == 0 && mode <= 6 && GL.currElementArrayBuffer) {
|
|
3932
|
+
GLctx.drawElements(mode, count, type, indices);
|
|
3883
3933
|
return;
|
|
3884
3934
|
}
|
|
3885
3935
|
#if ASSERTIONS
|
|
3886
3936
|
if (!GL.currElementArrayBuffer) {
|
|
3887
|
-
assert(type ==
|
|
3937
|
+
assert(type == GLctx.UNSIGNED_SHORT); // We can only emulate buffers of this kind, for now
|
|
3888
3938
|
}
|
|
3889
3939
|
console.log("DrawElements doesn't actually prepareClientAttributes properly.");
|
|
3890
3940
|
#endif
|
|
3891
|
-
|
|
3892
|
-
|
|
3941
|
+
GLImmediate.prepareClientAttributes(count, false);
|
|
3942
|
+
GLImmediate.mode = mode;
|
|
3893
3943
|
if (!GL.currArrayBuffer) {
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3944
|
+
GLImmediate.firstVertex = end ? start : TOTAL_MEMORY; // if we don't know the start, set an invalid value and we will calculate it later from the indices
|
|
3945
|
+
GLImmediate.lastVertex = end ? end+1 : 0;
|
|
3946
|
+
GLImmediate.vertexData = {{{ makeHEAPView('F32', 'GLImmediate.vertexPointer', '(end ? GLImmediate.vertexPointer + (end+1)*GLImmediate.stride : TOTAL_MEMORY)') }}}; // XXX assuming float
|
|
3897
3947
|
}
|
|
3898
|
-
|
|
3899
|
-
|
|
3948
|
+
GLImmediate.flush(count, 0, indices);
|
|
3949
|
+
GLImmediate.mode = -1;
|
|
3900
3950
|
};
|
|
3901
3951
|
|
|
3902
3952
|
// TexEnv stuff needs to be prepared early, so do it here.
|
|
3903
3953
|
// init() is too late for -O2, since it freezes the GL functions
|
|
3904
3954
|
// by that point.
|
|
3905
|
-
|
|
3906
|
-
|
|
3955
|
+
GLImmediate.MapTreeLib = GLImmediate.spawnMapTreeLib();
|
|
3956
|
+
GLImmediate.spawnMapTreeLib = null;
|
|
3907
3957
|
|
|
3908
|
-
|
|
3909
|
-
|
|
3958
|
+
GLImmediate.TexEnvJIT = GLImmediate.spawnTexEnvJIT();
|
|
3959
|
+
GLImmediate.spawnTexEnvJIT = null;
|
|
3910
3960
|
|
|
3911
|
-
|
|
3961
|
+
GLImmediate.setupHooks();
|
|
3912
3962
|
},
|
|
3913
3963
|
|
|
3914
3964
|
setupHooks: function() {
|
|
@@ -3918,36 +3968,36 @@ var LibraryGL = {
|
|
|
3918
3968
|
|
|
3919
3969
|
var glActiveTexture = _glActiveTexture;
|
|
3920
3970
|
_glActiveTexture = function _glActiveTexture(texture) {
|
|
3921
|
-
|
|
3971
|
+
GLImmediate.TexEnvJIT.hook_activeTexture(texture);
|
|
3922
3972
|
glActiveTexture(texture);
|
|
3923
3973
|
};
|
|
3924
3974
|
|
|
3925
3975
|
var glEnable = _glEnable;
|
|
3926
3976
|
_glEnable = function _glEnable(cap) {
|
|
3927
|
-
|
|
3977
|
+
GLImmediate.TexEnvJIT.hook_enable(cap);
|
|
3928
3978
|
glEnable(cap);
|
|
3929
3979
|
};
|
|
3930
3980
|
var glDisable = _glDisable;
|
|
3931
3981
|
_glDisable = function _glDisable(cap) {
|
|
3932
|
-
|
|
3982
|
+
GLImmediate.TexEnvJIT.hook_disable(cap);
|
|
3933
3983
|
glDisable(cap);
|
|
3934
3984
|
};
|
|
3935
3985
|
|
|
3936
3986
|
var glTexEnvf = (typeof(_glTexEnvf) != 'undefined') ? _glTexEnvf : function(){};
|
|
3937
3987
|
_glTexEnvf = function _glTexEnvf(target, pname, param) {
|
|
3938
|
-
|
|
3988
|
+
GLImmediate.TexEnvJIT.hook_texEnvf(target, pname, param);
|
|
3939
3989
|
// Don't call old func, since we are the implementor.
|
|
3940
3990
|
//glTexEnvf(target, pname, param);
|
|
3941
3991
|
};
|
|
3942
3992
|
var glTexEnvi = (typeof(_glTexEnvi) != 'undefined') ? _glTexEnvi : function(){};
|
|
3943
3993
|
_glTexEnvi = function _glTexEnvi(target, pname, param) {
|
|
3944
|
-
|
|
3994
|
+
GLImmediate.TexEnvJIT.hook_texEnvi(target, pname, param);
|
|
3945
3995
|
// Don't call old func, since we are the implementor.
|
|
3946
3996
|
//glTexEnvi(target, pname, param);
|
|
3947
3997
|
};
|
|
3948
3998
|
var glTexEnvfv = (typeof(_glTexEnvfv) != 'undefined') ? _glTexEnvfv : function(){};
|
|
3949
3999
|
_glTexEnvfv = function _glTexEnvfv(target, pname, param) {
|
|
3950
|
-
|
|
4000
|
+
GLImmediate.TexEnvJIT.hook_texEnvfv(target, pname, param);
|
|
3951
4001
|
// Don't call old func, since we are the implementor.
|
|
3952
4002
|
//glTexEnvfv(target, pname, param);
|
|
3953
4003
|
};
|
|
@@ -3957,8 +4007,8 @@ var LibraryGL = {
|
|
|
3957
4007
|
switch (pname) {
|
|
3958
4008
|
case 0x8B8D: { // GL_CURRENT_PROGRAM
|
|
3959
4009
|
// Just query directly so we're working with WebGL objects.
|
|
3960
|
-
var cur =
|
|
3961
|
-
if (cur ==
|
|
4010
|
+
var cur = GLctx.getParameter(GLctx.CURRENT_PROGRAM);
|
|
4011
|
+
if (cur == GLImmediate.fixedFunctionProgram) {
|
|
3962
4012
|
// Pretend we're not using a program.
|
|
3963
4013
|
{{{ makeSetValue('params', '0', '0', 'i32') }}};
|
|
3964
4014
|
return;
|
|
@@ -3974,56 +4024,48 @@ var LibraryGL = {
|
|
|
3974
4024
|
initted: false,
|
|
3975
4025
|
init: function() {
|
|
3976
4026
|
Module.printErr('WARNING: using emscripten GL immediate mode emulation. This is very limited in what it supports');
|
|
3977
|
-
|
|
4027
|
+
GLImmediate.initted = true;
|
|
3978
4028
|
|
|
3979
4029
|
if (!Module.useWebGL) return; // a 2D canvas may be currently used TODO: make sure we are actually called in that case
|
|
3980
4030
|
|
|
3981
|
-
|
|
4031
|
+
GLImmediate.TexEnvJIT.init(GLctx);
|
|
3982
4032
|
|
|
3983
4033
|
// User can override the maximum number of texture units that we emulate. Using fewer texture units increases runtime performance
|
|
3984
4034
|
// slightly, so it is advantageous to choose as small value as needed.
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
4035
|
+
GLImmediate.MAX_TEXTURES = Module['GL_MAX_TEXTURE_IMAGE_UNITS'] || GLctx.getParameter(GLctx.MAX_TEXTURE_IMAGE_UNITS);
|
|
4036
|
+
GLImmediate.NUM_ATTRIBUTES = 3 /*pos+normal+color attributes*/ + GLImmediate.MAX_TEXTURES;
|
|
4037
|
+
GLImmediate.clientAttributes = [];
|
|
3988
4038
|
GLEmulation.enabledClientAttribIndices = [];
|
|
3989
|
-
for (var i = 0; i <
|
|
3990
|
-
|
|
4039
|
+
for (var i = 0; i < GLImmediate.NUM_ATTRIBUTES; i++) {
|
|
4040
|
+
GLImmediate.clientAttributes.push({});
|
|
3991
4041
|
GLEmulation.enabledClientAttribIndices.push(false);
|
|
3992
4042
|
}
|
|
3993
4043
|
|
|
3994
|
-
this.matrixStack['m'] = [];
|
|
3995
|
-
this.matrixStack['p'] = [];
|
|
3996
|
-
for (var i = 0; i < GL.immediate.MAX_TEXTURES; i++) {
|
|
3997
|
-
this.matrixStack['t' + i] = [];
|
|
3998
|
-
}
|
|
3999
|
-
|
|
4000
4044
|
// Initialize matrix library
|
|
4001
4045
|
// When user sets a matrix, increment a 'version number' on the new data, and when rendering, submit
|
|
4002
4046
|
// the matrices to the shader program only if they have an old version of the data.
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
GL.immediate.matrix['t' + i] = GL.immediate.matrix.lib.mat4.create();
|
|
4012
|
-
GL.immediate.matrixVersion['t' + i] = 0;
|
|
4047
|
+
GLImmediate.matrix = [];
|
|
4048
|
+
GLImmediate.matrixStack = [];
|
|
4049
|
+
GLImmediate.matrixVersion = [];
|
|
4050
|
+
for (var i = 0; i < 2 + GLImmediate.MAX_TEXTURES; i++) { // Modelview, Projection, plus one matrix for each texture coordinate.
|
|
4051
|
+
GLImmediate.matrixStack.push([]);
|
|
4052
|
+
GLImmediate.matrixVersion.push(0);
|
|
4053
|
+
GLImmediate.matrix.push(GLImmediate.matrixLib.mat4.create());
|
|
4054
|
+
GLImmediate.matrixLib.mat4.identity(GLImmediate.matrix[i]);
|
|
4013
4055
|
}
|
|
4014
4056
|
|
|
4015
4057
|
// Renderer cache
|
|
4016
|
-
|
|
4058
|
+
GLImmediate.rendererCache = GLImmediate.MapTreeLib.create();
|
|
4017
4059
|
|
|
4018
4060
|
// Buffers for data
|
|
4019
|
-
|
|
4020
|
-
|
|
4061
|
+
GLImmediate.tempData = new Float32Array(GL.MAX_TEMP_BUFFER_SIZE >> 2);
|
|
4062
|
+
GLImmediate.indexData = new Uint16Array(GL.MAX_TEMP_BUFFER_SIZE >> 1);
|
|
4021
4063
|
|
|
4022
|
-
|
|
4064
|
+
GLImmediate.vertexDataU8 = new Uint8Array(GLImmediate.tempData.buffer);
|
|
4023
4065
|
|
|
4024
4066
|
GL.generateTempBuffers(true);
|
|
4025
4067
|
|
|
4026
|
-
|
|
4068
|
+
GLImmediate.clientColor = new Float32Array([1, 1, 1, 1]);
|
|
4027
4069
|
},
|
|
4028
4070
|
|
|
4029
4071
|
// Prepares and analyzes client attributes.
|
|
@@ -4034,17 +4076,17 @@ var LibraryGL = {
|
|
|
4034
4076
|
// If no client attributes were modified since we were last called, do nothing. Note that this
|
|
4035
4077
|
// does not work for glBegin/End, where we generate renderer components dynamically and then
|
|
4036
4078
|
// disable them ourselves, but it does help with glDrawElements/Arrays.
|
|
4037
|
-
if (!
|
|
4038
|
-
|
|
4079
|
+
if (!GLImmediate.modifiedClientAttributes) {
|
|
4080
|
+
GLImmediate.vertexCounter = (GLImmediate.stride * count) / 4; // XXX assuming float
|
|
4039
4081
|
return;
|
|
4040
4082
|
}
|
|
4041
|
-
|
|
4083
|
+
GLImmediate.modifiedClientAttributes = false;
|
|
4042
4084
|
|
|
4043
4085
|
var stride = 0, start;
|
|
4044
|
-
var attributes =
|
|
4086
|
+
var attributes = GLImmediate.liveClientAttributes;
|
|
4045
4087
|
attributes.length = 0;
|
|
4046
|
-
for (var i = 0; i <
|
|
4047
|
-
if (
|
|
4088
|
+
for (var i = 0; i < GLImmediate.NUM_ATTRIBUTES; i++) {
|
|
4089
|
+
if (GLImmediate.enabledClientAttributes[i]) attributes.push(GLImmediate.clientAttributes[i]);
|
|
4048
4090
|
}
|
|
4049
4091
|
attributes.sort(function(x, y) { return !x ? (!y ? 0 : 1) : (!y ? -1 : (x.pointer - y.pointer)) });
|
|
4050
4092
|
start = GL.currArrayBuffer ? 0 : attributes[0].pointer;
|
|
@@ -4066,8 +4108,8 @@ var LibraryGL = {
|
|
|
4066
4108
|
#if ASSERTIONS
|
|
4067
4109
|
Runtime.warnOnce('Unpacking/restriding attributes, this is slow and dangerous');
|
|
4068
4110
|
#endif
|
|
4069
|
-
if (!
|
|
4070
|
-
start =
|
|
4111
|
+
if (!GLImmediate.restrideBuffer) GLImmediate.restrideBuffer = _malloc(GL.MAX_TEMP_BUFFER_SIZE);
|
|
4112
|
+
start = GLImmediate.restrideBuffer;
|
|
4071
4113
|
#if ASSERTIONS
|
|
4072
4114
|
assert(start % 4 == 0);
|
|
4073
4115
|
#endif
|
|
@@ -4117,14 +4159,14 @@ var LibraryGL = {
|
|
|
4117
4159
|
bytes = stride;
|
|
4118
4160
|
}
|
|
4119
4161
|
}
|
|
4120
|
-
|
|
4162
|
+
GLImmediate.stride = bytes;
|
|
4121
4163
|
|
|
4122
4164
|
if (!beginEnd) {
|
|
4123
4165
|
bytes *= count;
|
|
4124
4166
|
if (!GL.currArrayBuffer) {
|
|
4125
|
-
|
|
4167
|
+
GLImmediate.vertexPointer = start;
|
|
4126
4168
|
}
|
|
4127
|
-
|
|
4169
|
+
GLImmediate.vertexCounter = bytes / 4; // XXX assuming float
|
|
4128
4170
|
}
|
|
4129
4171
|
},
|
|
4130
4172
|
|
|
@@ -4135,10 +4177,10 @@ var LibraryGL = {
|
|
|
4135
4177
|
startIndex = startIndex || 0;
|
|
4136
4178
|
ptr = ptr || 0;
|
|
4137
4179
|
|
|
4138
|
-
var renderer =
|
|
4180
|
+
var renderer = GLImmediate.getRenderer();
|
|
4139
4181
|
|
|
4140
4182
|
// Generate index data in a format suitable for GLES 2.0/WebGL
|
|
4141
|
-
var numVertexes = 4 *
|
|
4183
|
+
var numVertexes = 4 * GLImmediate.vertexCounter / GLImmediate.stride;
|
|
4142
4184
|
#if ASSERTIONS
|
|
4143
4185
|
assert(numVertexes % 1 == 0, "`numVertexes` must be an integer.");
|
|
4144
4186
|
#endif
|
|
@@ -4146,7 +4188,7 @@ var LibraryGL = {
|
|
|
4146
4188
|
var numIndexes = 0;
|
|
4147
4189
|
if (numProvidedIndexes) {
|
|
4148
4190
|
numIndexes = numProvidedIndexes;
|
|
4149
|
-
if (!GL.currArrayBuffer &&
|
|
4191
|
+
if (!GL.currArrayBuffer && GLImmediate.firstVertex > GLImmediate.lastVertex) {
|
|
4150
4192
|
// Figure out the first and last vertex from the index data
|
|
4151
4193
|
#if ASSERTIONS
|
|
4152
4194
|
assert(!GL.currElementArrayBuffer); // If we are going to upload array buffer data, we need to find which range to
|
|
@@ -4156,8 +4198,8 @@ var LibraryGL = {
|
|
|
4156
4198
|
#endif
|
|
4157
4199
|
for (var i = 0; i < numProvidedIndexes; i++) {
|
|
4158
4200
|
var currIndex = {{{ makeGetValue('ptr', 'i*2', 'i16', null, 1) }}};
|
|
4159
|
-
|
|
4160
|
-
|
|
4201
|
+
GLImmediate.firstVertex = Math.min(GLImmediate.firstVertex, currIndex);
|
|
4202
|
+
GLImmediate.lastVertex = Math.max(GLImmediate.lastVertex, currIndex+1);
|
|
4161
4203
|
}
|
|
4162
4204
|
}
|
|
4163
4205
|
if (!GL.currElementArrayBuffer) {
|
|
@@ -4166,98 +4208,101 @@ var LibraryGL = {
|
|
|
4166
4208
|
assert(numProvidedIndexes << 1 <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (a)');
|
|
4167
4209
|
#endif
|
|
4168
4210
|
var indexBuffer = GL.tempIndexBuffers[GL.tempBufferIndexLookup[numProvidedIndexes << 1]];
|
|
4169
|
-
|
|
4170
|
-
|
|
4211
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, indexBuffer);
|
|
4212
|
+
GLctx.bufferSubData(GLctx.ELEMENT_ARRAY_BUFFER, 0, {{{ makeHEAPView('U16', 'ptr', 'ptr + (numProvidedIndexes << 1)') }}});
|
|
4171
4213
|
ptr = 0;
|
|
4172
4214
|
emulatedElementArrayBuffer = true;
|
|
4173
4215
|
}
|
|
4174
|
-
} else if (
|
|
4175
|
-
if (
|
|
4176
|
-
//
|
|
4216
|
+
} else if (GLImmediate.mode > 6) { // above GL_TRIANGLE_FAN are the non-GL ES modes
|
|
4217
|
+
if (GLImmediate.mode != 7) throw 'unsupported immediate mode ' + GLImmediate.mode; // GL_QUADS
|
|
4218
|
+
// GLImmediate.firstVertex is the first vertex we want. Quad indexes are in the pattern
|
|
4177
4219
|
// 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at index firstVertex * 1.5 to see it.
|
|
4178
4220
|
// Then since indexes are 2 bytes each, that means 3
|
|
4179
4221
|
#if ASSERTIONS
|
|
4180
|
-
assert(
|
|
4222
|
+
assert(GLImmediate.firstVertex % 4 == 0);
|
|
4181
4223
|
#endif
|
|
4182
|
-
ptr =
|
|
4224
|
+
ptr = GLImmediate.firstVertex*3;
|
|
4183
4225
|
var numQuads = numVertexes / 4;
|
|
4184
4226
|
numIndexes = numQuads * 6; // 0 1 2, 0 2 3 pattern
|
|
4185
4227
|
#if ASSERTIONS
|
|
4186
4228
|
assert(ptr + (numIndexes << 1) <= GL.MAX_TEMP_BUFFER_SIZE, 'too many immediate mode indexes (b)');
|
|
4187
4229
|
#endif
|
|
4188
|
-
|
|
4230
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, GL.tempQuadIndexBuffer);
|
|
4189
4231
|
emulatedElementArrayBuffer = true;
|
|
4190
4232
|
}
|
|
4191
4233
|
|
|
4192
4234
|
renderer.prepare();
|
|
4193
4235
|
|
|
4194
4236
|
if (numIndexes) {
|
|
4195
|
-
|
|
4237
|
+
GLctx.drawElements(GLctx.TRIANGLES, numIndexes, GLctx.UNSIGNED_SHORT, ptr);
|
|
4196
4238
|
} else {
|
|
4197
|
-
|
|
4239
|
+
GLctx.drawArrays(GLImmediate.mode, startIndex, numVertexes);
|
|
4198
4240
|
}
|
|
4199
4241
|
|
|
4200
4242
|
if (emulatedElementArrayBuffer) {
|
|
4201
|
-
|
|
4243
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, GL.buffers[GL.currElementArrayBuffer] || null);
|
|
4202
4244
|
}
|
|
4203
4245
|
|
|
4204
|
-
#if GL_UNSAFE_OPTS == 0
|
|
4246
|
+
#if GL_UNSAFE_OPTS == 0
|
|
4247
|
+
#if !GL_FFP_ONLY
|
|
4205
4248
|
renderer.cleanup();
|
|
4249
|
+
#endif
|
|
4206
4250
|
#endif
|
|
4207
4251
|
}
|
|
4208
4252
|
},
|
|
4209
4253
|
|
|
4210
|
-
$
|
|
4254
|
+
$GLImmediateSetup: {},
|
|
4255
|
+
$GLImmediateSetup__deps: ['$GLImmediate', function() { return 'GLImmediate.matrixLib = ' + read('gl-matrix.js') + ';\n' }],
|
|
4211
4256
|
$GLImmediateSetup: {},
|
|
4212
4257
|
|
|
4213
4258
|
glBegin__deps: ['$GLImmediateSetup'],
|
|
4214
4259
|
glBegin: function(mode) {
|
|
4215
4260
|
// Push the old state:
|
|
4216
|
-
|
|
4217
|
-
|
|
4261
|
+
GLImmediate.enabledClientAttributes_preBegin = GLImmediate.enabledClientAttributes;
|
|
4262
|
+
GLImmediate.enabledClientAttributes = [];
|
|
4218
4263
|
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
for (var i = 0; i <
|
|
4222
|
-
|
|
4264
|
+
GLImmediate.clientAttributes_preBegin = GLImmediate.clientAttributes;
|
|
4265
|
+
GLImmediate.clientAttributes = []
|
|
4266
|
+
for (var i = 0; i < GLImmediate.clientAttributes_preBegin.length; i++) {
|
|
4267
|
+
GLImmediate.clientAttributes.push({});
|
|
4223
4268
|
}
|
|
4224
4269
|
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
var components =
|
|
4228
|
-
for (var i = 0; i <
|
|
4270
|
+
GLImmediate.mode = mode;
|
|
4271
|
+
GLImmediate.vertexCounter = 0;
|
|
4272
|
+
var components = GLImmediate.rendererComponents = [];
|
|
4273
|
+
for (var i = 0; i < GLImmediate.NUM_ATTRIBUTES; i++) {
|
|
4229
4274
|
components[i] = 0;
|
|
4230
4275
|
}
|
|
4231
|
-
|
|
4232
|
-
|
|
4276
|
+
GLImmediate.rendererComponentPointer = 0;
|
|
4277
|
+
GLImmediate.vertexData = GLImmediate.tempData;
|
|
4233
4278
|
},
|
|
4234
4279
|
|
|
4235
4280
|
glEnd: function() {
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4281
|
+
GLImmediate.prepareClientAttributes(GLImmediate.rendererComponents[GLImmediate.VERTEX], true);
|
|
4282
|
+
GLImmediate.firstVertex = 0;
|
|
4283
|
+
GLImmediate.lastVertex = GLImmediate.vertexCounter / (GLImmediate.stride >> 2);
|
|
4284
|
+
GLImmediate.flush();
|
|
4285
|
+
GLImmediate.disableBeginEndClientAttributes();
|
|
4286
|
+
GLImmediate.mode = -1;
|
|
4242
4287
|
|
|
4243
4288
|
// Pop the old state:
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4289
|
+
GLImmediate.enabledClientAttributes = GLImmediate.enabledClientAttributes_preBegin;
|
|
4290
|
+
GLImmediate.clientAttributes = GLImmediate.clientAttributes_preBegin;
|
|
4291
|
+
GLImmediate.currentRenderer = null; // The set of active client attributes changed, we must re-lookup the renderer to use.
|
|
4292
|
+
GLImmediate.modifiedClientAttributes = true;
|
|
4248
4293
|
},
|
|
4249
4294
|
|
|
4250
4295
|
glVertex3f: function(x, y, z) {
|
|
4251
4296
|
#if ASSERTIONS
|
|
4252
|
-
assert(
|
|
4297
|
+
assert(GLImmediate.mode >= 0); // must be in begin/end
|
|
4253
4298
|
#endif
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4299
|
+
GLImmediate.vertexData[GLImmediate.vertexCounter++] = x;
|
|
4300
|
+
GLImmediate.vertexData[GLImmediate.vertexCounter++] = y;
|
|
4301
|
+
GLImmediate.vertexData[GLImmediate.vertexCounter++] = z || 0;
|
|
4257
4302
|
#if ASSERTIONS
|
|
4258
|
-
assert(
|
|
4303
|
+
assert(GLImmediate.vertexCounter << 2 < GL.MAX_TEMP_BUFFER_SIZE);
|
|
4259
4304
|
#endif
|
|
4260
|
-
|
|
4305
|
+
GLImmediate.addRendererComponent(GLImmediate.VERTEX, 3, GLctx.FLOAT);
|
|
4261
4306
|
},
|
|
4262
4307
|
glVertex2f: 'glVertex3f',
|
|
4263
4308
|
|
|
@@ -4276,11 +4321,11 @@ var LibraryGL = {
|
|
|
4276
4321
|
|
|
4277
4322
|
glTexCoord2i: function(u, v) {
|
|
4278
4323
|
#if ASSERTIONS
|
|
4279
|
-
assert(
|
|
4324
|
+
assert(GLImmediate.mode >= 0); // must be in begin/end
|
|
4280
4325
|
#endif
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4326
|
+
GLImmediate.vertexData[GLImmediate.vertexCounter++] = u;
|
|
4327
|
+
GLImmediate.vertexData[GLImmediate.vertexCounter++] = v;
|
|
4328
|
+
GLImmediate.addRendererComponent(GLImmediate.TEXTURE0, 2, GLctx.FLOAT);
|
|
4284
4329
|
},
|
|
4285
4330
|
glTexCoord2f: 'glTexCoord2i',
|
|
4286
4331
|
|
|
@@ -4298,19 +4343,19 @@ var LibraryGL = {
|
|
|
4298
4343
|
a = Math.max(Math.min(a, 1), 0);
|
|
4299
4344
|
|
|
4300
4345
|
// TODO: make ub the default, not f, save a few mathops
|
|
4301
|
-
if (
|
|
4302
|
-
var start =
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4346
|
+
if (GLImmediate.mode >= 0) {
|
|
4347
|
+
var start = GLImmediate.vertexCounter << 2;
|
|
4348
|
+
GLImmediate.vertexDataU8[start + 0] = r * 255;
|
|
4349
|
+
GLImmediate.vertexDataU8[start + 1] = g * 255;
|
|
4350
|
+
GLImmediate.vertexDataU8[start + 2] = b * 255;
|
|
4351
|
+
GLImmediate.vertexDataU8[start + 3] = a * 255;
|
|
4352
|
+
GLImmediate.vertexCounter++;
|
|
4353
|
+
GLImmediate.addRendererComponent(GLImmediate.COLOR, 4, GLctx.UNSIGNED_BYTE);
|
|
4309
4354
|
} else {
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4355
|
+
GLImmediate.clientColor[0] = r;
|
|
4356
|
+
GLImmediate.clientColor[1] = g;
|
|
4357
|
+
GLImmediate.clientColor[2] = b;
|
|
4358
|
+
GLImmediate.clientColor[3] = a;
|
|
4314
4359
|
}
|
|
4315
4360
|
},
|
|
4316
4361
|
glColor4d: 'glColor4f',
|
|
@@ -4382,9 +4427,17 @@ var LibraryGL = {
|
|
|
4382
4427
|
switch (param) {
|
|
4383
4428
|
case 0x0801: // GL_EXP2
|
|
4384
4429
|
case 0x2601: // GL_LINEAR
|
|
4385
|
-
GLEmulation.fogMode
|
|
4430
|
+
if (GLEmulation.fogMode != param) {
|
|
4431
|
+
GLImmediate.currentRenderer = null; // Fog mode is part of the FFP shader state, we must re-lookup the renderer to use.
|
|
4432
|
+
GLEmulation.fogMode = param;
|
|
4433
|
+
}
|
|
4434
|
+
break;
|
|
4386
4435
|
default: // default to GL_EXP
|
|
4387
|
-
GLEmulation.fogMode
|
|
4436
|
+
if (GLEmulation.fogMode != 0x0800 /* GL_EXP */) {
|
|
4437
|
+
GLImmediate.currentRenderer = null; // Fog mode is part of the FFP shader state, we must re-lookup the renderer to use.
|
|
4438
|
+
GLEmulation.fogMode = 0x0800 /* GL_EXP */;
|
|
4439
|
+
}
|
|
4440
|
+
break;
|
|
4388
4441
|
}
|
|
4389
4442
|
break;
|
|
4390
4443
|
}
|
|
@@ -4438,7 +4491,7 @@ var LibraryGL = {
|
|
|
4438
4491
|
|
|
4439
4492
|
// ClientState/gl*Pointer
|
|
4440
4493
|
|
|
4441
|
-
glEnableClientState: function(cap
|
|
4494
|
+
glEnableClientState: function(cap) {
|
|
4442
4495
|
var attrib = GLEmulation.getAttributeFromCapability(cap);
|
|
4443
4496
|
if (attrib === null) {
|
|
4444
4497
|
#if ASSERTIONS
|
|
@@ -4446,65 +4499,73 @@ var LibraryGL = {
|
|
|
4446
4499
|
#endif
|
|
4447
4500
|
return;
|
|
4448
4501
|
}
|
|
4449
|
-
if (
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
if (GLEmulation.currentVao) delete GLEmulation.currentVao.enabledClientStates[cap];
|
|
4454
|
-
} else if (!disable && !GL.immediate.enabledClientAttributes[attrib]) {
|
|
4455
|
-
GL.immediate.enabledClientAttributes[attrib] = true;
|
|
4456
|
-
GL.immediate.totalEnabledClientAttributes++;
|
|
4457
|
-
this.currentRenderer = null; // Will need to change current renderer, since the set of active vertex pointers changed.
|
|
4502
|
+
if (!GLImmediate.enabledClientAttributes[attrib]) {
|
|
4503
|
+
GLImmediate.enabledClientAttributes[attrib] = true;
|
|
4504
|
+
GLImmediate.totalEnabledClientAttributes++;
|
|
4505
|
+
GLImmediate.currentRenderer = null; // Will need to change current renderer, since the set of active vertex pointers changed.
|
|
4458
4506
|
if (GLEmulation.currentVao) GLEmulation.currentVao.enabledClientStates[cap] = 1;
|
|
4507
|
+
GLImmediate.modifiedClientAttributes = true;
|
|
4459
4508
|
}
|
|
4460
|
-
GL.immediate.modifiedClientAttributes = true;
|
|
4461
4509
|
},
|
|
4462
4510
|
glDisableClientState: function(cap) {
|
|
4463
|
-
|
|
4511
|
+
var attrib = GLEmulation.getAttributeFromCapability(cap);
|
|
4512
|
+
if (attrib === null) {
|
|
4513
|
+
#if ASSERTIONS
|
|
4514
|
+
Module.printErr('WARNING: unhandled clientstate: ' + cap);
|
|
4515
|
+
#endif
|
|
4516
|
+
return;
|
|
4517
|
+
}
|
|
4518
|
+
if (GLImmediate.enabledClientAttributes[attrib]) {
|
|
4519
|
+
GLImmediate.enabledClientAttributes[attrib] = false;
|
|
4520
|
+
GLImmediate.totalEnabledClientAttributes--;
|
|
4521
|
+
GLImmediate.currentRenderer = null; // Will need to change current renderer, since the set of active vertex pointers changed.
|
|
4522
|
+
if (GLEmulation.currentVao) delete GLEmulation.currentVao.enabledClientStates[cap];
|
|
4523
|
+
GLImmediate.modifiedClientAttributes = true;
|
|
4524
|
+
}
|
|
4464
4525
|
},
|
|
4465
4526
|
|
|
4466
4527
|
glVertexPointer__deps: ['$GLEmulation'], // if any pointers are used, glVertexPointer must be, and if it is, then we need emulation
|
|
4467
4528
|
glVertexPointer: function(size, type, stride, pointer) {
|
|
4468
|
-
|
|
4529
|
+
GLImmediate.setClientAttribute(GLImmediate.VERTEX, size, type, stride, pointer);
|
|
4469
4530
|
#if GL_FFP_ONLY
|
|
4470
4531
|
if (GL.currArrayBuffer) {
|
|
4471
|
-
|
|
4472
|
-
GL.enableVertexAttribArray(
|
|
4532
|
+
GLctx.vertexAttribPointer(GLImmediate.VERTEX, size, type, false, stride, pointer);
|
|
4533
|
+
GL.enableVertexAttribArray(GLImmediate.VERTEX);
|
|
4473
4534
|
}
|
|
4474
4535
|
#endif
|
|
4475
4536
|
},
|
|
4476
4537
|
glTexCoordPointer: function(size, type, stride, pointer) {
|
|
4477
|
-
|
|
4538
|
+
GLImmediate.setClientAttribute(GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture, size, type, stride, pointer);
|
|
4478
4539
|
#if GL_FFP_ONLY
|
|
4479
4540
|
if (GL.currArrayBuffer) {
|
|
4480
|
-
var loc =
|
|
4481
|
-
|
|
4541
|
+
var loc = GLImmediate.TEXTURE0 + GLImmediate.clientActiveTexture;
|
|
4542
|
+
GLctx.vertexAttribPointer(loc, size, type, false, stride, pointer);
|
|
4482
4543
|
GL.enableVertexAttribArray(loc);
|
|
4483
4544
|
}
|
|
4484
4545
|
#endif
|
|
4485
4546
|
},
|
|
4486
4547
|
glNormalPointer: function(type, stride, pointer) {
|
|
4487
|
-
|
|
4548
|
+
GLImmediate.setClientAttribute(GLImmediate.NORMAL, 3, type, stride, pointer);
|
|
4488
4549
|
#if GL_FFP_ONLY
|
|
4489
4550
|
if (GL.currArrayBuffer) {
|
|
4490
|
-
|
|
4491
|
-
GL.enableVertexAttribArray(
|
|
4551
|
+
GLctx.vertexAttribPointer(GLImmediate.NORMAL, size, type, true, stride, pointer);
|
|
4552
|
+
GL.enableVertexAttribArray(GLImmediate.NORMAL);
|
|
4492
4553
|
}
|
|
4493
4554
|
#endif
|
|
4494
4555
|
},
|
|
4495
4556
|
glColorPointer: function(size, type, stride, pointer) {
|
|
4496
|
-
|
|
4557
|
+
GLImmediate.setClientAttribute(GLImmediate.COLOR, size, type, stride, pointer);
|
|
4497
4558
|
#if GL_FFP_ONLY
|
|
4498
4559
|
if (GL.currArrayBuffer) {
|
|
4499
|
-
|
|
4500
|
-
GL.enableVertexAttribArray(
|
|
4560
|
+
GLctx.vertexAttribPointer(GLImmediate.COLOR, size, type, true, stride, pointer);
|
|
4561
|
+
GL.enableVertexAttribArray(GLImmediate.COLOR);
|
|
4501
4562
|
}
|
|
4502
4563
|
#endif
|
|
4503
4564
|
},
|
|
4504
4565
|
|
|
4505
4566
|
glClientActiveTexture__sig: 'vi',
|
|
4506
4567
|
glClientActiveTexture: function(texture) {
|
|
4507
|
-
|
|
4568
|
+
GLImmediate.clientActiveTexture = texture - 0x84C0; // GL_TEXTURE0
|
|
4508
4569
|
},
|
|
4509
4570
|
|
|
4510
4571
|
// Vertex array object (VAO) support. TODO: when the WebGL extension is popular, use that and remove this code and GL.vaos
|
|
@@ -4536,21 +4597,21 @@ var LibraryGL = {
|
|
|
4536
4597
|
glBindVertexArray: function(vao) {
|
|
4537
4598
|
// undo vao-related things, wipe the slate clean, both for vao of 0 or an actual vao
|
|
4538
4599
|
GLEmulation.currentVao = null; // make sure the commands we run here are not recorded
|
|
4539
|
-
if (
|
|
4540
|
-
_glBindBuffer(
|
|
4541
|
-
_glBindBuffer(
|
|
4600
|
+
if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup();
|
|
4601
|
+
_glBindBuffer(GLctx.ARRAY_BUFFER, 0); // XXX if one was there before we were bound?
|
|
4602
|
+
_glBindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, 0);
|
|
4542
4603
|
for (var vaa in GLEmulation.enabledVertexAttribArrays) {
|
|
4543
|
-
|
|
4604
|
+
GLctx.disableVertexAttribArray(vaa);
|
|
4544
4605
|
}
|
|
4545
4606
|
GLEmulation.enabledVertexAttribArrays = {};
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4607
|
+
GLImmediate.enabledClientAttributes = [0, 0];
|
|
4608
|
+
GLImmediate.totalEnabledClientAttributes = 0;
|
|
4609
|
+
GLImmediate.modifiedClientAttributes = true;
|
|
4549
4610
|
if (vao) {
|
|
4550
4611
|
// replay vao
|
|
4551
4612
|
var info = GLEmulation.vaos[vao];
|
|
4552
|
-
_glBindBuffer(
|
|
4553
|
-
_glBindBuffer(
|
|
4613
|
+
_glBindBuffer(GLctx.ARRAY_BUFFER, info.arrayBuffer); // XXX overwrite current binding?
|
|
4614
|
+
_glBindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, info.elementArrayBuffer);
|
|
4554
4615
|
for (var vaa in info.enabledVertexAttribArrays) {
|
|
4555
4616
|
_glEnableVertexAttribArray(vaa);
|
|
4556
4617
|
}
|
|
@@ -4569,132 +4630,132 @@ var LibraryGL = {
|
|
|
4569
4630
|
glMatrixMode__deps: ['$GL', '$GLImmediateSetup', '$GLEmulation'], // emulation is not strictly needed, this is a workaround
|
|
4570
4631
|
glMatrixMode: function(mode) {
|
|
4571
4632
|
if (mode == 0x1700 /* GL_MODELVIEW */) {
|
|
4572
|
-
|
|
4633
|
+
GLImmediate.currentMatrix = 0/*m*/;
|
|
4573
4634
|
} else if (mode == 0x1701 /* GL_PROJECTION */) {
|
|
4574
|
-
|
|
4635
|
+
GLImmediate.currentMatrix = 1/*p*/;
|
|
4575
4636
|
} else if (mode == 0x1702) { // GL_TEXTURE
|
|
4576
|
-
|
|
4577
|
-
|
|
4637
|
+
GLImmediate.useTextureMatrix = true;
|
|
4638
|
+
GLImmediate.currentMatrix = 2/*t*/ + GLImmediate.clientActiveTexture;
|
|
4578
4639
|
} else {
|
|
4579
4640
|
throw "Wrong mode " + mode + " passed to glMatrixMode";
|
|
4580
4641
|
}
|
|
4581
4642
|
},
|
|
4582
4643
|
|
|
4583
4644
|
glPushMatrix: function() {
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
Array.prototype.slice.call(
|
|
4645
|
+
GLImmediate.matricesModified = true;
|
|
4646
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4647
|
+
GLImmediate.matrixStack[GLImmediate.currentMatrix].push(
|
|
4648
|
+
Array.prototype.slice.call(GLImmediate.matrix[GLImmediate.currentMatrix]));
|
|
4588
4649
|
},
|
|
4589
4650
|
|
|
4590
4651
|
glPopMatrix: function() {
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4652
|
+
GLImmediate.matricesModified = true;
|
|
4653
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4654
|
+
GLImmediate.matrix[GLImmediate.currentMatrix] = GLImmediate.matrixStack[GLImmediate.currentMatrix].pop();
|
|
4594
4655
|
},
|
|
4595
4656
|
|
|
4596
4657
|
glLoadIdentity__deps: ['$GL', '$GLImmediateSetup'],
|
|
4597
4658
|
glLoadIdentity: function() {
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4659
|
+
GLImmediate.matricesModified = true;
|
|
4660
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4661
|
+
GLImmediate.matrixLib.mat4.identity(GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4601
4662
|
},
|
|
4602
4663
|
|
|
4603
4664
|
glLoadMatrixd: function(matrix) {
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4665
|
+
GLImmediate.matricesModified = true;
|
|
4666
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4667
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F64', 'matrix', 'matrix+' + (16*8)) }}}, GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4607
4668
|
},
|
|
4608
4669
|
|
|
4609
4670
|
glLoadMatrixf: function(matrix) {
|
|
4610
4671
|
#if GL_DEBUG
|
|
4611
4672
|
if (GL.debug) Module.printErr('glLoadMatrixf receiving: ' + Array.prototype.slice.call(HEAPF32.subarray(matrix >> 2, (matrix >> 2) + 16)));
|
|
4612
4673
|
#endif
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4674
|
+
GLImmediate.matricesModified = true;
|
|
4675
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4676
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F32', 'matrix', 'matrix+' + (16*4)) }}}, GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4616
4677
|
},
|
|
4617
4678
|
|
|
4618
4679
|
glLoadTransposeMatrixd: function(matrix) {
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4680
|
+
GLImmediate.matricesModified = true;
|
|
4681
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4682
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F64', 'matrix', 'matrix+' + (16*8)) }}}, GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4683
|
+
GLImmediate.matrixLib.mat4.transpose(GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4623
4684
|
},
|
|
4624
4685
|
|
|
4625
4686
|
glLoadTransposeMatrixf: function(matrix) {
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4687
|
+
GLImmediate.matricesModified = true;
|
|
4688
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4689
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F32', 'matrix', 'matrix+' + (16*4)) }}}, GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4690
|
+
GLImmediate.matrixLib.mat4.transpose(GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4630
4691
|
},
|
|
4631
4692
|
|
|
4632
4693
|
glMultMatrixd: function(matrix) {
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4694
|
+
GLImmediate.matricesModified = true;
|
|
4695
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4696
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix],
|
|
4636
4697
|
{{{ makeHEAPView('F64', 'matrix', 'matrix+' + (16*8)) }}});
|
|
4637
4698
|
},
|
|
4638
4699
|
|
|
4639
4700
|
glMultMatrixf: function(matrix) {
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4701
|
+
GLImmediate.matricesModified = true;
|
|
4702
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4703
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix],
|
|
4643
4704
|
{{{ makeHEAPView('F32', 'matrix', 'matrix+' + (16*4)) }}});
|
|
4644
4705
|
},
|
|
4645
4706
|
|
|
4646
4707
|
glMultTransposeMatrixd: function(matrix) {
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
var colMajor =
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4708
|
+
GLImmediate.matricesModified = true;
|
|
4709
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4710
|
+
var colMajor = GLImmediate.matrixLib.mat4.create();
|
|
4711
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F64', 'matrix', 'matrix+' + (16*8)) }}}, colMajor);
|
|
4712
|
+
GLImmediate.matrixLib.mat4.transpose(colMajor);
|
|
4713
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix], colMajor);
|
|
4653
4714
|
},
|
|
4654
4715
|
|
|
4655
4716
|
glMultTransposeMatrixf: function(matrix) {
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
var colMajor =
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4717
|
+
GLImmediate.matricesModified = true;
|
|
4718
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4719
|
+
var colMajor = GLImmediate.matrixLib.mat4.create();
|
|
4720
|
+
GLImmediate.matrixLib.mat4.set({{{ makeHEAPView('F32', 'matrix', 'matrix+' + (16*4)) }}}, colMajor);
|
|
4721
|
+
GLImmediate.matrixLib.mat4.transpose(colMajor);
|
|
4722
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix], colMajor);
|
|
4662
4723
|
},
|
|
4663
4724
|
|
|
4664
4725
|
glFrustum: function(left, right, bottom, top_, nearVal, farVal) {
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4726
|
+
GLImmediate.matricesModified = true;
|
|
4727
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4728
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix],
|
|
4729
|
+
GLImmediate.matrixLib.mat4.frustum(left, right, bottom, top_, nearVal, farVal));
|
|
4669
4730
|
},
|
|
4670
4731
|
glFrustumf: 'glFrustum',
|
|
4671
4732
|
|
|
4672
4733
|
glOrtho: function(left, right, bottom, top_, nearVal, farVal) {
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4734
|
+
GLImmediate.matricesModified = true;
|
|
4735
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4736
|
+
GLImmediate.matrixLib.mat4.multiply(GLImmediate.matrix[GLImmediate.currentMatrix],
|
|
4737
|
+
GLImmediate.matrixLib.mat4.ortho(left, right, bottom, top_, nearVal, farVal));
|
|
4677
4738
|
},
|
|
4678
4739
|
glOrthof: 'glOrtho',
|
|
4679
4740
|
|
|
4680
4741
|
glScaled: function(x, y, z) {
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4742
|
+
GLImmediate.matricesModified = true;
|
|
4743
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4744
|
+
GLImmediate.matrixLib.mat4.scale(GLImmediate.matrix[GLImmediate.currentMatrix], [x, y, z]);
|
|
4684
4745
|
},
|
|
4685
4746
|
glScalef: 'glScaled',
|
|
4686
4747
|
|
|
4687
4748
|
glTranslated: function(x, y, z) {
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4749
|
+
GLImmediate.matricesModified = true;
|
|
4750
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4751
|
+
GLImmediate.matrixLib.mat4.translate(GLImmediate.matrix[GLImmediate.currentMatrix], [x, y, z]);
|
|
4691
4752
|
},
|
|
4692
4753
|
glTranslatef: 'glTranslated',
|
|
4693
4754
|
|
|
4694
4755
|
glRotated: function(angle, x, y, z) {
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4756
|
+
GLImmediate.matricesModified = true;
|
|
4757
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4758
|
+
GLImmediate.matrixLib.mat4.rotate(GLImmediate.matrix[GLImmediate.currentMatrix], angle*Math.PI/180, [x, y, z]);
|
|
4698
4759
|
},
|
|
4699
4760
|
glRotatef: 'glRotated',
|
|
4700
4761
|
|
|
@@ -4775,17 +4836,17 @@ var LibraryGL = {
|
|
|
4775
4836
|
// GLU
|
|
4776
4837
|
|
|
4777
4838
|
gluPerspective: function(fov, aspect, near, far) {
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4839
|
+
GLImmediate.matricesModified = true;
|
|
4840
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4841
|
+
GLImmediate.matrix[GLImmediate.currentMatrix] =
|
|
4842
|
+
GLImmediate.matrixLib.mat4.perspective(fov, aspect, near, far,
|
|
4843
|
+
GLImmediate.matrix[GLImmediate.currentMatrix]);
|
|
4783
4844
|
},
|
|
4784
4845
|
|
|
4785
4846
|
gluLookAt: function(ex, ey, ez, cx, cy, cz, ux, uy, uz) {
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4847
|
+
GLImmediate.matricesModified = true;
|
|
4848
|
+
GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0;
|
|
4849
|
+
GLImmediate.matrixLib.mat4.lookAt(GLImmediate.matrix[GLImmediate.currentMatrix], [ex, ey, ez],
|
|
4789
4850
|
[cx, cy, cz], [ux, uy, uz]);
|
|
4790
4851
|
},
|
|
4791
4852
|
|
|
@@ -4794,9 +4855,9 @@ var LibraryGL = {
|
|
|
4794
4855
|
|
|
4795
4856
|
var inVec = new Float32Array(4);
|
|
4796
4857
|
var outVec = new Float32Array(4);
|
|
4797
|
-
|
|
4858
|
+
GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}},
|
|
4798
4859
|
[objX, objY, objZ, 1.0], outVec);
|
|
4799
|
-
|
|
4860
|
+
GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}},
|
|
4800
4861
|
outVec, inVec);
|
|
4801
4862
|
if (inVec[3] == 0.0) {
|
|
4802
4863
|
return 0 /* GL_FALSE */;
|
|
@@ -4820,7 +4881,7 @@ var LibraryGL = {
|
|
|
4820
4881
|
},
|
|
4821
4882
|
|
|
4822
4883
|
gluUnProject: function(winX, winY, winZ, model, proj, view, objX, objY, objZ) {
|
|
4823
|
-
var result =
|
|
4884
|
+
var result = GLImmediate.matrixLib.mat4.unproject([winX, winY, winZ],
|
|
4824
4885
|
{{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}},
|
|
4825
4886
|
{{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}},
|
|
4826
4887
|
{{{ makeHEAPView('32', 'view', 'view+' + (4*4)) }}});
|
|
@@ -4864,7 +4925,7 @@ var LibraryGL = {
|
|
|
4864
4925
|
#if GL_ASSERTIONS
|
|
4865
4926
|
GL.validateVertexAttribPointer(size, type, stride, ptr);
|
|
4866
4927
|
#endif
|
|
4867
|
-
|
|
4928
|
+
GLctx.vertexAttribPointer(index, size, type, normalized, stride, ptr);
|
|
4868
4929
|
},
|
|
4869
4930
|
|
|
4870
4931
|
glEnableVertexAttribArray__sig: 'vi',
|
|
@@ -4876,7 +4937,7 @@ var LibraryGL = {
|
|
|
4876
4937
|
#endif
|
|
4877
4938
|
cb.enabled = true;
|
|
4878
4939
|
#endif
|
|
4879
|
-
|
|
4940
|
+
GLctx.enableVertexAttribArray(index);
|
|
4880
4941
|
},
|
|
4881
4942
|
|
|
4882
4943
|
glDisableVertexAttribArray__sig: 'vi',
|
|
@@ -4888,7 +4949,7 @@ var LibraryGL = {
|
|
|
4888
4949
|
#endif
|
|
4889
4950
|
cb.enabled = false;
|
|
4890
4951
|
#endif
|
|
4891
|
-
|
|
4952
|
+
GLctx.disableVertexAttribArray(index);
|
|
4892
4953
|
},
|
|
4893
4954
|
|
|
4894
4955
|
glDrawArrays__sig: 'viii',
|
|
@@ -4898,7 +4959,7 @@ var LibraryGL = {
|
|
|
4898
4959
|
GL.preDrawHandleClientVertexAttribBindings(first + count);
|
|
4899
4960
|
#endif
|
|
4900
4961
|
|
|
4901
|
-
|
|
4962
|
+
GLctx.drawArrays(mode, first, count);
|
|
4902
4963
|
|
|
4903
4964
|
#if FULL_ES2
|
|
4904
4965
|
GL.postDrawHandleClientVertexAttribBindings();
|
|
@@ -4912,8 +4973,8 @@ var LibraryGL = {
|
|
|
4912
4973
|
if (!GL.currElementArrayBuffer) {
|
|
4913
4974
|
var size = GL.calcBufLength(1, type, 0, count);
|
|
4914
4975
|
buf = GL.tempIndexBuffers[GL.tempBufferIndexLookup[size]];
|
|
4915
|
-
|
|
4916
|
-
|
|
4976
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, buf);
|
|
4977
|
+
GLctx.bufferSubData(GLctx.ELEMENT_ARRAY_BUFFER,
|
|
4917
4978
|
0,
|
|
4918
4979
|
HEAPU8.subarray(indices, indices + size));
|
|
4919
4980
|
// the index is now 0
|
|
@@ -4924,13 +4985,13 @@ var LibraryGL = {
|
|
|
4924
4985
|
GL.preDrawHandleClientVertexAttribBindings(count);
|
|
4925
4986
|
#endif
|
|
4926
4987
|
|
|
4927
|
-
|
|
4988
|
+
GLctx.drawElements(mode, count, type, indices);
|
|
4928
4989
|
|
|
4929
4990
|
#if FULL_ES2
|
|
4930
4991
|
GL.postDrawHandleClientVertexAttribBindings(count);
|
|
4931
4992
|
|
|
4932
4993
|
if (!GL.currElementArrayBuffer) {
|
|
4933
|
-
|
|
4994
|
+
GLctx.bindBuffer(GLctx.ELEMENT_ARRAY_BUFFER, null);
|
|
4934
4995
|
}
|
|
4935
4996
|
#endif
|
|
4936
4997
|
},
|
|
@@ -4956,9 +5017,48 @@ var LibraryGL = {
|
|
|
4956
5017
|
GL.lastError = 0/*GL_NO_ERROR*/;
|
|
4957
5018
|
return error;
|
|
4958
5019
|
} else { // If there were none, return the GL error from the browser GL context.
|
|
4959
|
-
return
|
|
5020
|
+
return GLctx.getError();
|
|
4960
5021
|
}
|
|
4961
5022
|
},
|
|
5023
|
+
|
|
5024
|
+
// ANGLE_instanced_arrays WebGL extension related functions
|
|
5025
|
+
|
|
5026
|
+
glVertexAttribDivisor__sig: 'vii',
|
|
5027
|
+
glVertexAttribDivisor: function(index, divisor) {
|
|
5028
|
+
#if GL_ASSERTIONS
|
|
5029
|
+
assert(GL.instancedArraysExt, 'Must have ANGLE_instanced_arrays extension to use WebGL instancing');
|
|
5030
|
+
#endif
|
|
5031
|
+
GL.instancedArraysExt.vertexAttribDivisorANGLE(index, divisor);
|
|
5032
|
+
},
|
|
5033
|
+
|
|
5034
|
+
glDrawArraysInstanced__sig: 'viiii',
|
|
5035
|
+
glDrawArraysInstanced: function(mode, first, count, primcount) {
|
|
5036
|
+
#if GL_ASSERTIONS
|
|
5037
|
+
assert(GL.instancedArraysExt, 'Must have ANGLE_instanced_arrays extension to use WebGL instancing');
|
|
5038
|
+
#endif
|
|
5039
|
+
GL.instancedArraysExt.drawArraysInstancedANGLE(mode, first, count, primcount);
|
|
5040
|
+
},
|
|
5041
|
+
|
|
5042
|
+
glDrawElementsInstanced__sig: 'viiiii',
|
|
5043
|
+
glDrawElementsInstanced: function(mode, count, type, indices, primcount) {
|
|
5044
|
+
#if GL_ASSERTIONS
|
|
5045
|
+
assert(GL.instancedArraysExt, 'Must have ANGLE_instanced_arrays extension to use WebGL instancing');
|
|
5046
|
+
#endif
|
|
5047
|
+
GL.instancedArraysExt.drawElementsInstancedANGLE(mode, count, type, indices, primcount);
|
|
5048
|
+
},
|
|
5049
|
+
|
|
5050
|
+
// OpenGL Desktop/ES 2.0 instancing extensions compatibility
|
|
5051
|
+
|
|
5052
|
+
glVertexAttribDivisorNV: 'glVertexAttribDivisor',
|
|
5053
|
+
glDrawArraysInstancedNV: 'glDrawArraysInstanced',
|
|
5054
|
+
glDrawElementsInstancedNV: 'glDrawElementsInstanced',
|
|
5055
|
+
glVertexAttribDivisorEXT: 'glVertexAttribDivisor',
|
|
5056
|
+
glDrawArraysInstancedEXT: 'glDrawArraysInstanced',
|
|
5057
|
+
glDrawElementsInstancedEXT: 'glDrawElementsInstanced',
|
|
5058
|
+
glVertexAttribDivisorARB: 'glVertexAttribDivisor',
|
|
5059
|
+
glDrawArraysInstancedARB: 'glDrawArraysInstanced',
|
|
5060
|
+
glDrawElementsInstancedARB: 'glDrawElementsInstanced',
|
|
5061
|
+
|
|
4962
5062
|
// signatures of simple pass-through functions, see later
|
|
4963
5063
|
|
|
4964
5064
|
glActiveTexture__sig: 'vi',
|
|
@@ -5008,8 +5108,8 @@ var LibraryGL = {
|
|
|
5008
5108
|
var num = data[0];
|
|
5009
5109
|
var names = data[1];
|
|
5010
5110
|
var args = range(num).map(function(i) { return 'x' + i }).join(', ');
|
|
5011
|
-
var plainStub = '(function(' + args + ') {
|
|
5012
|
-
var returnStub = '(function(' + args + ') { return
|
|
5111
|
+
var plainStub = '(function(' + args + ') { GLctx.NAME(' + args + ') })';
|
|
5112
|
+
var returnStub = '(function(' + args + ') { return GLctx.NAME(' + args + ') })';
|
|
5013
5113
|
var sigEnd = range(num).map(function() { return 'i' }).join('');
|
|
5014
5114
|
names.split(' ').forEach(function(name) {
|
|
5015
5115
|
var stub = plainStub;
|