comparison gldragon.cpp @ 24:c1897cfc8463

Add shader compilation error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Nov 2019 05:49:14 +0200
parents f080349584b8
children 2403030a0352
comparison
equal deleted inserted replaced
23:f080349584b8 24:c1897cfc8463
252 for (const DMModel &model : scene.models) 252 for (const DMModel &model : scene.models)
253 dmDrawModel(model); 253 dmDrawModel(model);
254 } 254 }
255 255
256 256
257 GLuint dmCompileShader(const GLenum stype, const std::string &src) 257 bool dmCompileShader(const GLenum stype, const std::string &src, GLuint &shader)
258 { 258 {
259 GLuint shader = glCreateShader(stype); 259 GLint status;
260 const char *tmp = src.c_str(); 260 const char *tmp = src.c_str();
261 261
262 shader = glCreateShader(stype);
262 glShaderSource(shader, 1, &tmp, 0); 263 glShaderSource(shader, 1, &tmp, 0);
263 glCompileShader(shader); 264 glCompileShader(shader);
264 265
265 return shader; 266 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
267 if (status == GL_TRUE)
268 return true;
269 else
270 {
271 char err[512];
272 glGetShaderInfoLog(shader, sizeof(err), NULL, err);
273 printf("ERROR: %s\n",
274 err);
275 return false;
276 }
266 } 277 }
267 278
268 279
269 void dmLinkModelShaders(DMModel &model) 280 void dmLinkModelShaders(DMModel &model)
270 { 281 {
418 // According to our mode .. 429 // According to our mode ..
419 if (optUseShaders) 430 if (optUseShaders)
420 { 431 {
421 for (DMModel &model : scene.models) 432 for (DMModel &model : scene.models)
422 { 433 {
423 model.id_fs = dmCompileShader(GL_FRAGMENT_SHADER, model.fragShaderStr); 434 if (!dmCompileShader(GL_FRAGMENT_SHADER, model.fragShaderStr, model.id_fs) ||
424 model.id_vs = dmCompileShader(GL_VERTEX_SHADER, model.vertShaderStr); 435 !dmCompileShader(GL_VERTEX_SHADER, model.vertShaderStr, model.id_vs))
436 goto exit;
437
425 dmLinkModelShaders(model); 438 dmLinkModelShaders(model);
426 } 439 }
427 } 440 }
428 else 441 else
429 { 442 {