예제 #1
0
void print_log(GLuint object) {
	GLint log_length = 0;
	if (glIsShader(object))
		glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);
	else if (glIsProgram(object))
		glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);
	else {
		fprintf(stderr, "printlog: Not a shader or a program\n");
		return;
	}

	char* log = (char*) malloc(log_length);

	if (glIsShader(object))
		glGetShaderInfoLog(object, log_length, NULL, log);
	else if (glIsProgram(object))
		glGetProgramInfoLog(object, log_length, NULL, log);

	fprintf(stderr, "%s", log);
	free(log);
}
예제 #2
0
bool GLHelper::setUniform(const GLuint programID, const GLuint uniformID, const glm::vec3 &vector) {
    if (!glIsProgram(programID)) {
        std::cerr << "invalid program for setting uniform." << std::endl;
        return false;
    } else {
        state->setProgram(programID);
        glUniform3fv(uniformID, 1, glm::value_ptr(vector));
        //state->setProgram(0);
        checkErrors("setUniformVector");
        return true;
    }
}
예제 #3
0
void ClearShaderObject(GLhandleARB GLSL_PO,GLhandleARB Attach_VS,GLhandleARB Attach_TC,GLhandleARB Attach_TE,GLhandleARB Attach_GS,GLhandleARB Attach_PS)
{
	if(glIsProgram(GLSL_PO)!=GL_FALSE)
	{
		if(glIsShader(Attach_VS)!=GL_FALSE){ glDetachObjectARB(GLSL_PO,Attach_VS);}
		if(glIsShader(Attach_TC)!=GL_FALSE){ glDetachObjectARB(GLSL_PO,Attach_TC);}
		if(glIsShader(Attach_TE)!=GL_FALSE){ glDetachObjectARB(GLSL_PO,Attach_TE);}
		if(glIsShader(Attach_GS)!=GL_FALSE){ glDetachObjectARB(GLSL_PO,Attach_GS);}
		if(glIsShader(Attach_PS)!=GL_FALSE){ glDetachObjectARB(GLSL_PO,Attach_PS);}
		glDeleteObjectARB(GLSL_PO);
	}
}
예제 #4
0
void SCE_RDeleteProgram (SCE_RProgram *prog)
{
    if (prog) {
        size_t i;
        if (glIsProgram (prog->id))
            glDeleteProgram (prog->id);
        for (i = 0; i < prog->n_varyings; i++)
            SCE_free (prog->fb_varyings[i]);
        SCE_free (prog->fb_varyings);
        SCE_free (prog);
    }
}
예제 #5
0
void lite3d_shader_program_attribute_index(
    lite3d_shader_program *program, const char *name, int32_t location)
{
    SDL_assert(program);
    SDL_assert(glIsProgram(program->programID));

    SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION,
        "%s: bind attribute %s:%d for program %p",
        LITE3D_CURRENT_FUNCTION, name, location, (void *)program);

    glBindAttribLocation(program->programID, location, name);
}
예제 #6
0
bool GLHelper::setUniform(const GLuint programID, const GLuint uniformID, const int value) {
    if (!glIsProgram(programID)) {
        std::cerr << "invalid program for setting uniform." << std::endl;
        return false;
    } else {
        state->setProgram(programID);
        glUniform1i(uniformID, value);
        //state->setProgram(0);
        checkErrors("setUniformInt");
        return true;
    }
}
예제 #7
0
bool GLHelper::setUniform(const GLuint programID, const GLuint uniformID, const glm::mat4 &matrix) {
    if (!glIsProgram(programID)) {
        std::cerr << "invalid program for setting uniform." << std::endl;
        return false;
    } else {
        state->setProgram(programID);
        glUniformMatrix4fv(uniformID, 1, GL_FALSE, glm::value_ptr(matrix));
        //state->setProgram(0);
        checkErrors("setUniformMatrix");
        return true;
    }

}
예제 #8
0
        ShaderProgram::ShaderProgram() {
            this->_checkError("Errors before create shader program");
            this->_shaderProgramID = glCreateProgram();

            if (this->_shaderProgramID == 0) {
                throw GraphicsException("Failed to create shader program");
            }
            else if (glIsProgram(this->_shaderProgramID) != GL_TRUE) {
                throw GraphicsException("Failed to create shader program, shader program is not a shader program");
            }

            this->_checkError("Failed to create shader program");
        }
