Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 108 | chris | 1 | package com.gebauz.pingK.common.framework.renderstates; |
| 2 | |||
| 3 | import javax.microedition.khronos.opengles.GL10; |
||
| 4 | |||
| 5 | import com.gebauz.pingK.common.framework.GLUtil; |
||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | public class CullingStates extends RenderStatesObject |
||
| 10 | { |
||
| 11 | public enum VertexWinding |
||
| 12 | { |
||
| 13 | CLOCKWISE, |
||
| 14 | COUNTERCLOCKWISE |
||
| 15 | } |
||
| 16 | |||
| 17 | private boolean mEnabled = true; |
||
| 18 | private VertexWinding mVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 19 | private boolean mCurrentlyEnabled = true; |
||
| 20 | private VertexWinding mCurrentVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 21 | private boolean mDefaultEnabled = true; |
||
| 22 | private VertexWinding mDefaultVisibleFaces = VertexWinding.CLOCKWISE; |
||
| 23 | |||
| 24 | |||
| 25 | public CullingStates(RenderStates renderStates) |
||
| 26 | { |
||
| 27 | super(renderStates); |
||
| 28 | } |
||
| 29 | |||
| 30 | @Override |
||
| 31 | public void activate(boolean force) |
||
| 32 | { |
||
| 33 | GL10 gl = GLUtil.getGL(); |
||
| 34 | |||
| 35 | if ((force) || (mEnabled != mCurrentlyEnabled)) |
||
| 36 | { |
||
| 37 | mCurrentlyEnabled = mEnabled; |
||
| 38 | if (mEnabled) |
||
| 39 | gl.glEnable(GL10.GL_CULL_FACE); |
||
| 40 | else |
||
| 41 | gl.glDisable(GL10.GL_CULL_FACE); |
||
| 42 | } |
||
| 43 | |||
| 44 | if ((force) || (mVisibleFaces != mCurrentVisibleFaces)) |
||
| 45 | { |
||
| 46 | mCurrentVisibleFaces = mVisibleFaces; |
||
| 47 | switch (mVisibleFaces) |
||
| 48 | { |
||
| 49 | case CLOCKWISE: |
||
| 50 | gl.glFrontFace(GL10.GL_CW); |
||
| 51 | break; |
||
| 52 | case COUNTERCLOCKWISE: |
||
| 53 | gl.glFrontFace(GL10.GL_CCW); |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public void reset() |
||
| 61 | { |
||
| 62 | mEnabled = mDefaultEnabled; |
||
| 63 | mVisibleFaces = mDefaultVisibleFaces; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | public final boolean isEnabled() { return mEnabled; } |
||
| 69 | public final boolean isDefaultEnabled() { return mDefaultEnabled; } |
||
| 70 | public final VertexWinding getVisibleFaces() { return mVisibleFaces; } |
||
| 71 | public final VertexWinding getDefaultVisibleFaces() { return mDefaultVisibleFaces; } |
||
| 72 | |||
| 73 | public final void setEnabled(boolean value) |
||
| 74 | { |
||
| 75 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 76 | return; |
||
| 77 | mEnabled = value; |
||
| 78 | } |
||
| 79 | |||
| 80 | public final void setDefaultEnabled(boolean value) |
||
| 81 | { |
||
| 82 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 83 | return; |
||
| 84 | mDefaultEnabled = value; |
||
| 85 | } |
||
| 86 | |||
| 87 | public final void setVisibleFaces(VertexWinding value) |
||
| 88 | { |
||
| 89 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 90 | return; |
||
| 91 | mVisibleFaces = value; |
||
| 92 | } |
||
| 93 | |||
| 94 | public final void setDefaultVisibleFaces(VertexWinding value) |
||
| 95 | { |
||
| 96 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 97 | return; |
||
| 98 | mDefaultVisibleFaces = value; |
||
| 99 | } |
||
| 100 | } |