剪刀测试

剪刀测试是一种有效的优化技术,它允许开发者指定屏幕的特定区域进行更新,避免不必要的刷新,提高应用性能。以下是一个实现剪刀测试的实例代码。
摘要由CSDN通过智能技术生成

剪刀测试可限制屏幕的某一部分更新,其他部分不更新。实例代码如下:

public class MyRenderer implements Renderer {

	
	public MyRenderer(Context ctx) {

	}
	
	@Override
	public void onDrawFrame(GL10 gl) {
		
        // Clear blue window
        gl.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        
        // Now set scissor to smaller red sub region
        gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        gl.glScissor(100, 100, 600, 400);
        gl.glEnable(GL10.GL_SCISSOR_TEST);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        
        // Finally, an even smaller green rectangle
        gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
        gl.glScissor(200, 200, 400, 200);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        
        // Turn scissor back off for next render
        gl.glDisable(GL10.GL_SCISSOR_TEST);

	}

	@Override
	public void onSurfaceChanged(GL10 gl, int w, int h) {
	    float aspectRatio;
	    float windowWidth;
	    float windowHeight;

	    // Prevent a divide by zero
	    if(h == 0)
	        h = 1;
			
	    // Set Viewport to window dimensions
	    gl.glViewport(0, 0, w, h);

	    // Reset coordinate system
	    gl.glMatrixMode(GL10.GL_PROJECTION);
	    gl.glLoadIdentity();

	    // Establish clipping volume (left, right, bottom, top, near, far)
	    aspectRatio = (float)w / (float)h;
	    if (w <= h) 
	        {
	        windowWidth = 100;
	        windowHeight = 100 / aspectRatio;
	        gl.glOrthof(-100.0f, 100.0f, -windowHeight, windowHeight, 1.0f, -1.0f);
	        }
	    else 
	        {
	        windowWidth = 100 * aspectRatio;
	        windowHeight = 100;
	        gl.glOrthof(-windowWidth, windowWidth, -100.0f, 100.0f, 1.0f, -1.0f);
	        }

	    gl.glMatrixMode(GL10.GL_MODELVIEW);
	    gl.glLoadIdentity();
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		// TODO Auto-generated method stub
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);  
		// Enable Smooth Shading, default not really needed.
		gl.glShadeModel(GL10.GL_SMOOTH);		

	}

}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值