• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <jni.h>
18 #include <android/log.h>
19 
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <math.h>
26 
27 #include "attach_shader_one.h"
28 #include "attach_shader_two.h"
29 #include "attach_shader_three.h"
30 #include "attach_shader_four.h"
31 #include "attach_shader_five.h"
32 #include "attach_shader_six.h"
33 #include "attach_shader_seven.h"
34 #include "attach_shader_eight.h"
35 #include "attach_shader_nine.h"
36 #include "attach_shader_ten.h"
37 #include "attach_shader_eleven.h"
38 #include "color_one.h"
39 
40 #define  LOG_TAG    "gl2_jni_libone"
41 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
42 #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
43 
44 static GLint errorAttachShader = -1;
45 static GLint shaderCount = -1;
46 
47 
Java_android_opengl_cts_GL2JniLibOne_init(JNIEnv *,jclass pClass,jint pCategory,jint pSubCategory,jint width,jint height)48 extern "C" JNIEXPORT void JNICALL Java_android_opengl_cts_GL2JniLibOne_init
49   (JNIEnv *, jclass pClass, jint pCategory, jint pSubCategory, jint width, jint height)  {
50     LOGI("Category :  %d\n", pCategory);
51 
52     if(pCategory == 1) {
53         if(pSubCategory == 1) {
54             Data data = attachShaderOne();
55             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
56             LOGI("Shader Count :  %d\n", data.mShaderCount);
57             errorAttachShader = data.mShaderError;
58             shaderCount = data.mShaderCount;
59         }else if(pSubCategory == 2) {
60             Data data = attachShaderTwo();
61             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
62             errorAttachShader = data.mShaderError;
63         }else if(pSubCategory == 3) {
64             Data data = attachShaderThree();
65             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
66             errorAttachShader = data.mShaderError;
67         }else if(pSubCategory == 4) {
68             Data data = attachShaderFour();
69             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
70             LOGI("Shader Count :  %d\n", data.mShaderCount);
71             errorAttachShader = data.mShaderError;
72             shaderCount = data.mShaderCount;
73         }else if(pSubCategory == 5) {
74             Data data = attachShaderFive();
75             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
76             errorAttachShader = data.mShaderError;
77         }else if(pSubCategory == 6) {
78             Data data = attachShaderSix();
79             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
80             errorAttachShader = data.mShaderError;
81         }else if(pSubCategory == 7) {
82             Data data = attachShaderSeven();
83             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
84             errorAttachShader = data.mShaderError;
85         }else if(pSubCategory == 8) {
86             Data data = attachShaderEight();
87             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
88             errorAttachShader = data.mShaderError;
89         }else if(pSubCategory == 9) {
90             Data data = attachShaderNine();
91             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
92             errorAttachShader = data.mShaderError;
93         }else if(pSubCategory == 10) {
94             Data data = attachShaderTen();
95             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
96             LOGI("Shader Count :  %d\n", data.mShaderCount);
97             errorAttachShader = data.mShaderError;
98             shaderCount = data.mShaderCount;
99         }else if(pSubCategory == 11) {
100             Data data = attachShaderEleven();
101             LOGI("Attach Shader Error :  %d\n", data.mShaderError);
102             LOGI("Shader Count :  %d\n", data.mShaderCount);
103             errorAttachShader = data.mShaderError;
104             shaderCount = data.mShaderCount;
105         }
106     }else if(pCategory == 3){//Color Test
107         if(pSubCategory == 1){
108             initColorOne( width,height);
109         }
110     }
111 }
112 
Java_android_opengl_cts_GL2JniLibOne_step(JNIEnv * env,jclass obj)113 extern "C" JNIEXPORT void JNICALL Java_android_opengl_cts_GL2JniLibOne_step(JNIEnv * env, jclass obj)
114 {
115     //implement later
116 }
117 
Java_android_opengl_cts_GL2JniLibOne_getAttachShaderError(JNIEnv * env,jclass obj)118 extern "C" JNIEXPORT jint JNICALL Java_android_opengl_cts_GL2JniLibOne_getAttachShaderError(JNIEnv * env, jclass obj){
119     return errorAttachShader;
120 }
121 
Java_android_opengl_cts_GL2JniLibOne_getLoadShaderError(JNIEnv * env,jclass obj)122 extern "C" JNIEXPORT jint JNICALL Java_android_opengl_cts_GL2JniLibOne_getLoadShaderError(JNIEnv * env, jclass obj){
123      return -1;
124 }
125 
Java_android_opengl_cts_GL2JniLibOne_getProgramError(JNIEnv * env,jclass obj)126 extern "C" JNIEXPORT jint JNICALL Java_android_opengl_cts_GL2JniLibOne_getProgramError(JNIEnv * env, jclass obj){
127      return -2;
128 }
129 
Java_android_opengl_cts_GL2JniLibOne_getAttachedShaderCount(JNIEnv * env,jclass obj)130 extern "C" JNIEXPORT jint JNICALL Java_android_opengl_cts_GL2JniLibOne_getAttachedShaderCount(JNIEnv * env, jclass obj){
131     return shaderCount;
132 }
133 
Java_android_opengl_cts_GL2JniLibOne_draw(JNIEnv * env,jclass obj,jint pCategory,jint pSubCategory,jfloatArray color)134 extern "C" JNIEXPORT jfloatArray JNICALL Java_android_opengl_cts_GL2JniLibOne_draw(JNIEnv * env,
135         jclass obj, jint pCategory, jint pSubCategory, jfloatArray color)
136 {
137     LOGI("Inside draw %d %d", pCategory, pSubCategory);
138     jfloatArray result = nullptr;
139     if(pCategory == 3){
140         if(pSubCategory == 1){
141             result = env->NewFloatArray(4);
142 
143             jfloat *lColor =  env->GetFloatArrayElements(color,0);
144 
145             float * actualColor = drawColorOne(lColor);
146             for(unsigned i = 0; i < sizeof(actualColor); i++) {
147                 LOGI("actualColor[%u] ; %f", i, actualColor[i]);
148             }
149             env->SetFloatArrayRegion(result, 0, 4, actualColor);
150         }
151     }
152     return result;
153 }
154