//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Texture::setFromImage(TextureImage* image) { CVF_ASSERT(textureType() == TEXTURE_2D || textureType() == TEXTURE_RECTANGLE); CVF_ASSERT(m_cubeMapImages.size() == 0); CVF_ASSERT(image); forgetCurrentOglTexture(); m_image = image; m_width = image->width(); m_height = image->height(); }
void FrameBuffer::automaticallyGenerateMipmaps(int attachment) { assert(m_automaticMipmapsEnabled); GLenum type = textureType(attachment); glBindTexture(type, textureID(attachment)); glGenerateMipmapEXT(type); glBindTexture(type, 0); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void Texture::setCubeMapImage(CubeMapFace face, TextureImage* cubeMapImage) { CVF_ASSERT(textureType() == TEXTURE_CUBE_MAP); CVF_ASSERT(m_image.isNull()); CVF_ASSERT(cubeMapImage); forgetCurrentOglTexture(); m_image = NULL; if (m_cubeMapImages.size() == 0) { m_cubeMapImages.resize(6); m_width = cubeMapImage->width(); m_height = cubeMapImage->height(); } else { CVF_ASSERT(m_width == cubeMapImage->width() && m_height == cubeMapImage->height()); } m_cubeMapImages[face] = cubeMapImage; }
int readRecord( std::ifstream &file, unsigned int level, std::deque<std::string> parentForms ) { static unsigned int numVerts = 0; bool isMainTexture = false; std::cout << std::endl; char buffer[10000]; char temp[5]; std::string group; file.read( temp, 4 ); if( file.eof() ) { return 0; } temp[4] = 0; group = temp; std::cout << "***** LEVEL " << level << " *****" << std::endl; std::cout << "Group: '" << group << "'" << std::endl; unsigned int size = 0; readBigEndian( file, sizeof( size ), (char *)&size ); std::cout << "Size: " << size << std::endl; if( "FORM" == group ) { std::string type; file.read( temp, 4 ); temp[4] = 0; type = temp; if( type == "0001" ) { std::cout << "Type: 0001" << std::endl; } else if( type == "0003" ) { std::cout << "Type: 0003" << std::endl; } else if( type == "EXBX" ) { std::cout << "Type: " << type << " (Bounding Box)" << std::endl; } else if( type == "EXSP" ) { std::cout << "Type: " << type << " (Bounding Sphere)" << std::endl; } else if( type == "HPNT" ) { std::cout << "Type: " << type << " (Hardpoint)" << std::endl; } else if( type == "CPIT" ) { std::cout << "Type: " << type << " (Cockpit)" << std::endl; } else if( type == "FCHS" ) { std::cout << "Type: " << type << " (Free chase camera)" << std::endl; } else if( type == "TXMS" ) { std::cout << "Type: " << type << " (Texture maps)" << std::endl; } else if( type == "TXM " ) { std::cout << "Type: " << type << " (Texture map)" << std::endl; } else if( type == "CACH" ) { std::cout << "Type: " << type << " (Cache)" << std::endl; } else if( type == "SD2D" ) { std::cout << "Type: " << type << " (2-D Sound)" << std::endl; } else { std::cout << "Type: '" << type << "'" << std::endl; } size -= 4; unsigned int sizeLeft = size; unsigned int sizeRead; parentForms.push_back( type ); while( 0 != sizeLeft ) { sizeRead = readRecord( file, level+1, parentForms ); if( sizeRead > sizeLeft ) { std::cout << "Error size mismatch!" << std::endl; exit( 0 ); } sizeLeft -= sizeRead; std::cout << type << " sizeLeft: " << sizeLeft << std::endl; } // Size of data plus 12 bytes of FORM header return size+12; } else if( "SPHR" == group ) { float X, Y, Z, R; file.read( (char *)&X, sizeof( X ) ); file.read( (char *)&Y, sizeof( Y ) ); file.read( (char *)&Z, sizeof( Z ) ); file.read( (char *)&R, sizeof( R ) ); std::cout << "X: " << X << std::endl; std::cout << "Y: " << Y << std::endl; std::cout << "Z: " << Z << std::endl; std::cout << "R: " << R << std::endl; } else if( "BOX " == group ) { float x1, x2, y1, y2, z1, z2; file.read( (char *)&x1, sizeof( x1 ) ); file.read( (char *)&y1, sizeof( y1 ) ); file.read( (char *)&z1, sizeof( z1 ) ); file.read( (char *)&x2, sizeof( x2 ) ); file.read( (char *)&y2, sizeof( y2 ) ); file.read( (char *)&z2, sizeof( z2 ) ); std::cout << "X1: " << x1 << std::endl; std::cout << "Y1: " << y1 << std::endl; std::cout << "Z1: " << z1 << std::endl; std::cout << "X2: " << x2 << std::endl; std::cout << "Y2: " << y2 << std::endl; std::cout << "Z2: " << z2 << std::endl; } else if( "DATA" == group ) { for( unsigned int i = 0; i < parentForms.size(); ++i ) { std::cout << parentForms[i] << "-"; } std::cout << std::endl; if( "TXM " == parentForms[parentForms.size()-2] ) { char tempType[5]; tempType[4] = 0; file.read( tempType, 4 ); std::string textureType( tempType ); isMainTexture = false; if( "PUKL" == textureType ) { std::cout << "Specular lookup texture "; } else if( "EBUC" == textureType ) { std::cout << "Cube map texture "; } else if( "NIAM" == textureType ) { std::cout << "Main texture "; isMainTexture = true; } else if( "LMRN" == textureType ) { std::cout << "Normal map texture "; } else { std::cout << textureType << " "; } // Data is a filename unsigned char data; for( unsigned int i = 0; i < size-4; ++i ) { file.read( (char*)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; } else if( "0001" == parentForms.back() ) { readUnknown( file, size ); } else if( "0004" == parentForms.back() ) { readUnknown( file, size ); } else if( "0008" == parentForms.back() ) { unsigned short data2; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; file.read( (char*)&data2, sizeof( data2 ) ); std::cout << data2 << std::endl; // Data is a filename unsigned char data; for( unsigned int i = 0; i < size-12; ++i ) { file.read( (char*)&data, sizeof( data ) ); if( i < 4 ) { std::cout << data << " "; } else { std::cout << (unsigned int)data << " "; } } std::cout << std::endl; } else { if( numVerts != 0 ) { readGeometryDATA( file, size, numVerts ); numVerts = 0; } else { readUnknown( file, size ); } } } else if( "CNT " == group ) { unsigned int data; file.read( (char *)&data, sizeof( data ) ); std::cout << "data: " << data << std::endl; } else if( "NAME" == group ) { file.read( buffer, size ); buffer[size] = 0; std::string name( buffer ); std::cout << name << std::endl; } else if( "INFO" == group ) { if( 8 == size ) { unsigned int data; file.read( (char *)&data, sizeof( data ) ); std::cout << "Unknown: " << data << std::endl; file.read( (char *)&numVerts, sizeof( numVerts ) ); std::cout << "numVerts: " << numVerts << std::endl; } else { readUnknown( file, size ); } } else if( "INDX" == group ) { #if 0 readUnknown( file, size ); #else readGeometryINDX( file, size ); #endif } else if( "MATL" == group ) { if( 68 != size ) { std::cout << "Expected MATL to be 68bytes!!!!!!!!!" << std::endl; exit( 0 ); } // Data in abgr? float data; std::cout << "Ambient: "; for( unsigned int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; std::cout << "Diffuse: "; for( int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; std::cout << "Specular: "; for( int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; std::cout << "Emissive: "; for( int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; std::cout << "Shininess: "; file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << std::endl; } else if( "NIAM" == group ) { file.seekg( size, std::ios_base::cur ); } else if( "0000" == group ) { if( "TCSS" == parentForms.back() || "ARVS" == parentForms.back() ) { unsigned int numEntry = size/5; for( unsigned int j = 0; j < numEntry; ++j ) { unsigned char data; for( int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << data; } file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << std::endl; } } else if( "TFNS" == parentForms.back() ) { unsigned int numColors = size/8; for( unsigned int j = 0; j < numColors; ++j ) { char tempColor[5]; file.read( tempColor, 4 ); tempColor[4] = 0; std::string color( tempColor ); std::cout << "color: " << color << " "; unsigned char data; for( int i = 0; i < 4; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; } } else if( "STAG" == parentForms.back() ) { unsigned short data1; for( unsigned int i = 0; i < 9; ++i ) { file.read( (char *)&data1, sizeof( data1 ) ); std::cout << (unsigned int)data1 << " "; } unsigned char data; for( unsigned int i = 0; i < 8; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << data << " "; } for( unsigned int i = 0; i < 7; ++i ) { file.read( (char *)&data, sizeof( data ) ); std::cout << (unsigned int)data << " "; } std::cout << std::endl; } else { readUnknown( file, size ); } } else if( "0001" == group ) { readUnknown( file, size ); } else if( "0002" == group ) { readUnknown( file, size ); } else if( "0003" == group ) { readUnknown( file, size ); } else if( "0005" == group ) { readUnknown( file, size ); } else if( "TAG " == group ) { file.read( buffer, size ); buffer[size] = 0; std::string tag( buffer ); std::cout << tag << std::endl; } else if( "SCAP" == group ) { readUnknown( file, size ); } else if( "OPTN" == group ) { readUnknown( file, size ); } else if( "XFIN" == group ) { readUnknown( file, size ); } else if( "LINK" == group ) { readUnknown( file, size ); } else if( "QCHN" == group ) { readUnknown( file, size ); } else if( "SROT" == group ) { readUnknown( file, size ); } else if( "CHNL" == group ) { readUnknown( file, size ); } else if( "STRN" == group ) { readUnknown( file, size ); } else if( "SFAM" == group ) { #if 0 char temp[255]; unsigned int num; file.read( (char *)&num, sizeof( num ) ); std::cout << "Num: " << num << std::endl; std::string name; file.getline( temp, 255, 0 ); name = temp; std::cout << "Name: " << name << std::endl; std::string name2; file.getline( temp, 255, 0 ); name2 = temp; std::cout << "Name2: " << name2 << std::endl; float f; unsigned int i; unsigned char c; file.read( (char *)&c, sizeof( c ) ); std::cout << (unsigned int)c << " "; file.read( (char *)&c, sizeof( c ) ); std::cout << (unsigned int)c << " "; file.read( (char *)&c, sizeof( c ) ); std::cout << (unsigned int)c << " "; file.read( (char *)&f, sizeof( f ) ); std::cout << f << " "; file.read( (char *)&f, sizeof( f ) ); std::cout << f << " "; file.read( (char *)&i, sizeof( i ) ); std::cout << i << " "; std::cout << std::endl; std::string name3; file.getline( temp, 255, 0 ); name3 = temp; std::cout << "Name3: " << name3 << std::endl; file.read( (char *)&f, sizeof( f ) ); std::cout << f << std::endl; #else readUnknown( file, size ); #endif } else if( "FFAM" == group ) { readUnknown( file, size ); } else if( "RFAM" == group ) { readUnknown( file, size ); } else if( "ADTA" == group ) { readUnknown( file, size ); } else if( "PARM" == group ) { readUnknown( file, size ); } else if( "SGMT" == group ) { readUnknown( file, size ); } else if( "WMAP" == group ) { readUnknown( file, size ); } else if( "SMAP" == group ) { readUnknown( file, size ); } else if( "XXXX" == group ) { readUnknown( file, size ); } else if( "PCNT" == group ) { if( 4 == size ) { int data; file.read( (char*)&data, sizeof( data ) ); std::cout << "Sibling Nodes: " << data << std::endl; } else { readUnknown( file, size ); } } else if( "NODE" == group ) { std::string name; file.width( size - 52 ); file >> name; std::cout << name << std::endl; std::string r; file.width( 4 ); file >> r; std::cout << r << std::endl; float data; std::cout << std::fixed; for( unsigned int i = 0; i < 12; ++i ) { file.read( (char*)&data, sizeof( data ) ); std::cout << data << " "; if( ((i+1) % 4) == 0 ) { std::cout << std::endl; } } std::cout << std::endl; }