public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
A GLSurfaceView provides the following features:
For more information about how to use OpenGL, read the OpenGL developer guide.
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 setRenderer(Renderer)
call.
setRenderer(Renderer)
.
However, if desired, you can modify the default behavior of GLSurfaceView by calling one or
more of these methods before calling setRenderer:
setDebugFlags(int)
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int, int, int, int, int, int)
setGLWrapper(GLWrapper)
By default GLSurfaceView chooses a EGLConfig that has an RGB_888 pixel format, with at least a 16-bit depth buffer and no stencil.
If you would prefer a different EGLConfig you can override the default behavior by calling one of the setEGLConfigChooser methods.
setDebugFlags(int)
,
and setGLWrapper(android.opengl.GLSurfaceView.GLWrapper)
. These methods may be called before and/or after setRenderer, but
typically they are called before setRenderer so that they take effect immediately.
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a GLSurfaceView.Renderer
.
The renderer is
responsible for doing the actual OpenGL rendering.
setRenderMode(int)
. The default is continuous rendering.
onPause()
when the activity pauses and
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.
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
queueEvent(Runnable)
. For example:
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); } }
Modifier and Type | Class and Description |
---|---|
static interface |
GLSurfaceView.EGLConfigChooser
An interface for choosing an EGLConfig configuration from a list of
potential configurations.
|
static interface |
GLSurfaceView.EGLContextFactory
An interface for customizing the eglCreateContext and eglDestroyContext calls.
|
static interface |
GLSurfaceView.EGLWindowSurfaceFactory
An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
|
static interface |
GLSurfaceView.GLWrapper
An interface used to wrap a GL interface.
|
static interface |
GLSurfaceView.Renderer
A generic renderer interface.
|
TextView.BufferType, TextView.OnEditorActionListener, TextView.SavedState
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnAttachStateChangeListener, View.OnClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
Modifier and Type | Field and Description |
---|---|
static int |
DEBUG_CHECK_GL_ERROR
Check glError() after every GL call and throw an exception if glError indicates
that an error has occurred.
|
static int |
DEBUG_LOG_GL_CALLS
Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
|
static int |
RENDERMODE_CONTINUOUSLY
The renderer is called
continuously to re-render the scene.
|
static int |
RENDERMODE_WHEN_DIRTY
The renderer only renders
when the surface is created, or when
requestRender() is called. |
ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, mBottom, mCachingFailed, mContext, mCurrentAnimation, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y
Constructor and Description |
---|
GLSurfaceView(Context context)
Standard View constructor.
|
GLSurfaceView(Context context,
AttributeSet attrs)
Standard View constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
int |
getDebugFlags()
Get the current value of the debug flags.
|
boolean |
getPreserveEGLContextOnPause() |
int |
getRenderMode()
Get the current rendering mode.
|
protected void |
onAttachedToWindow()
This method is used as part of the View class and is not normally
called or subclassed by clients of GLSurfaceView.
|
protected void |
onDetachedFromWindow()
This method is used as part of the View class and is not normally
called or subclassed by clients of GLSurfaceView.
|
void |
onPause()
Inform the view that the activity is paused.
|
void |
onResume()
Inform the view that the activity is resumed.
|
void |
queueEvent(Runnable r)
Queue a runnable to be run on the GL rendering thread.
|
void |
requestRender()
Request that the renderer render a frame.
|
void |
setDebugFlags(int debugFlags)
Set the debug flags to a new value.
|
void |
setEGLConfigChooser(boolean needDepth)
Install a config chooser which will choose a config
as close to 16-bit RGB as possible, with or without an optional depth
buffer as close to 16-bits as possible.
|
void |
setEGLConfigChooser(GLSurfaceView.EGLConfigChooser configChooser)
Install a custom EGLConfigChooser.
|
void |
setEGLConfigChooser(int redSize,
int greenSize,
int blueSize,
int alphaSize,
int depthSize,
int stencilSize)
Install a config chooser which will choose a config
with at least the specified depthSize and stencilSize,
and exactly the specified redSize, greenSize, blueSize and alphaSize.
|
void |
setEGLContextClientVersion(int version)
Inform the default EGLContextFactory and default EGLConfigChooser
which EGLContext client version to pick.
|
void |
setEGLContextFactory(GLSurfaceView.EGLContextFactory factory)
Install a custom EGLContextFactory.
|
void |
setEGLWindowSurfaceFactory(GLSurfaceView.EGLWindowSurfaceFactory factory)
Install a custom EGLWindowSurfaceFactory.
|
void |
setGLWrapper(GLSurfaceView.GLWrapper glWrapper)
Set the glWrapper.
|
void |
setPreserveEGLContextOnPause(boolean preserveOnPause)
Control whether the EGL context is preserved when the GLSurfaceView is paused and
resumed.
|
void |
setRenderer(GLSurfaceView.Renderer renderer)
Set the renderer associated with this view.
|
void |
setRenderMode(int renderMode)
Set the rendering mode.
|
void |
surfaceChanged(SurfaceHolder holder,
int format,
int w,
int h)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
void |
surfaceCreated(SurfaceHolder holder)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
void |
surfaceDestroyed(SurfaceHolder holder)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
getHolder
addTextChangedListener, append, append, beginBatchEdit, bringPointIntoView, cancelLongPress, clearComposingText, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollRange, debug, deleteText_internal, didTouchFocusSelect, dispatchFinishTemporaryDetach, drawableStateChanged, endBatchEdit, extractText, findViewsWithText, getAccessibilityCursorPosition, getAutoLinkMask, getBaseline, getBottomPaddingOffset, getCompoundDrawablePadding, getCompoundDrawables, getCompoundDrawablesRelative, getCompoundPaddingBottom, getCompoundPaddingEnd, getCompoundPaddingLeft, getCompoundPaddingRight, getCompoundPaddingStart, getCompoundPaddingTop, getCurrentHintTextColor, getCurrentTextColor, getCustomSelectionActionModeCallback, getDefaultEditable, getDefaultMovementMethod, getEditableText, getEllipsize, getError, getExtendedPaddingBottom, getExtendedPaddingTop, getFadeHeight, getFadeTop, getFilters, getFocusedRect, getFreezesText, getGravity, getHighlightColor, getHint, getHintTextColors, getHorizontallyScrolling, getImeActionId, getImeActionLabel, getImeOptions, getIncludeFontPadding, getInputExtras, getInputType, getIterableTextForAccessibility, getIteratorForGranularity, getKeyListener, getLayout, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLineBounds, getLineCount, getLineHeight, getLineSpacingExtra, getLineSpacingMultiplier, getLinksClickable, getLinkTextColors, getMarqueeRepeatLimit, getMaxEms, getMaxHeight, getMaxLines, getMaxWidth, getMinEms, getMinHeight, getMinLines, getMinWidth, getMovementMethod, getOffsetForPosition, getPaint, getPaintFlags, getPrivateImeOptions, getRightFadingEdgeStrength, getRightPaddingOffset, getSelectionEnd, getSelectionStart, getShadowColor, getShadowDx, getShadowDy, getShadowRadius, getShowSoftInputOnFocus, getText, getTextColor, getTextColors, getTextColors, getTextForAccessibility, getTextLocale, getTextScaleX, getTextServicesLocale, getTextSize, getTopPaddingOffset, getTotalPaddingBottom, getTotalPaddingEnd, getTotalPaddingLeft, getTotalPaddingRight, getTotalPaddingStart, getTotalPaddingTop, getTransformationMethod, getTypeface, getUrls, getWordIterator, hasOverlappingRendering, hasSelection, hideErrorIfUnchanged, invalidateDrawable, isCursorVisible, isInputMethodTarget, isPaddingOffsetRequired, isSuggestionsEnabled, isTextSelectable, jumpDrawablesToCurrentState, length, makeNewLayout, moveCursorToVisibleOffset, onBeginBatchEdit, onCheckIsTextEditor, onCommitCompletion, onCommitCorrection, onCreateDrawableState, onCreateInputConnection, onDragEvent, onEditorAction, onEndBatchEdit, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onMeasure, onPopulateAccessibilityEvent, onPreDraw, onPrivateIMECommand, onResolveDrawables, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSelectionChanged, onStartTemporaryDetach, onTextChanged, onTextContextMenuItem, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, performLongClick, removeTextChangedListener, replaceText_internal, resetErrorChangedFlag, resetResolvedDrawables, sendAccessibilityEvent, setAccessibilityCursorPosition, setAllCaps, setAutoLinkMask, setCompoundDrawablePadding, setCompoundDrawables, setCompoundDrawablesRelative, setCompoundDrawablesRelativeWithIntrinsicBounds, setCompoundDrawablesRelativeWithIntrinsicBounds, setCompoundDrawablesWithIntrinsicBounds, setCompoundDrawablesWithIntrinsicBounds, setCursorPosition_internal, setCursorVisible, setCustomSelectionActionModeCallback, setEditableFactory, setEllipsize, setEms, setEnabled, setError, setError, setExtractedText, setExtracting, setFilters, setFrame, setFreezesText, setGravity, setHeight, setHighlightColor, setHint, setHint, setHintTextColor, setHintTextColor, setHorizontallyScrolling, setImeActionLabel, setImeOptions, setIncludeFontPadding, setInputExtras, setInputType, setKeyListener, setLines, setLineSpacing, setLinksClickable, setLinkTextColor, setLinkTextColor, setMarqueeRepeatLimit, setMaxEms, setMaxHeight, setMaxLines, setMaxWidth, setMinEms, setMinHeight, setMinLines, setMinWidth, setMovementMethod, setOnEditorActionListener, setPadding, setPaddingRelative, setPaintFlags, setPrivateImeOptions, setRawInputType, setScroller, setSelectAllOnFocus, setSelected, setShadowLayer, setShowSoftInputOnFocus, setSingleLine, setSingleLine, setSpan_internal, setSpannableFactory, setText, setText, setText, setText, setText, setTextAppearance, setTextColor, setTextColor, setTextIsSelectable, setTextKeepState, setTextKeepState, setTextLocale, setTextScaleX, setTextSize, setTextSize, setTransformationMethod, setTypeface, setTypeface, setWidth, stopSelectionActionMode, verifyDrawable, viewClicked
addChildrenForAccessibility, addFocusables, addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, canHaveDisplayList, canResolveLayoutDirection, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeOpaqueFlags, computeVerticalScrollOffset, createAccessibilityNodeInfo, createContextMenu, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, draw, findFocus, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitsSystemWindows, fitSystemWindows, focusSearch, forceLayout, gatherTransparentRegion, generateViewId, getAccessibilityDelegate, getAccessibilityNodeProvider, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBottom, getBottomFadingEdgeStrength, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDisplayList, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getId, getImportantForAccessibility, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hackTurnOffWindowResizeAnim, hasFocus, hasFocusable, hasHoveredChild, hasOnClickListeners, hasOpaqueScrollbars, hasTransientState, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeScrollbars, internalSetPadding, invalidate, invalidate, invalidate, invalidateParentCaches, invalidateParentIfNeeded, isActionableForAccessibility, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInScrollingContainer, isInTouchMode, isLayoutDirectionInherited, isLayoutRequested, isLayoutRtl, isLongClickable, isOpaque, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTextAlignmentInherited, isTextDirectionInherited, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, layout, makeOptionalFitsSystemWindows, measure, mergeDrawableStates, notifyAccessibilityStateChanged, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onDisplayHint, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFocusLost, onHoverChanged, onHoverEvent, onKeyLongPress, onOverScrolled, onSetAlpha, onSizeChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performButtonActionOnTouchDown, performClick, performHapticFeedback, performHapticFeedback, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resetAccessibilityStateChanged, resetPaddingToInitialValues, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutInsets, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, showContextMenu, startActionMode, startAnimation, startDrag, toString, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
public static final int RENDERMODE_WHEN_DIRTY
requestRender()
is called.public static final int RENDERMODE_CONTINUOUSLY
public static final int DEBUG_CHECK_GL_ERROR
public static final int DEBUG_LOG_GL_CALLS
public GLSurfaceView(Context context)
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a renderer.public GLSurfaceView(Context context, AttributeSet attrs)
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a renderer.protected void finalize() throws Throwable
Object
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
public void setGLWrapper(GLSurfaceView.GLWrapper glWrapper)
GLSurfaceView.GLWrapper.wrap(GL)
method is called
whenever a surface is created. A GLWrapper can be used to wrap
the GL object that's passed to the renderer. Wrapping a GL
object enables examining and modifying the behavior of the
GL calls made by the renderer.
Wrapping is typically used for debugging purposes.
The default value is null.
glWrapper
- the new GLWrapperpublic void setDebugFlags(int debugFlags)
debugFlags
- the new debug flagsDEBUG_CHECK_GL_ERROR
,
DEBUG_LOG_GL_CALLS
public int getDebugFlags()
public void setPreserveEGLContextOnPause(boolean preserveOnPause)
If set to true, then the EGL context may be preserved when the GLSurfaceView is paused. Whether the EGL context is actually preserved or not depends upon whether the Android device that the program is running on can support an arbitrary number of EGL contexts or not. Devices that can only support a limited number of EGL contexts must release the EGL context in order to allow multiple applications to share the GPU.
If set to false, the EGL context will be released when the GLSurfaceView is paused, and recreated when the GLSurfaceView is resumed.
The default is false.
preserveOnPause
- preserve the EGL context when pausedpublic boolean getPreserveEGLContextOnPause()
public void setRenderer(GLSurfaceView.Renderer renderer)
This method should be called once and only once in the life-cycle of a GLSurfaceView.
The following GLSurfaceView methods can only be called before setRenderer is called:
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int, int, int, int, int, int)
The following GLSurfaceView methods can only be called after setRenderer is called:
renderer
- the renderer to use to perform OpenGL drawing.public void setEGLContextFactory(GLSurfaceView.EGLContextFactory factory)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If this method is not called, then by default a context will be created with no shared context and with a null attribute list.
public void setEGLWindowSurfaceFactory(GLSurfaceView.EGLWindowSurfaceFactory factory)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If this method is not called, then by default a window surface will be created with a null attribute list.
public void setEGLConfigChooser(GLSurfaceView.EGLConfigChooser configChooser)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an EGLConfig that is compatible with the current android.view.Surface, with a depth buffer depth of at least 16 bits.
configChooser
- public void setEGLConfigChooser(boolean needDepth)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.
needDepth
- public void setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.
public void setEGLContextClientVersion(int version)
Use this method to create an OpenGL ES 2.0-compatible context. Example:
public MyView(Context context) { super(context); setEGLContextClientVersion(2); // Pick an OpenGL ES 2.0 context. setRenderer(new MyRenderer()); }
Note: Activities which require OpenGL ES 2.0 should indicate this by setting @lt;uses-feature android:glEsVersion="0x00020000" /> in the activity's AndroidManifest.xml file.
If this method is called, it must be called before setRenderer(Renderer)
is called.
This method only affects the behavior of the default EGLContexFactory and the
default EGLConfigChooser. If
setEGLContextFactory(EGLContextFactory)
has been called, then the supplied
EGLContextFactory is responsible for creating an OpenGL ES 2.0-compatible context.
If
setEGLConfigChooser(EGLConfigChooser)
has been called, then the supplied
EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config.
version
- The EGLContext client version to choose. Use 2 for OpenGL ES 2.0public void setRenderMode(int renderMode)
requestRender()
is called. Defaults to RENDERMODE_CONTINUOUSLY.
Using RENDERMODE_WHEN_DIRTY can improve battery life and overall system performance by allowing the GPU and CPU to idle when the view does not need to be updated.
This method can only be called after setRenderer(Renderer)
renderMode
- one of the RENDERMODE_X constantsRENDERMODE_CONTINUOUSLY
,
RENDERMODE_WHEN_DIRTY
public int getRenderMode()
RENDERMODE_CONTINUOUSLY
,
RENDERMODE_WHEN_DIRTY
public void requestRender()
RENDERMODE_WHEN_DIRTY
, so that frames are only rendered on demand.
May be called
from any thread. Must not be called before a renderer has been set.public void surfaceCreated(SurfaceHolder holder)
surfaceCreated
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface is being created.public void surfaceDestroyed(SurfaceHolder holder)
surfaceDestroyed
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface is being destroyed.public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
surfaceChanged
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface has changed.format
- The new PixelFormat of the surface.w
- The new width of the surface.h
- The new height of the surface.public void onPause()
public void onResume()
public void queueEvent(Runnable r)
r
- the runnable to be run on the GL rendering thread.protected void onAttachedToWindow()
onAttachedToWindow
in class TextView
View.onDetachedFromWindow()
protected void onDetachedFromWindow()
onDetachedFromWindow
in class TextView
View.onAttachedToWindow()