// ############################################################
// ############################################################
//
// This class is a replacement for the original GLSurfaceView, due to issue:
// http://code.google.com/p/android/issues/detail?id=2828
//
// Reason: Two sequential Activities using a GLSurfaceView leads to a deadlock in the GLThread!
//
// ############################################################
// ############################################################
package org.anddev.andengine.opengl.view;
import java.util.ArrayList;
import java.util.concurrent.Semaphore;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGL11;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
* An implementation of SurfaceView that uses the dedicated surface for
* displaying OpenGL rendering.
* <p>
* A GLSurfaceView provides the following features:
* <p>
* <ul>
* <li>Manages a surface, which is a special piece of memory that can be
* composited into the Android view system.
* <li>Manages an EGL display, which enables OpenGL to render into a surface.
* <li>Accepts a user-provided Renderer object that does the actual rendering.
* <li>Renders on a dedicated thread to decouple rendering performance from the
* UI thread.
* <li>Supports both on-demand and continuous rendering.
* <li>Optionally wraps, traces, and/or error-checks the renderer's OpenGL
* calls.
* </ul>
*
* <h3>Using GLSurfaceView</h3>
* <p>
* Typically you use GLSurfaceView by subclassing it and overriding one or more
* of the View system input event methods. If your application does not need to
* override event methods then GLSurfaceView can be used as-is. For the most
* part GLSurfaceView behavior is customized by calling "set" methods rather
* than by subclassing. For example, unlike a regular View, drawing is delegated
* to a separate Renderer object which is registered with the GLSurfaceView
* using the {@link #setRenderer(Renderer)} call.
* <p>
* <h3>Initializing GLSurfaceView</h3>
* All you have to do to initialize a GLSurfaceView is call
* {@link #setRenderer(Renderer)}. However, if desired, you can modify the
* default behavior of GLSurfaceView by calling one or more of these methods
* before calling setRenderer:
* <ul>
* <li>{@link #setDebugFlags(int)}
* <li>{@link #setEGLConfigChooser(boolean)}
* <li>{@link #setEGLConfigChooser(EGLConfigChooser)}
* <li>{@link #setEGLConfigChooser(int, int, int, int, int, int)}
* <li>{@link #setGLWrapper(GLWrapper)}
* </ul>
* <p>
* <h4>Choosing an EGL Configuration</h4>
* A given Android device may support multiple possible types of drawing
* surfaces. The available surfaces may differ in how may channels of data are
* present, as well as how many bits are allocated to each channel. Therefore,
* the first thing GLSurfaceView has to do when starting to render is choose
* what type of surface to use.
* <p>
* By default GLSurfaceView chooses an available surface that's closest to a
* 16-bit R5G6B5 surface with a 16-bit depth buffer and no stencil. If you would
* prefer a different surface (for example, if you do not need a depth buffer)
* you can override the default behavior by calling one of the
* setEGLConfigChooser methods.
* <p>
* <h4>Debug Behavior</h4>
* You can optionally modify the behavior of GLSurfaceView by calling one or
* more of the debugging methods {@link #setDebugFlags(int)}, and
* {@link #setGLWrapper}. These methods may be called before and/or after
* setRenderer, but typically they are called before setRenderer so that they
* take effect immediately.
* <p>
* <h4>Setting a Renderer</h4>
* Finally, you must call {@link #setRenderer} to register a {@link Renderer}.
* The renderer is responsible for doing the actual OpenGL rendering.
* <p>
* <h3>Rendering Mode</h3>
* Once the renderer is set, you can control whether the renderer draws
* continuously or on-demand by calling {@link #setRenderMode}. The default is
* continuous rendering.
* <p>
* <h3>Activity Life-cycle</h3>
* A GLSurfaceView must be notified when the activity is paused and resumed.
* GLSurfaceView clients are required to call {@link #onPause()} when the
* activity pauses and {@link #onResume()} when the activity resumes. These
* calls allow GLSurfaceView to pause and resume the rendering thread, and also
* allow GLSurfaceView to release and recreate the OpenGL display.
* <p>
* <h3>Handling events</h3>
* <p>
* To handle an event you will typically subclass GLSurfaceView and override the
* appropriate method, just as you would with any other View. However, when
* handling the event, you may need to communicate with the Renderer object
* that's running in the rendering thread. You can do this using any standard
* Java cross-thread communication mechanism. In addition, one relatively easy
* way to communicate with your renderer is to call
* {@link #queueEvent(Runnable)}. For example:
*
* <pre class="prettyprint">
* class MyGLSurfaceView extends GLSurfaceView {
*
* private MyRenderer mMyRenderer;
*
* public void start() {
* mMyRenderer = ...;
* setRenderer(mMyRenderer);
* }
*
* public boolean onKeyDown(int keyCode, KeyEvent event) {
* if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
* queueEvent(new Runnable() {
* // This method will be called on the rendering
* // thread:
* public void run() {
* mMyRenderer.handleDpadCenter();
* }
* });
* return true;
* }
* return super.onKeyDown(keyCode, event);
* }
* }
* </pre>
*
*/
public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
// ===========================================================
// Constants
// ===========================================================
/**
* The renderer only renders when the surface is created, or when
* {@link #requestRender} is called.
*
* @see #getRenderMode()
* @see #setRenderMode(int)
*/
public final static int RENDERMODE_WHEN_DIRTY = 0;
/**
* The renderer is called continuously to re-render the scene.
*
* @see #getRenderMode()
* @see #setRenderMode(int)
* @see #requestRender()
*/
public final static int RENDERMODE_CONTINUOUSLY = 1;
/**
* Check glError() after every GL call and throw an exception if glError
* indicates that an error has occurred. This can be used to help track down
* which OpenGL ES call is causing an error.
*
* @see #getDebugFlags
* @see #setDebugFlags
*/
public final static int DEBUG_CHECK_GL_ERROR = 1;
/**
* Log GL calls to the system log at "verbose" level with tag
* "GLSurfaceView".
*
* @see #getDebugFlags
* @see #setDebugFlags
*/
public final static int DEBUG_LOG_GL_CALLS = 2;
private static final Semaphore sEglSemaphore = new Semaphore(1);
// ===========================================================
// Fields
// ===========================================================
private GLThread mGLThread;
private EGLConfigChooser mEGLConfigChooser;
private GLWrapper mGLWrapper;
private int mDebugFlags;
private int mRenderMode;
private Renderer mRenderer;
private int mSurfaceWidth;
private int mSurfaceHeight;
private boolean mHasSurface;
// ===========================================================
// Constructors
// ===========================================================
/**
* Standard View constructor. In order to render something, you must call
* {@link #setRenderer} to register a renderer.
*/
public GLSurfaceView(final Context context) {
super(contex
没有合适的资源?快使用搜索试试~ 我知道了~
Android游戏引擎andengine
共1095个文件
i:694个
java:363个
svg:9个
4星 · 超过85%的资源 需积分: 9 33 下载量 140 浏览量
2011-09-23
22:08:27
上传
评论 2
收藏 2.52MB ZIP 举报
温馨提示
andengine同样是一款基于OpenGL ES技术的Android游戏引擎,物理引擎同样为Box2D。该框架性能普通,文档缺乏,但示例较为丰富。
资源推荐
资源详情
资源评论
收起资源包目录
Android游戏引擎andengine (1095个子文件)
push_google_code.bat 51B
branch 8B
undo.branch 7B
branchheads.cache 1KB
tags.cache 271B
.classpath 345B
00manifest.d 265KB
00changelog.d 148KB
undo.desc 44B
dirstate 29KB
undo.dirstate 0B
fncache 47KB
.hgignore 44B
hgrc 57B
00changelog.i 46KB
00manifest.i 46KB
logo.png.i 45KB
_engine.java.i 35KB
andengine__classdiagram.png.i 32KB
logo3.png.i 29KB
logo2.png.i 29KB
splash.png.i 25KB
source.png.i 23KB
_g_l_surface_view.java.i 23KB
clapboard.png.i 22KB
logo.svg.i 19KB
_scene.java.i 18KB
source.svg.i 15KB
_shape.java.i 14KB
_t_m_x_layer.java.i 14KB
badge.png.i 13KB
_camera.java.i 13KB
_texture.java.i 13KB
_entity.java.i 13KB
_base64.java.i 12KB
_base_game_activity.java.i 11KB
andengine__classdiagram.ucls.i 11KB
_base_sprite.java.i 10KB
logo4.png.i 10KB
_g_l_helper.java.i 10KB
_text.java.i 9KB
logo__icon.svg.i 9KB
_particle_system.java.i 9KB
_scene.java.i 9KB
_font.java.i 8KB
_render_surface_view.java.i 8KB
icon.svg.i 8KB
_animated_sprite.java.i 8KB
_g_l_helper.java.i 7KB
_base_on_screen_control.java.i 7KB
_math_utils.java.i 7KB
_texture_manager.java.i 7KB
_path_modifier.java.i 7KB
_t_m_x_tiled_map.java.i 6KB
_screen_capture.java.i 6KB
_t_m_x_tile_set.java.i 6KB
_t_m_x_parser.java.i 6KB
_dynamic_entity.java.i 6KB
export_jar_to_all.xml.i 6KB
_i_entity.java.i 6KB
_line.java.i 5KB
_base_menu_item_decorator.java.i 5KB
_base_splash_activity.java.i 5KB
_line.java.i 5KB
_static_entity.java.i 5KB
_user_task.java.i 5KB
_black_pawn_texture_builder.java.i 5KB
_shape.java.i 5KB
_shape_collision_checker.java.i 4KB
_sequence_modifier.java.i 4KB
clapboard.svg.i 4KB
_menu_scene.java.i 4KB
_buffer_object.java.i 4KB
_double_scene_split_screen_engine.java.i 4KB
_rectangular_shape.java.i 4KB
_rectangular_shape.java.i 4KB
_scale_modifier.java.i 4KB
_buffer_object_manager.java.i 4KB
_sprite.java.i 4KB
_rectangle_vertex_buffer.java.i 4KB
_menu_scene.java.i 4KB
_base_activity.java.i 4KB
_i_shape.java.i 4KB
_hold_detector.java.i 4KB
_texture_region_factory.java.i 4KB
_fixed_capacity_layer.java.i 4KB
_base_entity.java.i 3KB
_single_scene_split_screen_engine.java.i 3KB
_f_p_s_counter.java.i 3KB
_layer.java.i 3KB
_base_texture_region_buffer.java.i 3KB
_text_vertex_buffer.java.i 3KB
_rectangular_shape_collision_checker.java.i 3KB
_zoom_camera.java.i 3KB
_t_m_x_loader.java.i 3KB
_s_a_x_utils.java.i 3KB
badge.svg.i 3KB
_rectangular_shape.java.i 3KB
_font.java.i 3KB
splash.svg.i 3KB
共 1095 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
- jinzhao3192013-06-07很不错 挺好用
- javaandj2me2012-07-18是官方实例
hotancle
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- stm32 usb接口通信
- Chessmate是一款完全免费的国际象棋学习软件,支持引擎分析,学开局、残局、棋书解读、大数据分析等功能
- 总结整理的Android面试Java基础知识点面试资料精编汇总文档资料合集.zip
- .android_lq
- FDN5632N-VB一款SOT23封装N-Channel场效应MOS管
- 毛老板-2404250902.amr
- Java类加载流程(双亲委派)流程图.zip
- FDN5632-NL-VB一款SOT23封装N-Channel场效应MOS管
- 新目标大学英语(第二版)视听说教程 第1册 Unit 4 TOP课件.zip
- 自动驾驶-状态估计和定位之Error State EKF.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功