Rev 798 | Go to most recent revision | Details | 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; |
||
| 9 | |||
| 10 | namespace BauzoidNET.graphics.renderstates |
||
| 11 | { |
||
| 12 | public class TextureStage |
||
| 13 | { |
||
| 14 | private RenderStates mRenderStates = null; |
||
| 15 | private Texture mBoundTexture = null; |
||
| 16 | private int mIndex = 0; |
||
| 17 | |||
| 18 | static int mMaxTextureUnits = -1; |
||
| 19 | |||
| 20 | /** Constructor. */ |
||
| 21 | public TextureStage(RenderStates renderStates, int index) |
||
| 22 | { |
||
| 23 | mIndex = index; |
||
| 24 | mRenderStates = renderStates; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** Initialize render state. */ |
||
| 28 | public void initialize() //throws BauzoidException |
||
| 29 | { |
||
| 30 | if (mMaxTextureUnits == -1) |
||
| 31 | { |
||
| 32 | /*IntBuffer numBuf = BufferUtils.newIntBuffer(16); |
||
| 33 | Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf); |
||
| 34 | mMaxTextureUnits = numBuf.get(0);*/ |
||
| 35 | int[] numBuf = new int[1]; |
||
| 36 | Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf); |
||
| 37 | mMaxTextureUnits = numBuf[0]; |
||
| 38 | } |
||
| 39 | |||
| 40 | //if (mIndex >= mMaxTextureUnits) |
||
| 41 | // throw new BauzoidException("Not enough texture stages to run this game!"); |
||
| 42 | |||
| 43 | Gl.glActiveTexture(Gl.GL_TEXTURE0 + mIndex); |
||
| 44 | |||
| 45 | Gl.glEnable(Gl.GL_TEXTURE_2D); |
||
| 46 | //gl.Disable(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 47 | Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0); |
||
| 48 | //gl.glBindTexture(GL10.GL_TEXTURE_CUBE_MAP); |
||
| 49 | |||
| 50 | //mBoundTarget = GL_TEXTURE_2D; |
||
| 51 | mBoundTexture = null; |
||
| 52 | } |
||
| 53 | |||
| 54 | public void bindTexture(Texture texture) |
||
| 55 | { |
||
| 56 | bindTexture(texture, false); |
||
| 57 | } |
||
| 58 | |||
| 59 | public void bindTexture(Texture texture, bool force) |
||
| 60 | { |
||
| 61 | if (mIndex >= mMaxTextureUnits) |
||
| 62 | return; |
||
| 63 | |||
| 64 | Gl.glActiveTexture(Gl.GL_TEXTURE0 + mIndex); |
||
| 65 | |||
| 66 | if ((mBoundTexture != texture) || (force)) |
||
| 67 | { |
||
| 68 | // Update the currently bound texture. |
||
| 69 | mBoundTexture = texture; |
||
| 70 | |||
| 71 | // Upload texture settings to GPU. |
||
| 72 | Gl.glEnable(Gl.GL_TEXTURE_2D); |
||
| 73 | |||
| 74 | if (mBoundTexture != null) |
||
| 75 | { |
||
| 76 | //Gl.glBindTexture(GL10.GL_TEXTURE_2D, mBoundTexture.getTextureObjectHandle()); |
||
| 77 | mBoundTexture.bind(); |
||
| 78 | } |
||
| 79 | else |
||
| 80 | { |
||
| 81 | Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | // HACK: should encapsulate Texture class instead |
||
| 87 | public void setTextureFilter(Texture texture, Texture.Filter minFilter, Texture.Filter magFilter) |
||
| 88 | { |
||
| 89 | //bindTexture(texture); |
||
| 90 | texture.setFilter(minFilter, magFilter); |
||
| 91 | } |
||
| 92 | |||
| 93 | public RenderStates getRenderStates() |
||
| 94 | { |
||
| 95 | return mRenderStates; |
||
| 96 | } |
||
| 97 | |||
| 98 | } |
||
| 99 | } |