static void realize(GtkWidget *widget, gpointer user_data) { gtk_gl_area_make_current(GTK_GL_AREA(widget)); glDebugMessageCallback(debug, NULL); char *str = pk_io_read_file("data/vs.glsl"); programs[0] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &str); free(str); str = pk_io_read_file("data/fs.glsl"); programs[1] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &str); free(str); /* set up pipeline for rendering fullscreen quad */ glCreateProgramPipelines(1, &pipeline); glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, programs[0]); glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, programs[1]); glBindProgramPipeline(pipeline); glCreateVertexArrays(1, &vao); glBindVertexArray(vao); }
void piglit_init(int argc, char **argv) { unsigned glsl_version; GLuint vs_prog; GLuint fs_prog_same_declaration_order; GLuint fs_prog_same_location_order; char *source; piglit_require_vertex_shader(); piglit_require_fragment_shader(); piglit_require_extension("GL_ARB_separate_shader_objects"); piglit_require_extension("GL_ARB_explicit_attrib_location"); glsl_version = pick_a_glsl_version(); (void)!asprintf(&source, vs_code_template, glsl_version); vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(vs_prog); free(source); (void)!asprintf(&source, fs_code_same_declaration_order_template, glsl_version); fs_prog_same_declaration_order = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(fs_prog_same_declaration_order); free(source); (void)!asprintf(&source, fs_code_same_location_order_template, glsl_version); fs_prog_same_location_order = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(fs_prog_same_location_order); free(source); glGenProgramPipelines(1, &pipeline_same_declaration_order); glUseProgramStages(pipeline_same_declaration_order, GL_VERTEX_SHADER_BIT, vs_prog); glUseProgramStages(pipeline_same_declaration_order, GL_FRAGMENT_SHADER_BIT, fs_prog_same_declaration_order); piglit_program_pipeline_check_status(pipeline_same_declaration_order); glGenProgramPipelines(1, &pipeline_same_location_order); glUseProgramStages(pipeline_same_location_order, GL_VERTEX_SHADER_BIT, vs_prog); glUseProgramStages(pipeline_same_location_order, GL_FRAGMENT_SHADER_BIT, fs_prog_same_location_order); piglit_program_pipeline_check_status(pipeline_same_location_order); if (!piglit_check_gl_error(0)) piglit_report_result(PIGLIT_FAIL); }
bool initProgram() { bool Validated(true); glGenProgramPipelines(pipeline::MAX, PipelineName); glBindProgramPipeline(PipelineName[pipeline::READ]); if(Validated) { std::string VertexSourceContent = glf::loadFile(glf::DATA_DIRECTORY + VERT_SHADER_SOURCE_READ); char const * VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::VERT]); } if(Validated) { std::string FragmentSourceContent = glf::loadFile(glf::DATA_DIRECTORY + FRAG_SHADER_SOURCE_READ); char const * FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::FRAG]); } if(Validated) { glUseProgramStages(PipelineName[pipeline::READ], GL_VERTEX_SHADER_BIT, ProgramName[program::VERT]); glUseProgramStages(PipelineName[pipeline::READ], GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG]); Validated = Validated && glf::checkError("initProgram - stage"); } glBindProgramPipeline(PipelineName[pipeline::SAVE]); if(Validated) { std::string VertexSourceContent = glf::loadFile(glf::DATA_DIRECTORY + VERT_SHADER_SOURCE_SAVE); char const * VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::VERT]); } if(Validated) { std::string FragmentSourceContent = glf::loadFile(glf::DATA_DIRECTORY + FRAG_SHADER_SOURCE_SAVE); char const * FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::FRAG]); } if(Validated) { glUseProgramStages(PipelineName[pipeline::SAVE], GL_VERTEX_SHADER_BIT, ProgramName[program::VERT]); glUseProgramStages(PipelineName[pipeline::SAVE], GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG]); Validated = Validated && glf::checkError("initProgram - stage"); } return Validated; }
bool initProgram() { bool Validated(true); if(Validated) { std::string VertexSourceContent = this->loadFile(getDataDirectory() + VERT_SHADER_SOURCE_READ); char const* VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT_READ] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); } if(Validated) { std::string FragmentSourceContent = this->loadFile(getDataDirectory() + FRAG_SHADER_SOURCE_READ); char const* FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG_READ] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); } if(Validated) { std::string VertexSourceContent = this->loadFile(getDataDirectory() + VERT_SHADER_SOURCE_SAVE); char const* VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT_SAVE] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); } if(Validated) { std::string FragmentSourceContent = this->loadFile(getDataDirectory() + FRAG_SHADER_SOURCE_SAVE); char const* FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG_SAVE] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); } if(Validated) { compiler Compiler; Validated = Validated && Compiler.check_program(ProgramName[program::VERT_READ]); Validated = Validated && Compiler.check_program(ProgramName[program::FRAG_READ]); Validated = Validated && Compiler.check_program(ProgramName[program::VERT_SAVE]); Validated = Validated && Compiler.check_program(ProgramName[program::FRAG_SAVE]); } if(Validated) { glGenProgramPipelines(pipeline::MAX, &PipelineName[0]); glUseProgramStages(PipelineName[pipeline::READ], GL_VERTEX_SHADER_BIT, ProgramName[program::VERT_READ]); glUseProgramStages(PipelineName[pipeline::READ], GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG_READ]); glUseProgramStages(PipelineName[pipeline::SAVE], GL_VERTEX_SHADER_BIT, ProgramName[program::VERT_SAVE]); glUseProgramStages(PipelineName[pipeline::SAVE], GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG_SAVE]); } return Validated; }
void initShader(void) { int maxImageUnits; loadETC1FragProg(); const GLsizei vertexShaderLines = sizeof(vertexShaderSource) / sizeof(char*); GLuint vertexShader = compileShaderSource(GL_VERTEX_SHADER, vertexShaderLines, vertexShaderSource); const GLsizei fragmentShaderLines = sizeof(fragmentShaderSource) / sizeof(char*); GLuint fragmentShader = compileShaderSource( GL_FRAGMENT_SHADER, fragmentShaderLines, fragmentShaderSource); GLuint program = createProgram(vertexShader, fragmentShader); checkError("createProgram"); u_TextureRender = glGetUniformLocation(program, "myt"); checkError("GetRenderUniform"); a_Position = glGetAttribLocation(program, "a_Position"); glEnableVertexAttribArray(a_Position); checkError("initRender"); computeProgramETC1 = glCreateShaderProgramv(GL_COMPUTE_SHADER, computeShaderSourceETC1LineCount, (const char**)computeShaderSourceETC1); if (!checkProgram(computeProgramETC1, "computeProgramETC1")) { exit(1); } renderProgram = program; u_TextureComputeETC1 = glGetUniformLocation(computeProgramETC1, "u_Texture"); u_OutComputeETC1 = glGetUniformLocation(computeProgramETC1, "u_Output"); printf( "u_TextureRender: %u, u_TextureComputeETC1: %u, u_OutComputeETC1: %u.\n", u_TextureRender, u_TextureComputeETC1, u_OutComputeETC1); computeProgramS3TC = glCreateShaderProgramv(GL_COMPUTE_SHADER, computeShaderSourceS3TCLineCount, (const char**)computeShaderSourceS3TC); if (!checkProgram(computeProgramS3TC, "computeProgramS3TC")) { exit(1); } u_TextureComputeS3TC = glGetUniformLocation(computeProgramS3TC, "u_Texture"); printf("u_TextureComputeS3TC: %u.\n", u_TextureComputeS3TC); glGetIntegerv(GL_MAX_IMAGE_UNITS, &maxImageUnits); printf("maxImageUnits: %d.\n", maxImageUnits); checkError("initCompute"); }
GLint ComputeWaterSimulation::createShaderPipelineProgram(GLuint target, const char* src, GLuint &pipeline, GLuint &program) { GLint status; glGenProgramPipelines(1, &pipeline); program = glCreateShaderProgramv(target, 1, (const GLchar **)&src); glBindProgramPipeline(pipeline); glUseProgramStages(pipeline, GL_COMPUTE_SHADER_BIT, program); glValidateProgramPipeline(pipeline); glGetProgramPipelineiv(pipeline, GL_VALIDATE_STATUS, &status); if (status != GL_TRUE) { GLint logLength; glGetProgramPipelineiv(pipeline, GL_INFO_LOG_LENGTH, &logLength); char *log = new char [logLength]; glGetProgramPipelineInfoLog(pipeline, logLength, 0, log); LOGI("Shader pipeline not valid:\n%s\n", log); delete [] log; } glBindProgramPipeline(0); return status; }
inline bool CompileShaderFromFile(ZZshProgram& program, const std::string& DefineString, std::string main_entry, GLenum ShaderType) { std::string header(""); header += format("#version %d\n", GLSL_VERSION); header += format("#define %s main\n", main_entry.c_str()); if (ShaderType == GL_VERTEX_SHADER) header += "#define VERTEX_SHADER 1\n"; else if (ShaderType == GL_FRAGMENT_SHADER) header += "#define FRAGMENT_SHADER 1\n"; header += DefineString; const GLchar* ShaderSource[2]; ShaderSource[0] = header.c_str(); ShaderSource[1] = (const GLchar*)ZZshSource; program = glCreateShaderProgramv(ShaderType, 2, &ShaderSource[0]); ZZLog::Debug_Log("Creating program %d for %s", program, main_entry.c_str()); #if defined(DEVBUILD) || defined(_DEBUG) if (!ValidateProgram(program)) return false; #endif return true; }
Shader::Shader(GLenum type, const std::string& source) { type_ = type; const GLchar* src = source.c_str(); id_ = glCreateShaderProgramv(type, 1, &src); link_flag_ = true; if (!id_) { link_log_ = "ERROR: Could not create OpenGL shader object"; link_flag_ = false; } else { if (source.empty()) { link_log_ = "ERORR: Shader source is empty."; link_flag_ = false; } else { GLint link_status; glGetProgramiv(id_, GL_LINK_STATUS, &link_status); if (link_status == GL_FALSE) { GLint info_log_len; glGetProgramiv(id_, GL_INFO_LOG_LENGTH, &info_log_len); GLchar* info_log = new GLchar[info_log_len]; glGetProgramInfoLog(id_, info_log_len, NULL, info_log); link_log_ = info_log; link_flag_ = false; delete info_log; } } } GL_CHECK_ERROR; }
GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel) { ASSERT(glsl_h_code != NULL); GLuint program = 0; // Note it is better to separate header and source file to have the good line number // in the glsl compiler report const int shader_nb = 3; const char* sources[shader_nb]; std::string header = GenGlslHeader(entry, type, macro_sel); sources[0] = header.c_str(); sources[1] = common_header_glsl; sources[2] = glsl_h_code; program = glCreateShaderProgramv(type, shader_nb, sources); bool status = ValidateProgram(program); if (!status) { // print extra info fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file.c_str(), entry.c_str(), program); fprintf(stderr, "\n%s", macro_sel.c_str()); fprintf(stderr, "\n"); } m_prog_to_delete.push_back(program); return program; }
void Triangle::init_shader() { glGenProgramPipelines(1, &m_pipe); auto vertSource = byhj::textFileRead("triangle.vert"); const char *ver = vertSource.c_str(); m_vert = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &ver); glUseProgramStages(m_pipe, GL_VERTEX_SHADER, m_vert); mvp_loc = glGetUniformLocation(m_vert, "mvp"); auto fragContext = textFileRead("triangle.frag"); const char *frg = fragContext.c_str(); m_frag = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &frg); glUseProgramStages(m_pipe, GL_FRAGMENT_SHADER_BIT, m_frag); color_loc = glGetUniformLocation(m_frag, "color"); }
bool initProgram() { bool Validated = true; glGenProgramPipelines(1, &PipelineName); glBindProgramPipeline(PipelineName); if(Validated) { std::string VertexSourceContent = glf::loadFile(glf::DATA_DIRECTORY + VERT_SHADER_SOURCE); char const * VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::VERT]); } if(Validated) { glUseProgramStages(PipelineName, GL_VERTEX_SHADER_BIT, ProgramName[program::VERT]); Validated = Validated && glf::checkError("initProgram - stage"); } if(Validated) { std::string FragmentSourceContent = glf::loadFile(glf::DATA_DIRECTORY + FRAG_SHADER_SOURCE); char const * FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); Validated = Validated && glf::checkProgram(ProgramName[program::FRAG]); } if(Validated) { glUseProgramStages(PipelineName, GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG]); Validated = Validated && glf::checkError("initProgram - stage"); } // Get variables locations if(Validated) { UniformMVP = glGetUniformLocation(ProgramName[program::VERT], "MVP"); UniformDiffuse = glGetUniformLocation(ProgramName[program::FRAG], "Diffuse"); } return Validated && glf::checkError("initProgram"); }
uint32 gfxCreateShaderSource(const char* src, uint8 shaderType) { uint32 program = glCreateShaderProgramv(s_shaderTypes[shaderType], 1, &src); int32 length; glGetProgramInfoLog(program, 4096, &length, s_shaderLog); if (length) { printf("Shader compilation failed:\n%s\n", s_shaderLog); return 0; } gctx.programs[gctx.shaderCnt++] = program; return program; }
bool initProgram() { bool Validated = true; if(Validated) { std::string VertexSourceContent = this->loadFile(getDataDirectory() + VERT_SHADER_SOURCE); char const * VertexSourcePointer = VertexSourceContent.c_str(); ProgramName[program::VERT] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); } if(Validated) { std::string FragmentSourceContent = this->loadFile(getDataDirectory() + FRAG_SHADER_SOURCE); char const * FragmentSourcePointer = FragmentSourceContent.c_str(); ProgramName[program::FRAG] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); } if(Validated) { compiler Compiler; Validated = Validated && Compiler.checkProgram(ProgramName[program::VERT]); Validated = Validated && Compiler.checkProgram(ProgramName[program::FRAG]); } if(Validated) { UniformMVP = glGetUniformLocation(ProgramName[program::VERT], "MVP"); UniformDiffuse = glGetUniformLocation(ProgramName[program::FRAG], "Diffuse"); } if(Validated) { glGenProgramPipelines(1, &PipelineName); glBindProgramPipeline(PipelineName); glUseProgramStages(PipelineName, GL_VERTEX_SHADER_BIT, ProgramName[program::VERT]); glUseProgramStages(PipelineName, GL_FRAGMENT_SHADER_BIT, ProgramName[program::FRAG]); } return Validated && this->checkError("initProgram"); }
void piglit_init(int argc, char **argv) { GLuint vs_prog, fs_prog; piglit_require_extension("GL_ARB_separate_shader_objects"); vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const*) &vs_code); piglit_link_check_status(vs_prog); fs_prog = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, (const GLchar *const *) &fs_code); piglit_link_check_status(fs_prog); glGenProgramPipelines(1, &pipeline); glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, vs_prog); glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, fs_prog); piglit_program_pipeline_check_status(pipeline); if (!piglit_check_gl_error(0)) piglit_report_result(PIGLIT_FAIL); }
GLUSboolean GLUSAPIENTRY glusBuildShaderProgramFromSource(GLUSshaderprogram* shaderProgram, const GLUSenum type, const GLUSchar** source) { GLUSint linked; GLUSint logLength, charsWritten; char* log; if (!shaderProgram || !source) { return GLUS_FALSE; } shaderProgram->program = 0; shaderProgram->compute = 0; shaderProgram->vertex = 0; shaderProgram->fragment = 0; shaderProgram->program = glCreateShaderProgramv(type, 1, (const char**)source); glGetProgramiv(shaderProgram->program, GL_LINK_STATUS, &linked); if (!linked) { glGetProgramiv(shaderProgram->program, GL_INFO_LOG_LENGTH, &logLength); log = (char*) malloc((size_t)logLength); if (!log) { glusDestroyProgram(shaderProgram); return GLUS_FALSE; } glGetProgramInfoLog(shaderProgram->program, logLength, &charsWritten, log); glusLogPrint(GLUS_LOG_ERROR, "Shader program link error:"); glusLogPrint(GLUS_LOG_ERROR, "%s", log); free(log); shaderProgram->program = 0; glusDestroyProgram(shaderProgram); return GLUS_FALSE; } return GLUS_TRUE; }
bool initSeparateProgram() { bool Validated = true; glGenProgramPipelines(1, &PipelineName); if(Validated) { std::string VertexSourceContent = glf::loadFile(VERTEX_SHADER_SOURCE); char const * VertexSourcePointer = VertexSourceContent.c_str(); SeparateProgramName[program::VERTEX] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &VertexSourcePointer); Validated = glf::checkProgram(SeparateProgramName[program::VERTEX]); } if(Validated) glUseProgramStages(PipelineName, GL_VERTEX_SHADER_BIT, SeparateProgramName[program::VERTEX]); if(Validated) { std::string FragmentSourceContent = glf::loadFile(FRAGMENT_SHADER_SOURCE); char const * FragmentSourcePointer = FragmentSourceContent.c_str(); SeparateProgramName[program::FRAGMENT] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &FragmentSourcePointer); Validated = glf::checkProgram(SeparateProgramName[program::FRAGMENT]); } if(Validated) glUseProgramStages(PipelineName, GL_FRAGMENT_SHADER_BIT, SeparateProgramName[program::FRAGMENT]); // Get variables locations if(Validated) { SeparateUniformMVP = glGetUniformLocation(SeparateProgramName[program::VERTEX], "MVP"); SeparateUniformDiffuse = glGetUniformLocation(SeparateProgramName[program::FRAGMENT], "Diffuse"); } return Validated && glf::checkError("initProgram"); }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL41_nglCreateShaderProgramv3(JNIEnv *env, jclass clazz, jint type, jint count, jobjectArray strings, jlong function_pointer) { unsigned int _ptr_i; jobject _ptr_object; GLchar **strings_ptr = (GLchar **) malloc(count * sizeof(GLchar *)); glCreateShaderProgramvPROC glCreateShaderProgramv = (glCreateShaderProgramvPROC)((intptr_t)function_pointer); GLuint __result; _ptr_i = 0; while ( _ptr_i < count ) { _ptr_object = (*env)->GetObjectArrayElement(env, strings, _ptr_i); strings_ptr[_ptr_i++] = (GLchar *)(intptr_t)getPointerWrapperAddress(env, _ptr_object); } __result = glCreateShaderProgramv(type, count, (const GLchar **)strings_ptr); free(strings_ptr); return __result; }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL41_nglCreateShaderProgramv2(JNIEnv *env, jclass clazz, jint type, jint count, jlong strings, jlong function_pointer) { const GLchar *strings_address = (const GLchar *)(intptr_t)strings; unsigned int _str_i; GLchar *_str_address; GLchar **strings_str = (GLchar **) malloc(count * sizeof(GLchar *)); glCreateShaderProgramvPROC glCreateShaderProgramv = (glCreateShaderProgramvPROC)((intptr_t)function_pointer); GLuint __result; _str_i = 0; _str_address = (GLchar *)strings_address; while ( _str_i < count ) { strings_str[_str_i++] = _str_address; _str_address += strlen(_str_address) + 1; } __result = glCreateShaderProgramv(type, count, (const GLchar **)&strings_str); free(strings_str); return __result; }
GLuint GSShaderOGL::Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel) { ASSERT(glsl_h_code != NULL); GLuint program = 0; if (type == GL_GEOMETRY_SHADER && !GLLoader::found_geometry_shader) { return program; } // Note it is better to separate header and source file to have the good line number // in the glsl compiler report const char* sources[2]; std::string header = GenGlslHeader(entry, type, macro_sel); int shader_nb = 1; #if 1 sources[0] = header.c_str(); sources[1] = glsl_h_code; shader_nb++; #else sources[0] = header.append(glsl_h_code).c_str(); #endif if (GLLoader::found_GL_ARB_separate_shader_objects) { program = glCreateShaderProgramv(type, shader_nb, sources); } else { program = glCreateShader(type); glShaderSource(program, shader_nb, sources, NULL); glCompileShader(program); } bool status; if (GLLoader::found_GL_ARB_separate_shader_objects) status = ValidateProgram(program); else status = ValidateShader(program); if (!status) { // print extra info fprintf(stderr, "%s (entry %s, prog %d) :", glsl_file.c_str(), entry.c_str(), program); fprintf(stderr, "\n%s", macro_sel.c_str()); fprintf(stderr, "\n"); } return program; }
uint32 gfxCreateShader(const char* filename, uint8 shaderType) { char* shaderSrc; size_t srcSize; int32 length; int ret = load_file(filename, &shaderSrc, &srcSize); ASSERT(ret == FILELOAD_SUCCESS); uint32 program = glCreateShaderProgramv(s_shaderTypes[shaderType], 1, (const char**)&shaderSrc); glGetProgramInfoLog(program, 4096, &length, s_shaderLog); if (length) { printf("Shader compilation failed for %s:\n%s\n", filename, s_shaderLog); return 0; } gctx.programs[gctx.shaderCnt++] = program; return program; }
//[-------------------------------------------------------] //[ Public static methods ] //[-------------------------------------------------------] uint32_t ShaderLanguageSeparate::loadShader(uint32_t shaderType, const char *sourceCode) { // Create the shader program const GLuint openGLProgram = glCreateShaderProgramv(shaderType, 1, &sourceCode); // Check the link status GLint linked = GL_FALSE; glGetObjectParameterivARB(openGLProgram, GL_LINK_STATUS, &linked); if (GL_TRUE == linked) { // All went fine, return the program return openGLProgram; } else { // Error, failed to compile the shader! #ifdef RENDERER_OUTPUT_DEBUG { // Get the length of the information GLint informationLength = 0; glGetObjectParameterivARB(openGLProgram, GL_OBJECT_INFO_LOG_LENGTH_ARB, &informationLength); if (informationLength > 1) { // Allocate memory for the information GLchar *informationLog = new GLchar[static_cast<uint32_t>(informationLength)]; // Get the information glGetInfoLogARB(openGLProgram, informationLength, nullptr, informationLog); // Output the debug string RENDERER_OUTPUT_DEBUG_STRING(informationLog) // Cleanup information memory delete [] informationLog; } } #endif // Destroy the program // -> A value of 0 for shader will be silently ignored glDeleteProgram(openGLProgram); // Error! return 0; } }
static GLuint generate_program(const char *code_template, unsigned glsl_version, GLenum program_target, GLint *uniform_loc) { char *code = NULL; GLuint prog; (void)!asprintf(&code, code_template, glsl_version); prog = glCreateShaderProgramv(program_target, 1, (const GLchar * const*) &code); free(code); piglit_link_check_status(prog); *uniform_loc = glGetUniformLocation(prog, "a"); return prog; }
GLSeparableProgram::GLSeparableProgram( GLSeparableProgram::Type shaderType, const char* sourceCode ) { GLenum type = static_cast< GLenum >( shaderType ); GLuint id = glCreateShaderProgramv( type, 1, &sourceCode ); m_infoLog = ::getInfoLog( id ); GLint status; glGetProgramiv( id, GL_LINK_STATUS, &status ); if( status == GL_TRUE ) { m_id = id; m_type = shaderType; } else { glDeleteProgram( id ); } }
GLuint ShaderPipeline::createShaderPipelineProgram(GLuint target, const char* src, const char* m_shaderPrefix, GLuint m_programPipeline) { GLuint object; GLint status; const GLchar* fullSrc[2] = { m_shaderPrefix, src }; object = glCreateShaderProgramv(target, 2, fullSrc); { GLint logLength; glGetProgramiv(object, GL_INFO_LOG_LENGTH, &logLength); if (logLength > 0) { // This log contains shader compile errors. char *log = new char[logLength]; glGetProgramInfoLog(object, logLength, 0, log); LOGI("Shader pipeline program not valid:\n%s\n", log); delete[] log; } } glBindProgramPipeline(m_programPipeline); glUseProgramStages(m_programPipeline, GL_COMPUTE_SHADER_BIT, object); glValidateProgramPipeline(m_programPipeline); glGetProgramPipelineiv(m_programPipeline, GL_VALIDATE_STATUS, &status); if (status != GL_TRUE) { GLint logLength; glGetProgramPipelineiv(m_programPipeline, GL_INFO_LOG_LENGTH, &logLength); if (logLength > 0) { char *log = new char[logLength]; glGetProgramPipelineInfoLog(m_programPipeline, logLength, 0, log); LOGI("Shader pipeline not valid:\n%s\n", log); delete[] log; } } glBindProgramPipeline(0); CHECK_GL_ERROR(); return object; }
static bool gl_shader_init(struct gs_shader *shader, struct gl_shader_parser *glsp, const char *file, char **error_string) { GLenum type = convert_shader_type(shader->type); int compiled = 0; bool success = true; shader->program = glCreateShaderProgramv(type, 1, (const GLchar**)&glsp->gl_string.array); if (!gl_success("glCreateShaderProgramv") || !shader->program) return false; blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); blog(LOG_DEBUG, " GL shader string for: %s", file); blog(LOG_DEBUG, "-----------------------------------"); blog(LOG_DEBUG, "%s", glsp->gl_string.array); blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); glGetProgramiv(shader->program, GL_LINK_STATUS, &compiled); if (!gl_success("glGetProgramiv")) return false; if (!compiled) success = false; gl_get_program_info(shader->program, file, error_string); if (success) success = gl_add_params(shader, glsp); /* Only vertex shaders actually require input attributes */ if (success && shader->type == SHADER_VERTEX) success = gl_process_attribs(shader, glsp); if (success) gl_add_samplers(shader, glsp); return success; }
GLuint TerrainTessellation::createShaderPipelineProgram(GLuint target, const char* src) { GLuint object; GLint status; object = glCreateShaderProgramv( target, 1, (const GLchar **)&src ); glGetProgramiv(object, GL_LINK_STATUS, &status); if (!status) { GLint charsWritten, infoLogLength; glGetProgramiv(object, GL_INFO_LOG_LENGTH, &infoLogLength); char * infoLog = new char[infoLogLength]; glGetProgramInfoLog(object, infoLogLength, &charsWritten, infoLog); LOGI("Error compiling %s:\n", GetShaderStageName(target)); LOGI("Log: %s", infoLog); delete [] infoLog; glDeleteProgram( object); object = 0; } return object; }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL41_nglCreateShaderProgramv(JNIEnv *env, jclass clazz, jint type, jint count, jlong string, jlong function_pointer) { const GLchar *string_address = (const GLchar *)(intptr_t)string; glCreateShaderProgramvPROC glCreateShaderProgramv = (glCreateShaderProgramvPROC)((intptr_t)function_pointer); GLuint __result = glCreateShaderProgramv(type, count, (const GLchar **)&string_address); return __result; }
int main(int argc, char **argv) { const char *filename = NULL; for (int i = 1; i < argc; i++) { if (strstr(argv[i], "-mcpu=") == argv[i]) { setenv("SI_FORCE_FAMILY", argv[i] + 6, 1); } else if (filename == NULL) { filename = argv[i]; } else { if (strcmp(argv[i], "--help") != 0 && strcmp(argv[i], "-h") != 0) fprintf(stderr, "Unknown option: %s\n\n", argv[i]); fprintf(stderr, "Usage: amdgcn_glslc -mcpu=[chip name] [glsl filename]\n"); return 1; } } if (filename == NULL) { fprintf(stderr, "No filename specified.\n"); return 1; } addenv("R600_DEBUG", "precompile,vs,tcs,tes,gs,ps,cs,noir,notgsi"); create_gl_core_context(); /* Read the source. */ char *input = read_file(filename); /* Comment out lines beginning with ; (FileCheck prefix). */ if (input[0] == ';') memcpy(input, "//", 2); char *s = input; while (s = strstr(s, "\n;")) memcpy(s + 1, "//", 2); s = input; while (s && (s = strstr(s, "#shader "))) { char type_str[16], name[128]; GLenum type; /* If #shader is not at the beginning of the line. */ if (s != input && s[-1] != '\n' && s[-1] != 0) { s = strstr(s, "\n"); continue; } /* Parse the #shader directive. */ if (sscanf(s + 8, "%s %s", type_str, name) != 2) { fprintf(stderr, "Cannot parse #shader directive.\n"); continue; } if (!strcmp(type_str, "vs")) type = GL_VERTEX_SHADER; else if (!strcmp(type_str, "tcs")) type = GL_TESS_CONTROL_SHADER; else if (!strcmp(type_str, "tes")) type = GL_TESS_EVALUATION_SHADER; else if (!strcmp(type_str, "gs")) type = GL_GEOMETRY_SHADER; else if (!strcmp(type_str, "fs")) type = GL_FRAGMENT_SHADER; else if (!strcmp(type_str, "cs")) type = GL_COMPUTE_SHADER; /* Go the next line. */ s = strstr(s, "\n"); if (!s) break; s++; const char *source = s; /* Cut the shader source at the end. */ s = strstr(s, "#shader"); if (s && s[-1] == '\n') s[-1] = 0; /* Compile the shader. */ printf("@%s:\n", name); /* Redirect stderr to stdout for the compiler. */ FILE *stderr_original = stderr; stderr = stdout; GLuint prog = glCreateShaderProgramv(type, 1, &source); stderr = stderr_original; GLint linked; glGetProgramiv(prog, GL_LINK_STATUS, &linked); if (!linked) { char log[4096]; GLsizei length; glGetProgramInfoLog(prog, sizeof(log), &length, log); fprintf(stderr, "ERROR: Compile failure:\n\n%s\n%s\n", source, log); return 1; } glDeleteProgram(prog); } return 0; }
void piglit_init(int argc, char **argv) { unsigned glsl_version; unsigned i; unsigned j; unsigned idx; const char *location; const char *vertex_name; const char *fragment_name; struct vertex { float x; float y; float r; float g; float b; } *vert; piglit_require_extension("GL_ARB_separate_shader_objects"); piglit_require_extension("GL_ARB_explicit_attrib_location"); if (argc > 1 && strcmp(argv[1], "--by-location") == 0) { location = "layout(location = 3)"; vertex_name = "a"; fragment_name = "b"; } else { location = ""; vertex_name = "in_color"; fragment_name = "in_color"; } glsl_version = pick_a_glsl_version(); /* Generate the vertex shader programs. Each vertex shader is * hardcoded to select a specific column on the display. */ printf("Generating vertex shaders...\n"); for (i = 0; i < ARRAY_SIZE(vs_programs); i++) { const unsigned base_x = (i * tile_size) + ((i + 1) * border_size); char *source = NULL; (void)!asprintf(&source, vs_code, glsl_version, location, vertex_name, base_x, vertex_name); vs_programs[i] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(vs_programs[i]); if (i == 0) puts(source); free(source); } printf("Generating fragment shaders...\n"); for (i = 0; i < ARRAY_SIZE(fs_programs); i++) { char *source = NULL; (void)!asprintf(&source, fs_code, glsl_version, location, fragment_name, RED(i), GREEN(i), BLUE(i), fragment_name); fs_programs[i] = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(fs_programs[i]); if (i == 3) puts(source); free(source); } glGenProgramPipelines(1, &pipe); /* Generate vertex data for the tests. The row of each block is * determined by the vertex data. The color data for the block comes * from the vertex data and the data baked into the fragment shader. */ if (piglit_get_gl_version() >= 30 || piglit_is_extension_supported("GL_ARB_vertex_array_object")) { glGenVertexArrays(1, &vao); glBindVertexArray(vao); } glGenBuffers(1, &bo); glBindBuffer(GL_ARRAY_BUFFER, bo); glBufferData(GL_ARRAY_BUFFER, sizeof(vert[0]) * 4 * ARRAY_SIZE(fs_programs), NULL, GL_STATIC_DRAW); vert = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); for (i = 0; i < ARRAY_SIZE(fs_programs); i++) { const unsigned base_y = (i * tile_size) + ((i + 1) * border_size); vert[(i * 4) + 0].x = 0.f; vert[(i * 4) + 0].y = (float) base_y; vert[(i * 4) + 0].r = (float) -RED(i); vert[(i * 4) + 0].g = (float) 1 - GREEN(i); vert[(i * 4) + 0].b = (float) -BLUE(i); vert[(i * 4) + 1].x = (float) tile_size; vert[(i * 4) + 1].y = (float) base_y; vert[(i * 4) + 1].r = (float) -RED(i); vert[(i * 4) + 1].g = (float) 1 - GREEN(i); vert[(i * 4) + 1].b = (float) -BLUE(i); vert[(i * 4) + 2].x = (float) tile_size; vert[(i * 4) + 2].y = (float) (base_y + tile_size); vert[(i * 4) + 2].r = (float) -RED(i); vert[(i * 4) + 2].g = (float) 1 - GREEN(i); vert[(i * 4) + 2].b = (float) -BLUE(i); vert[(i * 4) + 3].x = 0.f; vert[(i * 4) + 3].y = (float) (base_y + tile_size); vert[(i * 4) + 3].r = (float) -RED(i); vert[(i * 4) + 3].g = (float) 1 - GREEN(i); vert[(i * 4) + 3].b = (float) -BLUE(i); } glUnmapBuffer(GL_ARRAY_BUFFER); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vert[0]), (void *)(intptr_t) offsetof(struct vertex, x)); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vert[0]), (void *)(intptr_t) offsetof(struct vertex, r)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); /* Generate the set of combinations of vertex shader programs and * fragment shader programs that will be used together. This is all * the possible combinations. The next step is to shuffle list so * that there's (hopefully) no pattern to the access combination... to * uncover driver bugs. */ idx = 0; for (i = 0; i < ARRAY_SIZE(vs_programs); i++) { for (j = 0; j < ARRAY_SIZE(fs_programs); j++) { combinations[idx].row = j; combinations[idx].col = i; idx++; } } for (i = ARRAY_SIZE(combinations); i > 1; i--) { const unsigned j = rand() % i; if (j != i - 1) { const struct combination temp = combinations[j]; combinations[j] = combinations[i - 1]; combinations[i - 1] = temp; } } }
void piglit_init(int argc, char **argv) { bool pass = true; GLuint pipe; GLuint vs_prog; GLuint active_prog; GLuint unlinked_prog; GLuint shader; unsigned glsl_version; char *source; piglit_require_extension("GL_ARB_separate_shader_objects"); glsl_version = pick_a_glsl_version(); glGenProgramPipelines(1, &pipe); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; glBindProgramPipeline(pipe); (void)!asprintf(&source, vs_code_template, glsl_version); vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &source); piglit_link_check_status(vs_prog); /* First, make a valid program active. */ glActiveShaderProgram(pipe, vs_prog); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* Next, try to make an invalid program active and verify that the * correct error is generated. Also make sure the old program is * still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_VALUE error is generated if program is not zero and * is not the name of either a program or shader object." */ glActiveShaderProgram(pipe, ~vs_prog); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with an invalid program name " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } /* Try the same thing with a valid shader object (that is not part of * a linked program). Verify that the correct error is generated, and * make sure the old program is still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_OPERATION error is generated if program is the name * of a shader object." */ shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source); glActiveShaderProgram(pipe, shader); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with a shader object " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } /* Finally, try the same thing with a valid program that is not * linked. Verify that the correct error is generated, and make sure * the old program is still active. * * Section 7.4 (Program Pipeline Objects) under ActiveShaderProgram of * the OpenGL 4.4 spec says: * * "An INVALID_OPERATION error is generated if program is not zero * and has not been linked, or was last linked unsuccessfully." */ unlinked_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, (const GLchar *const *) &invalid_code); glActiveShaderProgram(pipe, unlinked_prog); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, (GLint *) &active_prog); if (active_prog != vs_prog) { printf("glActiveShaderProgram with an unlinked program " "changed the active program state.\n"); pass = false; } else { glActiveShaderProgram(pipe, vs_prog); } free(source); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }