?? fasttexturedpolygonrenderer.java
字號:
//================================================
// METHOD 4: reduce the number of divides
// (interpolate every 16 pixels)
// Also, apply a VM optimization by referring to
// the texture's class rather than it's parent class.
//================================================
// the following three ScanRenderers are the same, but refer
// to textures explicitly as either a PowerOf2Texture, a
// ShadedTexture, or a ShadedSurface.
// This allows HotSpot to do some inlining of the textures'
// getColor() method, which significantly increases
// performance.
public class PowerOf2TextureRenderer extends ScanRenderer {
public void render(int offset, int left, int right) {
PowerOf2Texture texture =
(PowerOf2Texture)currentTexture;
float u = SCALE * a.getDotProduct(viewPos);
float v = SCALE * b.getDotProduct(viewPos);
float z = c.getDotProduct(viewPos);
float du = INTERP_SIZE * SCALE * a.x;
float dv = INTERP_SIZE * SCALE * b.x;
float dz = INTERP_SIZE * c.x;
int nextTx = (int)(u/z);
int nextTy = (int)(v/z);
int x = left;
while (x <= right) {
int tx = nextTx;
int ty = nextTy;
int maxLength = right-x+1;
if (maxLength > INTERP_SIZE) {
u+=du;
v+=dv;
z+=dz;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
int dtx = (nextTx-tx) >> INTERP_SIZE_BITS;
int dty = (nextTy-ty) >> INTERP_SIZE_BITS;
int endOffset = offset + INTERP_SIZE;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=INTERP_SIZE;
}
else {
// variable interpolation size
int interpSize = maxLength;
u += interpSize * SCALE * a.x;
v += interpSize * SCALE * b.x;
z += interpSize * c.x;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
int dtx = (nextTx-tx) / interpSize;
int dty = (nextTy-ty) / interpSize;
int endOffset = offset + interpSize;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=interpSize;
}
}
}
}
public class ShadedTextureRenderer extends ScanRenderer {
public void render(int offset, int left, int right) {
ShadedTexture texture =
(ShadedTexture)currentTexture;
float u = SCALE * a.getDotProduct(viewPos);
float v = SCALE * b.getDotProduct(viewPos);
float z = c.getDotProduct(viewPos);
float du = INTERP_SIZE * SCALE * a.x;
float dv = INTERP_SIZE * SCALE * b.x;
float dz = INTERP_SIZE * c.x;
int nextTx = (int)(u/z);
int nextTy = (int)(v/z);
int x = left;
while (x <= right) {
int tx = nextTx;
int ty = nextTy;
int maxLength = right-x+1;
if (maxLength > INTERP_SIZE) {
u+=du;
v+=dv;
z+=dz;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
int dtx = (nextTx-tx) >> INTERP_SIZE_BITS;
int dty = (nextTy-ty) >> INTERP_SIZE_BITS;
int endOffset = offset + INTERP_SIZE;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=INTERP_SIZE;
}
else {
// variable interpolation size
int interpSize = maxLength;
u += interpSize * SCALE * a.x;
v += interpSize * SCALE * b.x;
z += interpSize * c.x;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
int dtx = (nextTx-tx) / interpSize;
int dty = (nextTy-ty) / interpSize;
int endOffset = offset + interpSize;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=interpSize;
}
}
}
}
public class ShadedSurfaceRenderer extends ScanRenderer {
public int checkBounds(int vScaled, int bounds) {
int v = vScaled >> SCALE_BITS;
if (v < 0) {
vScaled = 0;
}
else if (v >= bounds) {
vScaled = (bounds - 1) << SCALE_BITS;
}
return vScaled;
}
public void render(int offset, int left, int right) {
ShadedSurface texture =
(ShadedSurface)currentTexture;
float u = SCALE * a.getDotProduct(viewPos);
float v = SCALE * b.getDotProduct(viewPos);
float z = c.getDotProduct(viewPos);
float du = INTERP_SIZE * SCALE * a.x;
float dv = INTERP_SIZE * SCALE * b.x;
float dz = INTERP_SIZE * c.x;
int nextTx = (int)(u/z);
int nextTy = (int)(v/z);
int x = left;
while (x <= right) {
int tx = nextTx;
int ty = nextTy;
int maxLength = right-x+1;
if (maxLength > INTERP_SIZE) {
u+=du;
v+=dv;
z+=dz;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
int dtx = (nextTx-tx) >> INTERP_SIZE_BITS;
int dty = (nextTy-ty) >> INTERP_SIZE_BITS;
int endOffset = offset + INTERP_SIZE;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=INTERP_SIZE;
}
else {
// variable interpolation size
int interpSize = maxLength;
u += interpSize * SCALE * a.x;
v += interpSize * SCALE * b.x;
z += interpSize * c.x;
nextTx = (int)(u/z);
nextTy = (int)(v/z);
// make sure tx, ty, nextTx, and nextTy are
// all within bounds
tx = checkBounds(tx, texture.getWidth());
ty = checkBounds(ty, texture.getHeight());
nextTx = checkBounds(nextTx, texture.getWidth());
nextTy = checkBounds(nextTy, texture.getHeight());
int dtx = (nextTx-tx) / interpSize;
int dty = (nextTy-ty) / interpSize;
int endOffset = offset + interpSize;
while (offset < endOffset) {
doubleBufferData[offset++] =
texture.getColor(
tx >> SCALE_BITS, ty >> SCALE_BITS);
tx+=dtx;
ty+=dty;
}
x+=interpSize;
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -