コード例 #1
0
void Shader::setParameter(const std::string &name, const Transform &transform) {
	if (mShaderProgram) {
		ensureGLContext();

		GLhandleARB program = glCheck(glGetHandleARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB)));
		glCheck(glUseProgramObjectARB(mShaderProgram));

		GLint location = getParamLocation(name);
		if (location != -1) {
			glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));
		}

		glCheck(glUseProgramObjectARB(program));
	}
}
コード例 #2
0
void Shader::setParameter(const std::string &name, float x, float y, float z, float w) {
	if (mShaderProgram) {
		ensureGLContext();

		GLhandleARB program = glCheck(glGetHandleARB(glGetHandleARB(GL_PROGRAM_OBJECT_ARB)));
		glCheck(glUseProgramObjectARB(mShaderProgram));

		GLint location = getParamLocation(name);
		if (location != -1) {
			glCheck(glUniform4fARB(location, x, y, z, w));
		}

		glCheck(glUseProgramObjectARB(program));
	}
}
コード例 #3
0
ファイル: Shader.cpp プロジェクト: GuoXinxiao/meshlab
void GPU::Shader::SetUniform( const std::string& name,
                              const void *value )
{
    UniformMap::iterator uu = m_Uniforms.find( name );
    if( uu != m_Uniforms.end() )
    {
	    GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
	    glUseProgramObjectARB( m_Id );

        Uniform &u = uu->second;
	    switch( u.type )
	    {
		    case GL_FLOAT:          glUniform1fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC2_ARB: glUniform2fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC3_ARB: glUniform3fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_FLOAT_VEC4_ARB: glUniform4fvARB( u.location, u.size, (GLfloat*) value ); break;
		    case GL_INT:            glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC2_ARB:   glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC3_ARB:   glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_INT_VEC4_ARB:   glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_ARB:       glUniform1ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC2_ARB:  glUniform2ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC3_ARB:  glUniform3ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_BOOL_VEC4_ARB:  glUniform4ivARB( u.location, u.size, (GLint*) value ); break;
		    case GL_FLOAT_MAT2_ARB: glUniformMatrix2fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
		    case GL_FLOAT_MAT3_ARB: glUniformMatrix3fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
		    case GL_FLOAT_MAT4_ARB: glUniformMatrix4fvARB( u.location, u.size, GL_FALSE, (GLfloat*) value ); break;
	    }

	    glUseProgramObjectARB( activeProgBackup );
    }
}
コード例 #4
0
ファイル: Volume.cpp プロジェクト: herbsolo/DynamO
  void 
  RVolume::glRender(magnet::GL::FBO& fbo)
  {
    if (!_visible || !_data.isValid()) return;

    //Before we render, we need the current depth buffer for depth testing.
    fbo.detach();   
    fbo.copyto(*_fbo, GL_DEPTH_BUFFER_BIT);
    fbo.attach();

    //Now bind this copied depth texture to texture unit 0
    _fbo->getDepthTexture().bind(0);
    _data.bind(1);
    _transferFuncTexture.bind(2);

    //Now we can render
    GLhandleARB oldshader = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);

    _shader["FocalLength"] = GLfloat(1.0f / std::tan(_viewPort->getFOVY() * (M_PI / 360.0f)));
    { 
      std::tr1::array<GLfloat,2> winsize = {{_viewPort->getWidth(), _viewPort->getHeight()}};
      _shader["WindowSize"] = winsize;
    }
    { 
      Vector eyeOrigin = _viewPort->getEyeLocation();
      std::tr1::array<GLfloat,3> origin = {{eyeOrigin[0], eyeOrigin[1], eyeOrigin[2]}};
      _shader["RayOrigin"] = origin;
    }
    _shader["DepthTexture"] = 0;
    _shader["NearDist"] = _viewPort->getZNear();
    _shader["FarDist"] = _viewPort->getZFar();
    _shader["DataTexture"] = 1;
    _shader["StepSize"] = _stepSizeVal;
    _shader["DiffusiveLighting"] = GLfloat(_diffusiveLighting->get_value());
    _shader["SpecularLighting"] = GLfloat(_specularLighting->get_value());
    _shader["DitherRay"] = GLfloat(_ditherRay->get_value());
    _shader["TransferTexture"] = 2;
    _shader.attach();
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT);
    glDepthMask(GL_FALSE);
    glDisable(GL_DEPTH_TEST);
    RQuads::glRender();
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDisable(GL_CULL_FACE);

    glUseProgramObjectARB(oldshader);
  }
