Ejemplo n.º 1
0
void tiny3d_ClearSurface(u32 color, clear_flags flags, u32 rsx_offset, u32 width, u32 height, u32 stride, u32 format)
{

    flag_vertex |= VERTEX_LOCK;

    render_target.target = 1;
    render_target.w = width;
    render_target.p = stride;
    render_target.h = height;


    if(flags & TINY3D_CLEAR_COLOR) {

        tiny3d_Project2D();

        tiny3d_SetProjectionMatrix(&matrix_ident);
        tiny3d_SetMatrixModelView(&matrix_ident);
        
        internal_reality_ZControl(context, 0, 1, 1); // disable viewport culling
 
        internal_reality_DepthTestFunc(context, REALITY_ZFUNC_LESSOREQUAL);
        internal_reality_DepthWriteEnable(context, 1);
        internal_reality_DepthTestEnable(context, 1);

        internal_reality_AlphaEnable(context, 0);

        internal_reality_BlendEnable(context, 0);

        internal_reality_Viewport(context, width, height);
        
        int n;

        for(n = 0; n < 8; n++)
            internal_reality_ViewportClip(context, n, width, height);

        setupRenderTarget2(rsx_offset, stride, width, height, format);

        rsxSetClearColor(context, color);

    }

    if(flags & TINY3D_CLEAR_ZBUFFER) {

        rsxSetClearDepthValue(context, 0xffffffff);
    }

    internal_reality_ClearBuffers(context, flags);
}
Ejemplo n.º 2
0
void drawFrame()
{
	u32 i, color = 0;
	Matrix4 viewMatrix,modelViewMatrix;

	//clear screen
	rsxSetClearColor(context, color);
	//rsxSetClearDepthValue(context,0xffff);
	rsxClearSurface(context,GCM_CLEAR_R |
							GCM_CLEAR_G |
							GCM_CLEAR_B |
							GCM_CLEAR_A  //|
							//GCM_CLEAR_S |
							//GCM_CLEAR_Z
							);


	for (i = 0; i < 8; i++) {
		rsxSetViewportClip(context, i, display_width, display_height);
	}

	viewMatrix = Matrix4::lookAt(eye_pos, eye_dir, up_vec);

	//draw background image
	modelViewMatrix = transpose(viewMatrix * modelMatrix);
	setDrawEnv(0);
	setTexture(textureW, textureH, texture_buffer, texture_offset);
	drawMesh(quad, &modelViewMatrix, (float*)&scanline);

	if (showUi) {
		//draw UI
		modelViewMatrix = transpose(viewMatrix * modelMatrixUi);
		setDrawEnv(1);
		setTexture(textureW_ui, textureH_ui, texture_buffer_ui, texture_offset_ui);
		drawMesh(quad_ui, &modelViewMatrix, (float*)&scanlineUi);
	}
}
Ejemplo n.º 3
0
void drawFrame()
{
	u32 i,offset,color = 0;
	Matrix4 rotX,rotY;
	Vector4 objEyePos,objLightPos;
	Matrix4 viewMatrix,modelMatrix,modelMatrixIT,modelViewMatrix;
	Point3 lightPos = Point3(250.0f,150.0f,150.0f);
	f32 globalAmbientColor[3] = {0.1f,0.1f,0.1f};
	f32 lightColor[3] = {0.95f,0.95f,0.95f};
	f32 materialColorDiffuse[3] = {0.5f,0.0f,0.0f};
	f32 materialColorSpecular[3] = {0.7f,0.6f,0.6f};
	f32 shininess = 17.8954f;
	static f32 rot = 0.0f;
	SMeshBuffer *mesh = NULL;

	setTexture();
	setDrawEnv();

	rsxSetClearColor(context,color);
	rsxSetClearDepthValue(context,0xffff);
	rsxClearSurface(context,GCM_CLEAR_R |
							GCM_CLEAR_G |
							GCM_CLEAR_B |
							GCM_CLEAR_A |
							GCM_CLEAR_S |
							GCM_CLEAR_Z);

	rsxZControl(context,0,1,1);

	for(i=0;i<8;i++)
		rsxSetViewportClip(context,i,display_width,display_height);

	viewMatrix = Matrix4::lookAt(eye_pos,eye_dir,up_vec);

	mesh = sphere;
	rotX = Matrix4::rotationX(DEGTORAD(30.0f));
	rotY = Matrix4::rotationY(DEGTORAD(rot));
	modelMatrix = rotX*rotY;
	modelMatrixIT = inverse(modelMatrix);
	modelViewMatrix = transpose(viewMatrix*modelMatrix);

	objEyePos = modelMatrixIT*eye_pos;
	objLightPos = modelMatrixIT*lightPos;

	rsxAddressToOffset(&mesh->vertices[0].pos,&offset);
	rsxBindVertexArrayAttrib(context,vertexPosition_id,offset,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxAddressToOffset(&mesh->vertices[0].nrm,&offset);
	rsxBindVertexArrayAttrib(context,vertexNormal_id,offset,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxAddressToOffset(&mesh->vertices[0].u,&offset);
	rsxBindVertexArrayAttrib(context,vertexTexcoord_id,offset,sizeof(S3DVertex),2,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxLoadVertexProgram(context,vpo,vp_ucode);
	rsxSetVertexProgramParameter(context,vpo,projMatrix_id,(float*)&P);
	rsxSetVertexProgramParameter(context,vpo,modelViewMatrix_id,(float*)&modelViewMatrix);

	rsxSetFragmentProgramParameter(context,fpo,eyePosition_id,(float*)&objEyePos,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,globalAmbient_id,globalAmbientColor,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,lightPosition_id,(float*)&objLightPos,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,lightColor_id,lightColor,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,shininess_id,&shininess,fp_offset);

	rsxSetFragmentProgramParameter(context,fpo,Kd_id,materialColorDiffuse,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,Ks_id,materialColorSpecular,fp_offset);

	rsxLoadFragmentProgramLocation(context,fpo,fp_offset,GCM_LOCATION_RSX);

	rsxSetUserClipPlaneControl(context,GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE);

	rsxAddressToOffset(&mesh->indices[0],&offset);
	rsxDrawIndexArray(context,GCM_TYPE_TRIANGLES,offset,mesh->cnt_indices,GCM_INDEX_TYPE_16B,GCM_LOCATION_RSX);

	mesh = donut;
	rotX = Matrix4::rotationX(DEGTORAD(rot));
	rotY = Matrix4::rotationY(DEGTORAD(30.0f));
	modelMatrix = rotX*rotY;
	modelMatrix.setTranslation(Vector3(3.0f,5.0f,-8.0f));

	modelMatrixIT = inverse(modelMatrix);
	modelViewMatrix = transpose(viewMatrix*modelMatrix);

	objEyePos = modelMatrixIT*eye_pos;
	objLightPos = modelMatrixIT*lightPos;

	rsxAddressToOffset(&mesh->vertices[0].pos,&offset);
	rsxBindVertexArrayAttrib(context,vertexPosition_id,offset,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxAddressToOffset(&mesh->vertices[0].nrm,&offset);
	rsxBindVertexArrayAttrib(context,vertexNormal_id,offset,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxAddressToOffset(&mesh->vertices[0].u,&offset);
	rsxBindVertexArrayAttrib(context,vertexTexcoord_id,offset,sizeof(S3DVertex),2,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);

	rsxLoadVertexProgram(context,vpo,vp_ucode);
	rsxSetVertexProgramParameter(context,vpo,projMatrix_id,(float*)&P);
	rsxSetVertexProgramParameter(context,vpo,modelViewMatrix_id,(float*)&modelViewMatrix);

	rsxSetFragmentProgramParameter(context,fpo,eyePosition_id,(float*)&objEyePos,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,globalAmbient_id,globalAmbientColor,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,lightPosition_id,(float*)&objLightPos,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,lightColor_id,lightColor,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,shininess_id,&shininess,fp_offset);

	rsxSetFragmentProgramParameter(context,fpo,Kd_id,materialColorDiffuse,fp_offset);
	rsxSetFragmentProgramParameter(context,fpo,Ks_id,materialColorSpecular,fp_offset);

	rsxLoadFragmentProgramLocation(context,fpo,fp_offset,GCM_LOCATION_RSX);

	rsxSetUserClipPlaneControl(context,GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE,
									   GCM_USER_CLIP_PLANE_DISABLE);

	rsxAddressToOffset(&mesh->indices[0],&offset);
	rsxDrawIndexArray(context,GCM_TYPE_TRIANGLES,offset,mesh->cnt_indices,GCM_INDEX_TYPE_16B,GCM_LOCATION_RSX);

	rot += 4.0f;
	if(rot>=360.0f) rot = 0.0f;
}
Ejemplo n.º 4
0
void tiny3d_Clear(u32 color, clear_flags flags)
{

    flag_vertex |= VERTEX_LOCK;

    render_target.target = 0;

    if(flags & TINY3D_CLEAR_COLOR) {
       
        tiny3d_Project2D();

        tiny3d_SetProjectionMatrix(&matrix_ident);
        tiny3d_SetMatrixModelView(&matrix_ident);
        
        internal_reality_ZControl(context, 0, 1, 1); // disable viewport culling
 
        internal_reality_DepthTestFunc(context, REALITY_ZFUNC_LESSOREQUAL);
        internal_reality_DepthWriteEnable(context, 1);
        internal_reality_DepthTestEnable(context, 1);

        internal_reality_AlphaEnable(context, 0);

        internal_reality_BlendEnable(context, 0);

        internal_reality_Viewport(context, Video_Resolution.width, Video_Resolution.height);
        
        
      
        int n;
       
        for(n = 0; n < 8; n++)
            {
            
            internal_reality_ViewportClip(context, n, Video_Resolution.width, Video_Resolution.height);
            }

        setupRenderTarget(Video_currentBuffer);

        rsxSetClearColor(context, color);

    }

    if(flags & TINY3D_CLEAR_ZBUFFER) {

        rsxSetClearDepthValue(context, 0xffffffff);
    }

    internal_reality_ClearBuffers(context, flags);

    if((flags & TINY3D_CLEAR_COLOR) && tiny_3d_alarm) {
        
        tiny3d_SetPolygon(TINY3D_QUADS);

        tiny3d_VertexPos(848/2  , 0  ,  65535);
        tiny3d_VertexColor(0xff0000ff);

        tiny3d_VertexPos(847, 0  , 65535);

        tiny3d_VertexPos(847, 511, 65535);

        tiny3d_VertexPos(848/2 , 511, 65535);
        tiny3d_End();

        internal_reality_Viewport(context, Video_Resolution.width*15/16, Video_Resolution.height);
        int n;
        for(n = 0; n < 8; n++)
            internal_reality_ViewportClip(context, n, Video_Resolution.width*15/16, Video_Resolution.height);
        internal_reality_ClearBuffers(context, flags);
    }
}