Skip to content

Commit

Permalink
Verify all faces of cubemap with DDSCAPS2_CUBEMAP
Browse files Browse the repository at this point in the history
  • Loading branch information
nopjia committed Sep 2, 2015
1 parent 460addd commit 48a4d9d
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions examples/js/loaders/DDSLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };

// Adapted from @toji's DDS utils
// https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
// https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js

// All values and structures referenced from:
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/
Expand Down Expand Up @@ -175,9 +175,9 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {

default:

if ( header[ off_RGBBitCount ] == 32
if ( header[ off_RGBBitCount ] === 32
&& header[ off_RBitMask ] & 0xff0000
&& header[ off_GBitMask ] & 0xff00
&& header[ off_GBitMask ] & 0xff00
&& header[ off_BBitMask ] & 0xff
&& header[ off_ABitMask ] & 0xff000000 ) {

Expand All @@ -201,9 +201,21 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {

}

//TODO: Verify that all faces of the cubemap are present with DDSCAPS2_CUBEMAP_POSITIVEX, etc.
var caps2 = header[ off_caps2 ];
dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
if ( dds.isCubemap && (
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ )
) ) {

console.error( 'THREE.DDSLoader.parse: Incomplete cubemap faces' );
return dds;

dds.isCubemap = header[ off_caps2 ] & DDSCAPS2_CUBEMAP ? true : false;
}

dds.width = header[ off_width ];
dds.height = header[ off_height ];
Expand All @@ -212,13 +224,13 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {

// Extract mipmaps buffers

var width = dds.width;
var height = dds.height;

var faces = dds.isCubemap ? 6 : 1;

for ( var face = 0; face < faces; face ++ ) {

var width = dds.width;
var height = dds.height;

for ( var i = 0; i < dds.mipmapCount; i ++ ) {

if ( isRGBAUncompressed ) {
Expand All @@ -232,23 +244,19 @@ THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
var byteArray = new Uint8Array( buffer, dataOffset, dataLength );

}

var mipmap = { "data": byteArray, "width": width, "height": height };
dds.mipmaps.push( mipmap );

dataOffset += dataLength;

width = Math.max( width * 0.5, 1 );
height = Math.max( height * 0.5, 1 );
width = Math.max( width >> 1, 1 );
height = Math.max( height >> 1, 1 );

}

width = dds.width;
height = dds.height;

}

return dds;

};

0 comments on commit 48a4d9d

Please sign in to comment.