void CzPlatformImaging::getTextureInfo(CzTexture texture, CzTextureinfo& texture_info)
{
	CIwTexture* t = static_cast<CIwTexture*>(texture);
	texture_info.Width = t->GetWidth();
	texture_info.Height = t->GetHeight();
	texture_info.Format = toCzImageFormat(t->GetFormat());
	texture_info.Filter = t->GetFiltering();
}
void CzPlatformRender::DrawPrimitives(CzRenderPrim3* prims, CzRenderMaterial* materials, int num_prims, bool single_material)
{
	while (num_prims-- > 0)
	{
		CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)materials->AlphaMode;	// TODO Add proper method to map Marmalade Alpha mode to Marmalade
		int vc = prims->VertCount;

		// Set up vertex streams
		if (prims->UVs != NULL)
			IwGxSetUVStream((CIwFVec2*)prims->UVs, 0);
		else
			IwGxSetUVStream(NULL);
		if (prims->ModelSpace)
			IwGxSetVertStreamModelSpace((CIwFVec3*)prims->Verts, vc);
		else
			IwGxSetVertStreamViewSpace((CIwFVec3*)prims->Verts, vc);
		IwGxSetColStream((CIwColour*)prims->Colours);
		IwGxSetNormStream((CIwFVec3*)prims->Normals);

		CzTexture texture = materials->Image->getTexture();
		CIwTexture* mt = static_cast<CIwTexture*>(texture);
		bool filter;
		if (materials->Image->isFilterSet())
			filter = mt->GetFiltering();
		else
			filter = materials->Filter;

		// Only create new render material if something important has changed
		if (texture != CurrentTexture || CurrentAlphaMode != materials->AlphaMode || CurrentFilter != filter || CurrentTexture == NULL || CurrentTiled != materials->Tiled)
		{
			CIwMaterial* mat = IW_GX_ALLOC_MATERIAL();
			mat->SetTexture(mt);
			mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED);
			mat->SetClamping(!materials->Tiled);
			mat->SetFiltering(filter);
			mat->SetAlphaMode(am);
			mat->SetCullMode(CIwMaterial::CULL_BACK);
//			mat->SetCullMode(CIwMaterial::CULL_NONE);
			IwGxSetMaterial(mat);
			CurrentTexture = texture;
			CurrentAlphaMode = materials->AlphaMode;
			CurrentTiled = materials->Tiled;
			CurrentFilter = filter;
		}
		else
		{
			RedundantTextureCalls++;
		}
	
		// Render the primitive
		IwGxDrawPrims(CzToIwGxPrimType[prims->Type], prims->Indices, prims->IndicesCount);

		// Move to next primitive
		prims++;
		if (!single_material)
			materials++;
	}
}
void CzPlatformImaging::ChangeTexture(CzTexture texture, void* pixels, CzImage::eFormat format)
{
	CIwImage::Format f = toMarmImageFormat(format);
	if (f == CIwImage::FORMAT_UNDEFINED)
		return;

	CIwTexture* t = static_cast<CIwTexture*>(texture);
	t->ChangeTexels((uint8*)pixels, f);
}
void ResourceManagerClass::LoadTextures()
{
	for (std::vector< TexturePair >::iterator it = textures.begin(); it != textures.end(); ++it)
	{
		CIwTexture* texture = new CIwTexture;
		texture->LoadFromFile(it->first.c_str());
		texture->Upload();
		it->second = new Texture;
		it->second->SetData((void*)texture);
	}
}
CzTexture CzPlatformImaging::CreateTexture(void* pixels, int width, int height, int pitch, CzImage::eFormat format, bool modifiable)
{
	if (pixels == NULL || width <= 0 || height <= 0)
		return false;

	CIwImage::Format f = toMarmImageFormat(format);
	if (f == CIwImage::FORMAT_UNDEFINED)
		return NULL;

	CIwTexture* texture = new CIwTexture();
	texture->_SetFlags( CIwTexture::NO_CHROMA_KEY_F );
	texture->SetMipMapping(false);
	texture->SetModifiable(modifiable);
	texture->CopyFromBuffer(width, height, f, pitch, (uint8*)pixels, NULL);

	return (CzTexture)texture;
}
示例#6
0
CIwTexture* Transitions2D::CaptureScreen()
{
	int w = IwGxGetDeviceWidth();
	int h = IwGxGetDeviceHeight();
	int length = w * h * 4;

	uint8* buffer = new uint8[length];

	glReadPixels(0, 0, w, h, 0x1908, 0x1401, buffer);

	uint8* buffer2 = new uint8[length];

	int lineSize = w * 4;
	uint8* b1 = buffer;
	uint8* b2 = buffer2 + h * lineSize;;
	for(int y = h; y > 0; y--)
	{
		b2 -= lineSize;
		for(int x = w; x > 0; x--)
		{
			*b2++ = *b1++;
			*b2++ = *b1++;
			*b2++ = *b1++;
			*b2++ = *b1++;
		}
		b2 -= lineSize;
	}

	CIwTexture* texture = new CIwTexture;
	CIwImage& img = texture->GetImage();

	img.SetFormat(CIwImage::ABGR_8888);
	img.SetWidth(w);
	img.SetHeight(h);
	img.SetBuffers(buffer2, length);
	//img.SaveBmp("screenshot.bmp");

	texture->SetMipMapping(false);
	texture->Upload();

	delete buffer;
	delete buffer2;

	return texture;
}
示例#7
0
CIwMaterial* ResourceManager::load(const char* name, int* w, int* h) {
	int width = 0, height = 0;
	char res[MAX_RES_NAME] = {0};
	sprintf(res, "images/%s/%s", desktop.getDevPath(), name);
	IIter p = imgs->find(res);
	if (p != imgs->end()) {
		if (w != NULL) {
			*w = p->second.width;
		}
		if (h != NULL) {
			*h = p->second.height;
		}
		return p->second.mat;
	}
	CIwTexture* texture = new CIwTexture;
    CIwImage image;
    s3eFile* pFile = s3eFileOpen(res, "rb");
    if (pFile) {
        image.ReadFile(pFile);
		width = image.GetWidth();
		height = image.GetHeight();
        s3eFileClose(pFile);
        texture->CopyFromImage(&image);
        texture->Upload();
    } else {
		delete texture;
		texture = NULL;
	}
	CIwMaterial* mat = new CIwMaterial;
	mat->SetTexture(texture);
	SImg s;
	s.texture = texture;
	s.mat = mat;
	s.width = width;
	s.height = height;
	imgs->insert(IPair(string(res), s));
	if (w != NULL) {
		*w = width;
	}
	if (h != NULL) {
		*h = height;
	}
	return mat;
}
CzTexture CzPlatformImaging::CreateTexture(void* memory_file, int memory_file_size)
{
	CzFile file;
	if (file.Open(memory_file, memory_file_size))
	{
		// Load the image
		CIwImage* image = new CIwImage();
		image->ReadFile((s3eFile*)file.getFileHandle());

		CIwTexture* texture = new CIwTexture();
		texture->_SetFlags( CIwTexture::NO_CHROMA_KEY_F );
		texture->CopyFromImage(image);

		delete image;

		return (CzTexture)texture;
	}

	return NULL;
}
示例#9
0
void Graphics::DrawTexture(const Rect& screenCoords, int textureId, const Rect& textureCoord, float xOffset, float yOffset)
{
    static CIwSVec2 textureUVs[4];
    static CIwSVec2 screenXY[4];
    static CIwMaterial material;

    CIwTexture* texture = (CIwTexture*)ResourceManager::GetInstance().GetTexture(textureId)->GetData();
    if (!texture)
        return;

    material.Reset();
    material.SetAlphaMode(CIwMaterial::ALPHA_BLEND);
    material.SetTexture(texture);

    int16 width = texture->GetWidth();
    int16 height = texture->GetHeight();

    static const int16 uvSize = 4096;

    // screen coordinates
    screenXY[0] = CIwSVec2((int16)(screenCoords.left + xOffset), (int16)(screenCoords.top + yOffset));
    screenXY[1] = CIwSVec2((int16)(screenCoords.left + xOffset), (int16)(screenCoords.bottom + yOffset));
    screenXY[2] = CIwSVec2((int16)(screenCoords.right + xOffset), (int16)(screenCoords.top + yOffset));
    screenXY[3] = CIwSVec2((int16)(screenCoords.right + xOffset), (int16)(screenCoords.bottom + yOffset));

    // texture's UV coordinates
    textureUVs[0] = CIwSVec2(((int16)textureCoord.left * uvSize) / width, ((int16)textureCoord.top * uvSize) / height);
    textureUVs[1] = CIwSVec2(((int16)textureCoord.left * uvSize) / width, ((int16)textureCoord.bottom * uvSize) / height);
    textureUVs[2] = CIwSVec2(((int16)textureCoord.right * uvSize) / width, ((int16)textureCoord.top * uvSize) / height);
    textureUVs[3] = CIwSVec2(((int16)textureCoord.right * uvSize) / width, ((int16)textureCoord.bottom * uvSize) / height);

    IwGxSetMaterial(&material);
    IwGxSetUVStream(textureUVs);

    IwGxSetColStream(NULL);
    IwGxSetVertStreamScreenSpace(screenXY, 4);
    IwGxDrawPrims(IW_GX_QUAD_STRIP, NULL, 4);

    IwGxFlush();
}
示例#10
0
void MapBackground::DownloadTiles()
{
	CIwTexture* tx = (CIwTexture*)IwGetResManager()->GetResNamed("logo", IW_GX_RESTYPE_TEXTURE);
	uint32 w1 = tx->GetWidth();
	uint32 h1 = tx->GetHeight();

	//static CIwSVec2 uvs[4] =
	//{
	//	CIwSVec2(0 << 12, 0 << 12),
	//	CIwSVec2(0 << 12, 1 << 12),
	//	CIwSVec2(1 << 12, 1 << 12),
	//	CIwSVec2(1 << 12, 0 << 12),
	//};

	static CIwSVec2 uvs[4] =
	{
		CIwSVec2((0 << 12) + 10, (0 << 12) + 10),
		CIwSVec2((0 << 12) + 10, (1 << 12) - 10),
		CIwSVec2((1 << 12) - 10, (1 << 12) - 10),
		CIwSVec2((1 << 12) - 10, (0 << 12) + 10),
	};
	
	int w = w1/2;
	int h = h1/2;

	int counter = 0;

	while (true)
	{
		IwGetHTTPQueue()->Update();
		IwGetNotificationHandler()->Update();
		IwGetMultiplayerHandler()->Update();

		IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);

		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
		pMat->SetTexture(tx);
		IwGxSetMaterial(pMat);

		CIwMat rotMat;
		rotMat.SetIdentity();
		double perCentAngle = (counter / 80.0);
		iwangle degAng = (iwangle)(IW_GEOM_ONE * perCentAngle);

		rotMat.SetRotZ(degAng);
		rotMat.t.z = -0x200;

		IwGxSetViewMatrix(&rotMat);

		CIwSVec3* pWSCoords= IW_GX_ALLOC(CIwSVec3, 4);
		pWSCoords[0].x = -w; pWSCoords[0].y = -h;
		pWSCoords[1].x = -w; pWSCoords[1].y = h;
		pWSCoords[2].x = w; pWSCoords[2].y = h;
		pWSCoords[3].x = w; pWSCoords[3].y = -h;
		pWSCoords[0].z = pWSCoords[1].z = pWSCoords[2].z = pWSCoords[3].z = 0;

		if (!g_bInProgress)
		{
			MapTile* pNextDownload = GetNextDownload(NULL);
			if (pNextDownload)
			{
				IwGetNotificationHandler()->PushNotification((int)this, pNextDownload->szImageUrl, 10*1000);
				g_bInProgress = true;
				LoadMapTileImage(pNextDownload);
			}
			else
			{
				IwGetNotificationHandler()->ClearNotification((int)this);
				break;
			}
		}

		IwGxSetVertStreamWorldSpace(pWSCoords, 4);
		IwGxSetUVStream(uvs);
		IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
		IwGetNotificationHandler()->Render();

		IwGxFlush();
		IwGxSwapBuffers();
		s3eDeviceYield(50);

		counter++;
	}
}
void CzPlatformImaging::SaveTextureAsJpeg(CzTexture texture, const char* filename)
{
	CIwTexture* t = static_cast<CIwTexture*>(texture);
	t->GetImage().SaveJpg(filename);
}
void CzPlatformImaging::setTextureFiltering(CzTexture texture, bool enable)
{
	CIwTexture* t = static_cast<CIwTexture*>(texture);
	t->SetFiltering(enable);
}
void CzPlatformImaging::UploadTexture(CzTexture texture)
{
	CIwTexture* t = static_cast<CIwTexture*>(texture);
	t->Upload();
}
CzTexture CzPlatformImaging::CreateTexture(CzTexture source, CzImage::eFormat format)
{
	CIwImage::Format f = toMarmImageFormat(format);
	if (f == CIwImage::FORMAT_UNDEFINED)
		return NULL;
	CIwTexture* t = static_cast<CIwTexture*>(source);

	CIwImage* image = new CIwImage();
	image->SetFormat(f);
	image->SetWidth(t->GetWidth());
	image->SetHeight(t->GetHeight());
	t->GetImage().ConvertToImage(image);

	CIwTexture* texture = new CIwTexture();
	texture->_SetFlags( CIwTexture::NO_CHROMA_KEY_F );
	texture->SetMipMapping(t->GetMipMapping());
	texture->SetFiltering(t->GetFiltering());
	texture->SetModifiable(t->GetModifiable());
	texture->CopyFromImage(image);

	delete image;

	return (CzTexture)texture;
}