示例#1
0
void Quads::refresh() {
	if (vertc > 0) {
		IwGxSetVertStreamScreenSpace(verts, vertc);
		IwGxSetColStream(cols, vertc);
		IwGxDrawPrims(IW_GX_TRI_LIST, NULL, vertc);
	}
}
示例#2
0
void renderMap() {
	IwGxLightingOff();
	
	CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
    pMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
    pMat->SetTexture(mapTexture);

	IwGxSetMaterial(pMat);

	IwGxSetScreenSpaceSlot(-1);

	float zoom = getMapZoom()->getZoom();

	int16 hScrW = (double)IwGxGetScreenWidth()*0.5f;
	int16 hScrH = (double)IwGxGetScreenHeight()*0.5f;
	int16 x1 = hScrW - hScrW*zoom;
	int16 x2 = hScrW + hScrW*zoom;
	int16 y1 = hScrH - hScrH*zoom;
	int16 y2 = hScrH + hScrH*zoom;

	mapVertZoom[0].x = x1, mapVertZoom[0].y = y1;
	mapVertZoom[1].x = x1, mapVertZoom[1].y = y2;
	mapVertZoom[2].x = x2, mapVertZoom[2].y = y2;
	mapVertZoom[3].x = x2, mapVertZoom[3].y = y1;

    IwGxSetUVStream(mapDefaultUvs);
    IwGxSetVertStreamScreenSpace(mapVertZoom, 4);

    IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
示例#3
0
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
void ImGui_Marmalade_RenderDrawLists(ImDrawData* draw_data)
{
    // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
    ImGuiIO& io = ImGui::GetIO();
    draw_data->ScaleClipRects(io.DisplayFramebufferScale);

    // Render command lists
    for(int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const unsigned char* vtx_buffer = (const unsigned char*)&cmd_list->VtxBuffer.front();
        const ImDrawIdx* idx_buffer = &cmd_list->IdxBuffer.front();
        int nVert = cmd_list->VtxBuffer.size();
        CIwFVec2* pVertStream = IW_GX_ALLOC(CIwFVec2, nVert);
        CIwFVec2* pUVStream = IW_GX_ALLOC(CIwFVec2, nVert);
        CIwColour* pColStream = IW_GX_ALLOC(CIwColour, nVert);

        for( int i=0; i < nVert; i++ )
        {
            // TODO: optimize multiplication on gpu using vertex shader
            pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_scale.x;
            pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_scale.y;
            pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x;
            pUVStream[i].y = cmd_list->VtxBuffer[i].uv.y;
            pColStream[i] = cmd_list->VtxBuffer[i].col;
        }

        IwGxSetVertStreamScreenSpace(pVertStream, nVert);
        IwGxSetUVStream(pUVStream);
        IwGxSetColStream(pColStream, nVert);
        IwGxSetNormStream(0);

        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.size(); cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list,pcmd);
            }
            else
            {
                CIwMaterial* pCurrentMaterial = IW_GX_ALLOC_MATERIAL();
                pCurrentMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT);
                pCurrentMaterial->SetCullMode(CIwMaterial::CULL_NONE);
                pCurrentMaterial->SetFiltering(false);
                pCurrentMaterial->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
                pCurrentMaterial->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_NORMAL);
                pCurrentMaterial->SetAlphaTestMode(CIwMaterial::ALPHATEST_DISABLED);
                pCurrentMaterial->SetTexture((CIwTexture*)pcmd->TextureId);
                IwGxSetMaterial(pCurrentMaterial);
                IwGxDrawPrims(IW_GX_TRI_LIST, (uint16*)idx_buffer, pcmd->ElemCount);
            }
            idx_buffer += pcmd->ElemCount;
        }
        IwGxFlush();
    }

    // TODO: restore modified state (i.e. mvp matrix)
}
示例#4
0
void myIwGxDoneStars()
{
    IwGxSetScreenSpaceSlot(3);
    IwGxSetVertStreamScreenSpace( svertices, ssend_vertices );
    CIwMaterial *pMat = IW_GX_ALLOC_MATERIAL();
    pMat->SetAlphaMode( CIwMaterial::ALPHA_ADD );
    pMat->SetTexture( star_texture );
    pMat->SetColAmbient( 0xFF, 0xFF, 0xFF, 0xFF );
    IwGxSetMaterial( pMat );
    IwGxSetUVStream( suvdata );
    IwGxSetColStream( scolors, ssend_vertices );
    IwGxDrawPrims( IW_GX_QUAD_LIST, NULL, ssend_vertices );
    IwGxFlush();
}
示例#5
0
void ResourceManager::paint(const char* res, int x, int y, int w, int h, int* lm, int* tm, int* rm, int* bm) {
	int width, height;
	if (res == NULL) return;
	CIwMaterial* t = load(res, &width, &height);
	if (t == NULL) return;
    if (vertC + 4 >= MAX_VERTS) return;
	if (width != 0) {
		if (lm != 0) {
			*lm = (*lm * w) / width;
			x -= *lm;
			w += *lm;
		}
		if (rm != 0) {
			*rm = (*rm * w) / width;
			w += *rm;
		}
	}
	if (height != 0) {
		if (tm != 0) {
			*tm = (*tm * h) / height;
			y -= *tm;
			h += *tm;
		}
		if (bm != NULL) {
			*bm = (*bm * h) / height;
			h += *bm;
		}
	}
    int offset = vertC;
	xy3[vertC].x = x,     xy3[vertC].y = y;      vertC++;
	xy3[vertC].x = x,     xy3[vertC].y = y + h;  vertC++;
	xy3[vertC].x = x + w, xy3[vertC].y = y + h;  vertC++;
	xy3[vertC].x = x + w, xy3[vertC].y = y;      vertC++;
	IwGxSetVertStreamScreenSpace(xy3 + offset, 4);
	IwGxSetMaterial(t);
	static CIwFVec2 uvs[4] = {
		CIwFVec2(0, 0),
		CIwFVec2(0, 1),
		CIwFVec2(1, 1),
		CIwFVec2(1, 0),
	};
/*	static CIwSVec2 uvs[4] = {
		CIwSVec2(0,           0),
		CIwSVec2(0,           IW_GEOM_ONE),
		CIwSVec2(IW_GEOM_ONE, IW_GEOM_ONE),
		CIwSVec2(IW_GEOM_ONE, 0),
	};*/
	IwGxSetUVStream(uvs);
	IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
示例#6
0
void Block::draw(int16 x, int16 y, int16 w, int16 h) {
    if (!enabled)
        return;
    
    xy4[0].x = x,     xy4[0].y = y;
    xy4[1].x = x,     xy4[1].y = y+h;
    xy4[2].x = x+w,   xy4[2].y = y+h;
    xy4[3].x = x+w,   xy4[3].y = y;
    
    IwGxSetVertStreamScreenSpace(xy4, 4);
    
    IwGxSetMaterial(IW_GX_ALLOC_MATERIAL());
    IwGxSetColStream(color, 4);
    
    // Draw single triangle
    IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
示例#7
0
void renderCamera() {

	IwGxLightingOff();

    // Refresh dynamic texture
    if (g_CameraTexture != NULL)
        g_CameraTexture->ChangeTexels((uint8*)g_pCameraTexelsRGB565, CIwImage::RGB_565);

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

    IwGxSetMaterial(pMat);

	IwGxSetScreenSpaceSlot(-1);

    IwGxSetUVStream(cameraUvs);
    IwGxSetVertStreamScreenSpace(cameraVert, 4);

    IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
示例#8
0
void CzPlatformRender::DrawPrimitives(CzRenderPrim* 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);
//			IwGxSetUVStream((CIwSVec2*)prims->UVs, 0, vc);
		}
		else
			IwGxSetUVStream(NULL);
		IwGxSetVertStreamScreenSpace((CIwFVec2*)prims->Verts, vc);
		if (prims->Colours != NULL)
			IwGxSetColStream((CIwColour*)prims->Colours);
		else
			IwGxSetColStream(NULL);
		IwGxSetNormStream(NULL);

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

		// 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;
			CurrentFilter = filter;
			CurrentTiled = materials->Tiled;
		}
		else
		{
			RedundantTextureCalls++;
		}

		// Render the primitive
		IwGxDrawPrims(CzToIwGxPrimType[prims->Type], prims->Indices, prims->IndicesCount);

		// Move to next primitive
		prims++;
		if (!single_material)
			materials++;
	}
}
示例#9
0
// BatchDrawPrims - Currently only supports batching of Quad lists
void CzPlatformRender::BatchDrawPrims(bool filter)
{
	if (NextMaterial == 0)
		return;

	// Allocate memory from data cache for verts, UV's and colours
	for (int t = 0; t < NextMaterial; t++)
	{
		int prim_count = MaterialUsedCounts[t] * 4;
		BatchVerts[t] = IW_GX_ALLOC(CzVec2, prim_count);
		BatchUVs[t] = IW_GX_ALLOC(CzVec2, prim_count);
		BatchColours[t] = IW_GX_ALLOC(CzColour, prim_count);
		BatchIndices[t] = IW_GX_ALLOC(uint16, prim_count);
	}

	// Populate the data cache
	CzRenderPrim** prims = Primitives;
	for (int t = 0; t < NextPrimitive; t++)
	{
		CzRenderPrim *prim = *prims;
		int mat_id = prim->MaterialID;
		int idx = MaterialIndices[mat_id];
		CzVec2* v = BatchVerts[mat_id] + idx;
		CzVec2* uv = BatchUVs[mat_id] + idx;
		CzColour* c = BatchColours[mat_id] + idx;
		uint16* i = BatchIndices[mat_id] + idx;
		for (int t2 = 0; t2 < 4; t2++)
		{
			v->x = (prim->Verts + t2)->x;
			v->y = (prim->Verts + t2)->y;
			uv->x = (prim->UVs + t2)->x;
			uv->y = (prim->UVs + t2)->y;
			c->set(*(prim->Colours + t2));
			v++; uv++; c++;
		}
// TODO: ERROR - Does not work with batched ngon
		*i++ = idx;
		*i++ = idx + 3;
		*i++ = idx + 2;
		*i++ = idx + 1;
		MaterialIndices[mat_id] += 4;
		prims++;
	}

	// Render batched streams
	CzRenderMaterial** mats = Materials;
	for (int t = 0; t < NextMaterial; t++)
	{
		int count = MaterialUsedCounts[t] * 4;
		IwGxSetUVStream((CIwFVec2*)BatchUVs[t], 0);
		IwGxSetVertStreamScreenSpace((CIwFVec2*)BatchVerts[t], count);
		IwGxSetColStream((CIwColour*)(BatchColours[t]), count);
		IwGxSetNormStream(NULL);
		CIwMaterial* mat = IW_GX_ALLOC_MATERIAL();
		CIwTexture* texture = static_cast<CIwTexture*>((*mats)->Image->getTexture());
		mat->SetTexture(texture);
		mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED);
		mat->SetClamping(false);
		mat->SetFiltering(filter);
		mat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		mat->SetCullMode(CIwMaterial::CULL_BACK);
//		mat->SetCullMode(CIwMaterial::CULL_NONE);
		IwGxSetMaterial(mat);
		IwGxDrawPrims(IW_GX_QUAD_LIST, BatchIndices[t], count);
		mats++;
	}

	// Reset batch pointers
	for (int t = 0; t < NextMaterial; t++)
		MaterialUsedCounts[t] = 0;
	for (int t = 0; t < NextMaterial; t++)
		MaterialIndices[t] = 0;
	NextPrimitive = 0;
	NextMaterial = 0;
}
示例#10
0
void CzPlatformRender::DrawText(CzFontPreparedText prepared_text, CzFont* font, CzMatrix3* transform, const CzColour& colour, CzVec4& skew, bool filter, eCzAlphaMode alpha_mode)
{
	CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)alpha_mode; // TODO Add proper method map Marmalade Alpha mode to Marmalade

	// Cache the transform
	float m00 = transform->m[0][0];
	float m01 = transform->m[0][1];
	float m10 = transform->m[1][0];
	float m11 = transform->m[1][1];
	float tx = transform->getX();
	float ty = transform->getY();
	float sx1 = (float)skew.x;
	float sx2 = (float)skew.y;
	float sy1 = (float)skew.z;
	float sy2 = (float)skew.w;