コード例 #5
0
ファイル: Shader.cpp プロジェクト: GuoXinxiao/meshlab
void GPU::Shader::SetSampler( const std::string& name,
                              const GLint texUnit )
{
    SamplerMap::iterator s = m_Samplers.find( name );
    if( s != m_Samplers.end() )
    {
	    GLuint activeProgBackup = glGetHandleARB( GL_PROGRAM_OBJECT_ARB );
	    glUseProgramObjectARB( m_Id );

        glUniform1iARB( s->second, texUnit );

	    glUseProgramObjectARB( activeProgBackup );
    }
}
コード例 #6
0
ファイル: shader.cpp プロジェクト: Ornito/ODFAEG
        void Shader::setParameter(const std::string& name, float x, float y, float z, float w)
        {
            if (m_shaderProgram)
            {
                ensureGlContext();
                // Enable program
                GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
                glCheck(glUseProgramObjectARB(m_shaderProgram));

                // Get parameter location and assign it new values
                GLint location = getParamLocation(name);
                if (location != -1)
                    glCheck(glUniform4fARB(location, x, y, z, w));

                // Disable program
                glCheck(glUseProgramObjectARB(program));
            }
        }
コード例 #7
0
void Shader::setParameter(const std::string& name, const sf::Transform& transform)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Enable program
        GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        glCheck(glUseProgramObjectARB(m_shaderProgram));

        // Get parameter location and assign it new values
        GLint location = getParamLocation(name);
        if (location != -1)
            glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.getMatrix()));

        // Disable program
        glCheck(glUseProgramObjectARB(program));
    }
}
コード例 #8
0
ファイル: shader.cpp プロジェクト: Ornito/ODFAEG
        void Shader::setParameter(const std::string& name, math::Matrix4f matrix)
        {
            if (m_shaderProgram)
            {
                ensureGlContext();
                // Enable program
                GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
                glCheck(glUseProgramObjectARB(m_shaderProgram));

                // Get parameter location and assign it new values
                GLint location = getParamLocation(name);
                if (location != -1) {
                    std::array<float, 16> glmatrix = matrix.toGlMatrix();
                    glCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, glmatrix.data()));
                }
                // Disable program
                glCheck(glUseProgramObjectARB(program));
            }
        }