예제 #9
0
static bool glslIsValid(GLuint obj)
{
	const bool isShader = glIsShader(obj);
	assert(glIsShader(obj) || glIsProgram(obj));

	GLint compiled;
	if (isShader)
		glGetShaderiv(obj, GL_COMPILE_STATUS, &compiled);
	else
		glGetProgramiv(obj, GL_LINK_STATUS, &compiled);

	return compiled;
}
예제 #10
0
/* Based on: see LINKS file: [1]. */
void printInfoLog(FILE * stream, GLuint obj)
{
    int infoLogLength = 0;
    char * infoLog = NULL;
    int charsWritten = 0;

    if (! glIsShader(obj) && ! glIsProgram(obj))
    {
        fprintf(stream,
            "Cannot print InfoLog, \
object is not shader or shader program.");
        return;
    }
예제 #11
0
void Shader::printShaderLog(GLuint shader, const char* shader_file)
{
   	GLint log_length = 0;
	if (glIsShader(shader))
		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
	else if (glIsProgram(shader))
		glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &log_length);
	else {
		fprintf(stderr, "printlog: Not a shader or a program\n");
		return;
	}

	char* log = (char*)malloc(log_length);

	if (glIsShader(shader))
		glGetShaderInfoLog(shader, log_length, NULL, log);
	else if (glIsProgram(shader))
		glGetProgramInfoLog(shader, log_length, NULL, log);

	fprintf(stderr, "%s", log);
	free(log);
}
예제 #12
0
void print_log(GLuint object)
{
   GLint log_length = 0;
   if (glIsShader(object))
       glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);
   else if (glIsProgram(object))
       glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);
   else {
       std::cout << "printlog: Not a shader or a program" << std::endl;
       return;
   }
   
   char* log = (char*)malloc(log_length);
   
   if (glIsShader(object))
       glGetShaderInfoLog(object, log_length, NULL, log);
   else if (glIsProgram(object))
       glGetProgramInfoLog(object, log_length, NULL, log);
   
   std::cout << log << std::endl;
   free(log);
}
예제 #13
0
파일: shader.cpp 프로젝트: jeando/vision
/**
 * @brief: Display compilation errors from the OpenGL shader compiler
 * WARNING: This doesn't display glErrors which might still happen depending on
 * the state machine's state.
 */
void Shader::printLog(GLuint object)
{
    GLint log_length = 0;
    if (glIsShader(object))
        glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);
    else if (glIsProgram(object))
        glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);
    else {
        std::cerr <<  "Shader::printLog: Not a shader or a program" << std::endl;
        return;
    }

    char* log = new char[log_length];

    if (glIsShader(object))
        glGetShaderInfoLog(object, log_length, NULL, log);
    else if (glIsProgram(object))
        glGetProgramInfoLog(object, log_length, NULL, log);

    std::cerr << log << std::endl;
    delete log;
}
예제 #14
0
파일: program.cpp 프로젝트: LBdN/Shaderkit
  bool GLProgram::isLinked()
  {
    glCheck("GLProgram::isLinked");
    if (!m_prog) return false;

    /// for example i915_program_error: Exceeded max instructions etc can be
    /// checked with this
    if (!glRun2(glIsProgram(m_prog))) return false;

    GLint b = 0;
    glRun(glGetProgramiv(m_prog, GL_LINK_STATUS, &b));
    return b;
  }
예제 #15
0
void PERect::drawFBO()
{
    if(m_isVisible == false){
        return;
    }
    m_program = m_program0;
    if(glIsProgram(m_program) == GL_FALSE){
        return;
    }
    glUseProgram(m_program);
    this->setLightProjectViewUniform(UNIFORM_MODELPROJECT);
    this->drawFunc();
}
/*! \fn SoXipGLSLUniformGroup::doAction(SoAction * action)
 *  Adds a node to the SoXipGLSLUniformGroupElement in the current state
 *  \param action - the current state action, no action taken if input action is NULL
 *  \return void
 */
