Rev 798 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tao.OpenGl;
using BauzoidNET.graphics.texture;
using BauzoidNET.app;
#pragma warning disable 0618
namespace BauzoidNET
.graphics.renderstates
{
public class TextureStage
{
private RenderStates mRenderStates
= null;
private Texture mBoundTexture
= null;
private int mIndex
= 0;
static int mMaxTextureUnits
= -1;
/** Constructor. */
public TextureStage
(RenderStates renderStates,
int index
)
{
mIndex
= index
;
mRenderStates
= renderStates
;
}
/** Initialize render state. */
public void initialize
() //throws BauzoidException
{
if (mMaxTextureUnits
== -1)
{
/*IntBuffer numBuf = BufferUtils.newIntBuffer(16);
Gl.glGetIntegerv(Gl.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf);
mMaxTextureUnits = numBuf.get(0);*/
int[] numBuf
= new int[1];
Gl
.glGetIntegerv(Gl
.GL_MAX_TEXTURE_IMAGE_UNITS, numBuf
);
mMaxTextureUnits
= numBuf
[0];
}
if (mIndex
>= mMaxTextureUnits
)
LogUtil
.log(Consts
.LOG_TAG,
"Not enough texture stages to run this game!");
//throw new BauzoidException("Not enough texture stages to run this game!");
Gl
.glActiveTexture(Gl
.GL_TEXTURE0 + mIndex
);
Gl
.glEnable(Gl
.GL_TEXTURE_2D);
//gl.Disable(GL10.GL_TEXTURE_CUBE_MAP);
Gl
.glBindTexture(Gl
.GL_TEXTURE_2D,
0);
//gl.glBindTexture(GL10.GL_TEXTURE_CUBE_MAP);
//mBoundTarget = GL_TEXTURE_2D;
mBoundTexture
= null;
}
public void bindTexture
(Texture texture
)
{
bindTexture
(texture,
false);
}
public void bindTexture
(Texture texture,
bool force
)
{
if (mIndex
>= mMaxTextureUnits
)
return;
Gl
.glActiveTexture(Gl
.GL_TEXTURE0 + mIndex
);
if ((mBoundTexture
!= texture
) || (force
))
{
// Update the currently bound texture.
mBoundTexture
= texture
;
// Upload texture settings to GPU.
Gl
.glEnable(Gl
.GL_TEXTURE_2D);
if (mBoundTexture
!= null)
{
//Gl.glBindTexture(GL10.GL_TEXTURE_2D, mBoundTexture.getTextureObjectHandle());
mBoundTexture
.bind();
}
else
{
Gl
.glBindTexture(Gl
.GL_TEXTURE_2D,
0);
}
}
}
// HACK: should encapsulate Texture class instead
public void setTextureFilter
(Texture texture, Texture
.Filter minFilter, Texture
.Filter magFilter
)
{
//bindTexture(texture);
texture
.setFilter(minFilter, magFilter
);
}
public RenderStates getRenderStates
()
{
return mRenderStates
;
}
}
}