Click here to Skip to main content
15,886,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
C++
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 :
C++
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 :
C++
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.
Posted
Comments
Santhosh G_ 27-Jun-13 8:44am    
Please check the performance of the shader without the rotation in shader. I suspect this issue is not related to the rotation code. It might be something else, like old driver etc.
Balaji_mcr 27-Jun-13 9:04am    
Thank you @Santhosh G_ your intuition is correct. It takes 50% of my processor usage for this driver itself. But why it is not taking 50% in some other PC's of same config?
I've also tried to load using some other library functions like GLFW & GLEW it took only 12-20% of CPU usage. But when loading Rotation Function's it takes 50% of CPU Usage in my pc. But not in others PC.
Santhosh G_ 27-Jun-13 9:48am    
>>> But when loading Rotation Function's it takes 50% of CPU Usage in my pc. But not in others PC.
What is the behavior without rotation code in shader ? Still CPU usage is 50% or decreased?
Santhosh G_ 27-Jun-13 9:52am    
Which process consumes cpu ? Is it your process or any other nvidia driver supporting process like nvsc32.exe etc ?
We also faced a problem, sometimes cpu usage of my app is increased.
https://forums.geforce.com/default/topic/481759/nvoglnt-dll-33-drvcopycontext-take-a-sleep-/#3455522
Balaji_mcr 28-Jun-13 10:27am    
Actually my application is taking too much of time due to 60 fps. I tried to control this CPU usage by putting the application to sleep for few ms in OnIdle(). then it worked. But i don't know which process is taking too much time even for a simple model rendering process.

1 solution

Hi the solution is very simple. By default freeglut is rendering at 60 fps & it is constantly calling the OnIdle() number of times.(OnIdle() is called when Message Queue is Empty).

That's why the application takes more CPU usage. so if u don't want to use this Idle function we can remove that function from call back list from the glut main loop in Header file.

By this way we can reduce the CPU usage.(if needed).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900