Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 200 | chris | 1 | package com.gebauz.Bauzoid.graphics.renderstates; |
| 2 | |||
| 3 | /** Manages culling render state. */ |
||
| 4 | public class CullingStates extends RenderStatesObject |
||
| 5 | { |
||
| 6 | /** Vertex winding. */ |
||
| 7 | public enum VertexWinding |
||
| 8 | { |
||
| 9 | CLOCKWISE, |
||
| 10 | COUNTERCLOCKWISE |
||
| 11 | } |
||
| 12 | |||
| 13 | private boolean mEnabled = true; |
||
| 14 | private VertexWinding mVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 15 | private boolean mCurrentlyEnabled = true; |
||
| 16 | private VertexWinding mCurrentVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 17 | private boolean mDefaultEnabled = true; |
||
| 18 | private VertexWinding mDefaultVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 19 | |||
| 20 | /** Constructor. */ |
||
| 21 | public CullingStates(RenderStates renderStates) |
||
| 22 | { |
||
| 23 | super(renderStates); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** Activate the render state. */ |
||
| 27 | @Override |
||
| 28 | public void activate(boolean force) |
||
| 29 | { |
||
| 30 | if ((force) || (mEnabled != mCurrentlyEnabled)) |
||
| 31 | { |
||
| 32 | mCurrentlyEnabled = mEnabled; |
||
| 33 | if (mEnabled) |
||
| 34 | GLES20.glEnable(GLES20.GL_CULL_FACE); |
||
| 35 | else |
||
| 36 | GLES20.glDisable(GLES20.GL_CULL_FACE); |
||
| 37 | } |
||
| 38 | |||
| 39 | if ((force) || (mVisibleFaces != mCurrentVisibleFaces)) |
||
| 40 | { |
||
| 41 | mCurrentVisibleFaces = mVisibleFaces; |
||
| 42 | switch (mVisibleFaces) |
||
| 43 | { |
||
| 44 | case CLOCKWISE: |
||
| 45 | GLES20.glFrontFace(GLES20.GL_CW); |
||
| 46 | break; |
||
| 47 | case COUNTERCLOCKWISE: |
||
| 48 | GLES20.glFrontFace(GLES20.GL_CCW); |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | /** Reset to default values. */ |
||
| 55 | @Override |
||
| 56 | public void reset() |
||
| 57 | { |
||
| 58 | mEnabled = mDefaultEnabled; |
||
| 59 | mVisibleFaces = mDefaultVisibleFaces; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** Check enabled state. */ |
||
| 63 | public final boolean isEnabled() |
||
| 64 | { |
||
| 65 | return mEnabled; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** Check default enabled state. */ |
||
| 69 | public final boolean isDefaultEnabled() |
||
| 70 | { |
||
| 71 | return mDefaultEnabled; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** Get vertex winding. */ |
||
| 75 | public final VertexWinding getVisibleFaces() |
||
| 76 | { |
||
| 77 | return mVisibleFaces; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** Get default vertex winding. */ |
||
| 81 | public final VertexWinding getDefaultVisibleFaces() |
||
| 82 | { |
||
| 83 | return mDefaultVisibleFaces; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** Set enabled state. */ |
||
| 87 | public final void setEnabled(boolean value) |
||
| 88 | { |
||
| 89 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 90 | return; |
||
| 91 | mEnabled = value; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** Set default enabled state. */ |
||
| 95 | public final void setDefaultEnabled(boolean value) |
||
| 96 | { |
||
| 97 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 98 | return; |
||
| 99 | mDefaultEnabled = value; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** Set vertex winding. */ |
||
| 103 | public final void setVisibleFaces(VertexWinding value) |
||
| 104 | { |
||
| 105 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 106 | return; |
||
| 107 | mVisibleFaces = value; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** Set default vertex winding. */ |
||
| 111 | public final void setDefaultVisibleFaces(VertexWinding value) |
||
| 112 | { |
||
| 113 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 114 | return; |
||
| 115 | mDefaultVisibleFaces = value; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 |