diff options
-rw-r--r-- | src/library_browser.js | 1 | ||||
-rw-r--r-- | src/library_gl.js | 29 | ||||
-rwxr-xr-x | tests/runner.py | 6 | ||||
-rw-r--r-- | tests/s3tc_crunch.c | 32 | ||||
-rw-r--r-- | tests/s3tc_crunch.png | bin | 235053 -> 353714 bytes | |||
-rw-r--r-- | tests/water.dds | bin | 0 -> 43920 bytes | |||
-rw-r--r-- | tools/crunch-worker.js | 12 |
7 files changed, 59 insertions, 21 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 75dfb9d0..db012e1d 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -86,6 +86,7 @@ mergeInto(LibraryManager.library, { requestFullScreen: function() { var canvas = Module.canvas; function fullScreenChange() { + if (Module['onFullScreen']) Module['onFullScreen'](); if (document['webkitFullScreenElement'] === canvas || document['mozFullScreenElement'] === canvas || document['fullScreenElement'] === canvas) { diff --git a/src/library_gl.js b/src/library_gl.js index 68f8248b..08cb7511 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -294,7 +294,7 @@ var LibraryGL = { } else { data = null; } - Module.ctx.compressedTexImage2D(target, level, internalformat, width, height, border, data); + Module.ctx['compressedTexImage2D'](target, level, internalformat, width, height, border, data); }, glCompressedTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, imageSize, data) { @@ -303,7 +303,7 @@ var LibraryGL = { } else { data = null; } - Module.ctx.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, data); + Module.ctx['compressedTexSubImage2D'](target, level, xoffset, yoffset, width, height, data); }, glTexImage2D: function(target, level, internalformat, width, height, border, format, type, pixels) { @@ -917,27 +917,28 @@ var LibraryGL = { // Add some emulation workarounds Module.printErr('WARNING: using emscripten GL emulation. This is a collection of limited workarounds, do not expect it to work'); - // XXX some of these ignored capabilities may lead to incorrect rendering, if we do not emulate them in shaders - var ignoredCapabilities = { - 0x0B20: 1, // GL_LINE_SMOOTH - 0x0B60: 1, // GL_FOG - 0x0BA1: 1, // GL_NORMALIZE - 0x0C60: 1, // GL_TEXTURE_GEN_S - 0x0C61: 1, // GL_TEXTURE_GEN_T - 0x0DE1: 1, // GL_TEXTURE_2D - 0x8513: 1, // GL_TEXTURE_CUBE_MAP - 0x2A02: 1 // GL_POLYGON_OFFSET_LINE + // XXX some of the capabilities we don't support may lead to incorrect rendering, if we do not emulate them in shaders + var validCapabilities = { + 0x0B44: 1, // GL_CULL_FACE + 0x0BE2: 1, // GL_BLEND + 0x0BD0: 1, // GL_DITHER, + 0x0B90: 1, // GL_STENCIL_TEST + 0x0B71: 1, // GL_DEPTH_TEST + 0x0C11: 1, // GL_SCISSOR_TEST + 0x8037: 1, // GL_POLYGON_OFFSET_FILL + 0x809E: 1, // GL_SAMPLE_ALPHA_TO_COVERAGE + 0x80A0: 1 // GL_SAMPLE_COVERAGE }; _glEnable = function(cap) { // Clean up the renderer on any change to the rendering state. The optimization of // skipping renderer setup is aimed at the case of multiple glDraw* right after each other if (GL.immediate.lastRenderer) GL.immediate.lastRenderer.cleanup(); - if (cap in ignoredCapabilities) return; + if (!(cap in validCapabilities)) return; Module.ctx.enable(cap); }; _glDisable = function(cap) { if (GL.immediate.lastRenderer) GL.immediate.lastRenderer.cleanup(); - if (cap in ignoredCapabilities) return; + if (!(cap in validCapabilities)) return; Module.ctx.disable(cap); }; diff --git a/tests/runner.py b/tests/runner.py index f94d9bda..61520d53 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7832,10 +7832,12 @@ elif 'browser' in str(sys.argv): def test_s3tc_crunch(self): shutil.copyfile(path_from_root('tests', 'ship.dds'), 'ship.dds') shutil.copyfile(path_from_root('tests', 'bloom.dds'), 'bloom.dds') - Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch', '--preload', 'ship.dds', 'bloom.dds'], stdout=open('pre.js', 'w')).communicate() - assert os.stat('test.data').st_size < 0.5*(os.stat('ship.dds').st_size+os.stat('bloom.dds').st_size), 'Compressed should be smaller than dds' + shutil.copyfile(path_from_root('tests', 'water.dds'), 'water.dds') + Popen(['python', FILE_PACKAGER, 'test.data', '--pre-run', '--crunch', '--preload', 'ship.dds', 'bloom.dds', 'water.dds'], stdout=open('pre.js', 'w')).communicate() + assert os.stat('test.data').st_size < 0.5*(os.stat('ship.dds').st_size+os.stat('bloom.dds').st_size+os.stat('water.dds').st_size), 'Compressed should be smaller than dds' shutil.move('ship.dds', 'ship.donotfindme.dds') # make sure we load from the compressed shutil.move('bloom.dds', 'bloom.donotfindme.dds') # make sure we load from the compressed + shutil.move('water.dds', 'water.donotfindme.dds') # make sure we load from the compressed self.btest('s3tc_crunch.c', reference='s3tc_crunch.png', args=['--pre-js', 'pre.js']) def test_pre_run_deps(self): diff --git a/tests/s3tc_crunch.c b/tests/s3tc_crunch.c index 1169f462..57974109 100644 --- a/tests/s3tc_crunch.c +++ b/tests/s3tc_crunch.c @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) GLuint texture; { - #define DDS_SIZE 65664 + const int DDS_SIZE = 65664; FILE *dds = fopen("ship.dds", "rb"); assert(dds); char *ddsdata = (char*)malloc(DDS_SIZE); @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) GLuint texture2; { - #define DDS_SIZE 32896 + const int DDS_SIZE = 32896; FILE *dds = fopen("bloom.dds", "rb"); assert(dds); char *ddsdata = (char*)malloc(DDS_SIZE); @@ -131,6 +131,29 @@ int main(int argc, char *argv[]) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); } + // third, a non-square texture with mipmaps + + GLuint texture3; + + { + const int DDS_SIZE = 43920; + FILE *dds = fopen("water.dds", "rb"); + assert(dds); + char *ddsdata = (char*)malloc(DDS_SIZE); + assert(fread(ddsdata, 1, DDS_SIZE, dds) == DDS_SIZE); + fclose(dds); + + glGenTextures( 1, &texture3 ); + glBindTexture( GL_TEXTURE_2D, texture3 ); + + assert(!glGetError()); + glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 512, 64, 0, 512*64, ddsdata+128); + assert(!glGetError()); + + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + } + // Prepare and Render // Clear the screen before drawing @@ -154,7 +177,10 @@ int main(int argc, char *argv[]) glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 4*4, &vertexData[2]); - glDrawArrays(GL_QUADS, 0, 8); + glDrawArrays(GL_QUADS, 0, 4); + + glBindTexture( GL_TEXTURE_2D, texture3 ); + glDrawArrays(GL_QUADS, 4, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); diff --git a/tests/s3tc_crunch.png b/tests/s3tc_crunch.png Binary files differindex 920f3915..383d4c5b 100644 --- a/tests/s3tc_crunch.png +++ b/tests/s3tc_crunch.png diff --git a/tests/water.dds b/tests/water.dds Binary files differnew file mode 100644 index 00000000..2a78a859 --- /dev/null +++ b/tests/water.dds diff --git a/tools/crunch-worker.js b/tools/crunch-worker.js index 7bc63870..5c48d009 100644 --- a/tools/crunch-worker.js +++ b/tools/crunch-worker.js @@ -66,7 +66,6 @@ if(format != cCRNFmtDXT1 && format != cCRNFmtDXT3 && format != cCRNFmtDXT5) { throw "Unsupported image format " + format + " for " + filename; } - width = Module._crn_get_width(src, srcSize); height = Module._crn_get_height(src, srcSize); levels = Module._crn_get_levels(src, srcSize); @@ -74,9 +73,18 @@ dst = Module._malloc(dstSize); var totalSize = 0; + var bytesPerPixel = format == cCRNFmtDXT1 ? 0.5 : 1; for(i = 0; i < levels; ++i) { - totalSize += Module._crn_get_uncompressed_size(src, srcSize, i); + totalSize += width * height * bytesPerPixel; + width *= 0.5; + height *= 0.5; + width = Math.max(width, 4); + height = Math.max(height, 4); } + + width = Module._crn_get_width(src, srcSize); + height = Module._crn_get_height(src, srcSize); + var ret = new Uint8Array(totalSize); var retIndex = 0; |