From 86e7afecead1089d337f526e72f995ff85e171c8 Mon Sep 17 00:00:00 2001 From: prideout Date: Tue, 28 Aug 2018 16:12:56 -0700 Subject: [PATCH] Minor code cleanup to filaweb. --- samples/web/CMakeLists.txt | 9 +++------ samples/web/filaweb.js | 33 +++++++++------------------------ 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/samples/web/CMakeLists.txt b/samples/web/CMakeLists.txt index b5d1db093e..60129dc05a 100644 --- a/samples/web/CMakeLists.txt +++ b/samples/web/CMakeLists.txt @@ -76,12 +76,9 @@ add_custom_command( MAIN_DEPENDENCY ${source_mesh} DEPENDS filamesh) -# Next build two cubemaps: (1) a single miplevel of a slightly large blurry PNG for the skybox, and -# (2) all miplevels for an RGBM (which is PNG in disguise) for the IBL. - -# TODO: invoke cmgen only once and simply use RGBM everywhere. The only reason we're using PNG for -# the skybox is to work around an RGBM coloration issue, probably something wrong in how we're -# decoding the alpha channel for images in the web app. +# Next build two cubemaps: +# (1) single miplevel of blurry skybox (png) +# (2) all miplevels for the IBL (rgbm) set(source_envmap "${CMAKE_CURRENT_SOURCE_DIR}/../../assets/environments/desert/desert.exr") diff --git a/samples/web/filaweb.js b/samples/web/filaweb.js index 0be1215ee4..463a5db5a6 100644 --- a/samples/web/filaweb.js +++ b/samples/web/filaweb.js @@ -79,7 +79,8 @@ function load_texture(url) { context2d.canvas.width = img.width; context2d.canvas.height = img.height; context2d.width = img.width; - context2d.height = img.height; + context2d.height = img.height + context2d.globalCompositeOperation = 'copy'; context2d.drawImage(img, 0, 0); var imgdata = context2d.getImageData(0, 0, img.width, img.height).data.buffer; success({ @@ -99,31 +100,15 @@ function load_cubemap(urlprefix, nmips) { let name = ''; promises['sh.txt'] = load_rawfile(urlprefix + 'sh.txt'); for (let i = 0; i < nmips; i++) { - name = 'm' + i + '_px.rgbm'; - promises[name] = load_texture(urlprefix + name); - name = 'm' + i + '_nx.rgbm'; - promises[name] = load_texture(urlprefix + name); - name = 'm' + i + '_py.rgbm'; - promises[name] = load_texture(urlprefix + name); - name = 'm' + i + '_ny.rgbm'; - promises[name] = load_texture(urlprefix + name); - name = 'm' + i + '_pz.rgbm'; - promises[name] = load_texture(urlprefix + name); - name = 'm' + i + '_nz.rgbm'; + for (let face of 'px nx py ny pz nz'.split(' ')) { + name = 'm' + i + '_' + face + '.rgbm'; + promises[name] = load_texture(urlprefix + name); + } + } + for (let face of 'px nx py ny pz nz'.split(' ')) { + name = face + '.png'; promises[name] = load_texture(urlprefix + name); } - name = 'px.png'; - promises[name] = load_texture(urlprefix + name); - name = 'nx.png'; - promises[name] = load_texture(urlprefix + name); - name = 'py.png'; - promises[name] = load_texture(urlprefix + name); - name = 'ny.png'; - promises[name] = load_texture(urlprefix + name); - name = 'pz.png'; - promises[name] = load_texture(urlprefix + name); - name = 'nz.png'; - promises[name] = load_texture(urlprefix + name); let numberRemaining = Object.keys(promises).length; var promise = new Promise((success) => { for (let name in promises) {