【第21期】观点:人工智能到底用 GPU?还是用 FPGA?

android学习笔记之3D--(03)-Renderer类 渲染类

转载 2012年03月29日 17:54:00
public static interface

GLSurfaceView.Renderer

android.opengl.GLSurfaceView.Renderer

Class Overview

A generic renderer interface.

是一个一般的渲染类接口

 

The renderer is responsible for making OpenGL calls to render a frame.

这个renderer类负责 让OpenGL调用去渲染一个框架。

 

GLSurfaceView clients typically create their own classes that implement this interface, and then callsetRenderer(GLSurfaceView.Renderer) to register the renderer with the GLSurfaceView.

通常使用GLSurfaceView的客户都会通过调用这个“renderer”类接口去创建他们自己的对象。同时也会通过调用GLSurfaceView类的GLSurfaceView类的setRenderer(GLSurfaceView.Renderer)方法去注册这个“renderer”。

 

Threading   线程

The renderer will be called on a separate thread, so that rendering performance is decoupled from the UI thread. Clients typically need to communicate with the renderer from the UI thread, because that's where input events are received. Clients can communicate using any of the standard Java techniques for cross-thread communication, or they can use thequeueEvent(Runnable) convenience method.
   这个渲染器会被当作一个独立的线程被调用,所以这个渲染性能和系统UI是不相干的。通常用户需要从UI中关联渲染器,因为UI线程是事件接受的地方。用户们可以用很多java技术上的方式去做到UI与渲染器的线程之间的调用或者也可以用queueEvent(Runnable) 这个便利的方法。

 

EGL Context Lost

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. TheonSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this.
   某些OpenGL ES渲染的地方会有丢失的局面,类似于失帧。这是典型的事件,如程序正从睡眠中唤醒。当这个EGL的环境丢失是,所有和环境有关联的OpenGL的资源(如纹理资源)都将被自动清除掉。为了保持正确的渲染效果,这个渲染器必须要重新绘制那些被丢失的重要的资源。然而,这个onSurfaceCreated(GL10, EGLConfig)方法最大好处就是解决上面的问题。

 

Summary

Public Methods
abstract void onDrawFrame(GL10 gl)
Called to draw the current frame.
绘制当前的框架时调用
abstract void onSurfaceChanged(GL10 gl, int width, int height)
Called when the surface changed size.
表层界面(主视图)发生改变时调用
abstract void onSurfaceCreated(GL10 gl, EGLConfig config)
Called when the surface is created or recreated.
框架被创建或者被重建的时候调用

Public Methods

public abstract void onDrawFrame (GL10 gl)

Since: API Level 3

Called to draw the current frame.

This method is responsible for drawing the current frame.

The implementation of this method typically looks like this:

 void onDrawFrame(GL10 gl) {
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//清除屏幕和深度缓存
     //... other gl calls to render the scene ...
 }
 

 

Parameters
gl the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

public abstract void onSurfaceChanged (GL10 gl, int width, int height)

Since: API Level 3

Called when the surface changed size.

Called after the surface is created and whenever the OpenGL ES surface size changes.

Typically you will set your viewport here. If your camera is fixed then you could also set your projection matrix here:

 void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height); //这是OpenGL场景的大小
     // for a fixed camera, set the projection too
     float ratio = (float) width / height;
     gl.glMatrixMode(GL10.GL_PROJECTION); //设置投影矩阵
     gl.glLoadIdentity();//重置当前的模型观察矩阵
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);//设置视口的大小
 }
 

 

Parameters
gl the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

public abstract void onSurfaceCreated (GL10 gl, EGLConfig config)

Since: API Level 3

Called when the surface is created or recreated.

Called when the rendering thread starts and whenever the EGL context is lost. The EGL context will typically be lost when the Android device awakes after going to sleep.

Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here.

Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.

 

Parameters
gl the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.
config the EGLConfig of the created surface. Can be used to create matching pbuffers.
举报

相关文章推荐

android学习笔记之3D--(03)-Renderer类 渲染类

public static interface GLSurfaceView.Rendererandroid.opengl.GLSurfaceView.RendererClass OverviewA ...
  • GEOLO
  • GEOLO
  • 2010-10-22 11:08
  • 7233

[Unity3D] 学习笔记——MonoBehaviour类Invoke, Coroutine

MonoBehaviour概述 MonoBehaviour 表示一个单一的行为。Unity中用户对游戏对象的操作被分割成若干个单一行为。每个单一行为都作为一个MonoBehaviour类来封装。再生成每个MonoBehaviour类的实例,并作为组件嵌入游戏对象。然后按照一定的顺序(从下到上)调用每个对象的重载方法来实现游戏对象的全部行为。   创建 在菜单Assets->create中选

开源3D图形渲染引擎OGRE学习笔记

参考资料: 电子书:《

unity3d学习笔记(六)--单例脚本和单例类

本系列文章由Aimar_Johnny编写,欢迎转载,转载请标明出处,谢谢。 http://blog.csdn.net/lzhq1982/article/details/12649281 ...

Android 3D 游戏学习笔记(3)-投影

小满(billman)个人原创,欢迎转载,转载请注明地址,小满(billman)的专栏地址htt
  • isiqi
  • isiqi
  • 2012-02-15 21:16
  • 331
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)