示例#1
0
void gkTextureLoader::loadResource(Ogre::Resource* resource)
{
	Ogre::Texture* texture = static_cast<Ogre::Texture*>(resource);

	if (!m_stream)
	{
		gkPrintf("Warning: Skipping image %s no packed file information is present!", texture->getName().c_str());
		return;
	}

	Ogre::DataStreamPtr stream(OGRE_NEW Ogre::MemoryDataStream(m_stream->ptr(), m_stream->size()));

	Ogre::Image ima;
	ima.load(stream);

	texture->setUsage(Ogre::TU_DEFAULT);
	texture->setTextureType(Ogre::TEX_TYPE_2D);
	texture->setNumMipmaps(gkEngine::getSingleton().getUserDefs().defaultMipMap);
	texture->setWidth(ima.getWidth());
	texture->setHeight(ima.getHeight());
	texture->setDepth(ima.getDepth());
	texture->setFormat(ima.getFormat());

	Ogre::ConstImagePtrList ptrs;
	ptrs.push_back(&ima);
	texture->_loadImages(ptrs);
}
    // ----------------------------------------------------------------------
    void FontSerializer::exportFont(const Font *pFont, const Ogre::String &fileName)
    {
        // Open/create the file
		mpfFile = fopen(fileName.c_str(), "wb");
		if (!mpfFile)
		{
		    // Throw an error if the file was not found, or was not possible to read
		    SONETTO_THROW("A file was not found!");
		}
		fwrite(&Font::mFourCC, sizeof(uint32), 1, mpfFile);

		fwrite(&pFont->mVersion, sizeof(uint32), 1, mpfFile);
		fwrite(&pFont->mEncode, sizeof(uint32), 1, mpfFile);
		fwrite(&pFont->mVerticalOffsetTop, sizeof(float), 1, mpfFile);
		fwrite(&pFont->mVerticalOffsetBottom, sizeof(float), 1, mpfFile);
		fwrite(&pFont->mHorizontalScale, sizeof(float), 1, mpfFile);

		saveString(pFont->mIName);

		if(pFont->mMaterial.isNull())
            SONETTO_THROW("Material does not exist");

		Ogre::Pass * pass = pFont->mMaterial->getTechnique(0)->getPass(0);

		bool has_separate_blend = pass->hasSeparateSceneBlending();

        uint32 mat_scene_blend_source = (uint32)pass->getSourceBlendFactor();
        uint32 mat_scene_blend_dest = (uint32)pass->getDestBlendFactor();
        uint32 mat_scene_blend_source_a = (uint32)pass->getSourceBlendFactorAlpha();
        uint32 mat_scene_blend_dest_a = (uint32)pass->getDestBlendFactorAlpha();

        fwrite(&has_separate_blend, sizeof(bool), 1, mpfFile);
        fwrite(&mat_scene_blend_source, sizeof(uint32), 1, mpfFile);
        fwrite(&mat_scene_blend_dest, sizeof(uint32), 1, mpfFile);
        fwrite(&mat_scene_blend_source_a, sizeof(uint32), 1, mpfFile);
        fwrite(&mat_scene_blend_dest_a, sizeof(uint32), 1, mpfFile);

        uint32 mat_alpha_reject_func = (uint32)pass->getAlphaRejectFunction();
        uint8 mat_alpha_reject_val = (uint8)pass->getAlphaRejectValue();
        bool map_alpha_reject_atc = pass->isAlphaToCoverageEnabled();

        fwrite(&mat_alpha_reject_func, sizeof(uint32), 1, mpfFile);
        fwrite(&mat_alpha_reject_val, sizeof(uint8), 1, mpfFile);
        fwrite(&map_alpha_reject_atc, sizeof(bool), 1, mpfFile);

        Ogre::TextureUnitState * texunit = pass->getTextureUnitState(0);

        Ogre::TextureUnitState::UVWAddressingMode tex_address_mode_uvw = texunit->getTextureAddressingMode();

        uint32 tex_address_mode_u = (uint32)tex_address_mode_uvw.u;
        uint32 tex_address_mode_v = (uint32)tex_address_mode_uvw.v;
        uint32 tex_address_mode_w = (uint32)tex_address_mode_uvw.w;

        uint32 tex_filtering_min = (uint32)texunit->getTextureFiltering(Ogre::FT_MIN);
        uint32 tex_filtering_mag = (uint32)texunit->getTextureFiltering(Ogre::FT_MAG);
        Ogre::ColourValue tex_border_color = texunit->getTextureBorderColour();

        fwrite(&tex_address_mode_u,sizeof(uint32), 1, mpfFile);
        fwrite(&tex_address_mode_v,sizeof(uint32), 1, mpfFile);
        fwrite(&tex_address_mode_w,sizeof(uint32), 1, mpfFile);
        fwrite(&tex_filtering_min,sizeof(uint32), 1, mpfFile);
        fwrite(&tex_filtering_mag,sizeof(uint32), 1, mpfFile);
        fwrite(tex_border_color.ptr(),sizeof(float)*4, 1, mpfFile);

        uint32 colsize = (uint32)pFont->mColorList.size();
        fwrite(&colsize,sizeof(uint32), 1, mpfFile);

        for(uint32 i = 0; i != colsize; ++i)
        {
            fwrite(pFont->mColorList[i].ptr(),sizeof(float)*4, 1, mpfFile);
        }

        for(uint32 i = 0; i != 256; ++i)
        {
            FontGlyph glyph = pFont->mGlyph[i];
            fwrite(&glyph, sizeof(FontGlyph), 1,mpfFile);
        }

        Ogre::Image * tex = pFont->mFontImage;

        size_t uWidth = tex->getWidth();
        size_t uHeight = tex->getHeight();
        size_t uDepth = tex->getDepth();
		size_t eFormat = (uint32)tex->getFormat();
		size_t numFaces = tex->getNumFaces();
		size_t numMipMaps = tex->getNumMipmaps();

		fwrite(&uWidth, sizeof(size_t), 1, mpfFile);
		fwrite(&uHeight, sizeof(size_t), 1, mpfFile);
		fwrite(&uDepth, sizeof(size_t), 1, mpfFile);
		fwrite(&eFormat, sizeof(size_t), 1, mpfFile);
		fwrite(&numFaces, sizeof(size_t), 1, mpfFile);
		fwrite(&numMipMaps, sizeof(size_t), 1, mpfFile);

		size_t texdatasize = Ogre::Image::calculateSize(numMipMaps,
                                                        numFaces,
                                                        uWidth,
                                                        uHeight,
                                                        uDepth,
                                                        (Ogre::PixelFormat)eFormat);

		fwrite(tex->getData(),texdatasize, 1,mpfFile);
    }