if (!dc.isPickingMode() && mustApplyTexture(i) && this.getTexture(i).bind(
dc)) // bind initiates retrieval
{
this.getTexture(i).applyInternalTransform(dc);
Geometry mesh = this.getCurrentShapeData().getMesh(i);
if (getOffsets(i, 0) != null) // if texture offsets exist
{
// apply offsets to texture coords to properly position and warp the texture
// TODO: should only do this when offsets have changed, e.g. during editing!
int bufferSize = mesh.getBuffer(Geometry.TEXTURE).limit();
FloatBuffer texCoords = (FloatBuffer) mesh.getBuffer(Geometry.TEXTURE);
FloatBuffer offsetCoords = Buffers.newDirectFloatBuffer(bufferSize);
for (int j = 0; j < bufferSize; j += 2)
{
float u = texCoords.get(j);
float v = texCoords.get(j + 1);
// bilinear interpolation of the uv corner offsets
float uOffset = -getOffsets(i, 0)[0] * (1 - u) * (v)
- getOffsets(i, 1)[0] * (u) * (v)
- getOffsets(i, 2)[0] * (1 - u) * (1 - v)
- getOffsets(i, 3)[0] * (u) * (1 - v)
+ u;
float vOffset = -getOffsets(i, 0)[1] * (1 - u) * (v)
- getOffsets(i, 1)[1] * (u) * (v)
- getOffsets(i, 2)[1] * (1 - u) * (1 - v)
- getOffsets(i, 3)[1] * (u) * (1 - v)
+ v;
offsetCoords.put(j, uOffset);
offsetCoords.put(j + 1, vOffset);
}
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, offsetCoords.rewind());
}
else
{
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, mesh.getBuffer(Geometry.TEXTURE).rewind());
}
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);