void SoXipGLSLUniformGroup::groupUpdate(SoAction * action)
{
    SoChildList * children = this->getChildren();
    GLint prg = SoXipGLSLShaderProgramElement::get(action->getState());

    if (mNumPrograms > GLSL_MAX_NUM_SHADERS)
    {
        SoDebugError::postWarning(__FUNCTION__, "supports %i shaders (requested %d)", GLSL_MAX_NUM_SHADERS, mNumPrograms);
        mNumPrograms = GLSL_MAX_NUM_SHADERS;
    }

    for (int i = 0; i < mNumPrograms; i++)
    {
/*
    To prevent uniforms from updating every frame
    we only update the uniform if the time stamp
    of the selected shader is out of date or if
    anything has changed among the uniforms such
    as names or values.

    TODO: This fix do not work since we have no
    way of knowing if other instances of this
    node also changes the same uniforms. Since
    this will not change the timestamp in the
    manager the uniform remains as last updated
    and fix don't work.

    No solution to the problem yet!
    Stefan Lindholm
*/
#if 0
        int handle = SoXipGLSLShaderProgramElement::getProgramID(action->getState(), prgTags[i].getString());
        if (glIsProgram(handle))
        {
            SoXipGLSLShaderProgramElement::set(action->getState(), prgTags[i].getString());
            children->traverse(action);
        }
#else
        __uint64 currTime = SoXipGLSLShaderProgramElement::getTimeStamp(action->getState(), prgTags[i].getString());
        if (currTime != mProgramTimeStamps[i] || mNeedsUpdate)
        {
            SoXipGLSLShaderProgramElement::set(action->getState(), prgTags[i].getString());
            children->traverse(action);
            mProgramTimeStamps[i] = currTime;
        }
#endif
    }

    SoXipGLSLShaderProgramElement::set(action->getState(), prg);
    mNeedsUpdate = false;
}
예제 #17
0
  Shader::Shader(const unsigned int vertex_program, const unsigned int fragment_program, const unsigned int geometry_program) : name("") {
    if(!glIsShader(vertex_program)) {
      throw Exceptions::InvalidVertexShaderException(vertex_program);
    }
    if(!glIsShader(fragment_program)) {
      throw Exceptions::InvalidFragmentShaderException(fragment_program);
    }
    if(geometry_program != 0 && !glIsShader(geometry_program)) {
      throw Exceptions::InvalidGeometryShaderException(geometry_program);
    }
    
    program_object = glCreateProgram();
    glAttachShader(program_object, vertex_program);
    glAttachShader(program_object, fragment_program);
    if(geometry_program != 0)
      glAttachShader(program_object, geometry_program);
    
    glLinkProgram(program_object);
    int is_linked = 0;
    glGetProgramiv(program_object, GL_LINK_STATUS, &is_linked);
    if(!is_linked)
    {
      int max_length = 0;
      glGetProgramiv(program_object, GL_INFO_LOG_LENGTH, &max_length);
      std::vector<char> info_log(max_length);
      glGetProgramInfoLog(program_object, max_length, &max_length, &info_log[0]);
      std::string output(info_log.begin(), info_log.end());
      LOG(ERROR)<<output;
      glDeleteProgram(program_object);

      throw Exceptions::InvalidShaderProgramException(program_object);
    }
    if(!glIsProgram(program_object)) {
      throw Exceptions::InvalidShaderProgramException(program_object);
    }

    int count = 0;
    glGetProgramiv(program_object, GL_ACTIVE_UNIFORMS, &count);
    for(int i = 0; i < count; i++) {
      int name_length;
      int arr_size;
      GLenum type;
      GLchar name[64];
      glGetActiveUniform(program_object, i, 64, &name_length, &arr_size, &type, name);
      int location = glGetUniformLocation(program_object, name);
      name_to_location[std::string(name)] = location;
      name_to_type[std::string(name)] = type;
      LOG(INFO)<<"Uniform found: "<<name<<" Location: "<<location;
    }
  }
