Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 265 | chris | 1 | package com.gebauz.Bauzoid.graphics.renderstates; |
| 2 | |||
| 3 | import java.nio.IntBuffer; |
||
| 4 | |||
| 5 | import com.badlogic.gdx.Gdx; |
||
| 6 | //import com.badlogic.gdx.graphics.GL10; |
||
| 7 | import com.badlogic.gdx.graphics.GL20; |
||
| 8 | import com.badlogic.gdx.graphics.Texture; |
||
| 9 | import com.badlogic.gdx.utils.BufferUtils; |
||
| 10 | import com.gebauz.Bauzoid.app.BauzoidException; |
||
| 11 | |||
| 12 | /** Special kind of render state managing a specific texture stage. */ |
||
| 13 | public class TextureStage |
||
| 14 | { |
||
| 15 | private RenderStates mRenderStates = null; |
||
| 16 | private Texture mBoundTexture = null; |
||
| 17 | private int mIndex = 0; |
||
| 18 | |||
| 19 | static int mMaxTextureUnits = -1; |
||
| 20 | |||
| 21 | /** Constructor. */ |
||
| 22 | public TextureStage(RenderStates renderStates, int index) |
||
| 23 | { |
||
| 24 | mIndex = index; |
||
| 25 | mRenderStates = renderStates; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** Initialize render state. */ |
||
| 29 | void initialize() throws BauzoidException |
||
| 30 | { |
||
| 31 | if (mMaxTextureUnits == -1) |
||
| 32 | { |
||
| 33 | IntBuffer numBuf = BufferUtils.newIntBuffer(16); |
||
| 34 | Gdx.gl20.glGetIntegerv(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf); |
||
| 35 | mMaxTextureUnits = numBuf.get(0); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (mIndex >= mMaxTextureUnits) |
||
| 39 | throw new BauzoidException("Not enough texture stages to run this game!"); |
||
| 40 | |||
| 41 | Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0 + mIndex); |
||
| 42 | |||
| 43 | Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D); |
||
| 44 | //gl.Disable(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 45 | Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_2D, 0); |
||
| 46 | //gl.glBindTexture(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 47 | |||
| 48 | //mBoundTarget = GL_TEXTURE_2D; |
||
| 49 | mBoundTexture = null; |
||
| 50 | } |
||
| 51 | |||
| 52 | public void bindTexture(Texture texture) |
||
| 53 | { |
||
| 54 | bindTexture(texture, false); |
||
| 55 | } |
||
| 56 | |||
| 57 | public void bindTexture(Texture texture, boolean force) |
||
| 58 | { |
||
| 59 | if (mIndex >= mMaxTextureUnits) |
||
| 60 | return; |
||
| 61 | |||
| 62 | Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0 + mIndex); |
||
| 63 | |||
| 64 | if ((mBoundTexture != texture) || (force)) |
||
| 65 | { |
||
| 66 | // Update the currently bound texture. |
||
| 67 | mBoundTexture = texture; |
||
| 68 | |||
| 69 | // Upload texture settings to GPU. |
||
| 70 | Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D); |
||
| 71 | |||
| 72 | if (mBoundTexture != null) |
||
| 73 | { |
||
| 74 | //Gdx.gl20.glBindTexture(GL10.GL_TEXTURE_2D, mBoundTexture.getTextureObjectHandle()); |
||
| 75 | mBoundTexture.bind(); |
||
| 76 | } |
||
| 77 | else |
||
| 78 | { |
||
| 79 | Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_2D, 0); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | public final RenderStates getRenderStates() |
||
| 85 | { |
||
| 86 | return mRenderStates; |
||
| 87 | } |
||
| 88 | |||
| 89 | |||
| 90 | } |