OpenGL testcases for Attach Shader and ColorBuffer
attach shader :
5 test cases in c
1 test case in java
color buffer :
7 test cases in C
7 test cases in Java
Change-Id: I63de8f6a5652fae4d1b3a28c74e6c6ac572593f4
diff --git a/tests/tests/opengl/AndroidManifest.xml b/tests/tests/opengl/AndroidManifest.xml
index ef1af51..9a9be62 100644
--- a/tests/tests/opengl/AndroidManifest.xml
+++ b/tests/tests/opengl/AndroidManifest.xml
@@ -30,15 +30,17 @@
<activity
android:label="@string/app_name"
android:name="android.opengl.cts.OpenGLES20ActivityOne">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
+ </activity>
+ <activity
+ android:label="@string/app_name"
+ android:name="android.opengl.cts.OpenGLES20ActivityTwo">
</activity>
<uses-library android:name="android.test.runner" />
<activity
- android:name="android.opengl.cts.OpenGLES20NativeActivity"
+ android:name="android.opengl.cts.OpenGLES20NativeActivityOne"
+ android:label="@string/app_name" />
+ <activity
+ android:name="android.opengl.cts.OpenGLES20NativeActivityTwo"
android:label="@string/app_name" />
</application>
diff --git a/tests/tests/opengl/libopengltest/Android.mk b/tests/tests/opengl/libopengltest/Android.mk
index a54816e..8f438d2 100755
--- a/tests/tests/opengl/libopengltest/Android.mk
+++ b/tests/tests/opengl/libopengltest/Android.mk
@@ -27,6 +27,12 @@
attach_shader_four.cpp \
attach_shader_five.cpp \
attach_shader_six.cpp \
+ attach_shader_seven.cpp \
+ attach_shader_eight.cpp \
+ attach_shader_nine.cpp \
+ attach_shader_ten.cpp \
+ attach_shader_eleven.cpp \
+ color_one.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/tests/tests/opengl/libopengltest/attach_shader_eight.cpp b/tests/tests/opengl/libopengltest/attach_shader_eight.cpp
new file mode 100755
index 0000000..180399b
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_eight.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "attach_shader_eight.h"
+
+#define LOG_TAG "attach_shader_eight"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+
+Data attachShaderEight(){
+ GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
+
+ GLuint program = glCreateProgram();
+ glAttachShader(program, fragmentShader);
+
+ GLint error = glGetError();
+ Data data = {error, -9 , -1};
+ glDeleteShader(fragmentShader);
+ glDeleteProgram(program);
+ return data;
+}
diff --git a/tests/tests/opengl/libopengltest/attach_shader_eight.h b/tests/tests/opengl/libopengltest/attach_shader_eight.h
new file mode 100755
index 0000000..2f317e2
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_eight.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef _ATTACH_SHADER_EIGHT_H_
+#define _ATTACH_SHADER_EIGHT_H_
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+Data attachShaderEight();
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/attach_shader_eleven.cpp b/tests/tests/opengl/libopengltest/attach_shader_eleven.cpp
new file mode 100755
index 0000000..597de83
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_eleven.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "attach_shader_eleven.h"
+#include "common.h"
+#include "vertex.h"
+
+#define LOG_TAG "attach_shader_eleven"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+
+Data attachShaderEleven(){
+ GLuint vertexShader = loadShader(GL_VERTEX_SHADER, attach_shader_successful_complile_vertex);
+ GLuint program = glCreateProgram();
+ glAttachShader(program, vertexShader);
+
+ GLsizei maxCount = 10;
+ GLsizei count;
+ GLuint shaders[maxCount];
+
+ glGetAttachedShaders(program, maxCount,
+ &count,
+ shaders);
+ LOGI("Attached Shader First element : %d\n", *shaders);
+ LOGI("ShaderCount %d\n", count);
+ GLint error = glGetError();
+ Data data = {error, count, -1};
+
+ glDeleteProgram(program);
+ return data;
+}
diff --git a/tests/tests/opengl/libopengltest/attach_shader_eleven.h b/tests/tests/opengl/libopengltest/attach_shader_eleven.h
new file mode 100755
index 0000000..5cb39c1
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_eleven.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+#ifndef _ATTACH_SHADER_ELEVEN_H_
+#define _ATTACH_SHADER_ELEVEN_H_
+
+Data attachShaderEleven();
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/attach_shader_nine.cpp b/tests/tests/opengl/libopengltest/attach_shader_nine.cpp
new file mode 100755
index 0000000..154c351
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_nine.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "attach_shader_nine.h"
+
+#define LOG_TAG "attach_shader_nine"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+
+Data attachShaderNine(){
+ GLuint fragmentShader = 0;
+ GLuint program = glCreateProgram();
+ glAttachShader(program, fragmentShader);
+
+ GLint error = glGetError();
+ Data data = {error, -9, -1};
+ glDeleteShader(fragmentShader);
+ glDeleteProgram(program);
+ return data;
+}
diff --git a/tests/tests/opengl/libopengltest/attach_shader_nine.h b/tests/tests/opengl/libopengltest/attach_shader_nine.h
new file mode 100755
index 0000000..e2ea44f
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_nine.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef _ATTACH_SHADER_NINE_H_
+#define _ATTACH_SHADER_NINE_H_
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+Data attachShaderNine();
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/attach_shader_seven.cpp b/tests/tests/opengl/libopengltest/attach_shader_seven.cpp
new file mode 100755
index 0000000..f7e9c47
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_seven.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "attach_shader_seven.h"
+
+#define LOG_TAG "attach_shader_seven"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+
+Data attachShaderSeven(){
+ GLuint vertexShaderOne = glCreateShader(GL_VERTEX_SHADER);
+ GLuint vertexShaderTwo = glCreateShader(GL_VERTEX_SHADER);
+
+ GLuint program = glCreateProgram();
+ glAttachShader(program, vertexShaderOne);
+ glAttachShader(program, vertexShaderTwo);
+
+
+ GLint error = glGetError();
+ Data data = {error, -9 , -1};
+ glDeleteShader(vertexShaderOne);
+ glDeleteShader(vertexShaderTwo);
+ glDeleteProgram(program);
+ return data;
+}
diff --git a/tests/tests/opengl/libopengltest/attach_shader_seven.h b/tests/tests/opengl/libopengltest/attach_shader_seven.h
new file mode 100755
index 0000000..b13ac55
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_seven.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef _ATTACH_SHADER_SEVEN_H_
+#define _ATTACH_SHADER_SEVEN_H_
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+Data attachShaderSeven();
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/attach_shader_ten.cpp b/tests/tests/opengl/libopengltest/attach_shader_ten.cpp
new file mode 100755
index 0000000..3bc197e
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_ten.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "attach_shader_ten.h"
+#include "common.h"
+#include "shader.h"
+#define LOG_TAG "attach_shader_ten"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+
+Data attachShaderTen(){
+ GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, attach_shader_successful_complile_shader);
+ GLuint program = glCreateProgram();
+ glAttachShader(program, fragmentShader);
+
+ GLsizei maxCount = 10;
+ GLsizei count;
+ GLuint shaders[maxCount];
+
+ glGetAttachedShaders(program, maxCount,
+ &count,
+ shaders);
+ LOGI("Attached Shader First element : %d\n", *shaders);
+ LOGI("ShaderCount %d\n", count);
+ GLint error = glGetError();
+ Data data = {error, count, -1};
+ glDeleteShader(fragmentShader);
+ glDeleteProgram(program);
+ return data;
+}
diff --git a/tests/tests/opengl/libopengltest/attach_shader_ten.h b/tests/tests/opengl/libopengltest/attach_shader_ten.h
new file mode 100755
index 0000000..9bb8d0b
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/attach_shader_ten.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+#ifndef _ATTACH_SHADER_TEN_H_
+#define _ATTACH_SHADER_TEN_H_
+
+Data attachShaderTen();
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/color_one.cpp b/tests/tests/opengl/libopengltest/color_one.cpp
new file mode 100755
index 0000000..27d400c
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/color_one.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "color_one.h"
+#include "common.h"
+#include "vertex.h"
+#include "shader.h"
+
+#define LOG_TAG "color_one"
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+
+static const GLfloat gTriangleVertices[] = { 0.0f, 0.5f, -0.5f, -0.5f,
+ 0.5f, -0.5f };
+GLuint gProgram;
+GLuint gvPositionHandle;
+GLuint gvColorHandle;
+int width;
+int height;
+
+float dataFloat[4];
+void initColorOne(int w, int h){
+ GLuint vertexShader = loadShader(GL_VERTEX_SHADER, color_one_vertex_shader_one);
+ GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, color_one_fragment_shader_one);
+ gProgram = glCreateProgram();
+ LOGI("Program %d\n", gProgram);
+ width = w;
+ height = h;
+ glAttachShader(gProgram, vertexShader);
+ checkGlError("glAttachShader");
+ glAttachShader(gProgram, fragmentShader);
+ checkGlError("glAttachShader");
+ glBindAttribLocation(gProgram, 0, "vPosition");
+ glBindAttribLocation(gProgram, 1, "vColor");
+ glLinkProgram(gProgram);
+ GLint linkStatus = GL_FALSE;
+ glGetProgramiv(gProgram, GL_LINK_STATUS, &linkStatus);
+ if (linkStatus != GL_TRUE) {
+ GLint bufLength = 0;
+ glGetProgramiv(gProgram, GL_INFO_LOG_LENGTH, &bufLength);
+ if (bufLength) {
+ char* buf = (char*) malloc(bufLength);
+ if (buf) {
+ glGetProgramInfoLog(gProgram, bufLength, NULL, buf);
+ LOGE("Could not link program:\n%s\n", buf);
+ free(buf);
+ }
+ }
+ }
+ LOGI("w %d, h %d\n",w, h);
+ glViewport(0, 0, w, h);
+
+ checkGlError("glViewport");
+ gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
+ gvColorHandle = glGetAttribLocation(gProgram, "vColor");
+ GLsizei maxCount = 10;
+ GLsizei count;
+ GLuint shaders[maxCount];
+
+ glGetAttachedShaders(gProgram, maxCount,
+ &count,
+ shaders);
+ LOGI("Attached Shader First element : %d\n", *shaders);
+ LOGI("ShaderCount %d\n", count);
+ GLint error = glGetError();
+ return;
+}
+
+float* drawColorOne(float mColor[]){
+ LOGI("drawColorOne start");
+ static float grey;
+ grey = 0.01f;
+
+ glClearColor(grey, grey, grey, 1.0f);
+ checkGlError("glClearColor");
+ glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+ checkGlError("glClear");
+
+ glUseProgram(gProgram);
+ checkGlError("glUseProgram");
+
+ glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
+ checkGlError("glVertexAttribPointer");
+ glEnableVertexAttribArray(0);
+ checkGlError("glEnableVertexAttribArray");
+
+ glVertexAttribPointer(gvColorHandle,4, GL_FLOAT, GL_FALSE, 0, mColor);
+ checkGlError("glVertexAttribPointer");
+ glEnableVertexAttribArray(1);
+ checkGlError("glEnableVertexAttribArray");
+
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+ checkGlError("glDrawArrays");
+ GLubyte data[4*1];
+
+
+ glReadPixels(width/2, height/2, 1,1, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)&data);
+ for(int i = 0; i < sizeof(data); i++){
+ dataFloat[i] = data[i];
+ }
+
+ return dataFloat;
+}
+
+void deleteColorOne() {
+ glDeleteProgram(gProgram);
+}
+
+static void checkGlError(const char* op) {
+ for (GLint error = glGetError(); error; error
+ = glGetError()) {
+ LOGI("after %s() glError (0x%x)\n", op, error);
+ }
+}
diff --git a/tests/tests/opengl/libopengltest/color_one.h b/tests/tests/opengl/libopengltest/color_one.h
new file mode 100755
index 0000000..21dd9fd
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/color_one.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef _COLOR_ONE_H_
+#define _COLOR_ONE_H_
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <android/log.h>
+#include "types.h"
+
+void initColorOne(int w,int h);
+float* drawColorOne(float color[]);
+
+static void checkGlError(const char* op);
+
+#endif
+
diff --git a/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp b/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
index 9433702..fe49b1b 100755
--- a/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
+++ b/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
#include <jni.h>
#include <android/log.h>
@@ -24,12 +23,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
+
#include "attach_shader_one.h"
#include "attach_shader_two.h"
#include "attach_shader_three.h"
#include "attach_shader_four.h"
#include "attach_shader_five.h"
#include "attach_shader_six.h"
+#include "attach_shader_seven.h"
+#include "attach_shader_eight.h"
+#include "attach_shader_nine.h"
+#include "attach_shader_ten.h"
+#include "attach_shader_eleven.h"
+#include "color_one.h"
#define LOG_TAG "gl2_jni_libone"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
@@ -40,7 +46,7 @@
extern "C" JNIEXPORT void JNICALL Java_android_opengl_cts_GL2JniLibOne_init
- (JNIEnv *, jclass pClass, jint pCategory, jint pSubCategory) {
+ (JNIEnv *, jclass pClass, jint pCategory, jint pSubCategory, jint width, jint height) {
LOGI("Category : %d\n", pCategory);
if(pCategory == 1) {
@@ -72,6 +78,34 @@
Data data = attachShaderSix();
LOGI("Attach Shader Error : %d\n", data.mShaderError);
errorAttachShader = data.mShaderError;
+ }else if(pSubCategory == 7) {
+ Data data = attachShaderSeven();
+ LOGI("Attach Shader Error : %d\n", data.mShaderError);
+ errorAttachShader = data.mShaderError;
+ }else if(pSubCategory == 8) {
+ Data data = attachShaderEight();
+ LOGI("Attach Shader Error : %d\n", data.mShaderError);
+ errorAttachShader = data.mShaderError;
+ }else if(pSubCategory == 9) {
+ Data data = attachShaderNine();
+ LOGI("Attach Shader Error : %d\n", data.mShaderError);
+ errorAttachShader = data.mShaderError;
+ }else if(pSubCategory == 10) {
+ Data data = attachShaderTen();
+ LOGI("Attach Shader Error : %d\n", data.mShaderError);
+ LOGI("Shader Count : %d\n", data.mShaderCount);
+ errorAttachShader = data.mShaderError;
+ shaderCount = data.mShaderCount;
+ }else if(pSubCategory == 11) {
+ Data data = attachShaderEleven();
+ LOGI("Attach Shader Error : %d\n", data.mShaderError);
+ LOGI("Shader Count : %d\n", data.mShaderCount);
+ errorAttachShader = data.mShaderError;
+ shaderCount = data.mShaderCount;
+ }
+ }else if(pCategory == 3){//Color Test
+ if(pSubCategory == 1){
+ initColorOne( width,height);
}
}
}
@@ -97,4 +131,23 @@
return shaderCount;
}
+extern "C" JNIEXPORT jfloatArray JNICALL Java_android_opengl_cts_GL2JniLibOne_draw(JNIEnv * env,
+ jclass obj, jint pCategory, jint pSubCategory, jfloatArray color)
+{
+ LOGI("Inside draw %d %d", pCategory, pSubCategory);
+ jfloatArray result;
+ if(pCategory == 3){
+ if(pSubCategory == 1){
+ result = env->NewFloatArray(4);
+ jfloat *lColor = env->GetFloatArrayElements(color,0);
+
+ float * actualColor = drawColorOne(lColor);
+ for( int i= 0; i < sizeof(actualColor); i++) {
+ LOGI("actualColor[%d] ; %f", i, actualColor[i]);
+ }
+ env->SetFloatArrayRegion(result, 0, 4, actualColor);
+ }
+ }
+ return result;
+}
diff --git a/tests/tests/opengl/libopengltest/shader.h b/tests/tests/opengl/libopengltest/shader.h
new file mode 100755
index 0000000..12131f1
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/shader.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#ifndef _SHADER_H_
+#define _SHADER_H_
+
+static const char attach_shader_successful_complile_shader[] =
+ "attribute vec3 gtf_Normal;\n"
+ "attribute vec4 gtf_Vertex;\n"
+ "uniform mat3 gtf_NormalMatrix;\n"
+ "uniform mat4 gtf_ModelViewMatrix;\n"
+ "uniform mat4 gtf_ModelViewProjectionMatrix;\n"
+
+ "varying float lightIntensity;\n"
+ "varying vec3 Position;\n"
+ "uniform vec3 LightPosition;\n"
+ "uniform float Scale;\n"
+ "void main(void) {\n"
+ "vec4 pos = gtf_ModelViewMatrix * gtf_Vertex;\n"
+ "Position = vec3(gtf_Vertex) * Scale;\n"
+ "vec3 tnorm = normalize(gtf_NormalMatrix * gtf_Normal);\n"
+ "lightIntensity = dot(normalize(LightPosition - vec3(pos)), tnorm) * 1.5;\n"
+ "gl_Position = gtf_ModelViewProjectionMatrix * gtf_Vertex;\n";
+
+static const char color_one_fragment_shader_one[] =
+ "precision mediump float; \n"
+ "varying vec4 varyColor; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = varyColor; \n"
+ "} ";
+
+static const char color_one_fragment_shader[] =
+ "precision mediump float; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \n"
+ "} ";
+
+#endif
diff --git a/tests/tests/opengl/libopengltest/vertex.h b/tests/tests/opengl/libopengltest/vertex.h
new file mode 100755
index 0000000..50a4c7a
--- /dev/null
+++ b/tests/tests/opengl/libopengltest/vertex.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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.
+ */
+#ifndef _VERTEX_H_
+#define _VERTEX_H_
+
+static const char attach_shader_successful_complile_vertex[] =
+ "#ifdef GL_ES \n"
+ "precision mediump float;\n"
+ "#endif\n"
+ "uniform float mortarThickness;\n"
+ "uniform vec3 brickColor;\n"
+ "uniform vec3 mortarColor;\n"
+ " \n"
+ "uniform float brickMortarWidth;\n"
+ "uniform float brickMortarHeight;\n"
+ "uniform float mwf; \n"
+ "uniform float mhf; \n"
+ ""
+ "varying vec3 Position; \n"
+ "varying float lightIntensity; \n"
+ " \n"
+ "void main (void) \n"
+ "{\n"
+ " vec3 ct; \n"
+ " float ss, tt, w, h; \n"
+ " \n"
+ " vec3 pos = Position; \n"
+ ""
+ " ss = pos.x / brickMortarWidth; \n"
+ " tt = pos.z / brickMortarHeight; \n"
+ ""
+ " if (fract (tt * 0.5) > 0.5) \n"
+ " ss += 0.5; \n"
+ ""
+ " ss = fract (ss); \n"
+ " tt = fract (tt); \n"
+
+ " w = step (mwf, ss) - step (1.0 - mwf, ss); \n"
+ " h = step (mhf, tt) - step (1.0 - mhf, tt); \n"
+ ""
+ " ct = clamp(mix (mortarColor, brickColor, w * h) * lightIntensity, 0.0, 1.0); \n"
+ ""
+ " gl_FragColor = vec4 (ct, 1.0); \n"
+ "} \n";
+
+static const char color_one_vertex_shader_one[] =
+ "attribute vec4 vPosition; \n"
+ "attribute vec4 vColor; \n"
+ "varying vec4 varyColor; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = vPosition; \n"
+ " varyColor = vColor; \n"
+ "} \n";
+
+static const char color_one_vertex_shader[] =
+ "attribute vec4 vPosition; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = vPosition; \n"
+ "} \n";
+
+#endif
diff --git a/tests/tests/opengl/src/android/opengl/cts/AttachShaderTest.java b/tests/tests/opengl/src/android/opengl/cts/AttachShaderTest.java
index 0ebfae0..817dcd7 100644
--- a/tests/tests/opengl/src/android/opengl/cts/AttachShaderTest.java
+++ b/tests/tests/opengl/src/android/opengl/cts/AttachShaderTest.java
@@ -200,4 +200,30 @@
int error = mActivity.glGetError();
assertEquals(GLES20.GL_NO_ERROR, error);
}
+
+ public void test_glAttachShaders_successfulcompile_attach_vert() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 11);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+
+ int error = mActivity.glGetError();
+ assertEquals(GLES20.GL_NO_ERROR, error);
+ }
+
+ public void test_glAttachShaders_successfulcompile_attach_invalid_handle_frag() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 12);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+
+ int error = mActivity.glGetError();
+ assertEquals(GLES20.GL_INVALID_VALUE, error);
+ }
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/ColorBufferTest.java b/tests/tests/opengl/src/android/opengl/cts/ColorBufferTest.java
new file mode 100755
index 0000000..0882259
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/ColorBufferTest.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class ColorBufferTest extends ActivityInstrumentationTestCase2<OpenGLES20ActivityTwo> {
+ private static final long SLEEP_TIME = 500l;
+ public ColorBufferTest(Class<OpenGLES20ActivityTwo> activityClass) {
+ super(activityClass);
+ }
+
+ private OpenGLES20ActivityTwo mActivity;
+
+ public ColorBufferTest() {
+ super(OpenGLES20ActivityTwo.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+ /**
+ *Test: Attach an two valid shaders to a program
+ * <pre>
+ * shader count : 2
+ * error : GLES20.GL_NO_ERROR
+ * </pre>
+ */
+ public void test_RGBA_1001() throws Throwable {
+ float r = 1.0f;
+ float g = 0.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+ mActivity = getActivity();
+ float[] expectedColor = {r, g, b, a};
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_1101() throws Throwable {
+ float r = 1.0f;
+ float g = 1.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_1111() throws Throwable {
+ float r = 1.0f;
+ float g = 1.0f;
+ float b = 1.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0101() throws Throwable {
+ float r = 0.0f;
+ float g = 1.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0011() throws Throwable {
+ float r = 0.0f;
+ float g = 0.0f;
+ float b = 1.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0000() throws Throwable {
+ float r = 0.0f;
+ float g = 0.0f;
+ float b = 0.0f;
+ float a = 0.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_rand_val_one() throws Throwable {
+ float r = 0.6f;
+ float g = 0.7f;
+ float b = 0.25f;
+ float a = 0.5f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ private float[] getVertexColors(float r, float g, float b, float a) {
+ float[] vertexColors =
+ { r, g, b, a,
+ r, g, b, a,
+ r, g, b, a,
+ r, g, b, a
+ };
+ return vertexColors;
+ }
+
+ private void compare(float[] expectedColor, float[] actualColor) {
+ assertNotNull(actualColor);
+ assertEquals(4, actualColor.length);
+ float r = expectedColor[0];
+ float g = expectedColor[1];
+ float b = expectedColor[2];
+ float a = expectedColor[3];
+ //We are giving 0.1 buffer as colors might not be exactly same as input color
+ assertTrue(Math.abs(r - (actualColor[0]/255)) < 0.1f);
+ assertTrue(Math.abs(g - (actualColor[1]/255)) < 0.1f);
+ assertTrue(Math.abs(b - (actualColor[2]/255)) < 0.1f);
+ //assertTrue(Math.abs(a - (actualColor[3]/255)) < 0.1f);
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/Constants.java b/tests/tests/opengl/src/android/opengl/cts/Constants.java
index 9bd1acc..cba455a 100644
--- a/tests/tests/opengl/src/android/opengl/cts/Constants.java
+++ b/tests/tests/opengl/src/android/opengl/cts/Constants.java
@@ -18,4 +18,5 @@
public class Constants {
public static final int SHADER = 1;
public static final int PROGRAM = 2;
+ public static final int COLOR = 3;
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/GL2JniLibOne.java b/tests/tests/opengl/src/android/opengl/cts/GL2JniLibOne.java
index 26de6ff..f30f417 100755
--- a/tests/tests/opengl/src/android/opengl/cts/GL2JniLibOne.java
+++ b/tests/tests/opengl/src/android/opengl/cts/GL2JniLibOne.java
@@ -21,8 +21,9 @@
System.loadLibrary("opengltest");
}
- public static native void init(int category, int subcategory);
+ public static native void init(int category, int subcategory, int width, int height);
public static native void step();
+ public static native float[] draw(int category, int subcategory, float[] color);
public static native int getAttachShaderError();
public static native int getLoadShaderError();
diff --git a/tests/tests/opengl/src/android/opengl/cts/NativeAttachShaderTest.java b/tests/tests/opengl/src/android/opengl/cts/NativeAttachShaderTest.java
index e6707da..b16a087 100755
--- a/tests/tests/opengl/src/android/opengl/cts/NativeAttachShaderTest.java
+++ b/tests/tests/opengl/src/android/opengl/cts/NativeAttachShaderTest.java
@@ -19,18 +19,18 @@
import android.test.ActivityInstrumentationTestCase2;
public class NativeAttachShaderTest
- extends ActivityInstrumentationTestCase2<OpenGLES20NativeActivity> {
+ extends ActivityInstrumentationTestCase2<OpenGLES20NativeActivityOne> {
private static final long SLEEP_TIME = 1000l;
- public NativeAttachShaderTest(Class<OpenGLES20NativeActivity> activityClass) {
+ public NativeAttachShaderTest(Class<OpenGLES20NativeActivityOne> activityClass) {
super(activityClass);
}
- private OpenGLES20NativeActivity mActivity;
+ private OpenGLES20NativeActivityOne mActivity;
public NativeAttachShaderTest() {
- super(OpenGLES20NativeActivity.class);
+ super(OpenGLES20NativeActivityOne.class);
}
@Override
@@ -153,4 +153,69 @@
int error = mActivity.mRenderer.mAttachShaderError;;
assertEquals(GLES20.GL_NO_ERROR, error);
}
+
+ public void test_glAttachShaders_emptyvertexshader_emptyvertexshader() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 7);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ int error = mActivity.mRenderer.mAttachShaderError;
+ assertEquals(GLES20.GL_INVALID_OPERATION, error);
+ }
+
+ public void test_glAttachShaders_programobject_attach_fragshaderobject() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 8);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+
+ int error = mActivity.mRenderer.mAttachShaderError;
+ assertEquals(GLES20.GL_INVALID_OPERATION, error);
+ }
+
+ public void test_glAttachShaders_invalidshader_attach_valid_handle() throws Throwable{
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 9);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+
+ int error = mActivity.mRenderer.mAttachShaderError;
+ assertEquals(GLES20.GL_INVALID_OPERATION, error);
+ }
+
+ public void test_glAttachShaders_successfulcompile_attach_frag() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 10);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ int shaderCount = mActivity.mRenderer.mShaderCount;
+ assertEquals(1,shaderCount);
+ int error = mActivity.mRenderer.mAttachShaderError;
+ assertEquals(GLES20.GL_NO_ERROR, error);
+ }
+
+ public void test_glAttachShaders_successfulcompile_attach_vert() throws Throwable {
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.SHADER, 11);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+
+ int error = mActivity.mRenderer.mAttachShaderError;
+ assertEquals(GLES20.GL_NO_ERROR, error);
+ }
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/NativeColorBufferTest.java b/tests/tests/opengl/src/android/opengl/cts/NativeColorBufferTest.java
new file mode 100755
index 0000000..6354c90
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/NativeColorBufferTest.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class NativeColorBufferTest extends ActivityInstrumentationTestCase2<OpenGLES20NativeActivityTwo> {
+ private static final long SLEEP_TIME = 500l;
+ private static final String TAG = NativeColorBufferTest.class.getName();
+ public NativeColorBufferTest(Class<OpenGLES20NativeActivityTwo> activityClass) {
+ super(activityClass);
+ }
+
+ private OpenGLES20NativeActivityTwo mActivity;
+
+ public NativeColorBufferTest() {
+ super(OpenGLES20NativeActivityTwo.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ public void test_RGBA_1001() throws Throwable {
+ float r = 1.0f;
+ float g = 0.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+ mActivity = getActivity();
+ float[] expectedColor = {r, g, b, a};
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_1101() throws Throwable {
+ float r = 1.0f;
+ float g = 1.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_1111() throws Throwable {
+ float r = 1.0f;
+ float g = 1.0f;
+ float b = 1.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0101() throws Throwable {
+ float r = 0.0f;
+ float g = 1.0f;
+ float b = 0.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0011() throws Throwable {
+ float r = 0.0f;
+ float g = 0.0f;
+ float b = 1.0f;
+ float a = 1.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_0000() throws Throwable {
+ float r = 0.0f;
+ float g = 0.0f;
+ float b = 0.0f;
+ float a = 0.0f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ public void test_RGBA_rand_val_one() throws Throwable {
+ float r = 0.6f;
+ float g = 0.7f;
+ float b = 0.25f;
+ float a = 0.5f;
+ final float[] vertexColors = getVertexColors(r, g, b, a);
+
+ float[] expectedColor = {r, g, b, a};
+ mActivity = getActivity();
+ this.runTestOnUiThread(new Runnable() {
+ public void run() {
+ mActivity.setView(Constants.COLOR, 1, vertexColors);
+ }
+ });
+ Thread.sleep(SLEEP_TIME);
+ float[] actualColor = mActivity.getActualColor();
+ compare(expectedColor, actualColor);
+ }
+
+ private float[] getVertexColors(float r, float g, float b, float a) {
+ float[] vertexColors =
+ { r, g, b, a,
+ r, g, b, a,
+ r, g, b, a
+ };
+ return vertexColors;
+ }
+
+ private void compare(float[] expectedColor, float[] actualColor) {
+ assertNotNull(actualColor);
+ assertEquals(4, actualColor.length);
+ float r = expectedColor[0];
+ float g = expectedColor[1];
+ float b = expectedColor[2];
+ float a = expectedColor[3];
+ //We are giving 0.1 buffer as colors might not be exactly same as input color
+ assertTrue(Math.abs(r - (actualColor[0]/255.0)) < 0.1f);
+ assertTrue(Math.abs(g - (actualColor[1]/255.0)) < 0.1f);
+ assertTrue(Math.abs(b - (actualColor[2]/255.0)) < 0.1f);
+ float actualAlpha = (float) (actualColor[3]/255.0);
+ //Commented as of now as the Alpha being returned is always 1
+ //assertTrue(Math.abs(a - (actualColor[3]/255)) < 0.1f);
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/NativeRendererOneColorBufferTest.java b/tests/tests/opengl/src/android/opengl/cts/NativeRendererOneColorBufferTest.java
new file mode 100755
index 0000000..02daee5
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/NativeRendererOneColorBufferTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.content.Context;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLU;
+import android.util.Log;
+
+public class NativeRendererOneColorBufferTest extends RendererBase {
+ private int mProgramObject;
+ private int mWidth;
+ private int mHeight;
+ private FloatBuffer mVertices;
+ private ShortBuffer mIndexBuffer;
+
+ private static String TAG = "HelloTriangleRenderer";
+
+ // Our vertices.
+ private float mVerticesData[] = {
+ -0.5f, 0.5f, 0.0f, // 0, Top Left
+ -0.5f, -0.5f, 0.0f, // 1, Bottom Left
+ 0.5f, -0.5f, 0.0f, // 2, Bottom Right
+ 0.5f, 0.5f, 0.0f, // 3, Top Right
+ };
+
+ private float[] mVertexColor = {};
+
+ private short[] mIndices = { 0, 1, 2, 0, 2, 3 };
+ private FloatBuffer mColor;
+
+ public NativeRendererOneColorBufferTest(Context context) {
+
+ }
+
+ public NativeRendererOneColorBufferTest(Context context, float[] color) {
+ this.mVertexColor = color;
+ }
+
+ public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
+
+ }
+
+ public void onDrawFrame(GL10 glUnused) {
+ Log.i(TAG,"onDrawFrame start");
+
+ float[] result = GL2JniLibOne.draw(3, 1, mVertexColor);
+ mColorOne = result;
+ }
+
+ public float[] getActualRGBA() {
+ return this.mColorOne;
+ }
+
+ public void onSurfaceChanged(GL10 glUnused, int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ Log.i(TAG,"onSurfaceCreated start");
+ GL2JniLibOne.init(3,1, width, height);
+ Log.i(TAG,"onSurfaceCreated finish");
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityOne.java b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityOne.java
index 809b640..9f808cb 100644
--- a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityOne.java
+++ b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityOne.java
@@ -49,6 +49,7 @@
protected void onPause() {
super.onPause();
view.onPause();
+
}
@Override
@@ -85,6 +86,10 @@
mRenderer = new RendererNineShaderTest();
}else if(index == 10) {
mRenderer = new RendererTenShaderTest();
+ }else if(index == 11) {
+ mRenderer = new RendererElevenShaderTest();
+ }else if(index == 12) {
+ mRenderer = new RendererTwelveShaderTest();
}else {
throw new RuntimeException();
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityTwo.java b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityTwo.java
new file mode 100755
index 0000000..c158c47
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20ActivityTwo.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import android.app.Activity;
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLSurfaceView.Renderer;
+import android.os.Bundle;
+
+public class OpenGLES20ActivityTwo extends Activity {
+ OpenGLES20View view;
+ Renderer mRenderer;
+ int mRendererType;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ public void setView(int type, int i, float[] vertexColors ) {
+ view = new OpenGLES20View(this,type,i, vertexColors);
+ setContentView(view);
+ }
+
+ public void setView(int type, int i) {
+ float[] f = {};
+ view = new OpenGLES20View(this,type,i, f ) ;
+ setContentView(view);
+ }
+
+ public int getNoOfAttachedShaders() {
+ return ((RendererBase)mRenderer).mShaderCount[0];
+ }
+
+ public int glGetError() {
+ return ((RendererBase)mRenderer).mError;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ view.onPause();
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if(view != null) {
+ view.onResume();
+ }
+ }
+
+ public float[] getActualColor() {
+ return ((RendererBase) mRenderer).mColorOne;
+ }
+
+ class OpenGLES20View extends GLSurfaceView {
+
+ public OpenGLES20View(Context context, int type, int index, float[] rgba) {
+ super(context);
+ setEGLContextClientVersion(2);
+ if(type == Constants.COLOR) {
+ if(index == 1) {
+ mRenderer = new RendererOneColorBufferTest(context, rgba);
+ }else {
+ throw new RuntimeException();
+ }
+ }
+ setRenderer(mRenderer);
+ }
+
+ @Override
+ public void setEGLContextClientVersion(int version) {
+ super.setEGLContextClientVersion(version);
+ }
+
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivity.java b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityOne.java
similarity index 76%
rename from tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivity.java
rename to tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityOne.java
index d642e7a..1e1783a 100755
--- a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivity.java
+++ b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityOne.java
@@ -1,24 +1,9 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * 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 android.opengl.cts;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
-import com.android.cts.opengl.R;
+//import com.android.cts.opengl.R;
import android.app.Activity;
import android.content.Context;
@@ -32,7 +17,7 @@
import android.widget.EditText;
import android.widget.TextView;
-public class OpenGLES20NativeActivity extends Activity {
+public class OpenGLES20NativeActivityOne extends Activity {
/** Called when the activity is first created. */
int mValue;
@@ -108,15 +93,15 @@
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
-
- }
-
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Log.i(TAG ,"onSurfaceCreated");
- GL2JniLibOne.init(mCategory, mTestCase);
+ GL2JniLibOne.init(mCategory, mTestCase, width, height);
this.mAttachShaderError = GL2JniLibOne.getAttachShaderError();
Log.i(TAG,"error:" + mAttachShaderError);
this.mShaderCount = GL2JniLibOne.getAttachedShaderCount();
Log.i(TAG,"ShaderCount:" + mShaderCount);
}
+
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+
+ }
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityTwo.java b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityTwo.java
new file mode 100755
index 0000000..9969ba4
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/OpenGLES20NativeActivityTwo.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import android.app.Activity;
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLSurfaceView.Renderer;
+import android.os.Bundle;
+
+public class OpenGLES20NativeActivityTwo extends Activity {
+ OpenGLES20View view;
+ Renderer mRenderer;
+ int mRendererType;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ public void setView(int type, int i, float[] vertexColors ) {
+ view = new OpenGLES20View(this,type,i, vertexColors);
+ setContentView(view);
+ }
+
+ public void setView(int type, int i) {
+
+ }
+
+ public int getNoOfAttachedShaders() {
+ return ((RendererBase)mRenderer).mShaderCount[0];
+ }
+
+ public int glGetError() {
+ return ((RendererBase)mRenderer).mError;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if(view != null) {
+ view.onPause();
+ }
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if(view != null) {
+ view.onResume();
+ }
+ }
+
+ public float[] getActualColor() {
+ return ((RendererBase) mRenderer).mColorOne;
+ }
+
+ class OpenGLES20View extends GLSurfaceView {
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ }
+
+ public OpenGLES20View(Context context, int type, int index, float[] rgba) {
+ super(context);
+ setEGLContextClientVersion(2);
+ if(type == Constants.COLOR) {
+ if(index == 1) {
+ mRenderer = new NativeRendererOneColorBufferTest(context, rgba);
+ }else {
+ throw new RuntimeException();
+ }
+ }
+ setRenderer(mRenderer);
+ }
+
+ @Override
+ public void setEGLContextClientVersion(int version) {
+ super.setEGLContextClientVersion(version);
+ }
+
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/RendererBase.java b/tests/tests/opengl/src/android/opengl/cts/RendererBase.java
index b64f47a..84234ea 100644
--- a/tests/tests/opengl/src/android/opengl/cts/RendererBase.java
+++ b/tests/tests/opengl/src/android/opengl/cts/RendererBase.java
@@ -28,6 +28,7 @@
FloatBuffer floatBuffer;
int mProgram;
int maPositionHandle;
+ float[] mColorOne = new float[4];
int[] mShaderCount;
int mError;
@@ -43,5 +44,4 @@
GLES20.glCompileShader(shader);
return shader;
}
-
}
diff --git a/tests/tests/opengl/src/android/opengl/cts/RendererElevenShaderTest.java b/tests/tests/opengl/src/android/opengl/cts/RendererElevenShaderTest.java
new file mode 100755
index 0000000..f301676
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/RendererElevenShaderTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.opengl.GLES20;
+
+public class RendererElevenShaderTest extends RendererBase {
+ private String fragmentShaderCode = Vertex.successfulcompile_vertex;
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
+ int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
+ mProgram = GLES20.glCreateProgram();
+
+ GLES20.glAttachShader(mProgram, fragmentShader);
+ GLES20.glLinkProgram(mProgram);
+
+ mError = GLES20.glGetError();
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/RendererOneColorBufferTest.java b/tests/tests/opengl/src/android/opengl/cts/RendererOneColorBufferTest.java
new file mode 100755
index 0000000..a79e71a
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/RendererOneColorBufferTest.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.content.Context;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLU;
+import android.util.Log;
+
+public class RendererOneColorBufferTest extends RendererBase {
+ private int mProgramObject;
+ private int mWidth;
+ private int mHeight;
+ private FloatBuffer mVertices;
+ private ShortBuffer mIndexBuffer;
+
+ private static String TAG = "HelloTriangleRenderer";
+
+ // Our vertices.
+ private float mVerticesData[] = {
+ -0.5f, 0.5f, 0.0f, // 0, Top Left
+ -0.5f, -0.5f, 0.0f, // 1, Bottom Left
+ 0.5f, -0.5f, 0.0f, // 2, Bottom Right
+ 0.5f, 0.5f, 0.0f, // 3, Top Right
+ };
+
+ private float[] mVertexColor = {1.0f,0.0f,0.0f,1.0f,
+ 1.0f,0.0f,0.0f,1.0f,
+ 1.0f,0.0f,0.0f,1.0f,
+ 1.0f,0.0f,0.0f,1.0f};
+
+ // The order we like to connect them.
+ private short[] mIndices = { 0, 1, 2, 0, 2, 3 };
+ private FloatBuffer mColor;
+
+
+ public RendererOneColorBufferTest(Context context) {
+ mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mVertices.put(mVerticesData).position(0);
+
+ ByteBuffer ibb = ByteBuffer.allocateDirect(mIndices.length * 2);
+ ibb.order(ByteOrder.nativeOrder());
+ mIndexBuffer = ibb.asShortBuffer();
+ mIndexBuffer.put(mIndices);
+ mIndexBuffer.position(0);
+
+ mColor = ByteBuffer.allocateDirect(mVertexColor.length*4).
+ order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mColor.put(mVertexColor).position(0);
+ }
+
+ public RendererOneColorBufferTest(Context context, float[] colors) {
+ mVertexColor = colors;
+ mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mVertices.put(mVerticesData).position(0);
+
+ ByteBuffer ibb = ByteBuffer.allocateDirect(mIndices.length * 2);
+ ibb.order(ByteOrder.nativeOrder());
+ mIndexBuffer = ibb.asShortBuffer();
+ mIndexBuffer.put(mIndices);
+ mIndexBuffer.position(0);
+
+ mColor = ByteBuffer.allocateDirect(mVertexColor.length*4).
+ order(ByteOrder.nativeOrder()).asFloatBuffer();
+ mColor.put(mVertexColor).position(0);
+ }
+
+ private int LoadShader(int type, String shaderSrc) {
+ int shader;
+ int[] compiled = new int[1];
+
+ // Create the shader object
+ shader = GLES20.glCreateShader(type);
+
+ if (shader == 0)
+ return 0;
+
+ // Load the shader source
+ GLES20.glShaderSource(shader, shaderSrc);
+
+ // Compile the shader
+ GLES20.glCompileShader(shader);
+
+ // Check the compile status
+ GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
+
+ if (compiled[0] == 0) {
+ Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
+ GLES20.glDeleteShader(shader);
+ return 0;
+ }
+ return shader;
+ }
+
+
+ public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
+ String vShaderStr =
+ "attribute vec4 vPosition; \n"
+ + "attribute vec4 vColor; \n"
+ + "varying vec4 varyColor; \n"
+ + "void main() \n"
+ + "{ \n"
+ + " gl_Position = vPosition; \n"
+ + " varyColor = vColor; \n"
+ + "} \n";
+
+ String fShaderStr =
+ "precision mediump float; \n"
+ + "varying vec4 varyColor; \n"
+ + "void main() \n"
+ + "{ \n"
+ + " gl_FragColor = varyColor; \n"
+ + "} \n";
+
+ int vertexShader;
+ int fragmentShader;
+ int programObject;
+ int[] linked = new int[1];
+
+ // Load the vertex/fragment shaders
+ vertexShader = LoadShader(GLES20.GL_VERTEX_SHADER, vShaderStr);
+ fragmentShader = LoadShader(GLES20.GL_FRAGMENT_SHADER, fShaderStr);
+
+ // Create the program object
+ programObject = GLES20.glCreateProgram();
+
+ if (programObject == 0)
+ return;
+
+ GLES20.glAttachShader(programObject, vertexShader);
+ GLES20.glAttachShader(programObject, fragmentShader);
+
+ // Bind vPosition to attribute 0
+ GLES20.glBindAttribLocation(programObject, 0, "vPosition");
+ GLES20.glBindAttribLocation(programObject, 1, "vColor");
+
+ // Link the program
+ GLES20.glLinkProgram(programObject);
+
+ // Check the link status
+ GLES20.glGetProgramiv(programObject, GLES20.GL_LINK_STATUS, linked, 0);
+
+ if (linked[0] == 0)
+ {
+ Log.e(TAG, "Error linking program:");
+ Log.e(TAG, GLES20.glGetProgramInfoLog(programObject));
+ GLES20.glDeleteProgram(programObject);
+ return;
+ }
+
+ // Store the program object
+ mProgramObject = programObject;
+
+ GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ }
+
+ public void onDrawFrame(GL10 glUnused)
+ {
+ // Set the viewport
+ GLES20.glViewport(0, 0, mWidth, mHeight);
+
+ // Clear the color buffer
+ GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
+
+ // Use the program object
+ GLES20.glUseProgram(mProgramObject);
+
+ // Load the vertex data
+ GLES20.glVertexAttribPointer(0,3, GLES20.GL_FLOAT, false, 0, mVertices);
+ GLES20.glEnableVertexAttribArray(0);
+
+ int mColorHandle = GLES20.glGetAttribLocation(mProgramObject, "vColor");
+ GLES20.glVertexAttribPointer(mColorHandle,4, GLES20.GL_FLOAT, false, 0, mColor);
+ GLES20.glEnableVertexAttribArray(1);
+
+ GLES20.glDrawElements(GLES20.GL_TRIANGLES, mIndices.length,
+ GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
+
+ int x = 1;
+ int y =1;
+ IntBuffer pinbuffer = IntBuffer.allocate(1*1*4);
+ IntBuffer poutbuffer = IntBuffer.allocate(x*y*4);
+ int i,j,z;
+ int [] pin = pinbuffer.array();
+ int [] pout = poutbuffer.array();
+
+ GLES20.glReadPixels(mWidth/2, mWidth/2, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE,
+ pinbuffer);
+ int pixel = pin[0];
+ float a = (pixel >> 24) & 0xFF;
+ float b = (pixel >> 16) & 0xFF;
+ float g = (pixel >> 8) & 0xFF;
+ float r = pixel & 0xFF;
+ Log.i(TAG,"rgba" + r + " " + g + " " + b + " " + a);
+ mColorOne[0] = r;
+ mColorOne[1] = g;
+ mColorOne[2] = b;
+ mColorOne[3] = a;
+ }
+
+ public float[] getActualRGBA() {
+ return this.mColorOne;
+ }
+
+ public void onSurfaceChanged(GL10 glUnused, int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/RendererTwelveShaderTest.java b/tests/tests/opengl/src/android/opengl/cts/RendererTwelveShaderTest.java
new file mode 100755
index 0000000..5d0d73d
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/RendererTwelveShaderTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.opengl.GLES20;
+
+public class RendererTwelveShaderTest extends RendererBase {
+ private String fragmentShaderCode = Shaders.successfulcompile_frag;
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
+ int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
+ //invalid value
+ mProgram = 0;
+
+ GLES20.glAttachShader(mProgram, fragmentShader);
+ GLES20.glLinkProgram(mProgram);
+
+ mError = GLES20.glGetError();
+ }
+}
diff --git a/tests/tests/opengl/src/android/opengl/cts/Vertex.java b/tests/tests/opengl/src/android/opengl/cts/Vertex.java
new file mode 100755
index 0000000..5041167
--- /dev/null
+++ b/tests/tests/opengl/src/android/opengl/cts/Vertex.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 android.opengl.cts;
+
+public class Vertex {
+ public static String successfulcompile_vertex =
+ "attribute vec3 gtf_Normal; \n"
+ + "attribute vec4 gtf_Vertex; \n"
+ + "uniform mat3 gtf_NormalMatrix; \n"
+ + "uniform mat4 gtf_ModelViewMatrix; \n"
+ + "uniform mat4 gtf_ModelViewProjectionMatrix; \n"
+ + "\n"
+ + "varying float lightIntensity; \n"
+ + "varying vec3 Position; \n"
+ + "uniform vec3 LightPosition; \n"
+ + "uniform float Scale; \n"
+ + "\n"
+ + "void main(void) { \n"
+ + " vec4 pos = gtf_ModelViewMatrix * gtf_Vertex; \n"
+ + " Position = vec3(gtf_Vertex) * Scale; \n"
+ + " vec3 tnorm = normalize(gtf_NormalMatrix * gtf_Normal); \n"
+ + " lightIntensity = dot(normalize(LightPosition - vec3(pos)), tnorm) * 1.5; \n"
+ + " gl_Position = gtf_ModelViewProjectionMatrix * gtf_Vertex; \n"
+ + "}";
+}