コード例 #9
0
ファイル: Shader.cpp プロジェクト: vidjogamer/ProjectTemplate
void Shader::SetParameter(const std::string& name, float x, float y, float z, float w)
{
    if (myShaderProgram)
    {
        // Enable program
        GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        GLCheck(glUseProgramObjectARB(myShaderProgram));

        // Get parameter location and assign it new values
        GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str());
        if (location != -1)
            GLCheck(glUniform4fARB(location, x, y, z, w));
        else
            Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;

        // Disable program
        GLCheck(glUseProgramObjectARB(program));
    }
}
コード例 #10
0
ファイル: Shader.cpp プロジェクト: AdamFlores/SFML
void Shader::setParameter(const std::string& name, float x, float y, float z)
{
    if (m_shaderProgram)
    {
        ensureGlContext();

        // Enable program
        GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        glCheck(glUseProgramObjectARB(m_shaderProgram));

        // Get parameter location and assign it new values
        GLint location = glGetUniformLocationARB(m_shaderProgram, name.c_str());
        if (location != -1)
            glCheck(glUniform3fARB(location, x, y, z));
        else
            err() << "Parameter \"" << name << "\" not found in shader" << std::endl;

        // Disable program
        glCheck(glUseProgramObjectARB(program));
    }
}
コード例 #11
0
ファイル: Shader.cpp プロジェクト: ChrisJansson/Graphics
void Shader::SetParameter(const std::string& name, const sf::Transform& transform)
{
    if (myShaderProgram)
    {
        EnsureGlContext();

        // Enable program
        GLhandleARB program = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        GLCheck(glUseProgramObjectARB(myShaderProgram));

        // Get parameter location and assign it new values
        GLint location = glGetUniformLocationARB(myShaderProgram, name.c_str());
        if (location != -1)
            GLCheck(glUniformMatrix4fvARB(location, 1, GL_FALSE, transform.GetMatrix()));
        else
            Err() << "Parameter \"" << name << "\" not found in shader" << std::endl;

        // Disable program
        GLCheck(glUseProgramObjectARB(program));
    }
}
コード例 #12
0
ファイル: glstate.cpp プロジェクト: pzick/apitrace
static inline void
dumpCurrentProgramObj(JSONWriter &json)
{
    GLhandleARB programObj = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
    if (!programObj) {
        return;
    }

    GLint attached_shaders = 0;
    glGetProgramivARB(programObj, GL_OBJECT_ATTACHED_OBJECTS_ARB, &attached_shaders);
    if (!attached_shaders) {
        return;
    }

    GLhandleARB *shaderObjs = new GLhandleARB[attached_shaders];
    GLsizei count = 0;
    glGetAttachedObjectsARB(programObj, attached_shaders, &count, shaderObjs);
    for (GLsizei i = 0; i < count; ++ i) {
       dumpShaderObj(json, shaderObjs[i]);
    }
    delete [] shaderObjs;
}
コード例 #13
0
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_ARBShaderObjects_nglGetHandleARB(JNIEnv *env, jclass clazz, jint pname, jlong function_pointer) {
	glGetHandleARBPROC glGetHandleARB = (glGetHandleARBPROC)((intptr_t)function_pointer);
	GLhandleARB __result = glGetHandleARB(pname);
	return __result;
}
コード例 #14
0
ファイル: p3dshaders.cpp プロジェクト: Benjamin-L/Dinosauria
GLhandleARB        P3DShaderLoader::GetProgramHandle
                                      (bool                HaveDiffuseTex,
                                       bool                HaveNormalMap,
                                       bool                TwoSided) const
 {
  GLhandleARB                          ProgHandle;
  GLhandleARB                          ShaderHandle;
  const GLcharARB                     *SourceStrings[ShaderSrcHeaderLineCount + 1];
  GLint                                LinkStatus;
  bool                                 ShaderOk;

  ProgHandle = FindByProps(HaveDiffuseTex,HaveNormalMap,TwoSided);

  if (ProgHandle != 0)
   {
    return(ProgHandle);
   }

  #ifdef USE_OPENGL_20
  ProgHandle = glCreateProgram();
  #else
  ProgHandle = glCreateProgramObjectARB();
  #endif

  if (ProgHandle != 0)
   {
    SourceStrings[0] = HaveDiffuseTex ? ShaderSrcDefineHaveDiffuseTex :
                                        ShaderSrcEmptyLine;
    SourceStrings[1] = HaveNormalMap  ? ShaderSrcDefineHaveNormalMap  :
                                        ShaderSrcEmptyLine;
    SourceStrings[2] = TwoSided ? ShaderSrcDefineTwoSided :
                                  ShaderSrcEmptyLine;
    SourceStrings[3] = ShaderSrcLineNumberSetup;

    ShaderOk = true;

    if (VertexProgramSrc != 0)
     {
      SourceStrings[ShaderSrcHeaderLineCount] = VertexProgramSrc;

      #ifdef USE_OPENGL_20
      ShaderOk = CompileShaderObject(&ShaderHandle,GL_VERTEX_SHADER,ShaderSrcHeaderLineCount + 1,SourceStrings);
      #else
      ShaderOk = CompileShaderObject(&ShaderHandle,GL_VERTEX_SHADER_ARB,ShaderSrcHeaderLineCount + 1,SourceStrings);
      #endif

      if (ShaderOk)
       {
        #ifdef USE_OPENGL_20
        glAttachShader(ProgHandle,ShaderHandle);
        glDeleteShader(ShaderHandle);
        #else
        glAttachObjectARB(ProgHandle,ShaderHandle);
        glDeleteObjectARB(ShaderHandle);
        #endif
       }
     }

    if (ShaderOk)
     {
      if (FragmentProgramSrc != 0)
       {
        SourceStrings[ShaderSrcHeaderLineCount] = FragmentProgramSrc;

        #ifdef USE_OPENGL_20
        ShaderOk = CompileShaderObject(&ShaderHandle,GL_FRAGMENT_SHADER,ShaderSrcHeaderLineCount + 1,SourceStrings);
        #else
        ShaderOk = CompileShaderObject(&ShaderHandle,GL_FRAGMENT_SHADER_ARB,ShaderSrcHeaderLineCount + 1,SourceStrings);
        #endif

        if (ShaderOk)
         {
          #ifdef USE_OPENGL_20
          glAttachShader(ProgHandle,ShaderHandle);
          glDeleteShader(ShaderHandle);
          #else
          glAttachObjectARB(ProgHandle,ShaderHandle);
          glDeleteObjectARB(ShaderHandle);
          #endif
         }
       }
     }

    if (ShaderOk)
     {
      #ifdef USE_OPENGL_20
      glLinkProgram(ProgHandle);
      #else
      glLinkProgramARB(ProgHandle);
      #endif

      #ifdef USE_OPENGL_20
      glGetProgramiv( ProgHandle,GL_LINK_STATUS,&LinkStatus);
      #else
      glGetObjectParameterivARB( ProgHandle,
                                 GL_OBJECT_LINK_STATUS_ARB,
                                &LinkStatus);
      #endif

      DumpInfoLog(ProgHandle);

      if (LinkStatus)
       {
        GLhandleARB    CurrProgHandle;

        #ifdef USE_OPENGL_20
        glGetIntegerv(GL_CURRENT_PROGRAM,(GLint*)&CurrProgHandle);
        #else
        CurrProgHandle = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
        #endif

        #ifdef USE_OPENGL_20
        glUseProgram(ProgHandle);
        #else
        glUseProgramObjectARB(ProgHandle);
        #endif

        GLint                    Location;

        #ifdef USE_OPENGL_20
        Location = glGetUniformLocation(ProgHandle,"DiffuseTexSampler");
        #else
        Location = glGetUniformLocationARB(ProgHandle,"DiffuseTexSampler");
        #endif

        if (Location != -1)
         {
          #ifdef USE_OPENGL_20
          glUniform1i(Location,0);
          #else
          glUniform1iARB(Location,0);
          #endif
         }

        #ifdef USE_OPENGL_20
        Location = glGetUniformLocation(ProgHandle,"NormalMapSampler");
        #else
        Location = glGetUniformLocationARB(ProgHandle,"NormalMapSampler");
        #endif

        if (Location != -1)
         {
          #ifdef USE_OPENGL_20
          glUniform1i(Location,1);
          #else
          glUniform1iARB(Location,1);
          #endif
         }

        #ifdef USE_OPENGL_20
        glUseProgram(CurrProgHandle);
        #else
        glUseProgramObjectARB(CurrProgHandle);
        #endif
       }
      else
       {
        fprintf(stderr,"error: shader linkage failed\n");

        #ifdef USE_OPENGL_20
        glDeleteProgram(ProgHandle);
        #else
        glDeleteObjectARB(ProgHandle);
        #endif

        ProgHandle = 0;
       }
     }
    else
     {
      #ifdef USE_OPENGL_20
      glDeleteProgram(ProgHandle);
      #else
      glDeleteObjectARB(ProgHandle);
      #endif

      ProgHandle = 0;
     }
   }
  else
   {
    fprintf(stderr,"error: unable to create GLSL program object\n");
   }

  if (ProgHandle != 0)
   {
    P3DShaderEntry Entry;

    Entry.ProgramHandle  = ProgHandle;
    Entry.HaveDiffuseTex = HaveDiffuseTex;
    Entry.HaveNormalMap  = HaveNormalMap;
    Entry.TwoSided       = TwoSided;

    ShaderSet.push_back(Entry);
   }

  return(ProgHandle);
 }
