1cfd74d65d832137e20e193c960802afba73b5d38sm/* 23c1e67e433728684b5f228c5d4f3e5b1457bb271sm * Copyright (C) 2010 The Android Open Source Project 3cfd74d65d832137e20e193c960802afba73b5d38sm * 4cfd74d65d832137e20e193c960802afba73b5d38sm * Licensed under the Apache License, Version 2.0 (the "License"); 5cfd74d65d832137e20e193c960802afba73b5d38sm * you may not use this file except in compliance with the License. 6cfd74d65d832137e20e193c960802afba73b5d38sm * You may obtain a copy of the License at 7cfd74d65d832137e20e193c960802afba73b5d38sm * 8cfd74d65d832137e20e193c960802afba73b5d38sm * http://www.apache.org/licenses/LICENSE-2.0 9cfd74d65d832137e20e193c960802afba73b5d38sm * 10cfd74d65d832137e20e193c960802afba73b5d38sm * Unless required by applicable law or agreed to in writing, software 11cfd74d65d832137e20e193c960802afba73b5d38sm * distributed under the License is distributed on an "AS IS" BASIS, 12cfd74d65d832137e20e193c960802afba73b5d38sm * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cfd74d65d832137e20e193c960802afba73b5d38sm * See the License for the specific language governing permissions and 14cfd74d65d832137e20e193c960802afba73b5d38sm * limitations under the License. 15cfd74d65d832137e20e193c960802afba73b5d38sm */ 16cfd74d65d832137e20e193c960802afba73b5d38sm 17cfd74d65d832137e20e193c960802afba73b5d38smpackage com.replica.replicaisland; 18cfd74d65d832137e20e193c960802afba73b5d38sm 19cfd74d65d832137e20e193c960802afba73b5d38smimport javax.microedition.khronos.opengles.GL10; 20cfd74d65d832137e20e193c960802afba73b5d38smimport javax.microedition.khronos.opengles.GL11; 21cfd74d65d832137e20e193c960802afba73b5d38smimport javax.microedition.khronos.opengles.GL11Ext; 22cfd74d65d832137e20e193c960802afba73b5d38sm 23cfd74d65d832137e20e193c960802afba73b5d38sm/** 24cfd74d65d832137e20e193c960802afba73b5d38sm * An object wrapper for a pointer to the OpenGL context. Note that the context is only valid 25cfd74d65d832137e20e193c960802afba73b5d38sm * in certain threads at certain times (namely, in the Rendering thread during draw time), and at 26cfd74d65d832137e20e193c960802afba73b5d38sm * other times getGL() will return null. 27cfd74d65d832137e20e193c960802afba73b5d38sm */ 28cfd74d65d832137e20e193c960802afba73b5d38smpublic class OpenGLSystem extends BaseObject { 29cfd74d65d832137e20e193c960802afba73b5d38sm 30cfd74d65d832137e20e193c960802afba73b5d38sm private static GL10 sGL; 31cfd74d65d832137e20e193c960802afba73b5d38sm private static int sLastBoundTexture; 32cfd74d65d832137e20e193c960802afba73b5d38sm private static int sLastSetCropSignature; 33cfd74d65d832137e20e193c960802afba73b5d38sm 34cfd74d65d832137e20e193c960802afba73b5d38sm public OpenGLSystem() { 35cfd74d65d832137e20e193c960802afba73b5d38sm super(); 36cfd74d65d832137e20e193c960802afba73b5d38sm sGL = null; 37cfd74d65d832137e20e193c960802afba73b5d38sm } 38cfd74d65d832137e20e193c960802afba73b5d38sm 39cfd74d65d832137e20e193c960802afba73b5d38sm public OpenGLSystem(GL10 gl) { 40cfd74d65d832137e20e193c960802afba73b5d38sm sGL = gl; 41cfd74d65d832137e20e193c960802afba73b5d38sm } 42cfd74d65d832137e20e193c960802afba73b5d38sm 43cfd74d65d832137e20e193c960802afba73b5d38sm public static final void setGL(GL10 gl) { 44cfd74d65d832137e20e193c960802afba73b5d38sm sGL = gl; 45cfd74d65d832137e20e193c960802afba73b5d38sm sLastBoundTexture = 0; 46cfd74d65d832137e20e193c960802afba73b5d38sm sLastSetCropSignature = 0; 47cfd74d65d832137e20e193c960802afba73b5d38sm } 48cfd74d65d832137e20e193c960802afba73b5d38sm 49cfd74d65d832137e20e193c960802afba73b5d38sm public static final GL10 getGL() { 50cfd74d65d832137e20e193c960802afba73b5d38sm return sGL; 51cfd74d65d832137e20e193c960802afba73b5d38sm } 52cfd74d65d832137e20e193c960802afba73b5d38sm 53cfd74d65d832137e20e193c960802afba73b5d38sm public static final void bindTexture(int target, int texture) { 54cfd74d65d832137e20e193c960802afba73b5d38sm if (sLastBoundTexture != texture) { 55cfd74d65d832137e20e193c960802afba73b5d38sm sGL.glBindTexture(target, texture); 56cfd74d65d832137e20e193c960802afba73b5d38sm sLastBoundTexture = texture; 57cfd74d65d832137e20e193c960802afba73b5d38sm sLastSetCropSignature = 0; 58cfd74d65d832137e20e193c960802afba73b5d38sm } 59cfd74d65d832137e20e193c960802afba73b5d38sm } 60cfd74d65d832137e20e193c960802afba73b5d38sm 61cfd74d65d832137e20e193c960802afba73b5d38sm public static final void setTextureCrop(int[] crop) { 62cfd74d65d832137e20e193c960802afba73b5d38sm int cropSignature = 0; 63cfd74d65d832137e20e193c960802afba73b5d38sm cropSignature = (crop[0] + crop[1]) << 16; 64cfd74d65d832137e20e193c960802afba73b5d38sm cropSignature |= crop[2] + crop[3]; 65cfd74d65d832137e20e193c960802afba73b5d38sm 66cfd74d65d832137e20e193c960802afba73b5d38sm if (cropSignature != sLastSetCropSignature) { 67cfd74d65d832137e20e193c960802afba73b5d38sm ((GL11) sGL).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, 68cfd74d65d832137e20e193c960802afba73b5d38sm crop, 0); 69cfd74d65d832137e20e193c960802afba73b5d38sm sLastSetCropSignature = cropSignature; 70cfd74d65d832137e20e193c960802afba73b5d38sm } 71cfd74d65d832137e20e193c960802afba73b5d38sm } 72cfd74d65d832137e20e193c960802afba73b5d38sm 73cfd74d65d832137e20e193c960802afba73b5d38sm @Override 74cfd74d65d832137e20e193c960802afba73b5d38sm public void reset() { 75cfd74d65d832137e20e193c960802afba73b5d38sm 76cfd74d65d832137e20e193c960802afba73b5d38sm } 77cfd74d65d832137e20e193c960802afba73b5d38sm 78cfd74d65d832137e20e193c960802afba73b5d38sm} 79