Rev 186 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.Bauzoid.graphics.renderstate;
import com.gebauz.Bauzoid.app.BauzoidException;
/** RenderStates
* Manage render states, tracking changes, supporting locking, and applying state switches only if necessary.
* Usage example:
* renderStates.blending.setBlendingMode(BlendingStates.BlendingMode.MULTIPLY);
* // ... set other render states
* renderStates.activate();
* // ...render object...
* renderStates.deactivate();
*
* All Render State Objects have three kinds of internal values: target, current, and default.
*
* Target values are those set by the user - those are the states the user wishes to set.
*
* Current values are those that the system is tracking, the current state. Each render state
* compares the target with the current value and only performs a state change when they differ
* to prevent unnecessary state changes.
*
* Default values are the base values that are set initially or when calling reset.
*
*/
public class RenderStates
{
public static final int NUM_TEXTURE_STAGES = 2;
public BlendingStates blending = new BlendingStates(this);
public CullingStates culling = new CullingStates(this);
public DepthTestStates depthTest = new DepthTestStates(this);
private TextureStage[] mTextureStages = new TextureStage[NUM_TEXTURE_STAGES];
private boolean mLocked = false;
/** Constructor. */
public RenderStates()
{
for (int i = 0; i < NUM_TEXTURE_STAGES; i++)
{
mTextureStages[i] = new TextureStage(this, i);
}
}
/** Initialize render states. */
public void initialize() throws BauzoidException
{
blending.initialize();
culling.initialize();
depthTest.initialize();
for (int i = 0; i < NUM_TEXTURE_STAGES; i++)
{
mTextureStages[i].initialize();
}
}
/** Activate renderstates - calls activate(false). */
public void activate()
{
activate(false);
}
/** Activate render states with force parameter. */
public void activate(boolean force)
{
blending.activate(force);
culling.activate(force);
depthTest.activate(force);
}
/** Reset to default values. */
public void reset()
{
blending.reset();
culling.reset();
depthTest.reset();
}
/** Deactivate render states. */
public void deactivate()
{
reset();
activate(false);
}
/** Check if the renderstates are locked. */
public boolean isLocked()
{
return mLocked;
}
/** Lock renderstates. */
public void lock(boolean lock)
{
mLocked = lock;
}
/** Get a texture stage. */
public final TextureStage getTextureStage(int index)
{
return mTextureStages[index];
}
}