예제 #18
0
static void createProgram(const char *vertProgFile,
                          const char *fragProgFile)
{
    GLuint fragShader = 0, vertShader = 0;

    program = glCreateProgram();
    if (vertProgFile) {
        vertShader = glCreateShader(GL_VERTEX_SHADER);
        readShader(vertShader, vertProgFile);
        glAttachShader(program, vertShader);
    }

    if (fragProgFile) {
        fragShader = glCreateShader(GL_FRAGMENT_SHADER);
        readShader(fragShader, fragProgFile);
        glAttachShader(program, fragShader);
    }

    glLinkProgram(program);
    checkLink(program);

    glUseProgram(program);

    assert(glIsProgram(program));
    assert(glIsShader(fragShader));
    assert(glIsShader(vertShader));

    checkError(__LINE__);
    {   /*texture*/
        GLuint texLoc = glGetUniformLocationARB(program, "srcTex");
        glUniform1iARB(texLoc, 0);
    }
    {   /*setup offsets */
        float offsets[] = { 1.0 / texture.width,  1.0 / texture.height,
                            0.0                ,  1.0 / texture.height,
                            -1.0 / texture.width,  1.0 / texture.height,
                            1.0 / texture.width,  0.0,
                            0.0                ,  0.0,
                            -1.0 / texture.width,  0.0,
                            1.0 / texture.width, -1.0 / texture.height,
                            0.0                , -1.0 / texture.height,
                            -1.0 / texture.width, -1.0 / texture.height
                          };
        GLuint offsetLoc = glGetUniformLocationARB(program, "Offset");
        glUniform2fv(offsetLoc, 9, offsets);
    }
    setupConvolution();

    checkError(__LINE__);
}
예제 #19
0
파일: xgl.cpp 프로젝트: attilaolah/bino
void xgl::DeleteProgram(GLuint program)
{
    if (glIsProgram(program))
    {
        GLint shader_count;
        glGetProgramiv(program, GL_ATTACHED_SHADERS, &shader_count);
        GLuint *shaders = new GLuint[shader_count];
        glGetAttachedShaders(program, shader_count, NULL, shaders);
        for (int i = 0; i < shader_count; i++)
            glDeleteShader(shaders[i]);
        delete[] shaders;
        glDeleteProgram(program);
    }
}
예제 #20
0
파일: glshader.cpp 프로젝트: Toeplitz/poll
void GLshader::print_log(GLuint object)
{
  GLint log_length = 0;

  if (glIsShader(object))
    glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);
  else if (glIsProgram(object))
    glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);
  else {
    POLL_ERROR(std::cerr, " Not a shader or a program\n");
    return;
  }

  char *log = (char *) malloc(log_length);

  if (glIsShader(object))
    glGetShaderInfoLog(object, log_length, NULL, log);
  else if (glIsProgram(object))
    glGetProgramInfoLog(object, log_length, NULL, log);

  std::cerr << log;
  free(log);
}
예제 #21
0
const bool ShaderProgram::_link_pass(void) const
{
	if (glIsProgram(_shaderProgramId) != GL_TRUE)
	{
		return false;
	}
	GLint linked;
	glGetProgramiv(_shaderProgramId, GL_LINK_STATUS, &linked);
	if (linked != GL_TRUE)
	{
		return false;
	}
	return true;
}
예제 #22
0
void PEPolygonNode::drawFBO()
{
    if (!m_isVisible) {
        return;
    }
    this->PENode::draw();
    m_program = m_program0;
    if (glIsProgram(m_program) == GL_FALSE) {
        return;
    }
    glUseProgram(m_program);
    this->setLightProjectViewUniform(UNIFORM_MODELPROJECT);
    this->drawMethod();
}
예제 #23
0
bool Shader::linkProgram(GLuint program) {
    if (glIsProgram(program)) {
        glLinkProgram(program);
        GLint status = GL_FALSE, len = 10;
        glGetProgramiv(program, GL_LINK_STATUS, &status);
        if (status == GL_TRUE) return true;
        // If we can't link, print the error to the console
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
        std::vector<char> log(len, 'X');
        glGetProgramInfoLog(program, len, nullptr, &log[0]);
        std::cerr << &log[0] << std::endl;
        //logOpenGLError("LINK_PROGRAM");
    }
    return false;
}
예제 #24
0
ShaderProgram::~ShaderProgram() {
    glGetError();
    if (glIsShader(m_vertex_shader_id)) {
        glDeleteShader(m_vertex_shader_id);
        CHECK_ERROR("ShaderProgram::~ShaderProgram", "glDeleteShader(m_vertex_shader_id)");
    }
    if (glIsShader(m_fragment_shader_id)) {
        glDeleteShader(m_fragment_shader_id);
        CHECK_ERROR("ShaderProgram::~ShaderProgram", "glDeleteShader(m_fragment_shader_id)");
    }
    if (glIsProgram(m_program_id)) {
        glDeleteProgram(m_program_id);
        CHECK_ERROR("ShaderProgram::~ShaderProgram", "glDeleteProgram()");
    }
}
예제 #25
0
Shader::~Shader()
{
    list<GLuint>::iterator it;
    for(it=shader_list.begin(); it!=shader_list.end(); ++it)
    {
        if (glIsShader(*it))
            glDeleteShader(*it);
    }

    for(it=program_list.begin(); it!=program_list.end(); ++it)
    {
        if (glIsProgram(*it))
            glDeleteProgram(*it);
    }
}
예제 #26
0
//Display compilation errors from the OpenGL shader compiler
void print_log(GLuint object)
{
	GLint log_length = 0;//this will be used to get the log length.
	if (glIsShader(object))//is the log we are going to be printing from a shadder?
		glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);//if it is we use this call
	else if (glIsProgram(object))//if not shader. is it a program maybe?
		glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);//then use this call
	else 
	{//if not either of those, we don't know what to do with it. probably that is the problem.
		fprintf(stderr, "printlog: Not a shader or a program\n");
		return;
	}

	char* log = (char*)malloc(log_length);
	//now that we know the length of the log. allocate memory for it to be dumped into.

	if (glIsShader(object))//get the log from a shader
		glGetShaderInfoLog(object, log_length, NULL, log);
	else if (glIsProgram(object))//get the log from a program
		glGetProgramInfoLog(object, log_length, NULL, log);

	fprintf(stderr, "%s", log);//print out the log to stderr.
	free(log);//free that memory.
}
예제 #27
0
void print_program_log(GLuint name)
{
	int maxlen, len;
	CHECK1(glIsProgram(name), "GL Name %d is not a program", name);
	glGetProgramiv(name, GL_INFO_LOG_LENGTH, &maxlen);
	INFO("GL_INFO_LOG_LENGTH = %d", maxlen);
	{
		char log[maxlen];
		glGetProgramInfoLog(name, maxlen, &len, log);
		if (len > 0)
			EPRINT("%s\n", log);
	}
error:
	return;
}
예제 #28
0
bool Program::CreateFromShaders(const GLuint* shaders, int count) {
  if (shaders == NULL || count == 0) {
    return false;
  }

  if (glIsProgram(_programObject)) {
    glDeleteProgram(_programObject);
    _programObject = 0;
  }

  _programObject = glCreateProgram();

  for (int k = 0; k < count; ++k) {
    if (!glIsShader(shaders[k])) {
      glDeleteProgram(_programObject);
      _programObject = 0;
      return false;
    }
    glAttachShader(_programObject, shaders[k]);
  }
  
  glLinkProgram(_programObject);

  GLint linkResult = 0;
  glGetProgramiv(_programObject, GL_LINK_STATUS, &linkResult);
  
  // Ouput log message on failure.
  if (linkResult == GL_FALSE) {
    GLchar* infoLog = NULL;
    GLint infoLogMaxLength = 0;
    GLint infoLogLength = 0;
    glGetProgramiv(_programObject, GL_INFO_LOG_LENGTH, &infoLogMaxLength);
    infoLog = static_cast<GLchar*>(malloc(infoLogMaxLength));
    glGetProgramInfoLog(_programObject, infoLogMaxLength, &infoLogLength, infoLog);

    LOGE("Fatal error in Shader::CreateFromShaders, "
         "failed to link program:\n%s", infoLog);
    free(infoLog);

    glDeleteProgram(_programObject);
    _programObject = 0;

    LIBME_ASSERT_TRUE(false);
    return false;
  }

  return (GetGLErrorVerbose() == GL_NO_ERROR);
}
// powi¹zanie shadera wierzcho³ków i shadera fragmentów,
// reprezentowanego przez kod Ÿród³owy, z obiektem programu;
// w razie potrzeby tworzony jest nowy obiekt programu
//////////////////////////////////////////////////////////////////////
void AttachVertexFragmentShader( GLuint &program, const char **vsSrc, const char **fsSrc )
{
    // odczyt kodu shadera wierzcho³ków i jego kompilacja
    GLuint vShader = LoadVertexShader( vsSrc );

    // odczyt kodu shadera fragmentów i jego kompilacja
    GLuint fShader = LoadFragmentShader( fsSrc );

    // w razie potrzeby tworzymy obiekt programu
    if( !glIsProgram( program ) )
        program = glCreateProgram();

    // do³¹czenie obiektów shaderów do obiektu programu
    glAttachShader( program, vShader );
    glAttachShader( program, fShader );
}
예제 #30
0
void PEPolygonNode::draw()
{
    if (!m_isVisible) {
        return;
    }
    this->PENode::draw();
    m_program = m_program1;
    if (glIsProgram(m_program) == GL_FALSE) {
        return;
    }
    glUseProgram(m_program);
    this->setModelViewProjectUniform();
    this->setLightProjectViewUniform();
    this->setDepthTexUnifrom();
    this->drawMethod();
}