MCPcopy Create free account
hub / github.com/android/ndk-samples / createProgram

Function createProgram

hello-gl2/app/src/main/cpp/gl_code.cpp:80–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80GLuint createProgram(const char* pVertexSource, const char* pFragmentSource) {
81 GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
82 if (!vertexShader) {
83 return 0;
84 }
85
86 GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
87 if (!pixelShader) {
88 return 0;
89 }
90
91 GLuint program = glCreateProgram();
92 if (program) {
93 glAttachShader(program, vertexShader);
94 checkGlError("glAttachShader");
95 glAttachShader(program, pixelShader);
96 checkGlError("glAttachShader");
97 glLinkProgram(program);
98 GLint linkStatus = GL_FALSE;
99 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
100 if (linkStatus != GL_TRUE) {
101 GLint bufLength = 0;
102 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
103 if (bufLength) {
104 char* buf = (char*)malloc(bufLength);
105 if (buf) {
106 glGetProgramInfoLog(program, bufLength, NULL, buf);
107 LOGE("Could not link program:\n%s\n", buf);
108 free(buf);
109 }
110 }
111 glDeleteProgram(program);
112 program = 0;
113 }
114 }
115 return program;
116}
117
118GLuint gProgram;
119GLuint gvPositionHandle;

Callers 2

setupGraphicsFunction · 0.70
surfaceCreatedMethod · 0.50

Calls 2

loadShaderFunction · 0.85
checkGlErrorFunction · 0.70

Tested by

no test coverage detected