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