コード例 #1
0
ファイル: Shader.cpp プロジェクト: AlexSnet/video_streamer
bool Shader::setup() {

  vert = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vert, 1, &GR_VS, NULL);
  glCompileShader(vert); 
  printShaderCompileInfo(vert);

  frag = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(frag, 1, &GR_FS, NULL);
  glCompileShader(frag);
  printShaderCompileInfo(frag);

  prog = glCreateProgram();
  glAttachShader(prog, vert);
  glAttachShader(prog, frag);
  glBindAttribLocation(prog, 0, "a_pos");
  glBindAttribLocation(prog, 1, "a_col");
  glLinkProgram(prog);
  printShaderLinkInfo(prog);
  
  u_pm = glGetUniformLocation(prog, "u_pm");
  if(u_pm < 0) {
    printf("error: u_pm not found.\n");
    return false;
  }

  return true;
}
コード例 #2
0
ファイル: gpuprogram.cpp プロジェクト: solael/Post_Processing
//====================================================================================================================================
GLuint GPUProgram::createShader( const std::string& _rstrShaderPath, GLenum _eShaderType )
{
    std::string strFragmentShader = readFileSrc( "data/" + _rstrShaderPath );
    const char* strSrc = strFragmentShader.c_str();

    GLuint iShader = glCreateShader( _eShaderType );
    glShaderSource( iShader, 1, & strSrc, 0 );
    glCompileShader( iShader );

    printShaderCompileInfo( iShader, "data/" + _rstrShaderPath );

    return iShader;
}
コード例 #3
0
ファイル: GPUProgram.cpp プロジェクト: solael/repo
//====================================================================================================================================
GLuint GPUProgram::createShader( const std::string& _rstrShaderPath, GLenum _eShaderType )
{
//        //--------------------------------------------------------------------------------------------------------------------
//        // precondition
//        TP_ASSERT( 0 == _rOutShaderID ,    "_rOutShaderID should be 0 (here it is '%d') - have you already called this function ?.\n", _rOutShaderID );
//        //--------------------------------------------------------------------------------------------------------------------

    std::string strFragmentShader = readFileSrc( TP_PATH_TO_DATA + _rstrShaderPath );
    const char* strSrc = strFragmentShader.c_str();

    GLuint iShader = glCreateShader( _eShaderType );
    glShaderSource( iShader, 1, & strSrc, 0 );
    glCompileShader( iShader );

    printShaderCompileInfo( iShader, TP_PATH_TO_DATA + _rstrShaderPath );

    //--------------------------------------------------------------------------------------------------------------------
    // iShader
    TP_ASSERT( 0 != iShader ,    "iShader should not be 0 (here it is '%d') - Did glCreateShader(...) succeed ?.\n", iShader );
    //--------------------------------------------------------------------------------------------------------------------

    return iShader;
}
コード例 #4
0
bool YUV420PGrabber::setupShaders() {
  GLint u_tex = -1;

  // Shared vertex shader 
  vert_yuv = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vert_yuv, 1, &YUV420P_YUV_VS, NULL);
  glCompileShader(vert_yuv);
  printShaderCompileInfo(vert_yuv);

  frag_y = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(frag_y, 1, &YUV420P_Y_FS, NULL);
  glCompileShader(frag_y);
  printShaderCompileInfo(frag_y);

  prog_y = glCreateProgram();
  glAttachShader(prog_y, vert_yuv);
  glAttachShader(prog_y, frag_y);

#if YUV420P_GRABBER_GLSL_VERSION == 150
  glBindFragDataLocation(prog_y, 0, "fragcol");
#endif

  glLinkProgram(prog_y);
  printShaderLinkInfo(prog_y);

  glUseProgram(prog_y);
  u_tex = glGetUniformLocation(prog_y, "u_tex");
  if(u_tex < 0) {
    printf("error: cannot find u_tex in the y-shader.\n");
    return false;
  }
  glUniform1i(u_tex, 0);

  // U & V - shader

  // U - shader
  frag_u = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(frag_u, 1, &YUV420P_U_FS, NULL);
  glCompileShader(frag_u);
  printShaderCompileInfo(frag_u);

  prog_u = glCreateProgram();
  glAttachShader(prog_u, vert_yuv);
  glAttachShader(prog_u, frag_u);
  glLinkProgram(prog_u);
  printShaderLinkInfo(prog_u);

  u_tex = glGetUniformLocation(prog_u, "u_tex");
  if(u_tex < 0) {
     printf("error: cannot find u_tex in frag_u shader.\n");
     return false;
  }
  glUseProgram(prog_u);
  glUniform1i(u_tex, 0);

  // V - Shader
  frag_v = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(frag_v, 1, &YUV420P_V_FS, NULL);
  glCompileShader(frag_v);
  printShaderCompileInfo(frag_v);

  prog_v = glCreateProgram();
  glAttachShader(prog_v, vert_yuv);
  glAttachShader(prog_v, frag_v);
  glLinkProgram(prog_v);
  printShaderLinkInfo(prog_v);

  u_tex = glGetUniformLocation(prog_v, "u_tex");
  if(u_tex < 0) {
     printf("error: cannot find u_tex in frag_u shader.\n");
     return false;
  }
  glUseProgram(prog_v);
  glUniform1i(u_tex, 0);

  // Pass through shader
  frag_pt = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(frag_pt, 1, &YUV420P_PT_FS, NULL);
  glCompileShader(frag_pt);
  printShaderCompileInfo(frag_pt);

  prog_pt = glCreateProgram();
  glAttachShader(prog_pt, vert_yuv);
  glAttachShader(prog_pt, frag_pt);

#if YUV420P_GRABBER_GLSL_VERSION == 150
  glBindFragDataLocation(prog_pt, 0, "fragcol");
#endif

  glLinkProgram(prog_pt);
  printShaderLinkInfo(prog_pt);

  glUseProgram(prog_pt);
  u_tex = glGetUniformLocation(prog_pt, "u_tex");
  if(u_tex < 0) {
    printf("error: cannot find u_tex in the y-shader.\n");
    return false;
  }
  glUniform1i(u_tex, 0);

  glUseProgram(0);
  return true;
}