void GLSLShader::compileFromSource(const char* vertexShaderSource, const char* fragmentShaderSource) { vs_object = createShaderFromSource(GL_VERTEX_SHADER, string(vertexShaderSource)); fs_object = createShaderFromSource(GL_FRAGMENT_SHADER, string(fragmentShaderSource)); prog_object = glCreateProgram(); if (vs_object) glAttachShader(prog_object, vs_object); if (fs_object) glAttachShader(prog_object, fs_object); glLinkProgram(prog_object); printProgramLog(prog_object); }
/** * \fn loadShader * @param src * @return */ bool shaderLoader::loadShader(const char *src) { if(!ADM_fileExist(src)) { ADM_warning("Shader file does not exist (%s)\n",src); return false; } int sourceSize=ADM_fileSize(src); if(sourceSize<5) { ADM_warning("Shader file is too short(%s)\n",src); return false; } uint8_t *buffer=(uint8_t *)admAlloca(sourceSize+1); FILE *f=fopen(params.shaderFile.c_str(),"rt"); if(!f) { ADM_warning("Cannot open file %s\n",src); return false; } fread(buffer,sourceSize,1,f); buffer[sourceSize]=0; fclose(f); f=NULL; if(glProgramY) { delete glProgramY; glProgramY=NULL; } glProgramY = createShaderFromSource(QOpenGLShader::Fragment,(char *)buffer); if(!glProgramY) { ADM_error("Shader compiling failed\n"); return false; } ADM_info("Shader %s successfully loaded an compiled\n",src); return true; }
GLuint createShader(GLuint stype, const std::string& file) { string str = readShaderSource(file); assert(!str.empty()); if(!str.empty()) { GLuint shader = createShaderFromSource(stype, str); if(!check(shader)) { cerr << file << endl; printShaderLog(shader); glDeleteShader(shader); return 0; } return shader; } return 0; }