// ############################################################
// ############################################################
//
// 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
没有合适的资源?快使用搜索试试~ 我知道了~
香蕉树之恋(高仿植物大战僵尸防守类游戏)源码
共1088个文件
class:570个
java:425个
png:41个
4星 · 超过85%的资源 需积分: 9 23 下载量 14 浏览量
2015-08-04
11:40:29
上传
评论 1
收藏 7.28MB ZIP 举报
温馨提示
香蕉树之恋(高仿植物大战僵尸防守类游戏)图片资源也一起赋在源码中了,请大家自行使用! 本作品由重庆Forty'7科技有限公司Android工程师:小王商务网络整合开发奉献。
资源推荐
资源详情
资源评论
收起资源包目录
香蕉树之恋(高仿植物大战僵尸防守类游戏)源码 (1088个子文件)
resources.ap_ 1MB
PlantsVsBugs.apk 1.21MB
jarlist.cache 120B
proguard.cfg 1KB
Engine.class 22KB
Entity.class 19KB
BaseMenuItemDecorator.class 14KB
GLHelper.class 13KB
TMXLayer.class 12KB
Scene.class 12KB
MainGame.class 11KB
Texture.class 10KB
TMXParser.class 10KB
BaseGameActivity.class 10KB
Camera.class 9KB
SpriteBatch.class 9KB
ActivityUtils.class 8KB
Tutorial.class 8KB
SequenceModifier.class 8KB
TMXTileSet.class 8KB
TMXTiledMap.class 8KB
PathModifier.class 8KB
Font.class 8KB
AnimatedSprite.class 8KB
TextureRegionFactory.class 7KB
ParticleSystem.class 7KB
Bug.class 7KB
LoopModifier.class 7KB
MainMenu.class 6KB
Text.class 6KB
MenuScene.class 6KB
RadialGradientFillTextureSourceDecorator.class 6KB
GLSurfaceView$GLThread.class 6KB
BaseOnScreenControl.class 6KB
FileUtils.class 6KB
SystemUtils.class 6KB
Plant.class 6KB
BuildableTexture.class 6KB
SAXUtils.class 6KB
AndEnviroment.class 5KB
AStarPathFinder.class 5KB
GLSurfaceView.class 5KB
Base64$Decoder.class 5KB
LinearGradientFillTextureSourceDecorator.class 5KB
Line.class 5KB
LevelLoader.class 5KB
AndResourceLoader.class 5KB
BaseSplashActivity.class 5KB
MathUtils.class 5KB
GameData.class 5KB
AnalogOnScreenControl.class 4KB
ParallelModifier.class 4KB
HoldDetector.class 4KB
SlideMenuAnimator.class 4KB
TMXLoader.class 4KB
AlphaMenuAnimator.class 4KB
Shape.class 4KB
SequenceBackgroundModifier.class 4KB
BlackPawnTextureBuilder.class 4KB
LoopBackgroundModifier.class 4KB
Card.class 4KB
DoubleSceneSplitScreenEngine.class 4KB
SpriteGroup.class 4KB
Transformation.class 4KB
SmartList.class 4KB
GenericInputDialogBuilder.class 4KB
ScaleAtModifier.class 4KB
BaseTextureRegion.class 4KB
ColorModifier.class 4KB
GLSurfaceView$EglHelper.class 4KB
RectangularShape.class 4KB
Base64$Encoder.class 4KB
ScaleModifier.class 4KB
SpriteBatchVertexBuffer.class 4KB
BlackPawnTextureBuilder$Node.class 4KB
LoopEntityModifier.class 4KB
BufferObjectManager.class 4KB
ColorSwapTextureSourceDecorator.class 4KB
SequenceEntityModifier.class 4KB
BaseTextureSourceDecorator.class 4KB
TextureManager.class 4KB
LevelStatsDBConnector$1.class 4KB
ScreenCapture.class 4KB
IEntity.class 4KB
AssetTextureSource.class 4KB
FontFactory.class 4KB
BaseActivity.class 4KB
BaseTouchController.class 4KB
EngineOptions.class 3KB
PoolUpdateHandler.class 3KB
RepeatingSpriteBackground.class 3KB
TSXParser.class 3KB
BugCaterpillar.class 3KB
TSXLoader.class 3KB
GenericPool.class 3KB
BufferObject.class 3KB
BaseDoubleValueSpanModifier.class 3KB
BaseSingleValueSpanModifier.class 3KB
FileTextureSource.class 3KB
ColorKeyTextureSourceDecorator.class 3KB
共 1088 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
- 海林862015-11-20是一个学习的参考例子,···
wp2463496
- 粉丝: 3
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功