• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 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 #ifndef SHADER_H_
18 #define SHADER_H_
19 
20 #include <jni.h>
21 
22 #include <vector>
23 #include <map>
24 #include <string>
25 
26 #include <EGL/egl.h>
27 #include <GLES/gl.h>
28 
29 #include <android/log.h>
30 
31 #include "JNIHelper.h"
32 
33 namespace ndk_helper
34 {
35 
36 namespace shader
37 {
38 
39 /******************************************************************
40  * Shader compiler helper
41  * namespace: ndkHelper::shader
42  *
43  */
44 
45 /******************************************************************
46  * CompileShader() with vector
47  *
48  * arguments:
49  *  out: shader, shader variable
50  *  in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER)
51  *  in: data, source vector
52  * return: true if a shader compilation succeeded, false if it failed
53  *
54  */
55 bool CompileShader( GLuint *shader, const GLenum type, std::vector<uint8_t>& data );
56 
57 /******************************************************************
58  * CompileShader() with buffer
59  *
60  * arguments:
61  *  out: shader, shader variable
62  *  in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER)
63  *  in: source, source buffer
64  *  in: iSize, buffer size
65  * return: true if a shader compilation succeeded, false if it failed
66  *
67  */
68 bool CompileShader( GLuint *shader,
69         const GLenum type,
70         const GLchar *source,
71         const int32_t iSize );
72 
73 /******************************************************************
74  * CompileShader() with filename
75  *
76  * arguments:
77  *  out: shader, shader variable
78  *  in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER)
79  *  in: strFilename, filename
80  * return: true if a shader compilation succeeded, false if it failed
81  *
82  */
83 bool CompileShader( GLuint *shader, const GLenum type, const char *strFileName );
84 
85 /******************************************************************
86  * CompileShader() with std::map helps patching on a shader on the fly.
87  *
88  * arguments:
89  *  out: shader, shader variable
90  *  in: type, shader type (i.e. GL_VERTEX_SHADER/GL_FRAGMENT_SHADER)
91  *  in: mapParameters
92  *      For a example,
93  *      map : %KEY% -> %VALUE% replaces all %KEY% entries in the given shader code to %VALUE"
94  * return: true if a shader compilation succeeded, false if it failed
95  *
96  */
97 bool CompileShader( GLuint *shader,
98         const GLenum type,
99         const char *str_file_name,
100         const std::map<std::string, std::string>& map_parameters );
101 
102 /******************************************************************
103  * LinkProgram()
104  *
105  * arguments:
106  *  in: program, program
107  * return: true if a shader linkage succeeded, false if it failed
108  *
109  */
110 bool LinkProgram( const GLuint prog );
111 
112 /******************************************************************
113  * validateProgram()
114  *
115  * arguments:
116  *  in: program, program
117  * return: true if a shader validation succeeded, false if it failed
118  *
119  */
120 bool ValidateProgram( const GLuint prog );
121 } //namespace shader
122 
123 } //namespace ndkHelper
124 #endif /* SHADER_H_ */
125