Rev 798 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 787 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.Linq; |
||
| 4 | using System.Text; |
||
| 5 | using System.Threading.Tasks; |
||
| 6 | |||
| 7 | using Tao.OpenGl; |
||
| 8 | using BauzoidNET.graphics.texture; |
||
| 798 | chris | 9 | using BauzoidNET.app; |
| 787 | chris | 10 | |
| 1451 | chris | 11 | #pragma warning disable 0618 |
| 12 | |||
| 787 | chris | 13 | namespace BauzoidNET.graphics.renderstates |
| 14 | { |
||
| 15 | public class TextureStage |
||
| 16 | { |
||
| 17 | private RenderStates mRenderStates = null; |
||
| 18 | private Texture mBoundTexture = null; |
||
| 19 | private int mIndex = 0; |
||
| 20 | |||
| 21 | static int mMaxTextureUnits = -1; |
||
| 22 | |||
| 23 | /** Constructor. */ |
||
| 24 | public TextureStage(RenderStates renderStates, int index) |
||
| 25 | { |
||
| 26 | mIndex = index; |
||
| 27 | mRenderStates = renderStates; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** Initialize render state. */ |
||
| 31 | public void initialize() //throws BauzoidException |
||
| 32 | { |
||
| 33 | if (mMaxTextureUnits == -1) |
||
| 34 | { |
||
| 35 | /*IntBuffer numBuf = BufferUtils.newIntBuffer(16); |
||
| 36 | Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf); |
||
| 37 | mMaxTextureUnits = numBuf.get(0);*/ |
||
| 38 | int[] numBuf = new int[1]; |
||
| 39 | Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf); |
||
| 40 | mMaxTextureUnits = numBuf[0]; |
||
| 41 | } |
||
| 42 | |||
| 798 | chris | 43 | if (mIndex >= mMaxTextureUnits) |
| 44 | LogUtil.log(Consts.LOG_TAG, "Not enough texture stages to run this game!"); |
||
| 45 | //throw new BauzoidException("Not enough texture stages to run this game!"); |
||
| 787 | chris | 46 | |
| 47 | Gl.glActiveTexture(Gl.GL_TEXTURE0 + mIndex); |
||
| 48 | |||
| 49 | Gl.glEnable(Gl.GL_TEXTURE_2D); |
||
| 50 | //gl.Disable(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 51 | Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0); |
||
| 52 | //gl.glBindTexture(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 53 | |||
| 54 | //mBoundTarget = GL_TEXTURE_2D; |
||
| 55 | mBoundTexture = null; |
||
| 56 | } |
||
| 57 | |||
| 58 | public void bindTexture(Texture texture) |
||
| 59 | { |
||
| 60 | bindTexture(texture, false); |
||
| 61 | } |
||
| 62 | |||
| 63 | public void bindTexture(Texture texture, bool force) |
||
| 64 | { |
||
| 65 | if (mIndex >= mMaxTextureUnits) |
||
| 66 | return; |
||
| 67 | |||
| 68 | Gl.glActiveTexture(Gl.GL_TEXTURE0 + mIndex); |
||
| 69 | |||
| 70 | if ((mBoundTexture != texture) || (force)) |
||
| 71 | { |
||
| 72 | // Update the currently bound texture. |
||
| 73 | mBoundTexture = texture; |
||
| 74 | |||
| 75 | // Upload texture settings to GPU. |
||
| 76 | Gl.glEnable(Gl.GL_TEXTURE_2D); |
||
| 77 | |||
| 78 | if (mBoundTexture != null) |
||
| 79 | { |
||
| 80 | //Gl.glBindTexture(GL10.GL_TEXTURE_2D, mBoundTexture.getTextureObjectHandle()); |
||
| 81 | mBoundTexture.bind(); |
||
| 82 | } |
||
| 83 | else |
||
| 84 | { |
||
| 85 | Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | // HACK: should encapsulate Texture class instead |
||
| 91 | public void setTextureFilter(Texture texture, Texture.Filter minFilter, Texture.Filter magFilter) |
||
| 92 | { |
||
| 93 | //bindTexture(texture); |
||
| 94 | texture.setFilter(minFilter, magFilter); |
||
| 95 | } |
||
| 96 | |||
| 97 | public RenderStates getRenderStates() |
||
| 98 | { |
||
| 99 | return mRenderStates; |
||
| 100 | } |
||
| 101 | |||
| 102 | } |
||
| 103 | } |