/*	CzIRect clip = ScreenClipRect;
	clip.x <<= 3;
	clip.y <<= 3;
	clip.w = clip.x + (clip.w << 3);
	clip.h = clip.y + (clip.h << 3);*/

	IwGxLightingOn();
	IwGxSetColStream(NULL);
	IwGxSetNormStream(NULL);

	CIwGxFont* mfont = static_cast<CIwGxFont*>(font->getFontHandle());
	CIwGxFontPreparedData* prep_text = static_cast<CIwGxFontPreparedData*>(prepared_text);

	// A font can consist of multiple materials so we need to process all of them
	for (int t = 0; t < mfont->GetNumberMaterials(); t++)
	{
		// Set UV stream
		uint32* char_ids;
		int num_chars = IwGxFontSetUVs(*prep_text, -1, t, &char_ids);

		// Generate transformed vertices from glyphs
		int nv = num_chars << 2;
		CzVec2* pVerts = IW_GX_ALLOC(CzVec2, nv);
		CzVec2* pVert = pVerts;
		if (m01 == 0 && m10 == 0)
		{
			// No rotation optimisation
			for (int t2 = 0; t2 < num_chars; t2++)
			{
				CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]);
				float x1 = (float)rc.x;
				float y1 = (float)rc.y;
				float x2 = x1 + (float)rc.w;
				float y2 = y1 + (float)rc.h;
				float ax = (m00 * x1) + tx;
				float ay = (m11 * y1) + ty;
				float bx = (m00 * x2) + tx;
				float by = (m11 * y2) + ty;

//				if ((ax < clip.w && bx >= clip.x) && (ay < clip.h && by >= clip.y))
//				{
					pVert->x = ax + sx1;
					pVert->y = ay + sy1;
					pVert++;
					pVert->x = ax - sx1;
					pVert->y = by + sy2;
					pVert++;
					pVert->x = bx - sx2;
					pVert->y = by - sy2;
					pVert++;
					pVert->x = bx + sx2;
					pVert->y = ay - sy1;
					pVert++;
//				}
			}
		}
		else
		{
			for (int t2 = 0; t2 < num_chars; t2++)
			{
				CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]);
				float x1 = (float)rc.x;
				float y1 = (float)rc.y;
				float x2 = x1 + (float)rc.w;
				float y2 = y1 + (float)rc.h;
				pVert->x = (m00 * x1 + m10 * y1 + tx + sx1);
				pVert->y = (m01 * x1 + m11 * y1 + ty + sy1);
				pVert++;
				pVert->x = (m00 * x1 + m10 * y2 + tx - sx1);
				pVert->y = (m01 * x1 + m11 * y2 + ty + sy2);
				pVert++;
				pVert->x = (m00 * x2 + m10 * y2 + tx - sx2);
				pVert->y = (m01 * x2 + m11 * y2 + ty - sy2);
				pVert++;
				pVert->x = (m00 * x2 + m10 * y1 + tx + sx2);
				pVert->y = (m01 * x2 + m11 * y1 + ty - sy1);
				pVert++;
			}
		}

		if (nv > 0)
		{
			// Set vertex stream
			IwGxSetVertStreamScreenSpace((CIwFVec2*)pVerts, nv);

			// Create a material
			CIwMaterial* mat = IW_GX_ALLOC_MATERIAL();
			mat->Copy(*IwGxFontGetFont()->GetMaterial(t));
			mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED);
			mat->SetColEmissive(colour.get());
			mat->SetClamping(true);
			mat->SetFiltering(filter);
			mat->SetAlphaMode(am);
			mat->SetCullMode(CIwMaterial::CULL_BACK);
