diff --git a/android/AndroidOpenGLESLessons/.classpath b/android/AndroidOpenGLESLessons/.classpath
index 6e9239f..a4f1e40 100644
--- a/android/AndroidOpenGLESLessons/.classpath
+++ b/android/AndroidOpenGLESLessons/.classpath
@@ -3,5 +3,6 @@
-
+
+
diff --git a/android/AndroidOpenGLESLessons/AUTHORS-LIBGDX.TXT b/android/AndroidOpenGLESLessons/AUTHORS-LIBGDX.TXT
new file mode 100644
index 0000000..e55a032
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/AUTHORS-LIBGDX.TXT
@@ -0,0 +1,10 @@
+# This is the official list of the AUTHORS of libgdx
+# for copyright purposes.
+# This file is distinct from the CONTRIBUTORS files.
+# See the latter for an explanation.
+
+# Names should be added to this file as
+# Name or Organization
+# The email address is not required for organizations.
+Mario Zechner
+Nathan Sweet
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/AndroidManifest.xml b/android/AndroidOpenGLESLessons/AndroidManifest.xml
index b5ad831..e48ba51 100644
--- a/android/AndroidOpenGLESLessons/AndroidManifest.xml
+++ b/android/AndroidOpenGLESLessons/AndroidManifest.xml
@@ -2,7 +2,7 @@
+ android:versionCode="8" android:versionName="1.0.6">
@@ -41,5 +41,8 @@
+
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/libs/armeabi-v7a/libandroidgl20.so b/android/AndroidOpenGLESLessons/libs/armeabi-v7a/libandroidgl20.so
new file mode 100644
index 0000000..7a7cd7f
Binary files /dev/null and b/android/AndroidOpenGLESLessons/libs/armeabi-v7a/libandroidgl20.so differ
diff --git a/android/AndroidOpenGLESLessons/libs/armeabi/libandroidgl20.so b/android/AndroidOpenGLESLessons/libs/armeabi/libandroidgl20.so
new file mode 100644
index 0000000..7a7cd7f
Binary files /dev/null and b/android/AndroidOpenGLESLessons/libs/armeabi/libandroidgl20.so differ
diff --git a/android/AndroidOpenGLESLessons/lint.xml b/android/AndroidOpenGLESLessons/lint.xml
new file mode 100644
index 0000000..ee0eead
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/lint.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/proguard.cfg b/android/AndroidOpenGLESLessons/proguard.cfg
index 12dd039..b1cdf17 100644
--- a/android/AndroidOpenGLESLessons/proguard.cfg
+++ b/android/AndroidOpenGLESLessons/proguard.cfg
@@ -18,14 +18,18 @@
native ;
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet);
}
--keepclasseswithmembernames class * {
+-keepclasseswithmembers class * {
public (android.content.Context, android.util.AttributeSet, int);
}
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
diff --git a/android/AndroidOpenGLESLessons/res/drawable-hdpi/ic_lesson_seven.png b/android/AndroidOpenGLESLessons/res/drawable-hdpi/ic_lesson_seven.png
new file mode 100644
index 0000000..10bb8f4
Binary files /dev/null and b/android/AndroidOpenGLESLessons/res/drawable-hdpi/ic_lesson_seven.png differ
diff --git a/android/AndroidOpenGLESLessons/res/drawable-nodpi/usb_android.png b/android/AndroidOpenGLESLessons/res/drawable-nodpi/usb_android.png
new file mode 100644
index 0000000..fa8e82c
Binary files /dev/null and b/android/AndroidOpenGLESLessons/res/drawable-nodpi/usb_android.png differ
diff --git a/android/AndroidOpenGLESLessons/res/layout/lesson_seven.xml b/android/AndroidOpenGLESLessons/res/layout/lesson_seven.xml
new file mode 100644
index 0000000..efef8e7
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/res/layout/lesson_seven.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/AndroidOpenGLESLessons/res/raw/lesson_seven_fragment_shader.glsl b/android/AndroidOpenGLESLessons/res/raw/lesson_seven_fragment_shader.glsl
new file mode 100644
index 0000000..943ca1c
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/res/raw/lesson_seven_fragment_shader.glsl
@@ -0,0 +1,32 @@
+precision mediump float; // Set the default precision to medium. We don't need as high of a
+ // precision in the fragment shader.
+uniform vec3 u_LightPos; // The position of the light in eye space.
+uniform sampler2D u_Texture; // The input texture.
+
+varying vec3 v_Position; // Interpolated position for this fragment.
+varying vec3 v_Normal; // Interpolated normal for this fragment.
+varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
+
+// The entry point for our fragment shader.
+void main()
+{
+ // Will be used for attenuation.
+ float distance = length(u_LightPos - v_Position);
+
+ // Get a lighting direction vector from the light to the vertex.
+ vec3 lightVector = normalize(u_LightPos - v_Position);
+
+ // Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
+ // pointing in the same direction then it will get max illumination.
+ float diffuse = max(dot(v_Normal, lightVector), 0.0);
+
+ // Add attenuation.
+ diffuse = diffuse * (1.0 / distance);
+
+ // Add ambient lighting
+ diffuse = diffuse + 0.2;
+
+ // Multiply the color by the diffuse illumination level and texture value to get final output color.
+ gl_FragColor = (diffuse * texture2D(u_Texture, v_TexCoordinate));
+ }
+
diff --git a/android/AndroidOpenGLESLessons/res/raw/lesson_seven_vertex_shader.glsl b/android/AndroidOpenGLESLessons/res/raw/lesson_seven_vertex_shader.glsl
new file mode 100644
index 0000000..2d2564e
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/res/raw/lesson_seven_vertex_shader.glsl
@@ -0,0 +1,27 @@
+uniform mat4 u_MVPMatrix; // A constant representing the combined model/view/projection matrix.
+uniform mat4 u_MVMatrix; // A constant representing the combined model/view matrix.
+
+attribute vec4 a_Position; // Per-vertex position information we will pass in.
+attribute vec3 a_Normal; // Per-vertex normal information we will pass in.
+attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.
+
+varying vec3 v_Position; // This will be passed into the fragment shader.
+varying vec3 v_Normal; // This will be passed into the fragment shader.
+varying vec2 v_TexCoordinate; // This will be passed into the fragment shader.
+
+// The entry point for our vertex shader.
+void main()
+{
+ // Transform the vertex into eye space.
+ v_Position = vec3(u_MVMatrix * a_Position);
+
+ // Pass through the texture coordinate.
+ v_TexCoordinate = a_TexCoordinate;
+
+ // Transform the normal's orientation into eye space.
+ v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
+
+ // gl_Position is a special variable used to store the final position.
+ // Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
+ gl_Position = u_MVPMatrix * a_Position;
+}
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/res/values/strings.xml b/android/AndroidOpenGLESLessons/res/values/strings.xml
index 7417e85..c14604c 100644
--- a/android/AndroidOpenGLESLessons/res/values/strings.xml
+++ b/android/AndroidOpenGLESLessons/res/values/strings.xml
@@ -32,4 +32,12 @@
GL_NEARESTGL_LINEAR
-
+ Lesson Seven: An Intro to VBOs
+ This lesson looks at vertex buffer objects (VBOs).
+ Increase cube count
+ Decrease cube count
+ Using VBOs
+ Not using VBOs
+ Using stride
+ Not using stride
+
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/backends/android/AndroidGL20.java b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/backends/android/AndroidGL20.java
new file mode 100644
index 0000000..1691828
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/backends/android/AndroidGL20.java
@@ -0,0 +1,324 @@
+/*******************************************************************************
+ * Copyright 2011 See AUTHORS-LIBGDX file.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.badlogic.gdx.backends.android;
+
+import java.nio.Buffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
+import com.badlogic.gdx.graphics.GL20;
+
+public class AndroidGL20 implements GL20 {
+ static {
+ System.loadLibrary("androidgl20");
+ init();
+ }
+
+ private static native void init ();
+
+ public native void glActiveTexture (int texture);
+
+ public native void glAttachShader (int program, int shader);
+
+ public native void glBindAttribLocation (int program, int index, String name);
+
+ public native void glBindBuffer (int target, int buffer);
+
+ public native void glBindFramebuffer (int target, int framebuffer);
+
+ public native void glBindRenderbuffer (int target, int renderbuffer);
+
+ public native void glBindTexture (int target, int texture);
+
+ public native void glBlendColor (float red, float green, float blue, float alpha);
+
+ public native void glBlendEquation (int mode);
+
+ public native void glBlendEquationSeparate (int modeRGB, int modeAlpha);
+
+ public native void glBlendFunc (int sfactor, int dfactor);
+
+ public native void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
+
+ public native void glBufferData (int target, int size, Buffer data, int usage);
+
+ public native void glBufferSubData (int target, int offset, int size, Buffer data);
+
+ public native int glCheckFramebufferStatus (int target);
+
+ public native void glClear (int mask);
+
+ public native void glClearColor (float red, float green, float blue, float alpha);
+
+ public native void glClearDepthf (float depth);
+
+ public native void glClearStencil (int s);
+
+ public native void glColorMask (boolean red, boolean green, boolean blue, boolean alpha);
+
+ public native void glCompileShader (int shader);
+
+ public native void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ int imageSize, Buffer data);
+
+ public native void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
+ int format, int imageSize, Buffer data);
+
+ public native void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border);
+
+ public native void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
+
+ public native int glCreateProgram ();
+
+ public native int glCreateShader (int type);
+
+ public native void glCullFace (int mode);
+
+ public native void glDeleteBuffers (int n, IntBuffer buffers);
+
+ public native void glDeleteFramebuffers (int n, IntBuffer framebuffers);
+
+ public native void glDeleteProgram (int program);
+
+ public native void glDeleteRenderbuffers (int n, IntBuffer renderbuffers);
+
+ public native void glDeleteShader (int shader);
+
+ public native void glDeleteTextures (int n, IntBuffer textures);
+
+ public native void glDepthFunc (int func);
+
+ public native void glDepthMask (boolean flag);
+
+ public native void glDepthRangef (float zNear, float zFar);
+
+ public native void glDetachShader (int program, int shader);
+
+ public native void glDisable (int cap);
+
+ public native void glDisableVertexAttribArray (int index);
+
+ public native void glDrawArrays (int mode, int first, int count);
+
+ public native void glDrawElements (int mode, int count, int type, Buffer indices);
+
+ public native void glDrawElements (int mode, int count, int type, int indices);
+
+ public native void glEnable (int cap);
+
+ public native void glEnableVertexAttribArray (int index);
+
+ public native void glFinish ();
+
+ public native void glFlush ();
+
+ public native void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer);
+
+ public native void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level);
+
+ public native void glFrontFace (int mode);
+
+ public native void glGenBuffers (int n, IntBuffer buffers);
+
+ public native void glGenerateMipmap (int target);
+
+ public native void glGenFramebuffers (int n, IntBuffer framebuffers);
+
+ public native void glGenRenderbuffers (int n, IntBuffer renderbuffers);
+
+ public native void glGenTextures (int n, IntBuffer textures);
+
+ public native String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type);
+
+ public native String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type);
+
+ public native void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders);
+
+ public native int glGetAttribLocation (int program, String name);
+
+ public native void glGetBooleanv (int pname, Buffer params);
+
+ public native void glGetBufferParameteriv (int target, int pname, IntBuffer params);
+
+ public native int glGetError ();
+
+ public native void glGetFloatv (int pname, FloatBuffer params);
+
+ public native void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params);
+
+ public native void glGetIntegerv (int pname, IntBuffer params);
+
+ public native void glGetProgramiv (int program, int pname, IntBuffer params);
+
+ public native String glGetProgramInfoLog (int program);
+
+ public native void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params);
+
+ public native void glGetShaderiv (int shader, int pname, IntBuffer params);
+
+ public native String glGetShaderInfoLog (int shader);
+
+ public native void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision);
+
+ public native void glGetShaderSource (int shader, int bufsize, Buffer length, String source);
+
+ public native String glGetString (int name);
+
+ public native void glGetTexParameterfv (int target, int pname, FloatBuffer params);
+
+ public native void glGetTexParameteriv (int target, int pname, IntBuffer params);
+
+ public native void glGetUniformfv (int program, int location, FloatBuffer params);
+
+ public native void glGetUniformiv (int program, int location, IntBuffer params);
+
+ public native int glGetUniformLocation (int program, String name);
+
+ public native void glGetVertexAttribfv (int index, int pname, FloatBuffer params);
+
+ public native void glGetVertexAttribiv (int index, int pname, IntBuffer params);
+
+ public native void glGetVertexAttribPointerv (int index, int pname, Buffer pointer);
+
+ public native void glHint (int target, int mode);
+
+ public native boolean glIsBuffer (int buffer);
+
+ public native boolean glIsEnabled (int cap);
+
+ public native boolean glIsFramebuffer (int framebuffer);
+
+ public native boolean glIsProgram (int program);
+
+ public native boolean glIsRenderbuffer (int renderbuffer);
+
+ public native boolean glIsShader (int shader);
+
+ public native boolean glIsTexture (int texture);
+
+ public native void glLineWidth (float width);
+
+ public native void glLinkProgram (int program);
+
+ public native void glPixelStorei (int pname, int param);
+
+ public native void glPolygonOffset (float factor, float units);
+
+ public native void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels);
+
+ public native void glReleaseShaderCompiler ();
+
+ public native void glRenderbufferStorage (int target, int internalformat, int width, int height);
+
+ public native void glSampleCoverage (float value, boolean invert);
+
+ public native void glScissor (int x, int y, int width, int height);
+
+ public native void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length);
+
+ public native void glShaderSource (int shader, String string);
+
+ public native void glStencilFunc (int func, int ref, int mask);
+
+ public native void glStencilFuncSeparate (int face, int func, int ref, int mask);
+
+ public native void glStencilMask (int mask);
+
+ public native void glStencilMaskSeparate (int face, int mask);
+
+ public native void glStencilOp (int fail, int zfail, int zpass);
+
+ public native void glStencilOpSeparate (int face, int fail, int zfail, int zpass);
+
+ public native void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format,
+ int type, Buffer pixels);
+
+ public native void glTexParameterf (int target, int pname, float param);
+
+ public native void glTexParameterfv (int target, int pname, FloatBuffer params);
+
+ public native void glTexParameteri (int target, int pname, int param);
+
+ public native void glTexParameteriv (int target, int pname, IntBuffer params);
+
+ public native void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int type, Buffer pixels);
+
+ public native void glUniform1f (int location, float x);
+
+ public native void glUniform1fv (int location, int count, FloatBuffer v);
+
+ public native void glUniform1i (int location, int x);
+
+ public native void glUniform1iv (int location, int count, IntBuffer v);
+
+ public native void glUniform2f (int location, float x, float y);
+
+ public native void glUniform2fv (int location, int count, FloatBuffer v);
+
+ public native void glUniform2i (int location, int x, int y);
+
+ public native void glUniform2iv (int location, int count, IntBuffer v);
+
+ public native void glUniform3f (int location, float x, float y, float z);
+
+ public native void glUniform3fv (int location, int count, FloatBuffer v);
+
+ public native void glUniform3i (int location, int x, int y, int z);
+
+ public native void glUniform3iv (int location, int count, IntBuffer v);
+
+ public native void glUniform4f (int location, float x, float y, float z, float w);
+
+ public native void glUniform4fv (int location, int count, FloatBuffer v);
+
+ public native void glUniform4i (int location, int x, int y, int z, int w);
+
+ public native void glUniform4iv (int location, int count, IntBuffer v);
+
+ public native void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public native void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public native void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public native void glUseProgram (int program);
+
+ public native void glValidateProgram (int program);
+
+ public native void glVertexAttrib1f (int indx, float x);
+
+ public native void glVertexAttrib1fv (int indx, FloatBuffer values);
+
+ public native void glVertexAttrib2f (int indx, float x, float y);
+
+ public native void glVertexAttrib2fv (int indx, FloatBuffer values);
+
+ public native void glVertexAttrib3f (int indx, float x, float y, float z);
+
+ public native void glVertexAttrib3fv (int indx, FloatBuffer values);
+
+ public native void glVertexAttrib4f (int indx, float x, float y, float z, float w);
+
+ public native void glVertexAttrib4fv (int indx, FloatBuffer values);
+
+ public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr);
+
+ public native void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr);
+
+ public native void glViewport (int x, int y, int width, int height);
+}
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GL20.java b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GL20.java
new file mode 100644
index 0000000..034e9b4
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GL20.java
@@ -0,0 +1,545 @@
+/*******************************************************************************
+ * Copyright 2011 See AUTHORS-LIBGDX file.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.badlogic.gdx.graphics;
+
+import java.nio.Buffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
+/** Interface wrapping all the methods of OpenGL ES 2.0
+ * @author mzechner */
+public interface GL20 extends GLCommon {
+ public static final int GL_ES_VERSION_2_0 = 1;
+ public static final int GL_DEPTH_BUFFER_BIT = 0x00000100;
+ public static final int GL_STENCIL_BUFFER_BIT = 0x00000400;
+ public static final int GL_COLOR_BUFFER_BIT = 0x00004000;
+ public static final int GL_FALSE = 0;
+ public static final int GL_TRUE = 1;
+ public static final int GL_POINTS = 0x0000;
+ public static final int GL_LINES = 0x0001;
+ public static final int GL_LINE_LOOP = 0x0002;
+ public static final int GL_LINE_STRIP = 0x0003;
+ public static final int GL_TRIANGLES = 0x0004;
+ public static final int GL_TRIANGLE_STRIP = 0x0005;
+ public static final int GL_TRIANGLE_FAN = 0x0006;
+ public static final int GL_ZERO = 0;
+ public static final int GL_ONE = 1;
+ public static final int GL_SRC_COLOR = 0x0300;
+ public static final int GL_ONE_MINUS_SRC_COLOR = 0x0301;
+ public static final int GL_SRC_ALPHA = 0x0302;
+ public static final int GL_ONE_MINUS_SRC_ALPHA = 0x0303;
+ public static final int GL_DST_ALPHA = 0x0304;
+ public static final int GL_ONE_MINUS_DST_ALPHA = 0x0305;
+ public static final int GL_DST_COLOR = 0x0306;
+ public static final int GL_ONE_MINUS_DST_COLOR = 0x0307;
+ public static final int GL_SRC_ALPHA_SATURATE = 0x0308;
+ public static final int GL_FUNC_ADD = 0x8006;
+ public static final int GL_BLEND_EQUATION = 0x8009;
+ public static final int GL_BLEND_EQUATION_RGB = 0x8009;
+ public static final int GL_BLEND_EQUATION_ALPHA = 0x883D;
+ public static final int GL_FUNC_SUBTRACT = 0x800A;
+ public static final int GL_FUNC_REVERSE_SUBTRACT = 0x800B;
+ public static final int GL_BLEND_DST_RGB = 0x80C8;
+ public static final int GL_BLEND_SRC_RGB = 0x80C9;
+ public static final int GL_BLEND_DST_ALPHA = 0x80CA;
+ public static final int GL_BLEND_SRC_ALPHA = 0x80CB;
+ public static final int GL_CONSTANT_COLOR = 0x8001;
+ public static final int GL_ONE_MINUS_CONSTANT_COLOR = 0x8002;
+ public static final int GL_CONSTANT_ALPHA = 0x8003;
+ public static final int GL_ONE_MINUS_CONSTANT_ALPHA = 0x8004;
+ public static final int GL_BLEND_COLOR = 0x8005;
+ public static final int GL_ARRAY_BUFFER = 0x8892;
+ public static final int GL_ELEMENT_ARRAY_BUFFER = 0x8893;
+ public static final int GL_ARRAY_BUFFER_BINDING = 0x8894;
+ public static final int GL_ELEMENT_ARRAY_BUFFER_BINDING = 0x8895;
+ public static final int GL_STREAM_DRAW = 0x88E0;
+ public static final int GL_STATIC_DRAW = 0x88E4;
+ public static final int GL_DYNAMIC_DRAW = 0x88E8;
+ public static final int GL_BUFFER_SIZE = 0x8764;
+ public static final int GL_BUFFER_USAGE = 0x8765;
+ public static final int GL_CURRENT_VERTEX_ATTRIB = 0x8626;
+ public static final int GL_FRONT = 0x0404;
+ public static final int GL_BACK = 0x0405;
+ public static final int GL_FRONT_AND_BACK = 0x0408;
+ public static final int GL_TEXTURE_2D = 0x0DE1;
+ public static final int GL_CULL_FACE = 0x0B44;
+ public static final int GL_BLEND = 0x0BE2;
+ public static final int GL_DITHER = 0x0BD0;
+ public static final int GL_STENCIL_TEST = 0x0B90;
+ public static final int GL_DEPTH_TEST = 0x0B71;
+ public static final int GL_SCISSOR_TEST = 0x0C11;
+ public static final int GL_POLYGON_OFFSET_FILL = 0x8037;
+ public static final int GL_SAMPLE_ALPHA_TO_COVERAGE = 0x809E;
+ public static final int GL_SAMPLE_COVERAGE = 0x80A0;
+ public static final int GL_NO_ERROR = 0;
+ public static final int GL_INVALID_ENUM = 0x0500;
+ public static final int GL_INVALID_VALUE = 0x0501;
+ public static final int GL_INVALID_OPERATION = 0x0502;
+ public static final int GL_OUT_OF_MEMORY = 0x0505;
+ public static final int GL_CW = 0x0900;
+ public static final int GL_CCW = 0x0901;
+ public static final int GL_LINE_WIDTH = 0x0B21;
+ public static final int GL_ALIASED_POINT_SIZE_RANGE = 0x846D;
+ public static final int GL_ALIASED_LINE_WIDTH_RANGE = 0x846E;
+ public static final int GL_CULL_FACE_MODE = 0x0B45;
+ public static final int GL_FRONT_FACE = 0x0B46;
+ public static final int GL_DEPTH_RANGE = 0x0B70;
+ public static final int GL_DEPTH_WRITEMASK = 0x0B72;
+ public static final int GL_DEPTH_CLEAR_VALUE = 0x0B73;
+ public static final int GL_DEPTH_FUNC = 0x0B74;
+ public static final int GL_STENCIL_CLEAR_VALUE = 0x0B91;
+ public static final int GL_STENCIL_FUNC = 0x0B92;
+ public static final int GL_STENCIL_FAIL = 0x0B94;
+ public static final int GL_STENCIL_PASS_DEPTH_FAIL = 0x0B95;
+ public static final int GL_STENCIL_PASS_DEPTH_PASS = 0x0B96;
+ public static final int GL_STENCIL_REF = 0x0B97;
+ public static final int GL_STENCIL_VALUE_MASK = 0x0B93;
+ public static final int GL_STENCIL_WRITEMASK = 0x0B98;
+ public static final int GL_STENCIL_BACK_FUNC = 0x8800;
+ public static final int GL_STENCIL_BACK_FAIL = 0x8801;
+ public static final int GL_STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802;
+ public static final int GL_STENCIL_BACK_PASS_DEPTH_PASS = 0x8803;
+ public static final int GL_STENCIL_BACK_REF = 0x8CA3;
+ public static final int GL_STENCIL_BACK_VALUE_MASK = 0x8CA4;
+ public static final int GL_STENCIL_BACK_WRITEMASK = 0x8CA5;
+ public static final int GL_VIEWPORT = 0x0BA2;
+ public static final int GL_SCISSOR_BOX = 0x0C10;
+ public static final int GL_COLOR_CLEAR_VALUE = 0x0C22;
+ public static final int GL_COLOR_WRITEMASK = 0x0C23;
+ public static final int GL_UNPACK_ALIGNMENT = 0x0CF5;
+ public static final int GL_PACK_ALIGNMENT = 0x0D05;
+ public static final int GL_MAX_TEXTURE_SIZE = 0x0D33;
+ public static final int GL_MAX_TEXTURE_UNITS = 0x84E2;
+ public static final int GL_MAX_VIEWPORT_DIMS = 0x0D3A;
+ public static final int GL_SUBPIXEL_BITS = 0x0D50;
+ public static final int GL_RED_BITS = 0x0D52;
+ public static final int GL_GREEN_BITS = 0x0D53;
+ public static final int GL_BLUE_BITS = 0x0D54;
+ public static final int GL_ALPHA_BITS = 0x0D55;
+ public static final int GL_DEPTH_BITS = 0x0D56;
+ public static final int GL_STENCIL_BITS = 0x0D57;
+ public static final int GL_POLYGON_OFFSET_UNITS = 0x2A00;
+ public static final int GL_POLYGON_OFFSET_FACTOR = 0x8038;
+ public static final int GL_TEXTURE_BINDING_2D = 0x8069;
+ public static final int GL_SAMPLE_BUFFERS = 0x80A8;
+ public static final int GL_SAMPLES = 0x80A9;
+ public static final int GL_SAMPLE_COVERAGE_VALUE = 0x80AA;
+ public static final int GL_SAMPLE_COVERAGE_INVERT = 0x80AB;
+ public static final int GL_NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2;
+ public static final int GL_COMPRESSED_TEXTURE_FORMATS = 0x86A3;
+ public static final int GL_DONT_CARE = 0x1100;
+ public static final int GL_FASTEST = 0x1101;
+ public static final int GL_NICEST = 0x1102;
+ public static final int GL_GENERATE_MIPMAP_HINT = 0x8192;
+ public static final int GL_BYTE = 0x1400;
+ public static final int GL_UNSIGNED_BYTE = 0x1401;
+ public static final int GL_SHORT = 0x1402;
+ public static final int GL_UNSIGNED_SHORT = 0x1403;
+ public static final int GL_INT = 0x1404;
+ public static final int GL_UNSIGNED_INT = 0x1405;
+ public static final int GL_FLOAT = 0x1406;
+ public static final int GL_FIXED = 0x140C;
+ public static final int GL_DEPTH_COMPONENT = 0x1902;
+ public static final int GL_ALPHA = 0x1906;
+ public static final int GL_RGB = 0x1907;
+ public static final int GL_RGBA = 0x1908;
+ public static final int GL_LUMINANCE = 0x1909;
+ public static final int GL_LUMINANCE_ALPHA = 0x190A;
+ public static final int GL_UNSIGNED_SHORT_4_4_4_4 = 0x8033;
+ public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034;
+ public static final int GL_UNSIGNED_SHORT_5_6_5 = 0x8363;
+ public static final int GL_FRAGMENT_SHADER = 0x8B30;
+ public static final int GL_VERTEX_SHADER = 0x8B31;
+ public static final int GL_MAX_VERTEX_ATTRIBS = 0x8869;
+ public static final int GL_MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB;
+ public static final int GL_MAX_VARYING_VECTORS = 0x8DFC;
+ public static final int GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D;
+ public static final int GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C;
+ public static final int GL_MAX_TEXTURE_IMAGE_UNITS = 0x8872;
+ public static final int GL_MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD;
+ public static final int GL_SHADER_TYPE = 0x8B4F;
+ public static final int GL_DELETE_STATUS = 0x8B80;
+ public static final int GL_LINK_STATUS = 0x8B82;
+ public static final int GL_VALIDATE_STATUS = 0x8B83;
+ public static final int GL_ATTACHED_SHADERS = 0x8B85;
+ public static final int GL_ACTIVE_UNIFORMS = 0x8B86;
+ public static final int GL_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87;
+ public static final int GL_ACTIVE_ATTRIBUTES = 0x8B89;
+ public static final int GL_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A;
+ public static final int GL_SHADING_LANGUAGE_VERSION = 0x8B8C;
+ public static final int GL_CURRENT_PROGRAM = 0x8B8D;
+ public static final int GL_NEVER = 0x0200;
+ public static final int GL_LESS = 0x0201;
+ public static final int GL_EQUAL = 0x0202;
+ public static final int GL_LEQUAL = 0x0203;
+ public static final int GL_GREATER = 0x0204;
+ public static final int GL_NOTEQUAL = 0x0205;
+ public static final int GL_GEQUAL = 0x0206;
+ public static final int GL_ALWAYS = 0x0207;
+ public static final int GL_KEEP = 0x1E00;
+ public static final int GL_REPLACE = 0x1E01;
+ public static final int GL_INCR = 0x1E02;
+ public static final int GL_DECR = 0x1E03;
+ public static final int GL_INVERT = 0x150A;
+ public static final int GL_INCR_WRAP = 0x8507;
+ public static final int GL_DECR_WRAP = 0x8508;
+ public static final int GL_VENDOR = 0x1F00;
+ public static final int GL_RENDERER = 0x1F01;
+ public static final int GL_VERSION = 0x1F02;
+ public static final int GL_EXTENSIONS = 0x1F03;
+ public static final int GL_NEAREST = 0x2600;
+ public static final int GL_LINEAR = 0x2601;
+ public static final int GL_NEAREST_MIPMAP_NEAREST = 0x2700;
+ public static final int GL_LINEAR_MIPMAP_NEAREST = 0x2701;
+ public static final int GL_NEAREST_MIPMAP_LINEAR = 0x2702;
+ public static final int GL_LINEAR_MIPMAP_LINEAR = 0x2703;
+ public static final int GL_TEXTURE_MAG_FILTER = 0x2800;
+ public static final int GL_TEXTURE_MIN_FILTER = 0x2801;
+ public static final int GL_TEXTURE_WRAP_S = 0x2802;
+ public static final int GL_TEXTURE_WRAP_T = 0x2803;
+ public static final int GL_TEXTURE = 0x1702;
+ public static final int GL_TEXTURE_CUBE_MAP = 0x8513;
+ public static final int GL_TEXTURE_BINDING_CUBE_MAP = 0x8514;
+ public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
+ public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
+ public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
+ public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
+ public static final int GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
+ public static final int GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A;
+ public static final int GL_MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C;
+ public static final int GL_TEXTURE0 = 0x84C0;
+ public static final int GL_TEXTURE1 = 0x84C1;
+ public static final int GL_TEXTURE2 = 0x84C2;
+ public static final int GL_TEXTURE3 = 0x84C3;
+ public static final int GL_TEXTURE4 = 0x84C4;
+ public static final int GL_TEXTURE5 = 0x84C5;
+ public static final int GL_TEXTURE6 = 0x84C6;
+ public static final int GL_TEXTURE7 = 0x84C7;
+ public static final int GL_TEXTURE8 = 0x84C8;
+ public static final int GL_TEXTURE9 = 0x84C9;
+ public static final int GL_TEXTURE10 = 0x84CA;
+ public static final int GL_TEXTURE11 = 0x84CB;
+ public static final int GL_TEXTURE12 = 0x84CC;
+ public static final int GL_TEXTURE13 = 0x84CD;
+ public static final int GL_TEXTURE14 = 0x84CE;
+ public static final int GL_TEXTURE15 = 0x84CF;
+ public static final int GL_TEXTURE16 = 0x84D0;
+ public static final int GL_TEXTURE17 = 0x84D1;
+ public static final int GL_TEXTURE18 = 0x84D2;
+ public static final int GL_TEXTURE19 = 0x84D3;
+ public static final int GL_TEXTURE20 = 0x84D4;
+ public static final int GL_TEXTURE21 = 0x84D5;
+ public static final int GL_TEXTURE22 = 0x84D6;
+ public static final int GL_TEXTURE23 = 0x84D7;
+ public static final int GL_TEXTURE24 = 0x84D8;
+ public static final int GL_TEXTURE25 = 0x84D9;
+ public static final int GL_TEXTURE26 = 0x84DA;
+ public static final int GL_TEXTURE27 = 0x84DB;
+ public static final int GL_TEXTURE28 = 0x84DC;
+ public static final int GL_TEXTURE29 = 0x84DD;
+ public static final int GL_TEXTURE30 = 0x84DE;
+ public static final int GL_TEXTURE31 = 0x84DF;
+ public static final int GL_ACTIVE_TEXTURE = 0x84E0;
+ public static final int GL_REPEAT = 0x2901;
+ public static final int GL_CLAMP_TO_EDGE = 0x812F;
+ public static final int GL_MIRRORED_REPEAT = 0x8370;
+ public static final int GL_FLOAT_VEC2 = 0x8B50;
+ public static final int GL_FLOAT_VEC3 = 0x8B51;
+ public static final int GL_FLOAT_VEC4 = 0x8B52;
+ public static final int GL_INT_VEC2 = 0x8B53;
+ public static final int GL_INT_VEC3 = 0x8B54;
+ public static final int GL_INT_VEC4 = 0x8B55;
+ public static final int GL_BOOL = 0x8B56;
+ public static final int GL_BOOL_VEC2 = 0x8B57;
+ public static final int GL_BOOL_VEC3 = 0x8B58;
+ public static final int GL_BOOL_VEC4 = 0x8B59;
+ public static final int GL_FLOAT_MAT2 = 0x8B5A;
+ public static final int GL_FLOAT_MAT3 = 0x8B5B;
+ public static final int GL_FLOAT_MAT4 = 0x8B5C;
+ public static final int GL_SAMPLER_2D = 0x8B5E;
+ public static final int GL_SAMPLER_CUBE = 0x8B60;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_SIZE = 0x8623;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_TYPE = 0x8625;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_POINTER = 0x8645;
+ public static final int GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F;
+ public static final int GL_IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A;
+ public static final int GL_IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B;
+ public static final int GL_COMPILE_STATUS = 0x8B81;
+ public static final int GL_INFO_LOG_LENGTH = 0x8B84;
+ public static final int GL_SHADER_SOURCE_LENGTH = 0x8B88;
+ public static final int GL_SHADER_COMPILER = 0x8DFA;
+ public static final int GL_SHADER_BINARY_FORMATS = 0x8DF8;
+ public static final int GL_NUM_SHADER_BINARY_FORMATS = 0x8DF9;
+ public static final int GL_LOW_FLOAT = 0x8DF0;
+ public static final int GL_MEDIUM_FLOAT = 0x8DF1;
+ public static final int GL_HIGH_FLOAT = 0x8DF2;
+ public static final int GL_LOW_INT = 0x8DF3;
+ public static final int GL_MEDIUM_INT = 0x8DF4;
+ public static final int GL_HIGH_INT = 0x8DF5;
+ public static final int GL_FRAMEBUFFER = 0x8D40;
+ public static final int GL_RENDERBUFFER = 0x8D41;
+ public static final int GL_RGBA4 = 0x8056;
+ public static final int GL_RGB5_A1 = 0x8057;
+ public static final int GL_RGB565 = 0x8D62;
+ public static final int GL_DEPTH_COMPONENT16 = 0x81A5;
+ public static final int GL_STENCIL_INDEX = 0x1901;
+ public static final int GL_STENCIL_INDEX8 = 0x8D48;
+ public static final int GL_RENDERBUFFER_WIDTH = 0x8D42;
+ public static final int GL_RENDERBUFFER_HEIGHT = 0x8D43;
+ public static final int GL_RENDERBUFFER_INTERNAL_FORMAT = 0x8D44;
+ public static final int GL_RENDERBUFFER_RED_SIZE = 0x8D50;
+ public static final int GL_RENDERBUFFER_GREEN_SIZE = 0x8D51;
+ public static final int GL_RENDERBUFFER_BLUE_SIZE = 0x8D52;
+ public static final int GL_RENDERBUFFER_ALPHA_SIZE = 0x8D53;
+ public static final int GL_RENDERBUFFER_DEPTH_SIZE = 0x8D54;
+ public static final int GL_RENDERBUFFER_STENCIL_SIZE = 0x8D55;
+ public static final int GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0;
+ public static final int GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1;
+ public static final int GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2;
+ public static final int GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3;
+ public static final int GL_COLOR_ATTACHMENT0 = 0x8CE0;
+ public static final int GL_DEPTH_ATTACHMENT = 0x8D00;
+ public static final int GL_STENCIL_ATTACHMENT = 0x8D20;
+ public static final int GL_NONE = 0;
+ public static final int GL_FRAMEBUFFER_COMPLETE = 0x8CD5;
+ public static final int GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6;
+ public static final int GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7;
+ public static final int GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9;
+ public static final int GL_FRAMEBUFFER_UNSUPPORTED = 0x8CDD;
+ public static final int GL_FRAMEBUFFER_BINDING = 0x8CA6;
+ public static final int GL_RENDERBUFFER_BINDING = 0x8CA7;
+ public static final int GL_MAX_RENDERBUFFER_SIZE = 0x84E8;
+ public static final int GL_INVALID_FRAMEBUFFER_OPERATION = 0x0506;
+ public static final int GL_VERTEX_PROGRAM_POINT_SIZE = 0x8642;
+
+ // Extensions
+ public static final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000;
+
+ public void glAttachShader (int program, int shader);
+
+ public void glBindAttribLocation (int program, int index, String name);
+
+ public void glBindBuffer (int target, int buffer);
+
+ public void glBindFramebuffer (int target, int framebuffer);
+
+ public void glBindRenderbuffer (int target, int renderbuffer);
+
+ public void glBlendColor (float red, float green, float blue, float alpha);
+
+ public void glBlendEquation (int mode);
+
+ public void glBlendEquationSeparate (int modeRGB, int modeAlpha);
+
+ public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
+
+ public void glBufferData (int target, int size, Buffer data, int usage);
+
+ public void glBufferSubData (int target, int offset, int size, Buffer data);
+
+ public int glCheckFramebufferStatus (int target);
+
+ public void glCompileShader (int shader);
+
+ public int glCreateProgram ();
+
+ public int glCreateShader (int type);
+
+ public void glDeleteBuffers (int n, IntBuffer buffers);
+
+ public void glDeleteFramebuffers (int n, IntBuffer framebuffers);
+
+ public void glDeleteProgram (int program);
+
+ public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers);
+
+ public void glDeleteShader (int shader);
+
+ public void glDetachShader (int program, int shader);
+
+ public void glDisableVertexAttribArray (int index);
+
+ public void glDrawElements (int mode, int count, int type, int indices);
+
+ public void glEnableVertexAttribArray (int index);
+
+ public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer);
+
+ public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level);
+
+ public void glGenBuffers (int n, IntBuffer buffers);
+
+ public void glGenerateMipmap (int target);
+
+ public void glGenFramebuffers (int n, IntBuffer framebuffers);
+
+ public void glGenRenderbuffers (int n, IntBuffer renderbuffers);
+
+ // deviates
+ public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type);
+
+ // deviates
+ public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type);
+
+ public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders);
+
+ public int glGetAttribLocation (int program, String name);
+
+ public void glGetBooleanv (int pname, Buffer params);
+
+ public void glGetBufferParameteriv (int target, int pname, IntBuffer params);
+
+ public void glGetFloatv (int pname, FloatBuffer params);
+
+ public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params);
+
+ public void glGetProgramiv (int program, int pname, IntBuffer params);
+
+ // deviates
+ public String glGetProgramInfoLog (int program);
+
+ public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params);
+
+ public void glGetShaderiv (int shader, int pname, IntBuffer params);
+
+ // deviates
+ public String glGetShaderInfoLog (int shader);
+
+ public void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision);
+
+ public void glGetShaderSource (int shader, int bufsize, Buffer length, String source);
+
+ public void glGetTexParameterfv (int target, int pname, FloatBuffer params);
+
+ public void glGetTexParameteriv (int target, int pname, IntBuffer params);
+
+ public void glGetUniformfv (int program, int location, FloatBuffer params);
+
+ public void glGetUniformiv (int program, int location, IntBuffer params);
+
+ public int glGetUniformLocation (int program, String name);
+
+ public void glGetVertexAttribfv (int index, int pname, FloatBuffer params);
+
+ public void glGetVertexAttribiv (int index, int pname, IntBuffer params);
+
+ public void glGetVertexAttribPointerv (int index, int pname, Buffer pointer);
+
+ public boolean glIsBuffer (int buffer);
+
+ public boolean glIsEnabled (int cap);
+
+ public boolean glIsFramebuffer (int framebuffer);
+
+ public boolean glIsProgram (int program);
+
+ public boolean glIsRenderbuffer (int renderbuffer);
+
+ public boolean glIsShader (int shader);
+
+ public boolean glIsTexture (int texture);
+
+ public void glLinkProgram (int program);
+
+ public void glReleaseShaderCompiler ();
+
+ public void glRenderbufferStorage (int target, int internalformat, int width, int height);
+
+ public void glSampleCoverage (float value, boolean invert);
+
+ public void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length);
+
+ // Deviates
+ public void glShaderSource (int shader, String string);
+
+ public void glStencilFuncSeparate (int face, int func, int ref, int mask);
+
+ public void glStencilMaskSeparate (int face, int mask);
+
+ public void glStencilOpSeparate (int face, int fail, int zfail, int zpass);
+
+ public void glTexParameterfv (int target, int pname, FloatBuffer params);
+
+ public void glTexParameteri (int target, int pname, int param);
+
+ public void glTexParameteriv (int target, int pname, IntBuffer params);
+
+ public void glUniform1f (int location, float x);
+
+ public void glUniform1fv (int location, int count, FloatBuffer v);
+
+ public void glUniform1i (int location, int x);
+
+ public void glUniform1iv (int location, int count, IntBuffer v);
+
+ public void glUniform2f (int location, float x, float y);
+
+ public void glUniform2fv (int location, int count, FloatBuffer v);
+
+ public void glUniform2i (int location, int x, int y);
+
+ public void glUniform2iv (int location, int count, IntBuffer v);
+
+ public void glUniform3f (int location, float x, float y, float z);
+
+ public void glUniform3fv (int location, int count, FloatBuffer v);
+
+ public void glUniform3i (int location, int x, int y, int z);
+
+ public void glUniform3iv (int location, int count, IntBuffer v);
+
+ public void glUniform4f (int location, float x, float y, float z, float w);
+
+ public void glUniform4fv (int location, int count, FloatBuffer v);
+
+ public void glUniform4i (int location, int x, int y, int z, int w);
+
+ public void glUniform4iv (int location, int count, IntBuffer v);
+
+ public void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value);
+
+ public void glUseProgram (int program);
+
+ public void glValidateProgram (int program);
+
+ public void glVertexAttrib1f (int indx, float x);
+
+ public void glVertexAttrib1fv (int indx, FloatBuffer values);
+
+ public void glVertexAttrib2f (int indx, float x, float y);
+
+ public void glVertexAttrib2fv (int indx, FloatBuffer values);
+
+ public void glVertexAttrib3f (int indx, float x, float y, float z);
+
+ public void glVertexAttrib3fv (int indx, FloatBuffer values);
+
+ public void glVertexAttrib4f (int indx, float x, float y, float z, float w);
+
+ public void glVertexAttrib4fv (int indx, FloatBuffer values);
+
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr);
+
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr);
+}
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GLCommon.java b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GLCommon.java
new file mode 100644
index 0000000..2462a82
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/badlogic/gdx/graphics/GLCommon.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright 2011 See AUTHORS-LIBGDX file.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+package com.badlogic.gdx.graphics;
+
+import java.nio.Buffer;
+import java.nio.IntBuffer;
+
+/** This interface defines methods common to GL10, GL11 and GL20.
+ * @author mzechner */
+public interface GLCommon {
+ public static final int GL_GENERATE_MIPMAP = 0x8191;
+ public static final int GL_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
+ public static final int GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
+
+ public void glActiveTexture (int texture);
+
+ public void glBindTexture (int target, int texture);
+
+ public void glBlendFunc (int sfactor, int dfactor);
+
+ public void glClear (int mask);
+
+ public void glClearColor (float red, float green, float blue, float alpha);
+
+ public void glClearDepthf (float depth);
+
+ public void glClearStencil (int s);
+
+ public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha);
+
+ public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ int imageSize, Buffer data);
+
+ public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int imageSize, Buffer data);
+
+ public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border);
+
+ public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
+
+ public void glCullFace (int mode);
+
+ public void glDeleteTextures (int n, IntBuffer textures);
+
+ public void glDepthFunc (int func);
+
+ public void glDepthMask (boolean flag);
+
+ public void glDepthRangef (float zNear, float zFar);
+
+ public void glDisable (int cap);
+
+ public void glDrawArrays (int mode, int first, int count);
+
+ public void glDrawElements (int mode, int count, int type, Buffer indices);
+
+ public void glEnable (int cap);
+
+ public void glFinish ();
+
+ public void glFlush ();
+
+ public void glFrontFace (int mode);
+
+ public void glGenTextures (int n, IntBuffer textures);
+
+ public int glGetError ();
+
+ public void glGetIntegerv (int pname, IntBuffer params);
+
+ public String glGetString (int name);
+
+ public void glHint (int target, int mode);
+
+ public void glLineWidth (float width);
+
+ public void glPixelStorei (int pname, int param);
+
+ public void glPolygonOffset (float factor, float units);
+
+ public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels);
+
+ public void glScissor (int x, int y, int width, int height);
+
+ public void glStencilFunc (int func, int ref, int mask);
+
+ public void glStencilMask (int mask);
+
+ public void glStencilOp (int fail, int zfail, int zpass);
+
+ public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
+ Buffer pixels);
+
+ public void glTexParameterf (int target, int pname, float param);
+
+ public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
+ Buffer pixels);
+
+ public void glViewport (int x, int y, int width, int height);
+}
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/src/com/learnopengles/android/TableOfContents.java b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/TableOfContents.java
index 1b6124f..1cf0b8b 100644
--- a/android/AndroidOpenGLESLessons/src/com/learnopengles/android/TableOfContents.java
+++ b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/TableOfContents.java
@@ -20,6 +20,7 @@
import com.learnopengles.android.lesson4.LessonFourActivity;
import com.learnopengles.android.lesson5.LessonFiveActivity;
import com.learnopengles.android.lesson6.LessonSixActivity;
+import com.learnopengles.android.lesson7.LessonSevenActivity;
public class TableOfContents extends ListActivity
{
@@ -94,6 +95,15 @@ public void onCreate(Bundle savedInstanceState)
activityMapping.put(i++, LessonSixActivity.class);
}
+ {
+ final Map item = new HashMap();
+ item.put(ITEM_IMAGE, R.drawable.ic_lesson_seven);
+ item.put(ITEM_TITLE, getText(R.string.lesson_seven));
+ item.put(ITEM_SUBTITLE, getText(R.string.lesson_seven_subtitle));
+ data.add(item);
+ activityMapping.put(i++, LessonSevenActivity.class);
+ }
+
final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
setListAdapter(dataAdapter);
diff --git a/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenActivity.java b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenActivity.java
new file mode 100644
index 0000000..54ea42b
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenActivity.java
@@ -0,0 +1,157 @@
+package com.learnopengles.android.lesson7;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.os.Bundle;
+import android.util.DisplayMetrics;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+import com.learnopengles.android.R;
+
+public class LessonSevenActivity extends Activity {
+ /** Hold a reference to our GLSurfaceView */
+ private LessonSevenGLSurfaceView mGLSurfaceView;
+ private LessonSevenRenderer mRenderer;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.lesson_seven);
+
+ mGLSurfaceView = (LessonSevenGLSurfaceView) findViewById(R.id.gl_surface_view);
+
+ // We need the
+
+ // Check if the system supports OpenGL ES 2.0.
+ final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+ final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
+
+ if (supportsEs2) {
+ // Request an OpenGL ES 2.0 compatible context.
+ mGLSurfaceView.setEGLContextClientVersion(2);
+
+ final DisplayMetrics displayMetrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+
+ // Set the renderer to our demo renderer, defined below.
+ mRenderer = new LessonSevenRenderer(this, mGLSurfaceView);
+ mGLSurfaceView.setRenderer(mRenderer, displayMetrics.density);
+ } else {
+ // This is where you could create an OpenGL ES 1.x compatible
+ // renderer if you wanted to support both ES 1 and ES 2.
+ return;
+ }
+
+ findViewById(R.id.button_decrease_num_cubes).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ decreaseCubeCount();
+ }
+ });
+
+ findViewById(R.id.button_increase_num_cubes).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ increaseCubeCount();
+ }
+ });
+
+ findViewById(R.id.button_switch_VBOs).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ toggleVBOs();
+ }
+ });
+
+ findViewById(R.id.button_switch_stride).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ toggleStride();
+ }
+ });
+ }
+
+ @Override
+ protected void onResume() {
+ // The activity must call the GL surface view's onResume() on activity
+ // onResume().
+ super.onResume();
+ mGLSurfaceView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ // The activity must call the GL surface view's onPause() on activity
+ // onPause().
+ super.onPause();
+ mGLSurfaceView.onPause();
+ }
+
+ private void decreaseCubeCount() {
+ mGLSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ mRenderer.decreaseCubeCount();
+ }
+ });
+ }
+
+ private void increaseCubeCount() {
+ mGLSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ mRenderer.increaseCubeCount();
+ }
+ });
+ }
+
+ private void toggleVBOs() {
+ mGLSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ mRenderer.toggleVBOs();
+ }
+ });
+ }
+
+ protected void toggleStride() {
+ mGLSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ mRenderer.toggleStride();
+ }
+ });
+ }
+
+ public void updateVboStatus(final boolean usingVbos) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (usingVbos) {
+ ((Button) findViewById(R.id.button_switch_VBOs)).setText(R.string.lesson_seven_using_VBOs);
+ } else {
+ ((Button) findViewById(R.id.button_switch_VBOs)).setText(R.string.lesson_seven_not_using_VBOs);
+ }
+ }
+ });
+ }
+
+ public void updateStrideStatus(final boolean useStride) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (useStride) {
+ ((Button) findViewById(R.id.button_switch_stride)).setText(R.string.lesson_seven_using_stride);
+ } else {
+ ((Button) findViewById(R.id.button_switch_stride)).setText(R.string.lesson_seven_not_using_stride);
+ }
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenGLSurfaceView.java b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenGLSurfaceView.java
new file mode 100644
index 0000000..1dcd63d
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenGLSurfaceView.java
@@ -0,0 +1,66 @@
+package com.learnopengles.android.lesson7;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+public class LessonSevenGLSurfaceView extends GLSurfaceView
+{
+ private LessonSevenRenderer mRenderer;
+
+ // Offsets for touch events
+ private float mPreviousX;
+ private float mPreviousY;
+
+ private float mDensity;
+
+ public LessonSevenGLSurfaceView(Context context)
+ {
+ super(context);
+ }
+
+ public LessonSevenGLSurfaceView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event)
+ {
+ if (event != null)
+ {
+ float x = event.getX();
+ float y = event.getY();
+
+ if (event.getAction() == MotionEvent.ACTION_MOVE)
+ {
+ if (mRenderer != null)
+ {
+ float deltaX = (x - mPreviousX) / mDensity / 2f;
+ float deltaY = (y - mPreviousY) / mDensity / 2f;
+
+ mRenderer.mDeltaX += deltaX;
+ mRenderer.mDeltaY += deltaY;
+ }
+ }
+
+ mPreviousX = x;
+ mPreviousY = y;
+
+ return true;
+ }
+ else
+ {
+ return super.onTouchEvent(event);
+ }
+ }
+
+ // Hides superclass method.
+ public void setRenderer(LessonSevenRenderer renderer, float density)
+ {
+ mRenderer = renderer;
+ mDensity = density;
+ super.setRenderer(renderer);
+ }
+}
diff --git a/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenRenderer.java b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenRenderer.java
new file mode 100644
index 0000000..58d4e84
--- /dev/null
+++ b/android/AndroidOpenGLESLessons/src/com/learnopengles/android/lesson7/LessonSevenRenderer.java
@@ -0,0 +1,850 @@
+package com.learnopengles.android.lesson7;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+import android.opengl.Matrix;
+import android.widget.Toast;
+
+import com.badlogic.gdx.backends.android.AndroidGL20;
+import com.learnopengles.android.R;
+import com.learnopengles.android.common.RawResourceReader;
+import com.learnopengles.android.common.ShaderHelper;
+import com.learnopengles.android.common.ShapeBuilder;
+import com.learnopengles.android.common.TextureHelper;
+
+/**
+ * This class implements our custom renderer. Note that the GL10 parameter
+ * passed in is unused for OpenGL ES 2.0 renderers -- the static class GLES20 is
+ * used instead.
+ */
+public class LessonSevenRenderer implements GLSurfaceView.Renderer {
+ /** Used for debug logs. */
+ private static final String TAG = "LessonSevenRenderer";
+
+ private final LessonSevenActivity mLessonSevenActivity;
+ private final GLSurfaceView mGlSurfaceView;
+
+ /** Android's OpenGL bindings are broken until Gingerbread, so we use LibGDX bindings here. */
+ private final AndroidGL20 mGlEs20;
+
+ /**
+ * Store the model matrix. This matrix is used to move models from object space (where each model can be thought
+ * of being located at the center of the universe) to world space.
+ */
+ private float[] mModelMatrix = new float[16];
+
+ /**
+ * Store the view matrix. This can be thought of as our camera. This matrix transforms world space to eye space;
+ * it positions things relative to our eye.
+ */
+ private float[] mViewMatrix = new float[16];
+
+ /** Store the projection matrix. This is used to project the scene onto a 2D viewport. */
+ private float[] mProjectionMatrix = new float[16];
+
+ /** Allocate storage for the final combined matrix. This will be passed into the shader program. */
+ private float[] mMVPMatrix = new float[16];
+
+ /** Store the accumulated rotation. */
+ private final float[] mAccumulatedRotation = new float[16];
+
+ /** Store the current rotation. */
+ private final float[] mCurrentRotation = new float[16];
+
+ /** A temporary matrix. */
+ private float[] mTemporaryMatrix = new float[16];
+
+ /**
+ * Stores a copy of the model matrix specifically for the light position.
+ */
+ private float[] mLightModelMatrix = new float[16];
+
+ /** This will be used to pass in the transformation matrix. */
+ private int mMVPMatrixHandle;
+
+ /** This will be used to pass in the modelview matrix. */
+ private int mMVMatrixHandle;
+
+ /** This will be used to pass in the light position. */
+ private int mLightPosHandle;
+
+ /** This will be used to pass in the texture. */
+ private int mTextureUniformHandle;
+
+ /** This will be used to pass in model position information. */
+ private int mPositionHandle;
+
+ /** This will be used to pass in model normal information. */
+ private int mNormalHandle;
+
+ /** This will be used to pass in model texture coordinate information. */
+ private int mTextureCoordinateHandle;
+
+ /** Additional info for cube generation. */
+ private int mLastRequestedCubeFactor;
+ private int mActualCubeFactor;
+
+ /** Control whether vertex buffer objects or client-side memory will be used for rendering. */
+ private boolean mUseVBOs = true;
+
+ /** Control whether strides will be used. */
+ private boolean mUseStride = true;
+
+ /** Size of the position data in elements. */
+ static final int POSITION_DATA_SIZE = 3;
+
+ /** Size of the normal data in elements. */
+ static final int NORMAL_DATA_SIZE = 3;
+
+ /** Size of the texture coordinate data in elements. */
+ static final int TEXTURE_COORDINATE_DATA_SIZE = 2;
+
+ /** How many bytes per float. */
+ static final int BYTES_PER_FLOAT = 4;
+
+ /** Used to hold a light centered on the origin in model space. We need a 4th coordinate so we can get translations to work when
+ * we multiply this by our transformation matrices. */
+ private final float[] mLightPosInModelSpace = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
+
+ /** Used to hold the current position of the light in world space (after transformation via model matrix). */
+ private final float[] mLightPosInWorldSpace = new float[4];
+
+ /** Used to hold the transformed position of the light in eye space (after transformation via modelview matrix) */
+ private final float[] mLightPosInEyeSpace = new float[4];
+
+ /** This is a handle to our cube shading program. */
+ private int mProgramHandle;
+
+ /** These are handles to our texture data. */
+ private int mAndroidDataHandle;
+
+ // These still work without volatile, but refreshes are not guaranteed to happen.
+ public volatile float mDeltaX;
+ public volatile float mDeltaY;
+
+ /** Thread executor for generating cube data in the background. */
+ private final ExecutorService mSingleThreadedExecutor = Executors.newSingleThreadExecutor();
+
+ /** The current cubes object. */
+ private Cubes mCubes;
+
+ /**
+ * Initialize the model data.
+ */
+ public LessonSevenRenderer(final LessonSevenActivity lessonSevenActivity, final GLSurfaceView glSurfaceView) {
+ mLessonSevenActivity = lessonSevenActivity;
+ mGlSurfaceView = glSurfaceView;
+ mGlEs20 = new AndroidGL20();
+ }
+
+ private void generateCubes(int cubeFactor, boolean toggleVbos, boolean toggleStride) {
+ mSingleThreadedExecutor.submit(new GenDataRunnable(cubeFactor, toggleVbos, toggleStride));
+ }
+
+ class GenDataRunnable implements Runnable {
+ final int mRequestedCubeFactor;
+ final boolean mToggleVbos;
+ final boolean mToggleStride;
+
+ GenDataRunnable(int requestedCubeFactor, boolean toggleVbos, boolean toggleStride) {
+ mRequestedCubeFactor = requestedCubeFactor;
+ mToggleVbos = toggleVbos;
+ mToggleStride = toggleStride;
+ }
+
+ @Override
+ public void run() {
+ try {
+ // X, Y, Z
+ // The normal is used in light calculations and is a vector which points
+ // orthogonal to the plane of the surface. For a cube model, the normals
+ // should be orthogonal to the points of each face.
+ final float[] cubeNormalData =
+ {
+ // Front face
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f,
+
+ // Right face
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+
+ // Back face
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 0.0f, -1.0f,
+
+ // Left face
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+
+ // Top face
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+
+ // Bottom face
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f
+ };
+
+ // S, T (or X, Y)
+ // Texture coordinate data.
+ // Because images have a Y axis pointing downward (values increase as you move down the image) while
+ // OpenGL has a Y axis pointing upward, we adjust for that here by flipping the Y axis.
+ // What's more is that the texture coordinates are the same for every face.
+ final float[] cubeTextureCoordinateData =
+ {
+ // Front face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // Right face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // Back face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // Left face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // Top face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+
+ // Bottom face
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f
+ };
+
+ final float[] cubePositionData = new float[108 * mRequestedCubeFactor * mRequestedCubeFactor * mRequestedCubeFactor];
+ int cubePositionDataOffset = 0;
+
+ final int segments = mRequestedCubeFactor + (mRequestedCubeFactor - 1);
+ final float minPosition = -1.0f;
+ final float maxPosition = 1.0f;
+ final float positionRange = maxPosition - minPosition;
+
+ for (int x = 0; x < mRequestedCubeFactor; x++) {
+ for (int y = 0; y < mRequestedCubeFactor; y++) {
+ for (int z = 0; z < mRequestedCubeFactor; z++) {
+ final float x1 = minPosition + ((positionRange / segments) * (x * 2));
+ final float x2 = minPosition + ((positionRange / segments) * ((x * 2) + 1));
+
+ final float y1 = minPosition + ((positionRange / segments) * (y * 2));
+ final float y2 = minPosition + ((positionRange / segments) * ((y * 2) + 1));
+
+ final float z1 = minPosition + ((positionRange / segments) * (z * 2));
+ final float z2 = minPosition + ((positionRange / segments) * ((z * 2) + 1));
+
+ // Define points for a cube.
+ // X, Y, Z
+ final float[] p1p = { x1, y2, z2 };
+ final float[] p2p = { x2, y2, z2 };
+ final float[] p3p = { x1, y1, z2 };
+ final float[] p4p = { x2, y1, z2 };
+ final float[] p5p = { x1, y2, z1 };
+ final float[] p6p = { x2, y2, z1 };
+ final float[] p7p = { x1, y1, z1 };
+ final float[] p8p = { x2, y1, z1 };
+
+ final float[] thisCubePositionData = ShapeBuilder.generateCubeData(p1p, p2p, p3p, p4p, p5p, p6p, p7p, p8p,
+ p1p.length);
+
+ System.arraycopy(thisCubePositionData, 0, cubePositionData, cubePositionDataOffset, thisCubePositionData.length);
+ cubePositionDataOffset += thisCubePositionData.length;
+ }
+ }
+ }
+
+ // Run on the GL thread -- the same thread the other members of the renderer run in.
+ mGlSurfaceView.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ if (mCubes != null) {
+ mCubes.release();
+ mCubes = null;
+ }
+
+ // Not supposed to manually call this, but Dalvik sometimes needs some additional prodding to clean up the heap.
+ System.gc();
+
+ try {
+ boolean useVbos = mUseVBOs;
+ boolean useStride = mUseStride;
+
+ if (mToggleVbos) {
+ useVbos = !useVbos;
+ }
+
+ if (mToggleStride) {
+ useStride = !useStride;
+ }
+
+ if (useStride) {
+ if (useVbos) {
+ mCubes = new CubesWithVboWithStride(cubePositionData, cubeNormalData, cubeTextureCoordinateData, mRequestedCubeFactor);
+ } else {
+ mCubes = new CubesClientSideWithStride(cubePositionData, cubeNormalData, cubeTextureCoordinateData, mRequestedCubeFactor);
+ }
+ } else {
+ if (useVbos) {
+ mCubes = new CubesWithVbo(cubePositionData, cubeNormalData, cubeTextureCoordinateData, mRequestedCubeFactor);
+ } else {
+ mCubes = new CubesClientSide(cubePositionData, cubeNormalData, cubeTextureCoordinateData, mRequestedCubeFactor);
+ }
+ }
+
+ mUseVBOs = useVbos;
+ mLessonSevenActivity.updateVboStatus(mUseVBOs);
+
+ mUseStride = useStride;
+ mLessonSevenActivity.updateStrideStatus(mUseStride);
+
+ mActualCubeFactor = mRequestedCubeFactor;
+ } catch (OutOfMemoryError err) {
+ if (mCubes != null) {
+ mCubes.release();
+ mCubes = null;
+ }
+
+ // Not supposed to manually call this, but Dalvik sometimes needs some additional prodding to clean up the heap.
+ System.gc();
+
+ mLessonSevenActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(mLessonSevenActivity, "Out of memory; Dalvik takes a while to clean up the memory. Please try again.\nExternal bytes allocated=" + dalvik.system.VMRuntime.getRuntime().getExternalBytesAllocated(), Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+ }
+ });
+ } catch (OutOfMemoryError e) {
+ // Not supposed to manually call this, but Dalvik sometimes needs some additional prodding to clean up the heap.
+ System.gc();
+
+ mLessonSevenActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(mLessonSevenActivity, "Out of memory; Dalvik takes a while to clean up the memory. Please try again.\nExternal bytes allocated=" + dalvik.system.VMRuntime.getRuntime().getExternalBytesAllocated(), Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+ }
+ }
+
+ public void decreaseCubeCount() {
+ if (mLastRequestedCubeFactor > 1) {
+ generateCubes(--mLastRequestedCubeFactor, false, false);
+ }
+ }
+
+ public void increaseCubeCount() {
+ if (mLastRequestedCubeFactor < 16) {
+ generateCubes(++mLastRequestedCubeFactor, false, false);
+ }
+ }
+
+ public void toggleVBOs() {
+ generateCubes(mLastRequestedCubeFactor, true, false);
+ }
+
+ public void toggleStride() {
+ generateCubes(mLastRequestedCubeFactor, false, true);
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
+ {
+ mLastRequestedCubeFactor = mActualCubeFactor = 3;
+ generateCubes(mActualCubeFactor, false, false);
+
+ // Set the background clear color to black.
+ GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ // Use culling to remove back faces.
+ GLES20.glEnable(GLES20.GL_CULL_FACE);
+
+ // Enable depth testing
+ GLES20.glEnable(GLES20.GL_DEPTH_TEST);
+
+ // Position the eye in front of the origin.
+ final float eyeX = 0.0f;
+ final float eyeY = 0.0f;
+ final float eyeZ = -0.5f;
+
+ // We are looking toward the distance
+ final float lookX = 0.0f;
+ final float lookY = 0.0f;
+ final float lookZ = -5.0f;
+
+ // Set our up vector. This is where our head would be pointing were we holding the camera.
+ final float upX = 0.0f;
+ final float upY = 1.0f;
+ final float upZ = 0.0f;
+
+ // Set the view matrix. This matrix can be said to represent the camera position.
+ // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
+ // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
+ Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
+
+ final String vertexShader = RawResourceReader.readTextFileFromRawResource(mLessonSevenActivity, R.raw.lesson_seven_vertex_shader);
+ final String fragmentShader = RawResourceReader.readTextFileFromRawResource(mLessonSevenActivity, R.raw.lesson_seven_fragment_shader);
+
+ final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
+ final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
+
+ mProgramHandle = ShaderHelper.createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle,
+ new String[] {"a_Position", "a_Normal", "a_TexCoordinate"});
+
+ // Load the texture
+ mAndroidDataHandle = TextureHelper.loadTexture(mLessonSevenActivity, R.drawable.usb_android);
+ GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
+
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
+
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
+ GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
+
+ // Initialize the accumulated rotation matrix
+ Matrix.setIdentityM(mAccumulatedRotation, 0);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 glUnused, int width, int height)
+ {
+ // Set the OpenGL viewport to the same size as the surface.
+ GLES20.glViewport(0, 0, width, height);
+
+ // Create a new perspective projection matrix. The height will stay the same
+ // while the width will vary as per aspect ratio.
+ final float ratio = (float) width / height;
+ final float left = -ratio;
+ final float right = ratio;
+ final float bottom = -1.0f;
+ final float top = 1.0f;
+ final float near = 1.0f;
+ final float far = 1000.0f;
+
+ Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+ }
+
+ @Override
+ public void onDrawFrame(GL10 glUnused)
+ {
+ GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
+
+ // Set our per-vertex lighting program.
+ GLES20.glUseProgram(mProgramHandle);
+
+ // Set program handles for cube drawing.
+ mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
+ mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
+ mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
+ mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
+ mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
+ mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
+ mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
+
+ // Calculate position of the light. Push into the distance.
+ Matrix.setIdentityM(mLightModelMatrix, 0);
+ Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -1.0f);
+
+ Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
+ Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
+
+ // Draw a cube.
+ // Translate the cube into the screen.
+ Matrix.setIdentityM(mModelMatrix, 0);
+ Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.5f);
+
+ // Set a matrix that contains the current rotation.
+ Matrix.setIdentityM(mCurrentRotation, 0);
+ Matrix.rotateM(mCurrentRotation, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
+ Matrix.rotateM(mCurrentRotation, 0, mDeltaY, 1.0f, 0.0f, 0.0f);
+ mDeltaX = 0.0f;
+ mDeltaY = 0.0f;
+
+ // Multiply the current rotation by the accumulated rotation, and then set the accumulated rotation to the result.
+ Matrix.multiplyMM(mTemporaryMatrix, 0, mCurrentRotation, 0, mAccumulatedRotation, 0);
+ System.arraycopy(mTemporaryMatrix, 0, mAccumulatedRotation, 0, 16);
+
+ // Rotate the cube taking the overall rotation into account.
+ Matrix.multiplyMM(mTemporaryMatrix, 0, mModelMatrix, 0, mAccumulatedRotation, 0);
+ System.arraycopy(mTemporaryMatrix, 0, mModelMatrix, 0, 16);
+
+ // This multiplies the view matrix by the model matrix, and stores
+ // the result in the MVP matrix
+ // (which currently contains model * view).
+ Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
+
+ // Pass in the modelview matrix.
+ GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
+
+ // This multiplies the modelview matrix by the projection matrix,
+ // and stores the result in the MVP matrix
+ // (which now contains model * view * projection).
+ Matrix.multiplyMM(mTemporaryMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
+ System.arraycopy(mTemporaryMatrix, 0, mMVPMatrix, 0, 16);
+
+ // Pass in the combined matrix.
+ GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
+
+ // Pass in the light position in eye space.
+ GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
+
+ // Pass in the texture information
+ // Set the active texture unit to texture unit 0.
+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
+
+ // Bind the texture to this unit.
+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mAndroidDataHandle);
+
+ // Tell the texture uniform sampler to use this texture in the
+ // shader by binding to texture unit 0.
+ GLES20.glUniform1i(mTextureUniformHandle, 0);
+
+ if (mCubes != null) {
+ mCubes.render();
+ }
+ }
+
+ abstract class Cubes {
+ abstract void render();
+
+ abstract void release();
+
+ FloatBuffer[] getBuffers(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ // First, copy cube information into client-side floating point buffers.
+ final FloatBuffer cubePositionsBuffer;
+ final FloatBuffer cubeNormalsBuffer;
+ final FloatBuffer cubeTextureCoordinatesBuffer;
+
+ cubePositionsBuffer = ByteBuffer.allocateDirect(cubePositions.length * BYTES_PER_FLOAT)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+ cubePositionsBuffer.put(cubePositions).position(0);
+
+ cubeNormalsBuffer = ByteBuffer.allocateDirect(cubeNormals.length * BYTES_PER_FLOAT * generatedCubeFactor * generatedCubeFactor * generatedCubeFactor)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+
+ for (int i = 0; i < (generatedCubeFactor * generatedCubeFactor * generatedCubeFactor); i++) {
+ cubeNormalsBuffer.put(cubeNormals);
+ }
+
+ cubeNormalsBuffer.position(0);
+
+ cubeTextureCoordinatesBuffer = ByteBuffer.allocateDirect(cubeTextureCoordinates.length * BYTES_PER_FLOAT * generatedCubeFactor * generatedCubeFactor * generatedCubeFactor)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+
+ for (int i = 0; i < (generatedCubeFactor * generatedCubeFactor * generatedCubeFactor); i++) {
+ cubeTextureCoordinatesBuffer.put(cubeTextureCoordinates);
+ }
+
+ cubeTextureCoordinatesBuffer.position(0);
+
+ return new FloatBuffer[] {cubePositionsBuffer, cubeNormalsBuffer, cubeTextureCoordinatesBuffer};
+ }
+
+ FloatBuffer getInterleavedBuffer(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ final int cubeDataLength = cubePositions.length
+ + (cubeNormals.length * generatedCubeFactor * generatedCubeFactor * generatedCubeFactor)
+ + (cubeTextureCoordinates.length * generatedCubeFactor * generatedCubeFactor * generatedCubeFactor);
+ int cubePositionOffset = 0;
+ int cubeNormalOffset = 0;
+ int cubeTextureOffset = 0;
+
+ final FloatBuffer cubeBuffer = ByteBuffer.allocateDirect(cubeDataLength * BYTES_PER_FLOAT)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+
+ for (int i = 0; i < generatedCubeFactor * generatedCubeFactor * generatedCubeFactor; i++) {
+ for (int v = 0; v < 36; v++) {
+ cubeBuffer.put(cubePositions, cubePositionOffset, POSITION_DATA_SIZE);
+ cubePositionOffset += POSITION_DATA_SIZE;
+ cubeBuffer.put(cubeNormals, cubeNormalOffset, NORMAL_DATA_SIZE);
+ cubeNormalOffset += NORMAL_DATA_SIZE;
+ cubeBuffer.put(cubeTextureCoordinates, cubeTextureOffset, TEXTURE_COORDINATE_DATA_SIZE);
+ cubeTextureOffset += TEXTURE_COORDINATE_DATA_SIZE;
+ }
+
+ // The normal and texture data is repeated for each cube.
+ cubeNormalOffset = 0;
+ cubeTextureOffset = 0;
+ }
+
+ cubeBuffer.position(0);
+
+ return cubeBuffer;
+ }
+ }
+
+ class CubesClientSide extends Cubes {
+ private FloatBuffer mCubePositions;
+ private FloatBuffer mCubeNormals;
+ private FloatBuffer mCubeTextureCoordinates;
+
+ CubesClientSide(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ FloatBuffer[] buffers = getBuffers(cubePositions, cubeNormals, cubeTextureCoordinates, generatedCubeFactor);
+
+ mCubePositions = buffers[0];
+ mCubeNormals = buffers[1];
+ mCubeTextureCoordinates = buffers[2];
+ }
+
+ @Override
+ public void render() {
+ // Pass in the position information
+ GLES20.glEnableVertexAttribArray(mPositionHandle);
+ GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mCubePositions);
+
+ // Pass in the normal information
+ GLES20.glEnableVertexAttribArray(mNormalHandle);
+ GLES20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mCubeNormals);
+
+ // Pass in the texture information
+ GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
+ GLES20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false,
+ 0, mCubeTextureCoordinates);
+
+ // Draw the cubes.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mActualCubeFactor * mActualCubeFactor * mActualCubeFactor * 36);
+ }
+
+ @Override
+ public void release() {
+ mCubePositions.limit(0);
+ mCubePositions = null;
+ mCubeNormals.limit(0);
+ mCubeNormals = null;
+ mCubeTextureCoordinates.limit(0);
+ mCubeTextureCoordinates = null;
+ }
+ }
+
+ class CubesClientSideWithStride extends Cubes {
+ private FloatBuffer mCubeBuffer;
+
+ CubesClientSideWithStride(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ mCubeBuffer = getInterleavedBuffer(cubePositions, cubeNormals, cubeTextureCoordinates, generatedCubeFactor);
+ }
+
+ @Override
+ public void render() {
+ final int stride = (POSITION_DATA_SIZE + NORMAL_DATA_SIZE + TEXTURE_COORDINATE_DATA_SIZE) * BYTES_PER_FLOAT;
+
+ // Pass in the position information
+ mCubeBuffer.position(0);
+ GLES20.glEnableVertexAttribArray(mPositionHandle);
+ GLES20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, stride, mCubeBuffer);
+
+ // Pass in the normal information
+ mCubeBuffer.position(POSITION_DATA_SIZE);
+ GLES20.glEnableVertexAttribArray(mNormalHandle);
+ GLES20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, false, stride, mCubeBuffer);
+
+ // Pass in the texture information
+ mCubeBuffer.position(POSITION_DATA_SIZE + NORMAL_DATA_SIZE);
+ GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
+ GLES20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false,
+ stride, mCubeBuffer);
+
+ // Draw the cubes.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mActualCubeFactor * mActualCubeFactor * mActualCubeFactor * 36);
+ }
+
+ @Override
+ public void release() {
+ mCubeBuffer.limit(0);
+ mCubeBuffer = null;
+ }
+ }
+
+ class CubesWithVbo extends Cubes {
+ final int mCubePositionsBufferIdx;
+ final int mCubeNormalsBufferIdx;
+ final int mCubeTexCoordsBufferIdx;
+
+ CubesWithVbo(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ FloatBuffer[] floatBuffers = getBuffers(cubePositions, cubeNormals, cubeTextureCoordinates, generatedCubeFactor);
+
+ FloatBuffer cubePositionsBuffer = floatBuffers[0];
+ FloatBuffer cubeNormalsBuffer = floatBuffers[1];
+ FloatBuffer cubeTextureCoordinatesBuffer = floatBuffers[2];
+
+ // Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
+ final int buffers[] = new int[3];
+ GLES20.glGenBuffers(3, buffers, 0);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
+ GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubePositionsBuffer.capacity() * BYTES_PER_FLOAT, cubePositionsBuffer, GLES20.GL_STATIC_DRAW);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
+ GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeNormalsBuffer.capacity() * BYTES_PER_FLOAT, cubeNormalsBuffer, GLES20.GL_STATIC_DRAW);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[2]);
+ GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeTextureCoordinatesBuffer.capacity() * BYTES_PER_FLOAT, cubeTextureCoordinatesBuffer,
+ GLES20.GL_STATIC_DRAW);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+
+ mCubePositionsBufferIdx = buffers[0];
+ mCubeNormalsBufferIdx = buffers[1];
+ mCubeTexCoordsBufferIdx = buffers[2];
+
+ cubePositionsBuffer.limit(0);
+ cubePositionsBuffer = null;
+ cubeNormalsBuffer.limit(0);
+ cubeNormalsBuffer = null;
+ cubeTextureCoordinatesBuffer.limit(0);
+ cubeTextureCoordinatesBuffer = null;
+ }
+
+ @Override
+ public void render() {
+ // Pass in the position information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubePositionsBufferIdx);
+ GLES20.glEnableVertexAttribArray(mPositionHandle);
+ mGlEs20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0);
+
+ // Pass in the normal information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubeNormalsBufferIdx);
+ GLES20.glEnableVertexAttribArray(mNormalHandle);
+ mGlEs20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, false, 0, 0);
+
+ // Pass in the texture information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubeTexCoordsBufferIdx);
+ GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
+ mGlEs20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false,
+ 0, 0);
+
+ // Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+
+ // Draw the cubes.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mActualCubeFactor * mActualCubeFactor * mActualCubeFactor * 36);
+ }
+
+ @Override
+ public void release() {
+ // Delete buffers from OpenGL's memory
+ final int[] buffersToDelete = new int[] { mCubePositionsBufferIdx, mCubeNormalsBufferIdx,
+ mCubeTexCoordsBufferIdx };
+ GLES20.glDeleteBuffers(buffersToDelete.length, buffersToDelete, 0);
+ }
+ }
+
+ class CubesWithVboWithStride extends Cubes {
+ final int mCubeBufferIdx;
+
+ CubesWithVboWithStride(float[] cubePositions, float[] cubeNormals, float[] cubeTextureCoordinates, int generatedCubeFactor) {
+ FloatBuffer cubeBuffer = getInterleavedBuffer(cubePositions, cubeNormals, cubeTextureCoordinates, generatedCubeFactor);
+
+ // Second, copy these buffers into OpenGL's memory. After, we don't need to keep the client-side buffers around.
+ final int buffers[] = new int[1];
+ GLES20.glGenBuffers(1, buffers, 0);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
+ GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, cubeBuffer.capacity() * BYTES_PER_FLOAT, cubeBuffer, GLES20.GL_STATIC_DRAW);
+
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+
+ mCubeBufferIdx = buffers[0];
+
+ cubeBuffer.limit(0);
+ cubeBuffer = null;
+ }
+
+ @Override
+ public void render() {
+ final int stride = (POSITION_DATA_SIZE + NORMAL_DATA_SIZE + TEXTURE_COORDINATE_DATA_SIZE) * BYTES_PER_FLOAT;
+
+ // Pass in the position information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubeBufferIdx);
+ GLES20.glEnableVertexAttribArray(mPositionHandle);
+ mGlEs20.glVertexAttribPointer(mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, stride, 0);
+
+ // Pass in the normal information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubeBufferIdx);
+ GLES20.glEnableVertexAttribArray(mNormalHandle);
+ mGlEs20.glVertexAttribPointer(mNormalHandle, NORMAL_DATA_SIZE, GLES20.GL_FLOAT, false, stride, POSITION_DATA_SIZE * BYTES_PER_FLOAT);
+
+ // Pass in the texture information
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mCubeBufferIdx);
+ GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
+ mGlEs20.glVertexAttribPointer(mTextureCoordinateHandle, TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false,
+ stride, (POSITION_DATA_SIZE + NORMAL_DATA_SIZE) * BYTES_PER_FLOAT);
+
+ // Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+
+ // Draw the cubes.
+ GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mActualCubeFactor * mActualCubeFactor * mActualCubeFactor * 36);
+ }
+
+ @Override
+ public void release() {
+ // Delete buffers from OpenGL's memory
+ final int[] buffersToDelete = new int[] { mCubeBufferIdx };
+ GLES20.glDeleteBuffers(buffersToDelete.length, buffersToDelete, 0);
+ }
+ }
+}