Пример #1
0
bool dxtc_pixels::VFlip() const
{
    // Check that the given dimensions are 2^x, 2^y
    if (! OpenGLSize())
        return false;

    // Check that the given format are supported
    if (! SupportedFormat())
        return false;

    // Nothing to do if Height == 1
    if (m_Height == 1)
        return true;

    if (DXT1())
        VFlip_DXT1();
    else if (DXT3())
        VFlip_DXT3();
    else if (DXT5())
        VFlip_DXT5();
    else
        return false; // We should never get there

    return true;
}
Пример #2
0
bool CDDS::LoadFile(std::istream & File)
{
	// Verify the type of file.
	char FileCode[4];
	if (! File.read(FileCode, 4))
		return false;
	if (strncmp(FileCode, "DDS ", 4) != 0)
		return false;
   
	// Get the surface descriptor.
	DDSURFACEDESC2 DDrawSD;
	if (! File.read((char *) &DDrawSD, sizeof(DDrawSD)))
		return false;

	// Set the attributes.
	switch(DDrawSD.ddpfPixelFormat.dwFourCC)
	{
	case FOURCC_DXT1:
		m_format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
		m_alphaChannel = CFalse;
		m_blockSize = 8;
		break;
	case FOURCC_DXT3:
		m_format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
		m_alphaChannel = CTrue;
		m_blockSize = 16;
		break;
	case FOURCC_DXT5:
		m_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
		m_alphaChannel = CTrue;
		m_blockSize = 16;
		break;
	default:
		return false;
	}

	m_width = DDrawSD.dwWidth;
	m_height = DDrawSD.dwHeight;
	m_nbMipmaps = DDrawSD.dwMipMapCount;

	if (m_nbMipmaps == 0)
		m_nbMipmaps = 1;

	// Check that the given dimentions are 2^x, 2^y
	if (! OpenGLSize())
		return false;

	// How big is it going to be including all mipmaps?
	size_t BufSize = 0;
	size_t Width = m_width;
	size_t Height = m_height;

	for (size_t i = 0; (i < m_nbMipmaps) && ((Width != 0) || (Height != 0)); ++i) {

		BufSize += ((Width + 3) / 4) * ((Height + 3) / 4) * m_blockSize;

		if ((i == 0) && (BufSize != DDrawSD.dwLinearSize))
			return false;

		if ((Width /= 2) == 0) Width = 1;
		if ((Height /= 2) == 0) Height = 1;
	}

	// Allocate pixels memory.
	m_pixels.resize(BufSize);

	// Read pixels.
	if (! File.read((char *) &m_pixels[0], std::streamsize(BufSize)))
		return false;

	return true;	
}