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