示例#1
0
bool MgShapeDoc::load(MgShapeFactory* factory, MgStorage* s, bool addOnly)
{
    bool ret = false;
    Box2d rect;

    if (!s || !s->readNode("shapedoc", -1, false)) {
        return s && s->setError("No shapedoc node.");
    }

    if (!addOnly) {
        s->readFloatArray("transform", &im->xf.m11, 6, false);
        im->rectWInitial.empty();
        if (s->readFloatArray("pageExtent", &im->rectW.xmin, 4, false) == 4 ||
            s->readFloatArray("zoomExtent", &im->rectW.xmin, 4, false) == 4) {
            im->rectWInitial = im->rectW;
        }
        im->viewScale = s->readFloat("viewScale", im->viewScale);
        s->readFloatArray("extent", &rect.xmin, 4, false);
        s->readInt("count", 0);
    }

    for (int i = 0; i < 99; i++) {
        if (i < getLayerCount()) {
            ret = im->layers[i]->load(factory, s, addOnly) >= 0 || ret;
        }
        else {
            MgLayer* layer = MgLayer::create(this, i);
            if (layer->load(factory, s, addOnly) >= 0) {
                im->layers.push_back(layer);
                ret = true;
            }
            else {
                layer->release();
                break;
            }
        }
        addOnly = false;
    }

    s->readNode("shapedoc", -1, true);

    return ret;
}
示例#2
0
void TPC::fixupCubeMap() {
	/* Do various fixups to the cube maps. This includes rotating and swapping a
	 * few sides around. This is done by the original games as well.
	 */

	if (!isCubeMap())
		return;

	// Since we need to rotate the individual cube sides, we need to decompress them all
	decompress();

	// Rotate the cube sides so that they're all oriented correctly
	for (size_t i = 0; i < getLayerCount(); i++) {
		for (size_t j = 0; j < getMipMapCount(); j++) {
			const size_t index = i * getMipMapCount() + j;
			assert(index < _mipMaps.size());

			MipMap &mipMap = *_mipMaps[index];

			static const int rotation[6] = { 3, 1, 0, 2, 2, 0 };

			rotate90(mipMap.data, mipMap.width, mipMap.height, getBPP(_format), rotation[i]);
		}
	}

	// Swap the first two sides of the cube maps
	for (size_t j = 0; j < getMipMapCount(); j++) {
		const size_t index0 = 0 * getMipMapCount() + j;
		const size_t index1 = 1 * getMipMapCount() + j;
			assert((index0 < _mipMaps.size()) && (index1 < _mipMaps.size()));

		MipMap &mipMap0 = *_mipMaps[index0];
		MipMap &mipMap1 = *_mipMaps[index1];

		assert((mipMap0.width == mipMap1.width) && (mipMap0.height == mipMap1.height));

		SWAP(mipMap0.data, mipMap1.data);
	}
}
示例#3
0
文件: tpc.cpp 项目: kevL/xoreos
void TPC::fixupCubeMap() {
	/* Do various fixups to the cube maps. This includes rotating and swapping a
	 * few sides around. This is done by the original games as well.
	 */

	if (!isCubeMap())
		return;

	for (size_t j = 0; j < getMipMapCount(); j++) {
		assert(getLayerCount() > 0);

		const size_t index0 = 0 * getMipMapCount() + j;
		assert(index0 < _mipMaps.size());

		const  int32 width  = _mipMaps[index0]->width;
		const  int32 height = _mipMaps[index0]->height;
		const uint32 size   = _mipMaps[index0]->size;

		for (size_t i = 1; i < getLayerCount(); i++) {
			const size_t index = i * getMipMapCount() + j;
			assert(index < _mipMaps.size());

			if ((width  != _mipMaps[index]->width ) ||
			    (height != _mipMaps[index]->height) ||
			    (size   != _mipMaps[index]->size  ))
				throw Common::Exception("Cube map layer dimensions mismatch");
		}
	}

	// Since we need to rotate the individual cube sides, we need to decompress them all
	decompress();

	// Swap the first two sides of the cube maps
	for (size_t j = 0; j < getMipMapCount(); j++) {
		const size_t index0 = 0 * getMipMapCount() + j;
		const size_t index1 = 1 * getMipMapCount() + j;
		assert((index0 < _mipMaps.size()) && (index1 < _mipMaps.size()));

		MipMap &mipMap0 = *_mipMaps[index0];
		MipMap &mipMap1 = *_mipMaps[index1];

		SWAP(mipMap0.data, mipMap1.data);
	}

	const int bpp = (_formatRaw == kPixelFormatRGB8) ? 3 : ((_formatRaw == kPixelFormatRGBA8) ? 4 : 0);
	if (bpp == 0)
		return;

	// Rotate the cube sides so that they're all oriented correctly
	for (size_t i = 0; i < getLayerCount(); i++) {
		for (size_t j = 0; j < getMipMapCount(); j++) {
			const size_t index = i * getMipMapCount() + j;
			assert(index < _mipMaps.size());

			MipMap &mipMap = *_mipMaps[index];

			static const int rotation[6] = { 1, 3, 0, 2, 2, 0 };

			rotate90(mipMap.data, mipMap.width, mipMap.height, bpp, rotation[i]);
		}
	}

}