Пример #1
0
void ya2d_drawRotateTexture(ya2d_Texture *texp, int x, int y, float angle)
{
        if(!texp->data) return;

		sceGuEnable(GU_TEXTURE_2D);

		sceGuTexMode(texp->texPSM, 0, 0, texp->isSwizzled);
		sceGuTexFunc(GU_TFX_REPLACE, texp->hasAlpha ? GU_TCC_RGBA : GU_TCC_RGB);
		
        ya2d_setTexture(texp);
			
		sceGumPushMatrix(); 
		sceGumLoadIdentity();
		{
			ScePspFVector3 pos = {x + (float)texp->centerX, y + (float)texp->centerY, 0.0f};
			sceGumTranslate(&pos);
			sceGumRotateZ(angle);
		}

		ya2d_FloatTextureVertex *vertices = (ya2d_FloatTextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_FloatTextureVertex));
		
		vertices[0] = (ya2d_FloatTextureVertex){0.0f, 0.0f, (float)-texp->centerX, (float)-texp->centerY, 0.0f};
        vertices[1] = (ya2d_FloatTextureVertex){0.0f, 1.0f, (float)-texp->centerX, (float)texp->centerY, 0.0f};
        vertices[2] = (ya2d_FloatTextureVertex){1.0f, 0.0f, (float)texp->centerX, (float)-texp->centerY, 0.0f};
        vertices[3] = (ya2d_FloatTextureVertex){1.0f, 1.0f, (float)texp->centerX, (float)texp->centerY, 0.0f};
        
		sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, vertices);
        
        sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_FloatTextureVertex));
        sceGumPopMatrix(); 
}
Пример #2
0
    void ya2d_drawTexture(ya2d_Texture *texp, int x, int y)
    {
        if(!texp->data) return;
        
		sceGuEnable(GU_TEXTURE_2D);

		sceGuTexMode(texp->texPSM, 0, 0, texp->isSwizzled);
		sceGuTexFunc(GU_TFX_REPLACE, texp->hasAlpha ? GU_TCC_RGBA : GU_TCC_RGB);
		
        ya2d_setTexture(texp);		

		if(texp->textureWidth <= YA2D_TEXTURE_SLICE)
		{
			ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_TextureVertex));

			vertices[0] = (ya2d_TextureVertex){0, 0, x, y, 0};
			vertices[1] = (ya2d_TextureVertex){0, texp->textureHeight, x, y+texp->textureHeight, 0};
			vertices[2] = (ya2d_TextureVertex){texp->textureWidth, 0, x+texp->textureWidth, y, 0};
			vertices[3] = (ya2d_TextureVertex){texp->textureWidth, texp->textureHeight, x+texp->textureWidth, y+texp->textureHeight, 0};

			sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 4, 0, vertices);
			
			sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_TextureVertex));
		}
		else //Fast draw for big textures
		{
			int i;
			for(i = 0; i < texp->textureWidth; i+= YA2D_TEXTURE_SLICE)
			{
				/*
				ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_TextureVertex));
				vertices[0] = (ya2d_TextureVertex){i, 0, x+i, y, 0};
				vertices[1] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, 0, x+i+YA2D_TEXTURE_SLICE, y, 0};
				vertices[2] = (ya2d_TextureVertex){i, texp->textureHeight, x+i, y+texp->textureHeight, 0};
				vertices[3] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, texp->textureHeight, x+i+YA2D_TEXTURE_SLICE, y+texp->textureHeight, 0};
				sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 4, 0, vertices);
				sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_TextureVertex));
				*/
				
				ya2d_TextureVertex *vertices = (ya2d_TextureVertex *)sceGuGetMemory(2 * sizeof(ya2d_TextureVertex));
				vertices[0] = (ya2d_TextureVertex){i, 0, x+i, y, 0};
				vertices[1] = (ya2d_TextureVertex){i+YA2D_TEXTURE_SLICE, texp->textureHeight, x+i+YA2D_TEXTURE_SLICE, y+texp->textureHeight, 0};
				sceGumDrawArray(GU_SPRITES, GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D, 2, 0, vertices);
				sceKernelDcacheWritebackRange(vertices, 2 * sizeof(ya2d_TextureVertex));
			}			
		}   
    }
Пример #3
0
void RenderCube(unsigned char x, unsigned char y, unsigned char z)
{
	ScePspFVector3 vec;
	//printf("FrontEnd::RenderCube() started\n");
	
	vec.x = -(float)x;
	vec.y = -(float)y;
	vec.z = -(float)z;
	sceGumTranslate(&vec);
	
	sceGumDrawArray(SCEGU_PRIM_TRIANGLES, SCEGU_VERTEX_FLOAT, 36, 0, Cube);
}
Пример #4
0
void drawTorus( int val )
{
    // setup a light

    ScePspFVector3 dir = { 0, 0, 1 };
    sceGuLight(0,GU_DIRECTIONAL,GU_DIFFUSE,&dir);
    sceGuLightColor(0,GU_DIFFUSE,0x00ff4040 );
    sceGuLightAtt(0,1.0f,0.0f,0.0f);
    sceGuAmbient(0x00202020);

    // setup texture
    sceGuDisable(GU_TEXTURE_2D);
    sceGuEnable(GU_LIGHTING);
    sceGuEnable(GU_LIGHT0);

    // setup matrices for torus

    sceGumMatrixMode(GU_PROJECTION);
    sceGumLoadIdentity();
    sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

    sceGumMatrixMode(GU_VIEW);
    {
        ScePspFVector3 pos = {0.0f,0.0f,-2.5f};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
    }

    sceGumMatrixMode(GU_MODEL);
    {
        ScePspFVector3 rot = {val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f)};

        sceGumLoadIdentity();
        sceGumRotateXYZ(&rot);
    }

    // draw torus

    sceGuColor(0xffffff);
    sceGumDrawArray(GU_TRIANGLES,GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D,sizeof(torus_indices)/sizeof(unsigned short),torus_indices,torus_vertices);


    // restore state

    sceGuDisable(GU_LIGHTING);
    sceGuDisable(GU_LIGHT0);
    sceGuEnable(GU_TEXTURE_2D);
}
Пример #5
0
int DrawLine3D(VECTOR pos1,VECTOR pos2,int color)
{
	GUSTART;
	dxpGraphicsSetup3D(color);
	DXP_FVF_3D *vtx = dxpGuGetMemory(sizeof(DXP_FVF_3D) * 2);
	if(!vtx)return -1;
	vtx[0].x = pos1.x;
	vtx[0].y = pos1.y;
	vtx[0].z = pos1.z;
	vtx[1].x = pos2.x;
	vtx[1].y = pos2.y;
	vtx[1].z = pos2.z;
	sceGumDrawArray(GU_LINES,DXP_VTYPE_3D | GU_TRANSFORM_3D,2,0,vtx);
	return 0;
}
		void SkyLight::Render()
		{
			sceGuEnable(GU_TEXTURE_2D);
			sceGuEnable(GU_BLEND);

			sceGuBlendFunc(GU_ADD, GU_FIX,GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF);

			sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, skyVertices);

			sceGuDisable(GU_TEXTURE_2D);
			sceGuDisable(GU_BLEND);

			//make default blend function
			sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
		}