コード例 #15
0
void	SoXipCPUMprRender::renderMPR(int texUnit)
{
	
	// If fragment program is present, get available texture stage and
	// bind it to "tex" in the FP.
	int fp;
	glGetIntegerv(GL_CURRENT_PROGRAM, &fp);
	if (fp && GLOW_ARB_fragment_shader)
	{
		GLhandleARB	programObject = glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
#ifndef DARWIN
		GLint loc	= glGetUniformLocation(programObject,  "tex");
#else /* DARWIN */
		GLint loc	= glGetUniformLocationARB(programObject,  "tex");
#endif /* DARWIN */
		if (loc != -1)
			glUniform1i(loc, texUnit);
	}
	
	GLboolean depthTestEnabled, texture2DEnabled, lightingEnabled,blendEnabled;
	depthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
	texture2DEnabled = glIsEnabled(GL_TEXTURE_2D);
	lightingEnabled = glIsEnabled(GL_LIGHTING);	
	blendEnabled = glIsEnabled(GL_BLEND);	
	
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glDepthMask(false);
	glDisable(GL_LIGHTING);
	
	if ( blendOn.getValue() )
		glEnable(GL_BLEND);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glColor3f(1.0f, 1.0f, 1.0f);
	// Draw a quad
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex2f(-1, -1);
	glTexCoord2f(1, 0);
    glVertex2f(1, -1);
	glTexCoord2f(1, 1);
	glVertex2f(1, 1);
	glTexCoord2f(0, 1);
	glVertex2f(-1, 1);
    glEnd();

	//restore some previous openGL states
	depthTestEnabled ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
	texture2DEnabled ? glEnable(GL_TEXTURE_2D) : glDisable(GL_TEXTURE_2D);
	lightingEnabled ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING);	
	blendEnabled ? glEnable(GL_BLEND) : glDisable(GL_BLEND);

	glPopMatrix();
	glMatrixMode(GL_TEXTURE);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
