Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Factors affecting the Efficiency of Shaders(GLSL)?

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    9

    Exclamation Factors affecting the Efficiency of Shaders(GLSL)?

    My application simply loads an image as a Texture & rotate it in Z-axis.This is my code.
    ----Beginning of code----
    Reference Source code.
    http://www.opengl.org/sdk/docs/tutor...SL_Texture.zip
    main.cpp
    Code :
    virtual void OnInit()
    {
    	glClearColor(0.0f,0.0f,0.0f,0.0f);
    	glShadeModel(GL_SMOOTH);
    	glEnable(GL_DEPTH_TEST);
    	glEnable(GL_TEXTURE_2D);
     
    	shader = SM.loadfromFile("vertexshader.txt","fragmentshader.txt"); // load (and compile, link) from file
    	if (shader==0) 
    	std::cout << "Error Loading, compiling or linking shader\n";
    	else
    	  {         
    		 ProgramObject = shader->GetProgramObject();
    		 locAngle = glGetUniformLocation(ProgramObject, "uAngle");         
    	  }
     
    	  // Create a Texture from file.
    	  pTexture = cwc::TextureFactory::CreateTextureFromFile("Penguins.jpg");
     
    	  if (!pTexture)
    		 std::cout << "***WARNING: Failed loading texture!!\n";
    }
     
    virtual void OnRender(void)
    {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
      if (pTexture) 
      {
    	 pTexture->bind(0);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);	
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Disable Filtering!
      }
     
      if (shader) 
      {
    	 shader->begin();
    	 glUniform1f(locAngle, angle);         
      }
     
      if (shader) shader->setUniform1i("myTexture", 0);
     
     
    	  glBegin(GL_QUADS);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-glXpos, -glYpos,  glZpos);//Left Bottom
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( glXpos, -glYpos,  glZpos);//Right Bottom
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( glXpos,  glYpos,  glZpos);//Right Top
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-glXpos,  glYpos,  glZpos);//Left Top		
    	  glEnd();
     
    	  if (shader) shader->end();
    	  glutSwapBuffers();	
    }

    Vertex Shader Source:
    Code :
    uniform float uAngle;
    varying vec2 vTexCoord;
    attribute vec4 position;
     
    void main(void)
    {
    	mat3 rotation = mat3
    	(
    		vec3( cos(uAngle),  sin(uAngle),  0.0),
    		vec3(-sin(uAngle),  cos(uAngle),  0.0),
    		vec3(        0.0,           0.0,  1.0)
    	);	
       vec3 projected_position =  rotation  * position.xyz;      
       vTexCoord = gl_MultiTexCoord0.xy;  
       gl_Position = gl_ModelViewProjectionMatrix * vec4(projected_position, 1.0); 
    }
    Fragment Shader Source:
    Code :
    uniform sampler2D myTexture;
    varying vec2 vTexCoord;
    void main (void)  
    {  
        vec4 color = texture2D(myTexture, vTexCoord);      
        gl_FragColor = color;
    }
    ----End----
    Now my question is when i run this application in my PC it runs well(Spec:nvidia Geforce 210 GPU ,Processor:Intel 3 GHz)
    But it consumes 50-55% of processor usage in my PC whereas it consumes only 2-8% of processor usage in some other PC's.
    I've also tried to do the same Image Rotation using glRotate() & through custom Rotation matrix methods. it consumes only 0-2% of processor usage only.
    How glRotate() consumes only 1 of processor usage?
    What causes this increased Processor usage?
    What are the factors which affect this GLSL performance?
    Experts please help me on this. Thank you.
    Last edited by Balaji_mcr; 06-27-2013 at 03:27 AM. Reason: Code Correction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •