OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Shader.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #include "Shader.h"
22 
23 #define LOG_TAG "libNative"
24 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
25 
26 namespace MaliSDK
27 {
28  /* Please see header for the specification. */
29  void Shader::processShader(GLuint* shaderPtr, const char* shaderSourcePtr, GLint shaderType)
30  {
31  GLint compilationStatus = GL_FALSE;
32 
33  /* Create shader and load into GL. */
34  *shaderPtr = GL_CHECK(glCreateShader(shaderType));
35 
36  GL_CHECK(glShaderSource(*shaderPtr, 1, &shaderSourcePtr, NULL));
37 
38  /* Try compiling the shader. */
39  GL_CHECK(glCompileShader(*shaderPtr));
40 
41  GL_CHECK(glGetShaderiv(*shaderPtr, GL_COMPILE_STATUS, &compilationStatus));
42 
43  /* Dump debug info (source and log) if compilation failed. */
44  if(compilationStatus != GL_TRUE)
45  {
46  GLint length;
47  char *debugSource = NULL;
48  char *errorLog = NULL;
49 
50  /* Get shader source. */
51  GL_CHECK(glGetShaderiv(*shaderPtr, GL_SHADER_SOURCE_LENGTH, &length));
52 
53  debugSource = (char *)malloc(length);
54 
55  GL_CHECK(glGetShaderSource(*shaderPtr, length, NULL, debugSource));
56 
57  LOGE("Debug source START:\n%s\nDebug source END\n\n", debugSource);
58 
59  free(debugSource);
60 
61  /* Now get the info log. */
62  GL_CHECK(glGetShaderiv(*shaderPtr, GL_INFO_LOG_LENGTH, &length));
63 
64  errorLog = (char *)malloc(length);
65 
66  GL_CHECK(glGetShaderInfoLog(*shaderPtr, length, NULL, errorLog));
67 
68  LOGE("Log START:\n%s\nLog END\n\n", errorLog);
69 
70  free(errorLog);
71 
72  LOGE("Compilation FAILED!\n\n");
73  exit(1);
74  }
75  }
76 }
#define LOGE(...)
Definition: Shader.cpp:24
#define GL_CHECK(x)
Definition: AstcTextures.h:59
GLenum GLuint GLenum GLsizei length
Definition: gl2ext.h:134
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
Definition: Shader.cpp:29
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count