//			mat->SetCullMode(CIwMaterial::CULL_NONE);
			IwGxSetMaterial(mat);

			// Finally draw the glyphs
			IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, nv);

			CurrentAlphaMode = alpha_mode;
		}
	}
	IwGxLightingOff();
	CurrentTexture = NULL;
}
示例#11
0
void CameraDefend::Render() {
	if (defended) {
		IwGxLightingOff();

		animMatSuccess->SetModulateMode(CIwMaterial::MODULATE_NONE);
		animMatSuccess->SetAlphaMode(CIwMaterial::ALPHA_BLEND);

		IwGxSetMaterial(animMatSuccess);
		IwGxSetUVStream(anim_uvs_success);

		IwGxSetVertStreamScreenSpace(animVertsLeftSuccess, 4);
		IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);

		IwGxSetVertStreamScreenSpace(animVertsRightSuccess, 4);
		IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);

		if (animMatSuccess->GetAnimCelID() == animMatSuccess->GetAnimCelNum() - 1) {
			defended = false;
		}
	} else {
		animMatSuccess->SetAnimCelID(0);
	}

	if (!isActive()) return;

	{
		Ghost* ghost = getGameState()->getGhost();
		GhostAttack* attack = (ghost != NULL) ? ghost->getAttack() : NULL;

		if (attack != NULL && 
			((attack->getInterval() <  750 && attack->getInterval() > 600) ||
			 (attack->getInterval() <  400 && attack->getInterval() > 250))) {
			dotTexture = dotTextureRed;
		} else {
			dotTexture = dotTextureGreen;
		}
	}

	Iw2DSetAlphaMode(IW_2D_ALPHA_NONE);
	Iw2DSetTransformMatrix(CIwFMat2D::g_Identity);

	CIwFMat2D rot;
	rot.SetRot(rad(dotAngle), CIwFVec2(
		dotVertsTopLeftLeft.x + dotVertsSizeLeft.x/2, 
		dotVertsTopLeftLeft.y + dotVertsSizeLeft.y/2));
	Iw2DSetTransformMatrix(rot);
	Iw2DDrawImage(dotTexture, dotVertsTopLeftLeft, dotVertsSizeLeft);

	rot.SetRot(rad(dotAngle), CIwFVec2(
		dotVertsTopLeftRight.x + dotVertsSizeRight.x/2, 
		dotVertsTopLeftRight.y + dotVertsSizeRight.y/2));
	Iw2DSetTransformMatrix(rot);
	Iw2DDrawImage(dotTexture, dotVertsTopLeftRight, dotVertsSizeRight);

	bool isDrwaing = true;
	for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) {
		// Is any touch drawing?
		if (touch[i]->drawing) break;

		if (i == DEFEND_TOUCHES_MAX - 1) {
			isDrwaing = false;
			animMat->SetAnimCelID(0);
		}
	}

	if (isDrwaing) {
		IwGxLightingOff();

		animMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
		animMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);

		IwGxSetMaterial(animMat);
		IwGxSetUVStream(anim_uvs);

		IwGxSetVertStreamScreenSpace(animVertsLeft, 4);
		IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);

		IwGxSetVertStreamScreenSpace(animVertsRight, 4);
		IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
	}
}