コード例 #16
0
ファイル: sotest.c プロジェクト: Distrotech/mesa-demos
void InitScene (void)
{
   GLint params[1];
   const char *tab[2];

   /*
    * GL should silently ignore calls that delete object 0.
    */
   begintest (TT_GETERROR_NOERROR, "glDeleteObject(0)");
   glDeleteObjectARB (0);
   endtest ();

   /*
    * GL generates an error on invalid object handle.
    */
   begintest (TT_GETERROR_INVALIDVALUE, "Pass invalid non-zero object handle");
   glDeleteObjectARB (find_invalid_handle ());
   endtest ();
   glUseProgramObjectARB (find_invalid_handle ());
   endtest ();

   /*
    * Create object. GL should return unique non-zero values.
    */
   begintest (TT_PARAM1_NONZERO, "Create object");
   vert = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);
   endtest1 (vert);
   frag = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
   endtest1 (frag);
   prog = glCreateProgramObjectARB ();
   endtest1 (prog);
   endtest1 (vert != frag && frag != prog && prog != vert);

   /*
    * Link empty program.
    */
   begintest (TT_PARAM1_NONZERO, "Link empty program");
   glLinkProgramARB (prog);
   endtest1 (CheckObjectStatus (prog));

   /*
    * Use empty program object. Empty program objects are valid.
    */
   begintest (TT_GETERROR_NOERROR, "Use empty program object");
   glUseProgramObjectARB (prog);
   endtest ();

   /*
    * Attach invalid object handles. Program object 0 should not be accepted.
    */
   begintest (TT_GETERROR_INVALIDVALUE, "Attach invalid object handle");
   glAttachObjectARB (0, find_invalid_handle ());
   endtest ();
   glAttachObjectARB (0, frag);
   endtest ();
   glAttachObjectARB (find_invalid_handle (), find_invalid_handle ());
   endtest ();
   glAttachObjectARB (find_invalid_handle (), frag);
   endtest ();
   glAttachObjectARB (prog, find_invalid_handle ());
   endtest ();

   /*
    * Attach valid object handles with wrong semantics.
    */
   begintest (TT_GETERROR_INVALIDOPERATION, "Attach object badly");
   glAttachObjectARB (vert, frag);
   endtest ();
   glAttachObjectARB (vert, prog);
   endtest ();
   glAttachObjectARB (prog, prog);
   endtest ();

   /*
    * Detach non-attached object.
    */
   begintest (TT_GETERROR_INVALIDOPERATION, "Detach non-attached object");
   glDetachObjectARB (prog, vert);
   endtest ();
   glDetachObjectARB (prog, frag);
   endtest ();

   /*
    * Attach shader.
    */
   begintest (TT_GETERROR_NOERROR, "Attach shader to program object");
   glAttachObjectARB (prog, vert);
   endtest ();
   glAttachObjectARB (prog, frag);
   endtest ();

   /*
    * Attach object twice.
    */
   begintest (TT_GETERROR_INVALIDOPERATION, "Attach object twice");
   glAttachObjectARB (prog, vert);
   endtest ();
   glAttachObjectARB (prog, frag);
   endtest ();

   /*
    * Detach attached object.
    */
   begintest (TT_GETERROR_NOERROR, "Detach attached object");
   glDetachObjectARB (prog, vert);
   endtest ();
   glDetachObjectARB (prog, frag);
   endtest ();

   /*
    * Attach shader again.
    */
   begintest (TT_GETERROR_NOERROR, "Attach shader again");
   glAttachObjectARB (prog, vert);
   endtest ();
   glAttachObjectARB (prog, frag);
   endtest ();

   /*
    * Delete attached object.
    */
   begintest (TT_GETERROR_NOERROR, "Delete attached object");
   glDeleteObjectARB (vert);
   endtest ();
   glDeleteObjectARB (frag);
   endtest ();

   /*
    * Query delete status. It should return TRUE. Object handles are still valid
    * as they are referenced by program object container.
    */
   begintest (TT_PARAM1_NONZERO, "Query delete status");
   glGetObjectParameterivARB (vert, GL_OBJECT_DELETE_STATUS_ARB, params);
   endtest1 (params[0]);
   glGetObjectParameterivARB (frag, GL_OBJECT_DELETE_STATUS_ARB, params);
   endtest1 (params[0]);

   /*
    * Delete already deleted attached object. The behaviour is undefined, but we
    * check for no errors. The object still exists, so the handle value is okay.
    * In other words, these calls should be silently ignored by GL.
    */
   begintest (TT_GETERROR_NOERROR, "Delete already deleted attached object");
   glDeleteObjectARB (vert);
   endtest ();
   glDeleteObjectARB (frag);
   endtest ();

   /*
    * Compile shader source with syntax error.
    */
   begintest (TT_PARAM1_ZERO, "Compile shader source with syntax error");
   glShaderSourceARB (vert, 1, &invsynvertsrc, NULL);
   glCompileShaderARB (vert);
   endtest1 (CheckObjectStatus (vert));
   glShaderSourceARB (frag, 1, &invsynfragsrc, NULL);
   glCompileShaderARB (frag);
   endtest1 (CheckObjectStatus (frag));

   /*
    * Compile shader source with semantic error.
    */
   begintest (TT_PARAM1_ZERO, "Compile shader source with semantic error");
   glShaderSourceARB (vert, 1, &invsemvertsrc, NULL);
   glCompileShaderARB (vert);
   endtest1 (CheckObjectStatus (vert));
   glShaderSourceARB (frag, 1, &invsemfragsrc, NULL);
   glCompileShaderARB (frag);
   endtest1 (CheckObjectStatus (frag));

   /*
    * Link ill-formed vertex-fragment program.
    */
   begintest (TT_PARAM1_ZERO, "Link ill-formed vertex-fragment program");
   glLinkProgramARB (prog);
   endtest1 (CheckObjectStatus (prog));

   /*
    * Use badly linked program object.
    */
   begintest (TT_GETERROR_INVALIDOPERATION, "Use badly linked program object");
   glUseProgramObjectARB (prog);
   endtest ();

   /*
    * Compile well-formed shader source. Check if multi-string sources can be handled.
    */
   begintest (TT_PARAM1_NONZERO, "Compile well-formed shader source");
   tab[0] = uniforms;
   tab[1] = validvertsrc;
   glShaderSourceARB (vert, 2, tab, NULL);
   glCompileShaderARB (vert);
   endtest1 (CheckObjectStatus (vert));
   tab[0] = uniforms;
   tab[1] = validfragsrc;
   glShaderSourceARB (frag, 2, tab, NULL);
   glCompileShaderARB (frag);
   endtest1 (CheckObjectStatus (frag));

   /*
    * Link vertex-fragment program.
    */
   begintest (TT_PARAM1_NONZERO, "Link vertex-fragment program");
   glLinkProgramARB (prog);
   endtest1 (CheckObjectStatus (prog));

   /*
    * Use valid linked program object.
    */
   begintest (TT_GETERROR_NOERROR, "Use linked program object");
   glUseProgramObjectARB (prog);
   endtest ();

   /*
    * Get current program.
    */
   begintest (TT_PARAM1_NONZERO, "Get current program");
   endtest1 (glGetHandleARB (GL_PROGRAM_OBJECT_ARB) == prog);

   /*
    * Use 0 program object.
    */
   begintest (TT_GETERROR_NOERROR, "Use 0 program object");
   glUseProgramObjectARB (0);
   endtest ();

   /*
    * Query uniform location. Uniforms with gl_ prefix cannot be queried.
    */
   begintest (TT_PARAM1_NONZERO, "Query uniform location");
   endtest1 (glGetUniformLocationARB (prog, "gl_ModelViewMatrix") == -1);
   endtest1 (glGetUniformLocationARB (prog, "UniformThatDoesNotExist") == -1);
   endtest1 (glGetUniformLocationARB (prog, "") == -1);
   endtest1 (glGetUniformLocationARB (prog, "CommonUniform") != -1);
   endtest1 (glGetUniformLocationARB (prog, "VertexUniform") != -1);
   endtest1 (glGetUniformLocationARB (prog, "FragmentUniform") != -1);

   /*
    * Query attrib location. Attribs with gl_ prefix cannot be queried.
    * When gl_Vertex is used, none of the generic attribs can have index 0.
    */
   begintest (TT_PARAM1_NONZERO, "Query attrib location");
   endtest1 (glGetAttribLocationARB (prog, "gl_Vertex") == -1);
   endtest1 (glGetAttribLocationARB (prog, "AttribThatDoesNotExist") == -1);
   endtest1 (glGetAttribLocationARB (prog, "") == -1);
   endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") > 0);
   endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") > 0);

   /*
    * Bind attrib locations, link and check if locations are correct.
    */
   begintest (TT_PARAM1_NONZERO, "Bind attrib location #1");
   glBindAttribLocationARB (prog, 1, "FirstAttrib");
   glBindAttribLocationARB (prog, 2, "SecondAttrib");
   glLinkProgramARB (prog);
   endtest1 (CheckObjectStatus (prog));
   endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") == 1);
   endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") == 2);

   /*
    * Bind attrib locations in different order. Link and check if locations are correct.
    */
   begintest (TT_PARAM1_NONZERO, "Bind attrib location #2");
   glBindAttribLocationARB (prog, 1, "SecondAttrib");
   glBindAttribLocationARB (prog, 2, "FirstAttrib");
   glLinkProgramARB (prog);
   endtest1 (CheckObjectStatus (prog));
   endtest1 (glGetAttribLocationARB (prog, "SecondAttrib") == 1);
   endtest1 (glGetAttribLocationARB (prog, "FirstAttrib") == 2);

   /*
    * Detach deleted object.
    */
   begintest (TT_GETERROR_NOERROR, "Detach deleted object");
   glDetachObjectARB (prog, vert);
   endtest ();
   glDetachObjectARB (prog, frag);
   endtest ();

   /*
    * Delete deleted detached object.
    */
   begintest (TT_GETERROR_INVALIDVALUE, "Delete deleted detached object");
   glDeleteObjectARB (vert);
   endtest ();
   glDeleteObjectARB (frag);
   endtest ();

   exit (0);
}
コード例 #17
0
ファイル: GLSLShader.cpp プロジェクト: mhdsedighi/SOFA
GLhandleARB GLSLShader::GetActiveShaderProgram()
{
    if (!GLSLIsSupported) return 0;
    return glGetHandleARB(GL_PROGRAM_OBJECT_ARB);
}