MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / compileGLSLprogram

Function compileGLSLprogram

cpp/0_Introduction/simpleCUDA2GL/main.cpp:541–608  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

539//!
540////////////////////////////////////////////////////////////////////////////////
541GLuint compileGLSLprogram(const char *vertex_shader_src, const char *fragment_shader_src)
542{
543 GLuint v, f, p = 0;
544
545 p = glCreateProgram();
546
547 if (vertex_shader_src) {
548 v = glCreateShader(GL_VERTEX_SHADER);
549 glShaderSource(v, 1, &vertex_shader_src, NULL);
550 glCompileShader(v);
551
552 // check if shader compiled
553 GLint compiled = 0;
554 glGetShaderiv(v, GL_COMPILE_STATUS, &compiled);
555
556 if (!compiled) {
557 // #ifdef NV_REPORT_COMPILE_ERRORS
558 char temp[256] = "";
559 glGetShaderInfoLog(v, 256, NULL, temp);
560 printf("Vtx Compile failed:\n%s\n", temp);
561 // #endif
562 glDeleteShader(v);
563 return 0;
564 }
565 else {
566 glAttachShader(p, v);
567 }
568 }
569
570 if (fragment_shader_src) {
571 f = glCreateShader(GL_FRAGMENT_SHADER);
572 glShaderSource(f, 1, &fragment_shader_src, NULL);
573 glCompileShader(f);
574
575 // check if shader compiled
576 GLint compiled = 0;
577 glGetShaderiv(f, GL_COMPILE_STATUS, &compiled);
578
579 if (!compiled) {
580 // #ifdef NV_REPORT_COMPILE_ERRORS
581 char temp[256] = "";
582 glGetShaderInfoLog(f, 256, NULL, temp);
583 printf("frag Compile failed:\n%s\n", temp);
584 // #endif
585 glDeleteShader(f);
586 return 0;
587 }
588 else {
589 glAttachShader(p, f);
590 }
591 }
592
593 glLinkProgram(p);
594
595 int infologLength = 0;
596 int charsWritten = 0;
597
598 glGetProgramiv(p, GL_INFO_LOG_LENGTH, (GLint *)&infologLength);

Callers 1

initGLBuffersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected