このメソッドを実行して、OpenGLドライバーの状態エラーを確認します。
public void checkGlError(String op) {
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
Log.e("ShadingZen", op + ": glError " + error);
//throw new RuntimeException(op + ": glError " + error);
}
}
テストデバイスによっては、2つのテクスチャのパワー以外を使用できない場合があります。このコードは、それらを^ 2サイズに変換する方法を示しています(Androidの場合)。
int calculateUpperPowerOfTwo(int v)
{
v--;
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
v++;
return v;
}
boolean isPowerOfTwo(int i){
return ( i & (i - 1)) == 0;
}
boolean loadAsTexture2D(Context context, String id, int resource_id, BitmapTexture.Parameters params){
_bmps = new Bitmap[1];
Matrix flip = new Matrix();
flip.postScale(1f, -1f);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
Bitmap textureBmp = BitmapFactory.decodeResource(context.getResources(), resource_id, opts);
if(!isPowerOfTwo(textureBmp.getWidth()) || !isPowerOfTwo(textureBmp.getHeight())){
int target_width = calculateUpperPowerOfTwo(textureBmp.getWidth());
int target_height = calculateUpperPowerOfTwo(textureBmp.getHeight());
Log.i("ShadingZen", "Texture id=" + id + " has no power of two dimesions " + textureBmp.getWidth() + "x" + textureBmp.getHeight() + " adjusting to " + target_width + "x" + target_height);
Bitmap temp = Bitmap.createBitmap(textureBmp, 0, 0, textureBmp.getWidth(), textureBmp.getHeight(), flip, false);
_bmps[0] = Bitmap.createScaledBitmap(temp, target_width, target_height, false);
temp.recycle();
} else{
_bmps[0] = Bitmap.createBitmap(textureBmp, 0, 0, textureBmp.getWidth(), textureBmp.getHeight(), flip, false);
}
textureBmp.recycle();
// At this point _bmp[0] contains a ^2 bitmap
}
詳細については、このクラスを確認してください:https ://github.com/TraxNet/ShadingZen/blob/master/library/src/main/java/org/traxnet/shadingzen/core/BitmapTexture.java