bool kore::ShaderProgram::init() { if (_programHandle != KORE_GLUINT_HANDLE_INVALID) { destroyProgram(); } _programHandle = glCreateProgram(); if (_vertex_prog) { glAttachShader(_programHandle, _vertex_prog->getHandle()); } if (_fragment_prog) { glAttachShader(_programHandle, _fragment_prog->getHandle()); } if (_geometry_prog) { glAttachShader(_programHandle, _geometry_prog->getHandle()); } if (_tess_ctrl) { glAttachShader(_programHandle, _tess_ctrl->getHandle()); } if (_tess_eval) { glAttachShader(_programHandle, _tess_eval->getHandle()); } glLinkProgram(_programHandle); bool success = checkProgramLinkStatus(_programHandle, _name); if (!success) { destroyProgram(); return false; } constructShaderInputInfo(GL_ACTIVE_ATTRIBUTES, _attributes); //for (uint i = 0; i < _attributes.size(); i++) { // kore::Log::getInstance()->write("\tAttribute '%s' at location %i\n", // _attributes[i].name.c_str(), // _attributes[i].location); //} constructShaderInputInfo(GL_ACTIVE_UNIFORMS, _uniforms); //for (uint j = 0; j < _uniforms.size(); j++) { // kore::Log::getInstance()->write("\tUniform '%s' at location %i\n", // _uniforms[j].name.c_str(), // _uniforms[j].location); //} /* /* OpenGL 4.3 or arb_program_interface_query needed /* constructShaderOutputInfo(_outputs); for (uint j = 0; j < _outputs.size(); j++) { kore::Log::getInstance()->write("\tOutput '%s'\n", _outputs[j].name.c_str()); } */ return success == GL_TRUE; }
static void deletePrograms(Programs *progs) { destroyProgram(progs->fill); destroyProgram(progs->tex); destroyProgram(progs->quad); destroyProgram(progs->circle); destroyProgram(progs->ring); }
int main(){ tas T = newProgram(); node n1 = newNode(FORWARD, 1, 1); node n2 = newNode(REPEAT, 2, 2); incrementerHauteur(); node n3 = newNode(RIGHT, 3, 3); node n4 = newNode(REPEAT,4, 4); incrementerHauteur(); node n5 = newNode(RIGHT,5, 5); decrementerHauteur(); decrementerHauteur(); node n6 = newNode(REPEAT,6, 6); incrementerHauteur(); node n7 = newNode(LEFT,7, 7); decrementerHauteur(); printf("Creation OK\n"); addNode(T, n1); addNode(T, n2); addNode(T, n3); addNode(T, n4); addNode(T, n5); addNode(T, n6); addNode(T, n7); printf("Ajout OK\n"); afficherProgramme(T); destroyProgram(T); return 0; }
/** * Finalize. */ void ShaderProgramFactory::Finalize() { // Release. for (int i = 0; i < ShaderType_MAX; ++i) { destroyProgram(mShaderPrograms[i]); mShaderPrograms[i] = INVALID_PROGRAM; } }
GLuint ShaderProgramFactory::createProgram( GLchar* vertexSource, GLsizei vertexSourceLength, GLchar* fragmentSource, GLsizei fragmentSourceLength) { // Load and compile shaders. GLuint vertexShader = loadShader(GL_VERTEX_SHADER, vertexSource, vertexSourceLength); GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentSource, fragmentSourceLength); if (vertexShader == 0 || fragmentShader == 0) { LOGE("Failed to loadShader()"); if (vertexShader != 0) { glDeleteShader(vertexShader); } if (fragmentShader != 0) { glDeleteShader(fragmentShader); } return INVALID_PROGRAM; } // Create and link program. GLuint program = glCreateProgram(); glAttachShader(program, vertexShader); glAttachShader(program, fragmentShader); glLinkProgram(program); checkGlError(__FUNCTION__); if (vertexShader != 0) { glDeleteShader(vertexShader); } if (fragmentShader != 0) { glDeleteShader(fragmentShader); } GLint isSuccess = GL_FALSE; glGetProgramiv(program, GL_LINK_STATUS, &isSuccess); if (isSuccess != GL_TRUE) { LOGE("Failed to link program."); GLint logLength; GLint writtenLength; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); char pLog[256]; if (256 < logLength) logLength = 256; glGetProgramInfoLog(program, logLength, &writtenLength, pLog); if (program != 0) { destroyProgram(program); } LOGE("ProgramInfoLog:%s", pLog); return INVALID_PROGRAM; } return program; }
kore::ShaderProgram::~ShaderProgram(void) { destroyProgram(); destroyShaders(); }