Пример #7
0
void Sprite::Draw()
{
    sceGumPushMatrix();

    ScePspFVector3 loc = {posX,posY,0.0f};
    sceGumTranslate(&loc);

    sceGuEnable(GU_TEXTURE_2D);
    TextureManager::Instance()->SetTexture(imageName,GU_NEAREST,GU_NEAREST);

    sceGumDrawArray(GU_TRIANGLE_STRIP,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, vertices);

    sceGuDisable(GU_TEXTURE_2D);
    sceGumPopMatrix();
}
Пример #8
0
void drawCube( Texture* texture, int val )
{
    // setup matrices for cube

    sceGumMatrixMode(GU_PROJECTION);
    sceGumLoadIdentity();
    sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

    sceGumMatrixMode(GU_VIEW);
    {
        ScePspFVector3 pos = {0.0f,0.0f,-2.5f};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
    }

    sceGumMatrixMode(GU_MODEL);
    {
        ScePspFVector3 rot = {val * 0.263f * (GU_PI/180.0f), val * 0.32f * (GU_PI/180.0f), val * 0.44f * (GU_PI/180.0f)};

        sceGumLoadIdentity();
        sceGumRotateXYZ(&rot);
    }

    // setup texture

    sceGuTexMode(texture->format,0,0,0);
    sceGuTexImage(texture->mipmap,texture->width,texture->height,texture->stride,texture->data);
    sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
    sceGuTexFilter(GU_LINEAR,GU_LINEAR);
    sceGuTexScale(1.0f,1.0f);
    sceGuTexOffset(0.0f,0.0f);
    sceGuAmbientColor(0xffffffff);

    sceGuEnable(GU_TEXTURE_2D);

    // draw cube

    sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cube_vertices);

    sceGuDisable(GU_TEXTURE_2D);
}
Пример #9
0
/* renders subset of billboards array */
void render_billboards(unsigned int i)
{
	if (i >= g_context.iterationCount) return;


	Vertex* vbuffer = g_context.vbuffer[i%NUM_VERTEX_BUFFERS];
	int sliceCount = NUM_SLICES / g_context.iterationCount;

	// fill current vertex buffer if we just started
	if (i == 0)
	{
		create_modified_torus_billboards(vbuffer,(float*)&g_context.world, g_context.sint, sliceCount*i, sliceCount);
	}

	// render previously generated vertex buffer
	sceGumMatrixMode(GU_MODEL);
	sceGumLoadMatrix(&g_context.world);
	sceGumDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,sliceCount*NUM_ROWS*2,0,vbuffer);
	g_context.vertsRendered += sliceCount*NUM_ROWS*2;

	// fill next vertex buffer for future rendering
	int nextI = i + 1;
	if (nextI < g_context.iterationCount )
	{	
		Vertex* vbufferNext;
		vbufferNext = g_context.vbuffer[nextI%NUM_VERTEX_BUFFERS];
		create_modified_torus_billboards(vbufferNext,(float*)&g_context.world, g_context.sint, sliceCount*nextI, sliceCount);
	}

#ifdef USING_SIGNALS
	// send a signal when rendering was completed
	// signals 0x01..0x03 - seems to be available for custom usage
	sceGuSignal( 1, nextI );

	// HACK: keeps CPU waiting until all jobs were submitted for GPU
	if (nextI == g_context.iterationCount)
		sceGuFinish();
#endif
}
Пример #10
0
int main(int argc, char* argv[])
{
	setupCallbacks();

	int i, j;

	// Load emd mesh from file
	EMD_MESH* mesh = EMD_LoadMeshFromFile("scene.emd");
	int vert_count = EMD_GetVertexCount(mesh);
	int idx_count = 0;

	int elem_count = EMD_GetElementCount(mesh);
	for (i=0; i<elem_count; i++)
	{
		idx_count += EMD_GetIndexCount(mesh, i);
	}

	VERTEX* vert_buf = (VERTEX*)memalign(16, sizeof(VERTEX) * vert_count);
	GW_UINT16* idx_buf = (GW_UINT16*)memalign(16, sizeof(GW_UINT16) * idx_count);

	for (i=0; i<vert_count; i++)
	{
		EMD_GetVertexByIndex(mesh, i, &vert_buf[i].x, &vert_buf[i].y, &vert_buf[i].z);
		EMD_GetTexcoordByIndex(mesh, i, &vert_buf[i].u, &vert_buf[i].v);
		EMD_GetNormalByIndex(mesh, i, &vert_buf[i].nx, &vert_buf[i].ny, &vert_buf[i].nz);
		//vert_buf[i].color = 0xffffffff;
	}

	GW_UINT32 idx_head = 0;
	GW_UINT32* data;
	GW_UINT32 count;

	// Pack 32-bit index into 16-bit buffer
	for (i=0; i<elem_count; i++)
	{
		count = EMD_GetIndexCount(mesh, i);
		data = EMD_GetIndexArray(mesh, i);
		for (j=0; j<count; j++)
		{
			idx_buf[j + idx_head] = (GW_UINT16)data[j];
		}

		idx_head += count;
	}

	EMD_FreeMesh(mesh);


	// flush cache so that no stray data remains

	sceKernelDcacheWritebackAll();

	// setup GU

	void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

	pspDebugScreenInit();
	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
	sceGuDepthBuffer(zbp,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(65535,0);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	//sceGuDisable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_LIGHTING);
	sceGuEnable(GU_LIGHT0);
	sceGuEnable(GU_LIGHT1);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

	int val = 0;

	while(running())
	{
		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0xff554433);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		
		// setup lights

		ScePspFVector3 light_dir = { 1.0f, 1.0f, 1.0f };

		// GU_DIRECTIONAL
		// GU_POINTLIGHT
		sceGuLight(0, GU_POINTLIGHT, GU_DIFFUSE, &light_dir);
		sceGuLightColor(0, GU_DIFFUSE, 0xffffffff);
		sceGuAmbient(0x00202020);

		light_dir.x = -light_dir.x;
		light_dir.y = -light_dir.y;
		light_dir.z = -light_dir.z;

		sceGuLight(1, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &light_dir);
		sceGuLightColor(1, GU_DIFFUSE, 0xff7f7f7f);
		

		// setup matrices for cube

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };
			ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		// setup texture

		//sceGuTexMode(GU_PSM_4444,0,0,0);
		// sceGuTexImage(0,64,64,64,logo_start);
		//sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
		//sceGuTexEnvColor(0xffff00);
		//sceGuTexFilter(GU_LINEAR,GU_LINEAR);
		//sceGuTexScale(1.0f,1.0f);
		//sceGuTexOffset(0.0f,0.0f);
		//sceGuAmbientColor(0xff7f7f7f);

		// draw cube

		sceGuColor(0xffffff);
		sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D,
				idx_count, idx_buf, vert_buf);
		

		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("v: %d", vert_count);
		pspDebugScreenSetXY(0, 1);
		pspDebugScreenPrintf("i: %d", idx_count);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;
	}

	sceGuTerm();

	// Release buffers
	free(vert_buf);
	free(idx_buf);

	sceKernelExitGame();
	return 0;
}
Пример #11
0
//--------------------------------------------------------------------
// Función:    CFade::Update
// Creador:    Nacho (AMD)
// Fecha:      Thursday  14/06/2007  11:56:53
//--------------------------------------------------------------------
void CFade::Update(float dt)
{
	if (m_fFadeTime > 0.0f)
	{
		m_fFadeState += dt;	

		if (m_fFadeState >= m_fFadeTime)
		{
			m_bFadeActive = false;
		}

		float alpha = 0.0f;

		///--- fade in
		if (m_bFadeIn)
		{
			alpha = 255.0f - ((m_fFadeState * 255.0f) / m_fFadeTime);
		}
		///--- fade out
		else
		{
			alpha = ((m_fFadeState * 255.0f) / m_fFadeTime);
		}

		alpha = MAT_Clampf(alpha, 0.0f, m_fTarget);		

		if (alpha > 0.0f)
		{		
			VERT* v = (VERT*)sceGuGetMemory(sizeof(VERT) * 2);
			
			VERT* v0 = &v[0];
			VERT* v1 = &v[1];

			int alpha_integer = (((int)alpha) & 0xFF) << 24;

			v0->x = -1.0f;
			v0->y = -1.0f;
			v0->z = 0.0f;
			
			v1->x = 481.0f;
			v1->y = 273.0f;
			v1->z = 0.0f;	

			sceGuColor((m_iColor & 0x00ffffff) | alpha_integer);

			sceGuDisable(GU_TEXTURE_2D);

			sceGuDisable(GU_DEPTH_TEST);		

			sceGuEnable(GU_BLEND);
			sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
			
			sceGumDrawArray(GU_SPRITES, GU_VERTEX_32BITF | GU_TRANSFORM_2D, 2, 0, v);		

			sceGuEnable(GU_DEPTH_TEST);
			
			sceGuDisable(GU_BLEND);

			sceGuEnable(GU_TEXTURE_2D);
			sceGuColor(0xffffffff);
		}
	}
}
/**
  * Created: 01/03/2011
  * Renders a cube to the demo space according to it's game location
  */
void FrontEnd::RenderCube(float x, float y, float z)
{
#ifdef PC
	/* Set the colour */
	_pd3dDevice->SetRenderState( D3DRS_AMBIENT, IntToD3DColor( _fgColour ) );

	D3DXMATRIXA16 rotation;
	D3DXMATRIXA16 world;
	D3DXMATRIXA16 temp;

	D3DXMatrixIdentity( &rotation );
	D3DXMatrixIdentity( &world );

	/* Create the rotation matrix */
	D3DXMatrixIdentity( &temp );
	D3DXMatrixRotationX( &temp, _rotation.y );
	rotation *= temp;
	D3DXMatrixRotationY( &temp, _rotation.z );
	rotation *= temp;
	D3DXMatrixRotationZ( &temp, _rotation.x );
	rotation *= temp;
	
	/* Translate the cube */
	D3DXMatrixIdentity( &temp );
	D3DXMatrixTranslation( &temp, -x, -y, z );
	world *= temp;

	/* Rotate the cube */
	D3DXMatrixIdentity( &temp );
	D3DXMatrixTranslation( &temp, _view.x, _view.y, -_view.z );
	world *= temp;
	world *= rotation;
	D3DXMatrixIdentity( &temp );
	D3DXMatrixTranslation( &temp, -_view.x, -_view.y, _view.z );
	world *= temp;

	/* Set the world matrix */
	_pd3dDevice->SetTransform( D3DTS_WORLD, &world );

	/* Render the cube */
	_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 36 );
#else
	ScePspFVector3 vec; 

	/* Create the rotation matrix */
	ScePspFMatrix4 rotation;
	ScePspFVector3 rotator;
	rotator.x = _rotation.x;
	rotator.y = _rotation.y;
	rotator.z = _rotation.z;
	sceGumPushMatrix();
	sceGumRotateXYZ( &rotator );
	sceGumStoreMatrix( &rotation);
	sceGumPopMatrix();

	/* Push a new matrix */
	sceGumPushMatrix();
	//printf("FrontEnd::RenderCube() started\n");

	/* Rotate the cube's translation */
	ScePspFVector3 view;
	view.x = -_view.x;
	view.y = -_view.y;
	view.z = -_view.z;
	sceGumTranslate( &view );
	sceGumRotateXYZ( &rotator );
	view.x = -view.x;
	view.y = -view.y;
	view.z = -view.z;
	sceGumTranslate( &view );

	vec.x = (float)-x;
	vec.y = (float)-y;
	vec.z = (float)-z;
	sceGumTranslate( &vec );
	
	/* Set the colour */
	sceGuColor( _fgColour );

	/* Render the cube */
	sceGumDrawArray(SCEGU_PRIM_TRIANGLES, SCEGU_VERTEX_FLOAT, 36, 0, Cube);

	/* Pop the matrix */
	sceGumPopMatrix();
#endif
}
Пример #13
0
//-------------------------------------------------------------------------------------------------
// displays a frame of the model between startFrame and endFrame with an interpolation percent
void JMD2Model::Render()
{

	CheckNextState();

	Vector3D *pointList;			// current frame vertices
	Vector3D *nextPointList;		// next frame vertices
	int i;						
	float x1, y1, z1;				// current frame point values
	float x2, y2, z2;				// next frame point values

	Vector3D vertex[3];	

	if (mModel == NULL)
		return;
	
	pointList = &mModel->pointList[mModel->numPoints*mModel->currentFrame];
	nextPointList = &mModel->pointList[mModel->numPoints*mModel->nextFrame];
	
	mRenderer->BindTexture(mModel->modelTex);

#if !defined (PSP)

#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
        // FIXME
#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
#else
        glBegin(GL_TRIANGLES);
#endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

        for (i = 0; i < mModel->numTriangles; i++)
	{
		// get first points of each frame
		x1 = pointList[mModel->triIndex[i].meshIndex[0]].x;
		y1 = pointList[mModel->triIndex[i].meshIndex[0]].y;
		z1 = pointList[mModel->triIndex[i].meshIndex[0]].z;
		x2 = nextPointList[mModel->triIndex[i].meshIndex[0]].x;
		y2 = nextPointList[mModel->triIndex[i].meshIndex[0]].y;
		z2 = nextPointList[mModel->triIndex[i].meshIndex[0]].z;

		// store first interpolated vertex of triangle
		vertex[0].x = x1 + mModel->interpol * (x2 - x1);
		vertex[0].y = y1 + mModel->interpol * (y2 - y1);
		vertex[0].z = z1 + mModel->interpol * (z2 - z1);

		// get second points of each frame
		x1 = pointList[mModel->triIndex[i].meshIndex[2]].x;
		y1 = pointList[mModel->triIndex[i].meshIndex[2]].y;
		z1 = pointList[mModel->triIndex[i].meshIndex[2]].z;
		x2 = nextPointList[mModel->triIndex[i].meshIndex[2]].x;
		y2 = nextPointList[mModel->triIndex[i].meshIndex[2]].y;
		z2 = nextPointList[mModel->triIndex[i].meshIndex[2]].z;

		// store second interpolated vertex of triangle
		vertex[2].x = x1 + mModel->interpol * (x2 - x1);
		vertex[2].y = y1 + mModel->interpol * (y2 - y1);
		vertex[2].z = z1 + mModel->interpol * (z2 - z1);	

		// get third points of each frame
		x1 = pointList[mModel->triIndex[i].meshIndex[1]].x;
		y1 = pointList[mModel->triIndex[i].meshIndex[1]].y;
		z1 = pointList[mModel->triIndex[i].meshIndex[1]].z;
		x2 = nextPointList[mModel->triIndex[i].meshIndex[1]].x;
		y2 = nextPointList[mModel->triIndex[i].meshIndex[1]].y;
		z2 = nextPointList[mModel->triIndex[i].meshIndex[1]].z;

		// store third interpolated vertex of triangle
		vertex[1].x = x1 + mModel->interpol * (x2 - x1);
		vertex[1].y = y1 + mModel->interpol * (y2 - y1);
		vertex[1].z = z1 + mModel->interpol * (z2 - z1);

		// calculate the normal of the triangle
		//CalculateNormal(vertex[0].v, vertex[2].v, vertex[1].v);

		// render properly textured triangle

#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
        // FIXME
#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
                float vertex_data[]={
                vertex[0].x, vertex[0].y, vertex[0].z,
                vertex[2].x, vertex[2].y, vertex[2].z,
                vertex[1].x, vertex[1].y, vertex[1].z,
                };
                float texcoord_data[] = {
                    mModel->st[mModel->triIndex[i].stIndex[0]].s,
                    mModel->st[mModel->triIndex[i].stIndex[0]].t,
                    mModel->st[mModel->triIndex[i].stIndex[2]].s,
                    mModel->st[mModel->triIndex[i].stIndex[2]].t,
                    mModel->st[mModel->triIndex[i].stIndex[1]].s,
                    mModel->st[mModel->triIndex[i].stIndex[1]].t,
                };

                glVertexPointer(3,GL_FLOAT,0,vertex_data);
                glTexCoordPointer(2,GL_FLOAT,0,texcoord_data);
#else
                glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[0]].s,
                        mModel->st[mModel->triIndex[i].stIndex[0]].t);
                glVertex3fv(vertex[0].v);

                glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[2]].s ,
                        mModel->st[mModel->triIndex[i].stIndex[2]].t);
                glVertex3fv(vertex[2].v);

                glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[1]].s,
                        mModel->st[mModel->triIndex[i].stIndex[1]].t);
                glVertex3fv(vertex[1].v);
#endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

        }
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)
        // FIXME
#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
        glDrawArrays(GL_TRIANGLES,0,3); // seems suspicious to put that here, should probably be in the loop
#else
        glEnd();
#endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

#else

	PSPVertex3D* vertices = (PSPVertex3D*) sceGuGetMemory(mModel->numTriangles * 3 * sizeof(PSPVertex3D));

	int n = 0;
		for (i = 0; i < mModel->numTriangles; i++)
		{
			// get first points of each frame
			x1 = pointList[mModel->triIndex[i].meshIndex[0]].x;
			y1 = pointList[mModel->triIndex[i].meshIndex[0]].y;
			z1 = pointList[mModel->triIndex[i].meshIndex[0]].z;
			x2 = nextPointList[mModel->triIndex[i].meshIndex[0]].x;
			y2 = nextPointList[mModel->triIndex[i].meshIndex[0]].y;
			z2 = nextPointList[mModel->triIndex[i].meshIndex[0]].z;

			// store first interpolated vertex of triangle
			vertex[0].x = x1 + mModel->interpol * (x2 - x1);
			vertex[0].y = y1 + mModel->interpol * (y2 - y1);
			vertex[0].z = z1 + mModel->interpol * (z2 - z1);
		
			// get second points of each frame
			x1 = pointList[mModel->triIndex[i].meshIndex[2]].x;
			y1 = pointList[mModel->triIndex[i].meshIndex[2]].y;
			z1 = pointList[mModel->triIndex[i].meshIndex[2]].z;
			x2 = nextPointList[mModel->triIndex[i].meshIndex[2]].x;
			y2 = nextPointList[mModel->triIndex[i].meshIndex[2]].y;
			z2 = nextPointList[mModel->triIndex[i].meshIndex[2]].z;

			// store second interpolated vertex of triangle
			vertex[2].x = x1 + mModel->interpol * (x2 - x1);
			vertex[2].y = y1 + mModel->interpol * (y2 - y1);
			vertex[2].z = z1 + mModel->interpol * (z2 - z1);	
	
			// get third points of each frame
			x1 = pointList[mModel->triIndex[i].meshIndex[1]].x;
			y1 = pointList[mModel->triIndex[i].meshIndex[1]].y;
			z1 = pointList[mModel->triIndex[i].meshIndex[1]].z;
			x2 = nextPointList[mModel->triIndex[i].meshIndex[1]].x;
			y2 = nextPointList[mModel->triIndex[i].meshIndex[1]].y;
			z2 = nextPointList[mModel->triIndex[i].meshIndex[1]].z;

			// store third interpolated vertex of triangle
			vertex[1].x = x1 + mModel->interpol * (x2 - x1);
			vertex[1].y = y1 + mModel->interpol * (y2 - y1);
			vertex[1].z = z1 + mModel->interpol * (z2 - z1);


			//CalculateNormal(&vertices[n].normal,
			//				vertex[0].v,
            //                vertex[2].v,
            //                vertex[1].v);
			
			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[0]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[0]].t;
			
			vertices[n].pos.x = vertex[0].x;
			vertices[n].pos.y = vertex[0].y;
			vertices[n].pos.z = vertex[0].z;
			n++;

			//vertices[n].normal.x = vertices[n-1].normal.x;
			//vertices[n].normal.y = vertices[n-1].normal.y;
			//vertices[n].normal.z = vertices[n-1].normal.z;

			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[2]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[2]].t;

			vertices[n].pos.x = vertex[2].x;
			vertices[n].pos.y = vertex[2].y;
			vertices[n].pos.z = vertex[2].z;
			n++;
            
			
			//vertices[n].normal.x = vertices[n-1].normal.x;
			//vertices[n].normal.y = vertices[n-1].normal.y;
			//vertices[n].normal.z = vertices[n-1].normal.z;
			
			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[1]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[1]].t;

			vertices[n].pos.x = vertex[1].x;
			vertices[n].pos.y = vertex[1].y;
			vertices[n].pos.z = vertex[1].z;
			n++;

		}

	sceGuColor(0xff000000);
	sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,mModel->numTriangles*3,0,vertices);

#endif

//	mModel->interpol += percent;	// increase percentage of interpolation between frames
}
Пример #14
0
//-------------------------------------------------------------------------------------------------
// render a single frame of a MD2 model
void JMD2Model::Render(int frameNum)
{
	Vector3D *pointList;
	int i;

    // create a pointer to the frame we want to show
    pointList = &mModel->pointList[mModel->numPoints * frameNum];

	// set the texture
	mRenderer->BindTexture(mModel->modelTex);


#if !defined (PSP)

	// display the textured model with proper lighting normals
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

#else
        glBegin(GL_TRIANGLES);
#endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

	for(i = 0; i < mModel->numTriangles; i++)
	{
		CalculateNormal(pointList[mModel->triIndex[i].meshIndex[0]].v,
			pointList[mModel->triIndex[i].meshIndex[2]].v,
			pointList[mModel->triIndex[i].meshIndex[1]].v);

#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1)|| (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
                float vertex_data[]={
                pointList[mModel->triIndex[i].meshIndex[0]].x, pointList[mModel->triIndex[i].meshIndex[0]].y, pointList[mModel->triIndex[i].meshIndex[0]].z,
                pointList[mModel->triIndex[i].meshIndex[2]].x, pointList[mModel->triIndex[i].meshIndex[2]].y, pointList[mModel->triIndex[i].meshIndex[2]].z,
                pointList[mModel->triIndex[i].meshIndex[1]].x, pointList[mModel->triIndex[i].meshIndex[1]].y, pointList[mModel->triIndex[i].meshIndex[1]].z,
                };
                float texcoord_data[] = {
                    mModel->st[mModel->triIndex[i].stIndex[0]].s,
                    mModel->st[mModel->triIndex[i].stIndex[0]].t,
                    mModel->st[mModel->triIndex[i].stIndex[2]].s,
                    mModel->st[mModel->triIndex[i].stIndex[2]].t,
                    mModel->st[mModel->triIndex[i].stIndex[1]].s,
                    mModel->st[mModel->triIndex[i].stIndex[1]].t,
                };

                glVertexPointer(3,GL_FLOAT,0,vertex_data);
                glTexCoordPointer(2,GL_FLOAT,0,texcoord_data);

#else
                glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[0]].s,
			mModel->st[mModel->triIndex[i].stIndex[0]].t);
		glVertex3fv(pointList[mModel->triIndex[i].meshIndex[0]].v);

		glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[2]].s ,
			mModel->st[mModel->triIndex[i].stIndex[2]].t);
		glVertex3fv(pointList[mModel->triIndex[i].meshIndex[2]].v);

		glTexCoord2f(mModel->st[mModel->triIndex[i].stIndex[1]].s,
			mModel->st[mModel->triIndex[i].stIndex[1]].t);
		glVertex3fv(pointList[mModel->triIndex[i].meshIndex[1]].v);
#endif //#if (!defined GL_ES_VERSION_2_0) && (!defined GL_VERSION_2_0)
        }
#if (defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)

#elif (defined GL_ES_VERSION_1_1) || (defined GL_VERSION_1_1) || (defined GL_VERSION_ES_CM_1_1) || (defined GL_OES_VERSION_1_1)
        glDrawArrays(GL_TRIANGLES,0,3); // seems suspicious to put that here, should probably be in the loop
#else
        glEnd();
#endif //(defined GL_ES_VERSION_2_0) || (defined GL_VERSION_2_0)


#else

	PSPVertex3D* vertices = (PSPVertex3D*) sceGuGetMemory(mModel->numTriangles * 3 * sizeof(PSPVertex3D));

		int n = 0;
		for(i = 0; i < mModel->numTriangles; i++)
        {
			//CalculateNormal(&vertices[n].normal,
			//				pointList[mModel->triIndex[i].meshIndex[0]].v,
            //                pointList[mModel->triIndex[i].meshIndex[2]].v,
            //                pointList[mModel->triIndex[i].meshIndex[1]].v);
			
			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[0]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[0]].t;
			
			vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[0]].x;
			vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[0]].y;
			vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[0]].z;
			n++;

			//vertices[n].normal.x = vertices[n-1].normal.x;
			//vertices[n].normal.y = vertices[n-1].normal.y;
			//vertices[n].normal.z = vertices[n-1].normal.z;

			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[2]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[2]].t;

			vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[2]].x;
			vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[2]].y;
			vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[2]].z;
			n++;
            
			
			//vertices[n].normal.x = vertices[n-1].normal.x;
			//vertices[n].normal.y = vertices[n-1].normal.y;
			//vertices[n].normal.z = vertices[n-1].normal.z;
			
			vertices[n].texture.x = mModel->st[mModel->triIndex[i].stIndex[1]].s;
			vertices[n].texture.y = mModel->st[mModel->triIndex[i].stIndex[1]].t;

			vertices[n].pos.x = pointList[mModel->triIndex[i].meshIndex[1]].x;
			vertices[n].pos.y = pointList[mModel->triIndex[i].meshIndex[1]].y;
			vertices[n].pos.z = pointList[mModel->triIndex[i].meshIndex[1]].z;
			n++;

            
        }

		
		sceGuColor(0xff000000);
		sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,mModel->numTriangles*3,0,vertices);
		

#endif

}
Пример #15
0
int main(int argc, char* argv[]) {
	/* Setup Homebutton Callbacks */
	setupCallbacks();

	sceKernelDcacheWritebackAll();

	// setup GU

	SceCtrlData pad;
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuColor(0xffffffff);
	sceGuShadeModel(GU_SMOOTH);
//	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexImage(0, 16, 16, 16, texture);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuTexEnvColor(0xffffff);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexScale(1.0f, 1.0f);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuAmbientColor(0xffffffff);

	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	
	void* buffer = 0;

	pspDebugScreenInit();

	unsigned int old = 0;
	unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS;

	int tex = 1;

	while(running()) {
		sceGuStart(GU_DIRECT,list);

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(90.0f, 480.0/272.0f, 0.1f, 10.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();
		ScePspFVector3 trans = { 0.0f, 0.0f, -1.8f };
		sceGumTranslate(&trans);
		
		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();

		sceGumDrawArray(objects[o].prim, objects[o].flags, objects[o].count, 0, objects[o].data);

		sceCtrlReadBufferPositive(&pad, 1);
		if(old != pad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				o++;
				if(o >= sizeof(objects) / sizeof(Object)) {
					o = 0;
				}
			}
			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				tex = !tex;
				if(tex) {
					sceGuEnable(GU_TEXTURE_2D);
				} else {
					sceGuDisable(GU_TEXTURE_2D);
				}
			}
		}
		old = pad.Buttons;

		sceGuFinish();
		sceGuSync(0,0);

		pspDebugScreenSetOffset((int)buffer);
		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("Mode: %s (X to change)    Texture: %s (O to change)", objects[o].text, tex ? "on " : "off");

		sceDisplayWaitVblankStart();
		buffer = sceGuSwapBuffers();
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Пример #16
0
void VertexBufferRenderer::render(Mesh &obj, int stage)
{
	#define BUFFER_OFFSET(i) ((char *)NULL + (i))
	
	// mat_reflist_i -- used to iterate through the material mat_reflist of the object
	std::map<Material *, map< unsigned int, std::map<cvrIndex, va_ref, ltindex>, ltuint > >::iterator obj_matref_i;
	// segment iterator
	map< unsigned int, std::map<cvrIndex, va_ref, ltindex>, ltuint >::iterator mat_segment_type_i;
	// mat_facetypelist_i -- used to iterate through the set of face types which belong to the mat_reflist_i map
	std::map<cvrIndex, va_ref, ltindex>::iterator matref_type_i;
	// mat_facetypelist_i -- used to iterate through the set of face types which belong to the mat_reflist_i map
	std::map<cvrIndex, va_ref, ltindex>::reverse_iterator matref_last_i;
	
	bool has_trans = false;
	unsigned int element_index = 0;
	unsigned int shadow_count = 0;
	Material *mat;
	set<Light *>::iterator light_i;

	if (!obj.buffer_state) element_index = (unsigned long)obj.cache_data.cache_element;
	
	// Reset mutitexture state
	Texture::clearAllTextures();
	
	// special lights which have been bound that contribute to texturing 
	unsigned int tex_offset = Texture::tex_use+1;

	
//#if !defined(OPENGL_ES) && !defined(ARCH_DC)
	// store attribs
//	glPushAttrib(GL_ENABLE_BIT);
//#endif
#ifndef ARCH_PSP	
	VertexBufferRenderer::setup(obj,stage != SHADER_STAGE_NOMATERIAL && stage != SHADER_STAGE_NOTEXTURE);
#else
	sceGuSignal(GU_BEHAVIOR_SUSPEND, 1);
#endif
	
	// iterate through the list of materials with face reference sets 
	for (obj_matref_i = obj.mat_cache_data.begin(); obj_matref_i != obj.mat_cache_data.end(); obj_matref_i++)
	{
		// (*obj_matref_i).first // material reference

		bool mat_use = false;
		
		mat = (*obj_matref_i).first;
		
		// store material transparency state
		bool has_mask = mat->hasMask();	
		
		unsigned int segLimit = (*obj_matref_i).second.size();
		unsigned int segIndex = 0;
		unsigned int segRun = 0;
		unsigned int segRangeIndex = 0;
		unsigned int segRangeType = 0;
		unsigned int segElementIndex = 0;
		
		bool fault = false;
		bool usefault = (obj.numSegments != 1);			// assume objects with one segment don't need segment fault tests
		
		//true; //((*mat_segment_type_i).second.size()==1 && (*obj_matref_i).second.size()!=1);
		
		va_ref segRange;
		
		segRange.range_min = obj.cache_data.vertex_count;
		segRange.range_max = 0;
		segRange.element_count = 0;	
		segRangeIndex = element_index;		
		
		for (mat_segment_type_i = (*obj_matref_i).second.begin(); mat_segment_type_i != (*obj_matref_i).second.end(); mat_segment_type_i++)
		{
			segIndex++;

			if (stage == SHADER_STAGE_TRANSPARENT) // we're in the transparency stage and opaque isn't needed, we have to increase the element count though 
			{
				if (!has_mask)
				{
					element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);
					segIndex++;
					continue;
				}
			}
			else if (stage == SHADER_STAGE_NULL || stage == SHADER_STAGE_OPAQUE || stage == SHADER_STAGE_NOTEXTURE)
			{
				if (has_mask) // vice-versa
				{
					element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);
					has_trans = true;
					segIndex++;
					continue;
				}				
			}
						
			if (obj.numSegments >= 1 && obj.segmentMask)
			{
				if (obj.segmentMask->isSet((*mat_segment_type_i).first) == false)
				{
					fault = true;
				}
			}
			
			segRangeType = (*(*mat_segment_type_i).second.begin()).first;
			
			if (fault) 
			{
				element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);				
				
				if (!usefault) 
				{
					fault=false;
					continue;
				}
			}
			else
			{				
				segRun++;
							
				segRange.element_count += (*(*mat_segment_type_i).second.begin()).second.group_size;
				
				if ((*(*mat_segment_type_i).second.begin()).second.range_min < segRange.range_min)
				{
					segRange.range_min = (*(*mat_segment_type_i).second.begin()).second.range_min;
				}
				
				if ((*(*mat_segment_type_i).second.begin()).second.range_max > segRange.range_max)
				{
					segRange.range_max = (*(*mat_segment_type_i).second.begin()).second.range_max;
				}				
				
				
				if (usefault) if (segIndex < segLimit) 
				{
					element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);
					continue;
				}
				
			}
			
			
		//**** Material Initialization *****/
		
		if (!mat_use)
		{
			mat_use = true;
			
			// if we're in the opaque shader stage then we need to discard the transparent materials and vice versa 
			// transparent shader stage 
			if (stage == SHADER_STAGE_TRANSPARENT)
			{
				// alpha mask
				if (has_mask)
				{
					if (stage == SHADER_STAGE_NOTEXTURE)	// no texture 
					{
						mat->surfaceSetup();
					}
					else // full material 
					{
						mat->use();
					}
				}
			}
			else if (stage == SHADER_STAGE_NULL || stage == SHADER_STAGE_OPAQUE || stage == SHADER_STAGE_NOTEXTURE)
			{
				if (!has_mask) // we're in the transparency stage and opaque isn't needed, we have to increase the element count though 
				{
					// no texturing, just use the surface setup for colors and transparencies 
					if (stage == SHADER_STAGE_NOTEXTURE)
					{
						mat->surfaceSetup();
					}
					else // else full material 
					{
						mat->use();
					}
					
				}
			}

#ifndef ARCH_PSP
			// the active texcoord states change on a per material basis 
			if (stage != SHADER_STAGE_NOMATERIAL && stage != SHADER_STAGE_NOTEXTURE) for (unsigned int m = 0; m < obj.cache_data.max_uvs; m++)
			{
				Texture::setTexture(tex_offset+m);
				glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			}
#endif			
			
#ifndef ARCH_PSP
			if (obj.cache_data.max_uvs == 0)
			{
				Texture::setTexture(tex_offset);
				glDisableClientState(GL_TEXTURE_COORD_ARRAY);
			}
#endif			

			if (stage == SHADER_STAGE_TRANSPARENT) 
			{
				mat->setupAlpha();
			}
			else if (mat->alpha_mask)
			{
				mat->setupAlpha();
			}
		}			
			
			
		shadow_count = 0;
		
		int numLights = 0;

#ifdef ARCH_PSP
//			sceGuDepthFunc( GU_GEQUAL );
#else
			glDepthFunc(GL_LEQUAL);
#endif
			
		numLights = lights?(*lights).size():0;
			
		if (numLights)
		{
			light_i = lights->begin();
		}
		
		//				if (obj.tangent_binormal_state)
		//				{
		//					GLShader::defaultShader.setShaderAttrib("binormal",(unsigned int)BUFFER_OFFSET(obj.binormalCacheOffset));
		//					GLShader::defaultShader.setShaderAttrib("tangent",(unsigned int)BUFFER_OFFSET(obj.binormalCacheOffset));
		//				}
		
		//				printf("vb numLights %d\n",(*lights).size());
			
#if !defined(OPENGL_ES) && !defined(ARCH_DC)  && !defined(ARCH_PSP)// shader light loop header
			
		RGB global_amb_temp = Light::global_ambient;
			
		for (int shaderCount = 0; shaderCount <= numLights; shaderCount++)
		{
			unsigned long shadowMask = 0;

			if (shaderCount < numLights) 
			{
				if ((mat->shader_mask & SHADER_VARIANT_LIGHTMAP) && shaderCount > 0) mat->shader_mask -= SHADER_VARIANT_LIGHTMAP;
				
				if (shaderCount > 0)
				{
					glEnable(GL_BLEND);
					
					glDepthMask(false);
					Light::setGlobalAmbient(RGB(0,0,0));
					
					if (stage == SHADER_STAGE_TRANSPARENT) 
					{
						glEnable(GL_BLEND);
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
						glDepthMask(false);
					}
					else 
					{
						glBlendFunc(GL_ONE, GL_ONE);
					}
				}
				else
				{
					glDepthMask(true);
					
					if (stage == SHADER_STAGE_TRANSPARENT) 
					{
						glEnable(GL_BLEND);
						glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
						glDepthMask(false);
					}
					else 
					{
						glDisable(GL_BLEND);
					}
				}
				
				if ((*light_i)->has_shadow)
				{
					switch ((*light_i)->type)
					{
						case LIGHT_SPOT:
							glActiveTexture(GL_TEXTURE0+(*light_i)->shadow_mtex);
							glClientActiveTexture(GL_TEXTURE0+(*light_i)->shadow_mtex);
							GLShader::defaultShader.setShaderValue("shadowMap0", (*light_i)->shadow_mtex); 
							
							glEnable(GL_TEXTURE_2D);
							glBindTexture(GL_TEXTURE_2D, (*light_i)->shadowmapTex);
							
							switch (shadow_count)
							{
								case 0: shadowMask |= SHADER_VARIANT_SHADOW0; break;
								case 1: shadowMask |= SHADER_VARIANT_SHADOW1; break;
								case 2: shadowMask |= SHADER_VARIANT_SHADOW2; break;
								case 3: shadowMask |= SHADER_VARIANT_SHADOW3; break;
								case 4: shadowMask |= SHADER_VARIANT_SHADOW4; break;
								case 5: shadowMask |= SHADER_VARIANT_SHADOW5; break;
								case 6: shadowMask |= SHADER_VARIANT_SHADOW6; break;
								case 7: shadowMask |= SHADER_VARIANT_SHADOW7; break;
							}
							
							shadow_count++;
						break;
						case LIGHT_AREA:
							AreaLight *aLight = (AreaLight*)(*light_i);
							
							glActiveTexture(GL_TEXTURE0+aLight->oLight[0].shadow_mtex);
							glClientActiveTexture(GL_TEXTURE0+aLight->oLight[0].shadow_mtex);
							GLShader::defaultShader.setShaderValue("shadowMap0", aLight->oLight[0].shadow_mtex); 

							glEnable(GL_TEXTURE_2D);
							glBindTexture(GL_TEXTURE_2D, aLight->oLight[0].shadowmapTex);

							
							glActiveTexture(GL_TEXTURE0+aLight->oLight[1].shadow_mtex);
							glClientActiveTexture(GL_TEXTURE0+aLight->oLight[1].shadow_mtex);
							GLShader::defaultShader.setShaderValue("shadowMap1", aLight->oLight[1].shadow_mtex); 

							glEnable(GL_TEXTURE_2D);
							glBindTexture(GL_TEXTURE_2D, aLight->oLight[1].shadowmapTex);

							
							glActiveTexture(GL_TEXTURE0+aLight->oLight[2].shadow_mtex);
							glClientActiveTexture(GL_TEXTURE0+aLight->oLight[2].shadow_mtex);
							GLShader::defaultShader.setShaderValue("shadowMap2", aLight->oLight[2].shadow_mtex); 
							
							glEnable(GL_TEXTURE_2D);
							glBindTexture(GL_TEXTURE_2D, aLight->oLight[2].shadowmapTex);

							
							for (int n = 0; n < 3; n++)
							{
								switch (shadow_count)
								{
									case 0: shadowMask |= SHADER_VARIANT_SHADOW0; break;
									case 1: shadowMask |= SHADER_VARIANT_SHADOW1; break;
									case 2: shadowMask |= SHADER_VARIANT_SHADOW2; break;
									case 3: shadowMask |= SHADER_VARIANT_SHADOW3; break;
									case 4: shadowMask |= SHADER_VARIANT_SHADOW4; break;
									case 5: shadowMask |= SHADER_VARIANT_SHADOW5; break;
									case 6: shadowMask |= SHADER_VARIANT_SHADOW6; break;
									case 7: shadowMask |= SHADER_VARIANT_SHADOW7; break;
								}
								
								shadow_count++;							
							}
							
						break;
					}
				}
				
				
				if (!GLShader::defaultShader.activateLight((*light_i)->type,shaderCount,(*light_i)->hasShadow()?(mat->shader_mask|shadowMask):mat->shader_mask,false)) 
				{
					light_i++;
					continue;
				}
				
				light_i++;
			}
			else if (!numLights)
			{
				if (shaderCount == 0) 
				{
					glDisable(GL_BLEND);
				}
				else 
				{
					glEnable(GL_BLEND);
					glBlendFunc(GL_ZERO, GL_SRC_COLOR);
				}
				
				glDepthMask(true);
				
				if (!GLShader::defaultShader.activateLight(LIGHT_NULL,0,mat->shader_mask,false)) continue;
			}
			else
			{
				glEnable(GL_BLEND);
				
				if (mat->shader_mask & SHADER_VARIANT_LIGHTMAP) 
				{
					glBlendFunc(GL_ONE, GL_ONE);
					
					if (!GLShader::defaultShader.activateLight(LIGHT_NULL,0,mat->shader_mask,false)) break;
				}
				else
				{
					Light::setGlobalAmbient(global_amb_temp);

					break;
				}
			}
			
#endif // end shader light loop header
			
			

			if (!usefault)	// no fault segments needed, just render all primitives
			{			
				segElementIndex = element_index;

				for (matref_type_i = (*mat_segment_type_i).second.begin(); matref_type_i != (*mat_segment_type_i).second.end(); matref_type_i++)
				{				
					if (!(*matref_type_i).second.element_count) continue;

#ifndef ARCH_PSP					
					switch((*matref_type_i).first)
					{
						case 1: glDrawRangeElements(GL_POINTS,(*matref_type_i).second.range_min,(*matref_type_i).second.range_max,(*matref_type_i).second.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segElementIndex));
						break;
						case 2:	glDrawRangeElements(GL_LINES,(*matref_type_i).second.range_min,(*matref_type_i).second.range_max,(*matref_type_i).second.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segElementIndex));
						break;
						case 3:	glDrawRangeElements(GL_TRIANGLES,(*matref_type_i).second.range_min,(*matref_type_i).second.range_max,(*matref_type_i).second.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segElementIndex));
						break;
#if !defined(OPENGL_ES)
						case 4:	glDrawRangeElements(GL_QUADS,(*matref_type_i).second.range_min,(*matref_type_i).second.range_max,(*matref_type_i).second.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segElementIndex));
						break;
#endif
					}
#else
//					sceGuDisable(GU_TEXTURE_2D);
//					sceGuDisable(GU_LIGHTING);
//					sceGuColor(0xff66ccff);
					
					unsigned int vtype = GU_INDEX_16BIT|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D;
					
					if (obj.cache_data.max_uvs) vtype |= GU_TEXTURE_32BITF;
					if (obj.hasColorMap) vtype |= GU_COLOR_8888;
					
					unsigned int ptype = 0;				
					
					switch ((*matref_type_i).first)
					{
						case 1: ptype = GU_POINTS; break;
						case 2: ptype = GU_LINES; break;
						case 3: ptype = GU_TRIANGLES; break;
					}

					
					sceGumDrawArray( ptype, vtype, (*matref_type_i).second.element_count, BUFFER_OFFSET(segElementIndex), obj.cache_data.data);

					int matLayerCount = mat->getLayerSize();
					for (unsigned int matLayer = 1; matLayer < matLayerCount; matLayer++)
					{
						mat->texSetup(matLayer);
						sceGumDrawArray( ptype, vtype, (*matref_type_i).second.element_count, BUFFER_OFFSET(segElementIndex), obj.cache_data.data);
					}
						
					
#endif					
					segElementIndex += (*matref_type_i).second.element_count*sizeof(cvrElement);
				}
			}
			else	// use accumulated cache fault runs
			{
#ifndef ARCH_PSP
				switch (segRangeType)
				{
					case 1:
						glDrawRangeElements(GL_POINTS,segRange.range_min,segRange.range_max,segRange.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segRangeIndex));
						break;
					case 2:
						glDrawRangeElements(GL_LINES,segRange.range_min,segRange.range_max,segRange.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segRangeIndex));
						break;
					case 3:
						glDrawRangeElements(GL_TRIANGLES,segRange.range_min,segRange.range_max,segRange.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segRangeIndex));
						break;
#if !defined(OPENGL_ES)
					case 4:
						glDrawRangeElements(GL_QUADS,segRange.range_min,segRange.range_max,segRange.element_count,GL_UNSIGNED_INT,BUFFER_OFFSET(segRangeIndex));
						break;
#endif					
				}
#else
				unsigned int vtype = GU_INDEX_16BIT|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D;
				
				if (obj.cache_data.max_uvs) vtype |= GU_TEXTURE_32BITF;
				if (obj.hasColorMap) vtype |= GU_COLOR_8888;

				unsigned int ptype = 0;				
				switch (segRangeType)
				{
					case 1: ptype = GU_POINTS; break;
					case 2: ptype = GU_LINES; break;
					case 3: ptype = GU_TRIANGLES; break;
				}
				
				if (ptype) sceGumDrawArray( ptype, vtype, segRange.element_count, BUFFER_OFFSET(segRangeIndex), obj.cache_data.data);
#endif
			}	

#if !defined(OPENGL_ES) && !defined(ARCH_DC) && !defined(ARCH_PSP)
			// end shader light loop
		}
#endif			
			if (!usefault) element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);
			
			if (usefault)	// reset fault line
			{
				segRange.range_min = obj.cache_data.vertex_count;
				segRange.range_max = 0;
				segRange.element_count = 0;	
				
				segRun = 0;
				if (!fault) element_index += (*(*mat_segment_type_i).second.begin()).second.group_size*sizeof(cvrElement);
				fault = false;
				segRangeIndex = element_index;
				
			}

		}

			
	}

	
	// clear the textures used in this material 
	if (stage != SHADER_STAGE_NOMATERIAL && stage != SHADER_STAGE_NOTEXTURE)
	{
		Texture::clearAllTextures();
	}
		
	// call the transparency stage if necessary 
	if (stage == SHADER_STAGE_NULL && has_trans) render(obj,SHADER_STAGE_TRANSPARENT);	
};