Rev 200 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 200 | chris | 1 | package com.gebauz.Bauzoid.graphics.renderstates; |
| 2 | |||
| 201 | chris | 3 | import com.badlogic.gdx.Gdx; |
| 4 | import com.badlogic.gdx.graphics.GL20; |
||
| 5 | |||
| 200 | chris | 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) |
||
| 201 | chris | 37 | Gdx.gl.glEnable(GL20.GL_CULL_FACE); |
| 200 | chris | 38 | else |
| 201 | chris | 39 | Gdx.gl.glDisable(GL20.GL_CULL_FACE); |
| 200 | chris | 40 | } |
| 41 | |||
| 42 | if ((force) || (mVisibleFaces != mCurrentVisibleFaces)) |
||
| 43 | { |
||
| 44 | mCurrentVisibleFaces = mVisibleFaces; |
||
| 45 | switch (mVisibleFaces) |
||
| 46 | { |
||
| 47 | case CLOCKWISE: |
||
| 201 | chris | 48 | Gdx.gl.glFrontFace(GL20.GL_CW); |
| 200 | chris | 49 | break; |
| 50 | case COUNTERCLOCKWISE: |
||
| 201 | chris | 51 | Gdx.gl.glFrontFace(GL20.GL_CCW); |
| 200 | chris | 52 | break; |
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | /** Reset to default values. */ |
||
| 58 | @Override |
||
| 59 | public void reset() |
||
| 60 | { |
||
| 61 | mEnabled = mDefaultEnabled; |
||
| 62 | mVisibleFaces = mDefaultVisibleFaces; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** Check enabled state. */ |
||
| 66 | public final boolean isEnabled() |
||
| 67 | { |
||
| 68 | return mEnabled; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** Check default enabled state. */ |
||
| 72 | public final boolean isDefaultEnabled() |
||
| 73 | { |
||
| 74 | return mDefaultEnabled; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** Get vertex winding. */ |
||
| 78 | public final VertexWinding getVisibleFaces() |
||
| 79 | { |
||
| 80 | return mVisibleFaces; |
||
| 81 | } |
||
| 82 | |||
| 83 | /** Get default vertex winding. */ |
||
| 84 | public final VertexWinding getDefaultVisibleFaces() |
||
| 85 | { |
||
| 86 | return mDefaultVisibleFaces; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** Set enabled state. */ |
||
| 90 | public final void setEnabled(boolean value) |
||
| 91 | { |
||
| 92 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 93 | return; |
||
| 94 | mEnabled = value; |
||
| 95 | } |
||
| 96 | |||
| 97 | /** Set default enabled state. */ |
||
| 98 | public final void setDefaultEnabled(boolean value) |
||
| 99 | { |
||
| 100 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 101 | return; |
||
| 102 | mDefaultEnabled = value; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** Set vertex winding. */ |
||
| 106 | public final void setVisibleFaces(VertexWinding value) |
||
| 107 | { |
||
| 108 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 109 | return; |
||
| 110 | mVisibleFaces = value; |
||
| 111 | } |
||
| 112 | |||
| 113 | /** Set default vertex winding. */ |
||
| 114 | public final void setDefaultVisibleFaces(VertexWinding value) |
||
| 115 | { |
||
| 116 | if ((mLocked) || (mRenderStates.isLocked())) |
||
| 117 | return; |
||
| 118 | mDefaultVisibleFaces = value; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 |