Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Should Allegro on OpenGL in Windows's cpu be fluctuating?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Should Allegro on OpenGL in Windows's cpu be fluctuating?
jmasterx
Member #11,410
October 2009

*Title should say CPU Usage

For my game, I want to use GLSL shaders so I explicitly set the ALLEGRO_OPENGL flag when creating a display. However, in Windows, it causes the cpu usage to fluctuate quite a bit compared to Direct3D. This is consistent with anything I compile with Allegro. Is this normal, is it actually consuming what it says?

This happens on my laptop which has an NVidia GeFoce 9400m video card. It also fluctuates on my PC too though, and both have latest drivers.

Is it because there is a substantial advantage to using Direct3D on Windows? If so, would CG be a better alternative?

Thanks

Trent Gamblin
Member #261
April 2000
avatar

Can you give me an example I can compile to test it? I have the same 9400M in my laptop. It really should not be doing that, if it is there might be a bug somewhere. One thing that might be an issue is reloading the matrices all the time. I noticed that using PROGRAMMBLE_PIPELINE is a bit slower running than those that don't use shaders (on iphone). My first guess in that case was transferring matrices into shaders. Anyway, I will test an example if you have one.

jmasterx
Member #11,410
October 2009

I've attached an exe I made which uses a shader. Although it happens even when shaders are not used. It goes anywhere from 5 to 50% on mine. But what it's doing is rather simple. Without shaders in D3D this runs consistently around 3%.

The SRC is a test bed and a bit of a mess but it might help:

#SelectExpand
1//Allegro 5 2#include <allegro5/allegro.h> 3#include <allegro5/allegro5.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_primitives.h> 6#include <allegro5/allegro_font.h> 7#include <allegro5/allegro_ttf.h> 8#include <allegro5/allegro_opengl.h> 9 10#include <allegro5/allegro_native_dialog.h> 11#include <stdlib.h> 12#include <vector> 13#include <string> 14#include <ctime> 15#include <iostream> 16#include <fstream> 17#include "SKALE/Skeleton.hpp" 18#include "SKALE/IKSolver.hpp" 19#include <math.h> 20 21ALLEGRO_BITMAP *backbuffer = NULL; 22GLhandleARB tinter; 23GLhandleARB tinter_shader; 24 25skl::IKSolver solver; 26 27 float r = 0.5, g = 0.5, b = 1, ratio = 0; 28 int dir = 1; 29 30 std::ifstream myFile = std::ifstream("shader.txt",std::ios::in); 31 32 double start; 33 GLint loc; 34 35#define FRAME_RATE 60 36 37//Globals 38ALLEGRO_DISPLAY *display = NULL; 39ALLEGRO_TIMER *timer = NULL; 40ALLEGRO_EVENT event; 41ALLEGRO_EVENT_QUEUE *queue = NULL; 42ALLEGRO_BITMAP *rope; 43bool done = false; 44skl::Skeleton skeleton; 45 46std::string shader; 47 48const char* shade[1]; 49 50void loadShader() 51{ 52 // Open the file 53 std::ifstream File("shader.txt", std::ios::in); 54 if (!File.is_open()) { }// Get the size of the file 55 File.seekg(0, std::ios::end);int Size = File.tellg(); 56 File.seekg(0, std::ios::beg); 57 File.clear();// Read in the shader source code 58 char *Source = new char[Size + 1];memset(Source, 0, Size); 59 File.read(Source, Size); 60 File.close(); 61 Source[Size] = '\0'; 62 63 shade[0] = Source; 64 65} 66void resizeBackBufferToDisplay() 67{ 68 if(backbuffer) 69 { 70 al_destroy_bitmap(backbuffer); 71 backbuffer = NULL; 72 } 73 74 backbuffer = al_create_bitmap(al_get_display_width(al_get_current_display()), 75 al_get_display_height(al_get_current_display())); 76} 77void initializeAllegro() { 78 //Initialize Allegro 79 if(!al_init()) 80 { 81 throw std::exception("Allegro failed to initialize"); 82 } 83 84 if(!al_init_image_addon()) 85 { 86 throw std::exception("Allegro image addon failed to initialize"); 87 } 88 al_init_font_addon(); 89 90 if(!al_init_ttf_addon()) 91 { 92 throw std::exception("Allegro ttf addon failed to initialize"); 93 } 94 95 if(!al_init_primitives_addon()) 96 { 97 throw std::exception("Allegro primitives addon failed to initialize"); 98 } 99 if(!al_install_mouse()) 100 { 101 throw std::exception("Allegro mouse failed to initialize"); 102 } 103 if(!al_install_keyboard()) 104 { 105 throw std::exception("Allegro keyboard failed to initialize"); 106 } 107 108 // Start a timer to regulate speed 109 timer = al_create_timer(1.0/FRAME_RATE); 110 al_start_timer(timer); 111 112 //show screen 113 114 al_set_new_display_flags(ALLEGRO_RESIZABLE | ALLEGRO_OPENGL); 115 116 display = al_create_display(640,480); 117 118 if(!display) 119 { 120 done = true; 121 } 122 //show the mouse 123 al_show_mouse_cursor(display); 124 125 126 127 //Window Title 128 al_set_window_title(display,"SKALE - Example"); 129 130 queue = al_create_event_queue(); 131 132 rope = al_load_bitmap("rope.png"); 133 resizeBackBufferToDisplay(); 134 135 loadShader(); 136 137 tinter_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 138 139 glShaderSourceARB(tinter_shader, 1, shade, NULL); 140 glCompileShaderARB(tinter_shader); 141 tinter = glCreateProgramObjectARB(); 142 glAttachObjectARB(tinter, tinter_shader); 143 glLinkProgramARB(tinter); 144 char log[500]; 145 146 glGetProgramInfoLog(tinter,500,NULL,log); 147 std::cout << log << std::endl; 148 149 loc = glGetUniformLocationARB(tinter, "backBuffer"); 150 glUniform1iARB(loc, al_get_opengl_texture(backbuffer)); 151 152} 153 154void buildSkeleton() 155{ 156 skeleton.load("Skeleton.txt"); 157 158} 159 160bool Inisde(float x,float y,float l,float t,float r,float b ) 161{ 162 return x > l && x < r && y > t && y < b; 163} 164 165skl::Bone* findBone(float x, float y, skl::Bone* root) 166{ 167 float x1, y1, x2, y2; 168 169 x1 = root->getFrameX(); 170 x2 = root->getFrameX(); 171 y1 = root->getFrameY(); 172 y2 = root->getFrameY(); 173 174 x1 -= 12.0f; 175 y1 -= 12.0f; 176 x2 += 12.0f; 177 y2 += 12.0f; 178 179 if(Inisde(x,y,x1,y1,x2,y2)) 180 { 181 return root; 182 } 183 184 skl::Bone* result = NULL; 185 for(std::list<skl::Bone>::iterator it = root->begin(); it != root->end(); ++it ) 186 { 187 result = findBone(x,y,&(*it)); 188 if(result) 189 { 190 return result; 191 } 192 } 193 194 return NULL; 195} 196bool inverse = false; 197int fr = 0; 198void renderSkeleton(skl::Bone* root) 199{ 200 201 if(root->getParent()) 202 { 203 204 al_draw_scaled_rotated_bitmap(rope,al_get_bitmap_width(rope) / 2.0f, 205 0, 206 root->getParent()->getFrameX(), root->getParent()->getFrameY(),0.1f,(root->getLength() * 1.1f) / 207 al_get_bitmap_height(rope) ,root->getFrameAngle() - (3.1415f / 2.0f),0); 208 209 al_draw_line( 210 root->getParent()->getFrameX(),root->getParent()->getFrameY(), 211 root->getFrameX(),root->getFrameY(),al_map_rgb(255,0,0),1.0f); 212 al_draw_filled_circle(root->getFrameX(),root->getFrameY(),4.0f,al_map_rgb(50,200,0)); 213 214 } 215 else 216 { 217 al_draw_filled_circle(root->getFrameX(),root->getFrameY(),4.0f,al_map_rgb(50,200,0)); 218 } 219 220 for(std::list<skl::Bone>::iterator it = root->begin(); it != root->end(); ++it) 221 { 222 renderSkeleton(&(*it)); 223 } 224} 225 226skl::Bone* boneUnderMouse = NULL; 227int mouseX = 0; 228int mouseY = 0; 229int startX = 0; 230int startY = 0; 231float startAngle; 232float realStartAngle; 233 234float mouseXF; 235float mouseYF; 236 237float dot(float aX, float aY, float bX, float bY) 238{ 239 return ((aX * bX) + (aY * bY)); 240} 241float dots(float aX, float aY, float bX, float bY) 242{ 243 return ((aX * bX) - (aY * bY)); 244} 245 246 247 float SimplifyAngle(float angle) 248{ 249 angle = fmod(angle,2.0f * 3.141592f); 250 251 if( angle < -3.141592f ) 252 angle += (2.0f * 3.141592); 253 else if( angle > 3.141592f ) 254 angle -= (2.0f * 3.141592f); 255 return angle; 256} 257 void render(); 258 void inverseKinematics(float targetX, float targetY, skl::Bone* targetBone) 259 { 260 261 std::string stopBone = "ROOT"; 262 //=== 263 // Track the end effector position (the final bone) 264 double endX = targetBone->getFrameX(); 265 double endY = targetBone->getFrameY(); 266 267 //=== 268 // Perform CCD on the bones by optimizing each bone in a loop 269 // from the final bone to the root bone 270 bool modifiedBones = false; 271 272 while(targetBone->getName() != stopBone) 273 { 274 // Get the vector from the current bone to the end effector position. 275 double curToEndX = endX - targetBone->getParent()->getFrameX(); 276 double curToEndY = endY - targetBone->getParent()->getFrameY(); 277 double curToEndMag = sqrt( curToEndX*curToEndX + curToEndY*curToEndY ); 278 279 // Get the vector from the current bone to the target position. 280 double curToTargetX = targetX - targetBone->getParent()->getFrameX(); 281 double curToTargetY = targetY - targetBone->getParent()->getFrameY(); 282 double curToTargetMag = sqrt( curToTargetX*curToTargetX 283 + curToTargetY*curToTargetY ); 284 285 // Get rotation to place the end effector on the line from the current 286 // joint position to the target position. 287 double cosRotAng; 288 double sinRotAng; 289 double endTargetMag = (curToEndMag*curToTargetMag); 290 if( endTargetMag <= 0.00001f ) 291 { 292 cosRotAng = 1.0f; 293 sinRotAng = 0.0f; 294 } 295 else 296 { 297 cosRotAng = (curToEndX*curToTargetX + curToEndY*curToTargetY) / endTargetMag; 298 sinRotAng = (curToEndX*curToTargetY - curToEndY*curToTargetX) / endTargetMag; 299 } 300 301 // Clamp the cosine into range when computing the angle (might be out of range 302 // due to floating point error). 303 double rotAng = acosf( max(-1.0f, min(1.0f,cosRotAng) ) ); 304 if( sinRotAng < 0.0f ) 305 rotAng = -rotAng; 306 307 if(targetBone->getName() == "RFoot") 308 { 309 float a = SimplifyAngle(targetBone->getAngle()) + SimplifyAngle(rotAng) > 3.14f; 310 if (a > 3.0 && a <= 3.14159) 311 a = 3.0; 312 else if (a > 3.14159 && a < 0.0) 313 a = 0.0; 314 315 rotAng = a - SimplifyAngle(targetBone->getAngle()); 316 317 } 318 // Rotate the end effector position. 319 endX = targetBone->getParent()->getFrameX() + cosRotAng*curToEndX - sinRotAng*curToEndY; 320 endY = targetBone->getParent()->getFrameY() + sinRotAng*curToEndX + cosRotAng*curToEndY; 321 322 // Rotate the current bone in local space (this value is output to the user) 323 targetBone->setAngle(SimplifyAngle(targetBone->getAngle()) + SimplifyAngle(rotAng)); 324 325 // Check for termination 326 double endToTargetX = (targetX-endX); 327 double endToTargetY = (targetY-endY); 328 329 330 // Track if the arc length that we moved the end effector was 331 // a nontrivial distance. 332 if( !modifiedBones && fabs(rotAng)*curToEndMag > 0.0001f ) 333 { 334 modifiedBones = true; 335 } 336 337 targetBone = targetBone->getParent(); 338 } 339 340 341 } 342 343void render() 344{ 345 346 347 al_set_target_bitmap(backbuffer); 348 349 double now, diff; 350 351 now = al_get_time(); 352 diff = now - start; 353 start = now; 354 ratio += diff * 0.5 * dir; 355 if (dir < 0 && ratio < 0) { 356 ratio = 0; 357 dir = -dir; 358 } 359 else if (dir > 0 && ratio > 1) { 360 ratio = 1; 361 dir = -dir; 362 } 363 364 al_clear_to_color(al_map_rgb(240,240,240)); 365 366 skeleton.processAnimation(); 367 skeleton.updateBones(); 368 369 renderSkeleton(skeleton.getRoot()); 370 371 glUseProgramObjectARB(tinter); 372 373 al_set_target_bitmap(al_get_backbuffer(al_get_current_display())); 374 al_draw_bitmap(backbuffer,0,0,0); 375 glUseProgramObjectARB(0); 376al_flip_display(); 377 378 379 380 381} 382 383 384int main(int argc, char *argv[]) 385 386{ 387 initializeAllegro(); 388 buildSkeleton(); 389 390 glUseProgramObjectARB(tinter); 391 loc = glGetUniformLocationARB(tinter, "resolution"); 392 glUniform2fARB(loc, (float)al_get_display_width(al_get_current_display()), 393 (float)al_get_display_height(al_get_current_display())); 394 395 start = al_get_time(); 396 397 bool needRedraw = true; 398 // Start the event queue to handle keyboard input, mouse and our timer 399 400 al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)al_get_keyboard_event_source()); 401 al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)al_get_mouse_event_source()); 402 al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)timer); 403 al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE*)display); 404 405 while(!done) { 406 407 // Block until an event enters the queue 408 al_wait_for_event(queue, &event); 409 410 //Handle rendering and logic 411 if (needRedraw && al_event_queue_is_empty(queue)) { 412 render(); 413 414 415 needRedraw = false; 416 } 417 418 419 switch(event.type) { 420 421 case ALLEGRO_EVENT_TIMER: 422 if(event.timer.source == timer) 423 { 424 425 needRedraw = true; 426 } 427 428 break; 429 case ALLEGRO_EVENT_DISPLAY_RESIZE: 430 431 al_acknowledge_resize(event.display.source); 432 resizeBackBufferToDisplay(); 433 al_set_target_bitmap(backbuffer); 434 435 double now, diff; 436 437 now = al_get_time(); 438 diff = now - start; 439 start = now; 440 ratio += diff * 0.5 * dir; 441 if (dir < 0 && ratio < 0) { 442 ratio = 0; 443 dir = -dir; 444 } 445 else if (dir > 0 && ratio > 1) { 446 ratio = 1; 447 dir = -dir; 448 } 449 450 al_clear_to_color(al_map_rgb(240,240,240)); 451 452 skeleton.processAnimation(); 453 skeleton.updateBones(); 454 455 renderSkeleton(skeleton.getRoot()); 456 457 458 459 al_set_target_bitmap(al_get_backbuffer(al_get_current_display())); 460 461 glUseProgramObjectARB(tinter); 462 loc = glGetUniformLocationARB(tinter, "resolution"); 463 glUniform2fARB(loc, (float)al_get_display_width(al_get_current_display()), 464 (float)al_get_display_height(al_get_current_display())); 465 466 al_draw_bitmap(backbuffer,0,0,0); 467 glUseProgramObjectARB(0); 468 al_flip_display(); 469 470 471 break; 472 case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: 473 resizeBackBufferToDisplay(); 474 break; 475 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: 476 mouseX = event.mouse.x; 477 mouseY = event.mouse.y; 478 startX = mouseX; 479 startY = mouseY; 480 boneUnderMouse = findBone((float)mouseX,(float)mouseY,skeleton.getRoot()); 481 if(boneUnderMouse) 482 { 483 if(boneUnderMouse->getParent()) 484 { 485 startX = boneUnderMouse->getParent()->getFrameX(); 486 startY = boneUnderMouse->getParent()->getFrameY(); 487 } 488 startAngle = boneUnderMouse->getAngle(); 489 realStartAngle = boneUnderMouse->getFrameAngle(); 490 } 491 492 493 break; 494 case ALLEGRO_EVENT_MOUSE_AXES: 495 496 497 498 if(boneUnderMouse) 499 { 500 /*boneUnderMouse->setAngle(boneUnderMouse->getAngle() - boneUnderMouse->getFrameAngle() + (atan2((float)startY - 501 event.mouse.y,startX - event.mouse.x)) + 3.1415f );*/ 502 solver.solve( 503 &skeleton,boneUnderMouse,(float)event.mouse.x,(float)event.mouse.y); 504 skeleton.updateBones(); 505 //skeleton.save("Skeleton.txt"); 506 } 507 mouseXF = (float)event.mouse.x / (float)(al_get_display_width(al_get_current_display()) + 1.0f); 508 mouseYF = (float)event.mouse.y / (float)(al_get_display_height(al_get_current_display()) + 1.0f); 509 glUseProgramObjectARB(tinter); 510 loc = glGetUniformLocationARB(tinter,"mouse"); 511 glUniform2fARB(loc,(float)event.mouse.x,(float)event.mouse.y / (float)al_get_display_height(al_get_current_display())); 512 513 glUseProgramObjectARB(0); 514 break; 515 case ALLEGRO_EVENT_MOUSE_BUTTON_UP: 516 boneUnderMouse = NULL; 517 break; 518 case ALLEGRO_EVENT_DISPLAY_CLOSE: 519 return 0; 520 break; 521 } 522 } 523 524 return 0; 525}

Thanks for testing.

Trent Gamblin
Member #261
April 2000
avatar

Can you include all the source that's needed to compile it? Have you tried profiling it to see where most time is spent? It seems to take around 100% cpu most of the time here.

jmasterx
Member #11,410
October 2009

Here is the source code for my SKALE API thus far, it is meant to be compiled with MSVC. Thanks

Trent Gamblin
Member #261
April 2000
avatar

Sorry, don't have an Allegro+MSVC environment set up. Will it compile with MinGW?

jmasterx
Member #11,410
October 2009

It uses std::exception with a constructor which is non standard, (for now) and you need to add an include directory of the solution dir since I use "SKALE/blah..." Other than that it should build in g++ / mingw

Trent Gamblin
Member #261
April 2000
avatar

I get a whole bunch of errors:


In file included from Animation.hpp:4,
                 from Animation.cpp:1:
../SKALE/KeyFrame.hpp:7: error: ‘size_t’ does not name a type
../SKALE/KeyFrame.hpp:9: error: ‘size_t’ has not been declared
../SKALE/KeyFrame.hpp:12: error: ISO C++ forbids declaration of ‘size_t’ with no type
../SKALE/KeyFrame.hpp:12: error: expected ‘;’ before ‘&’ token
In file included from Bone.cpp:1:
../SKALE/Bone.hpp:19: error: field ‘mName’ has incomplete type
../SKALE/Bone.hpp:42: error: default argument for parameter of type ‘const std::string&’ has type ‘const char [1]’
Bone.cpp: In constructor ‘skl::Bone::Bone(float, float, float, float, float, float, bool, const std::string&, skl::Bone*)’:
Bone.cpp:15: error: class ‘skl::Bone’ does not have any field named ‘mName’
Bone.cpp: In member function ‘const std::string& skl::Bone::getName() const’:
Bone.cpp:149: error: ‘mName’ was not declared in this scope
Bone.cpp: In member function ‘void skl::Bone::setName(const std::string&)’:
Bone.cpp:186: error: ‘mName’ was not declared in this scope
/usr/include/c++/4.2.1/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = KeyFrame]’:
/usr/include/c++/4.2.1/bits/stl_algo.h:2758:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<KeyFrame*, std::vector<KeyFrame, std::allocator<KeyFrame> > >, _Size = long int]’
/usr/include/c++/4.2.1/bits/stl_algo.h:2829:   instantiated from ‘void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<KeyFrame*, std::vector<KeyFrame, std::allocator<KeyFrame> > >]’
Bone.cpp:200:   instantiated from here
/usr/include/c++/4.2.1/bits/stl_algo.h:91: error: passing ‘const KeyFrame’ as ‘this’ argument of ‘bool KeyFrame::operator<(const KeyFrame&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:92: error: passing ‘const KeyFrame’ as ‘this’ argument of ‘bool KeyFrame::operator<(const KeyFrame&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:94: error: passing ‘const KeyFrame’ as ‘this’ argument of ‘bool KeyFrame::operator<(const KeyFrame&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:98: error: passing ‘const KeyFrame’ as ‘this’ argument of ‘bool KeyFrame::operator<(const KeyFrame&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:100: error: passing ‘const KeyFrame’ as ‘this’ argument of ‘bool KeyFrame::operator<(const KeyFrame&)’ discards qualifiers
In file included from ../SKALE/IKSolver.hpp:4,
                 from IKSolver.cpp:1:
../SKALE/Bone.hpp:19: error: field ‘mName’ has incomplete type
../SKALE/Bone.hpp:42: error: default argument for parameter of type ‘const std::string&’ has type ‘const char [1]’
In file included from KeyFrame.cpp:1:
KeyFrame.hpp:7: error: ‘size_t’ does not name a type
KeyFrame.hpp:9: error: ‘size_t’ has not been declared
KeyFrame.hpp:12: error: ISO C++ forbids declaration of ‘size_t’ with no type
KeyFrame.hpp:12: error: expected ‘;’ before ‘&’ token
KeyFrame.cpp:4: error: ‘size_t’ has not been declared
KeyFrame.cpp: In constructor ‘KeyFrame::KeyFrame(float, int)’:
KeyFrame.cpp:5: error: class ‘KeyFrame’ does not have any field named ‘mFrame’
KeyFrame.cpp: At global scope:
KeyFrame.cpp:20: error: expected initializer before ‘&’ token
KeyFrame.cpp: In member function ‘bool KeyFrame::operator<(const KeyFrame&)’:
KeyFrame.cpp:27: error: ‘getFrame’ was not declared in this scope
KeyFrame.cpp:27: error: ‘const class KeyFrame’ has no member named ‘getFrame’
In file included from Skeleton.hpp:4,
                 from Skeleton.cpp:1:
../SKALE/Bone.hpp:19: error: field ‘mName’ has incomplete type
../SKALE/Bone.hpp:42: error: default argument for parameter of type ‘const std::string&’ has type ‘const char [1]’
/usr/include/c++/4.2.1/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/bits/ios_base.h:779: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/include/c++/4.2.1/iosfwd:55: error: within this context
/usr/include/c++/4.2.1/iosfwd: In copy constructor ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/iosfwd:92: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here 
/usr/include/c++/4.2.1/streambuf: In copy constructor ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/streambuf:794: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]’ is private
/usr/include/c++/4.2.1/iosfwd:86: error: within this context
/usr/include/c++/4.2.1/iosfwd: In copy constructor ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’:
/usr/include/c++/4.2.1/iosfwd:92: note: synthesized method ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’ first required here 
Skeleton.cpp: In member function ‘bool skl::Skeleton::save(const std::string&) const’:
Skeleton.cpp:138: note: synthesized method ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’ first required here 
Skeleton.cpp: In member function ‘bool skl::Skeleton::_sortLinesByLevel(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::pair<int, std::string*>, std::allocator<std::pair<int, std::string*> > >&)’:
Skeleton.cpp:345: warning: NULL used in arithmetic

No time to dig into it right now. Can you at least build me a d3d version of the exe so I can see if it's any better?

jmasterx
Member #11,410
October 2009

Here is the D3D version (no shader)
Thanks

Trent Gamblin
Member #261
April 2000
avatar

Well that's a VERY apples and oranges test. The GL version has a bunch of shaders and the d3d version is just drawing a man shaped rope. I can't come to any conclusion with just that. I'd say port your shaders to HLSL and try it, it's not much different from GLSL. Or use Cg.

jmasterx
Member #11,410
October 2009

Well right now, I just compiled ex_bitmap with D3D, and one with OpenGL and the OpenGL version clearly takes much more cpu and fluctuates in cpu usage. I checked in Process Explorer and there is a clear fluctuation in the GL version. In a game like M.A.R.S (http://mars-game.sourceforge.net/) (Which uses pure OpenGL and shaders) on my laptop, there is no fluctuation.

Also profiling all my executables reveals that 95% of the time is spent in al_wait_for_event()

Trent Gamblin
Member #261
April 2000
avatar

I can't reproduce it here with ex_bitmap. It's the same, 0-2% with both OpenGL and Direct3D. I tried with Aero on and off and it's the same. What type of percentages are you seeing for ex_bitmap?

jmasterx
Member #11,410
October 2009

With D3D:
1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 1

With al_set_new_display_flags(ALLEGRO_OPENGL):

5, 6, 5, 6, 51, 39, 23, 16, 5, 6, 27, 39, 17, 6, 5

Thomas Fjellstrom
Member #476
June 2000
avatar

Have you checked for a driver update for your card recently?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

Those are pretty crazy numbers. Do you have some strange OpenGL settings in your gfx card settings panel?

jmasterx
Member #11,410
October 2009

I updated to the latest ones this morning. I should note though, that on ex_bitmap I did bring the frame rate from 30 to 60, this seems to make a difference.

Actually, on my game, lowering the frame rate to 30 frames per second fixes the problem. I'm confused now.

So at 60 frames per second, GL fluctuates like mad, but at 30 it is totally stable.

Thomas Fjellstrom
Member #476
June 2000
avatar

Any background crap running? Including windows updates and crap?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

Nope, I tried rebooting, killing several processes, this behavior is consistent. Changing the timer from 1.0f / 60.0f to 1.0f / 30.0f makes it stable. All of them are like this.

Trent Gamblin
Member #261
April 2000
avatar

What happens if you, say, bump it to 100fps, keep record of fps. After 10 seconds is it running @ full 100fps?

Arthur Kalliokoski
Second in Command
February 2005
avatar

jmasterx said:

it causes the cpu usage to fluctuate quite a bit compared to Direct3D.

It occurs to me that you might be seeing some type of aliasing (google Nyquist frequency and moire patterns). If you can tweak either the loop speed of your program or the update period of Process Explorer.

[EDIT]

I was going to post this an hour ago but canceled, the reply box offered to put it back.

They all watch too much MSNBC... they get ideas.

jmasterx
Member #11,410
October 2009

When I set it to 100 fps, I get around 62fps and 100% (both cores!) cpu usage. When I lower to < 60, I get that desired frame rate.

In D3D I get my 100fps no problem.

On my PC with a GTA 275 it still uses 100% and only 60 fps. (supposed to be getting 100 fps)

I attached it if you want to try.

Trent Gamblin
Member #261
April 2000
avatar

Can you see if vsync is force enabled in your opengl settings and try to turn it off?

jmasterx
Member #11,410
October 2009

It was not force enabled, it said it was going based on the 3D application settings, but setting it to force off solved the problem. Still though, why didn't other GL games give me this problem?

Oh and thanks again to everyone who helped me get to the bottom of this!

Trent Gamblin
Member #261
April 2000
avatar

I'm not sure. Did you mention what version of Windows you're using? I'm on Windows 7 64 bit. I have the same gpu and even forcing vsync on I don't see any fluctuation.

jmasterx
Member #11,410
October 2009

Windows 7 32 bit on Laptop

Driver Version is 275.33

on PC it is 64 bit with a GTX 275 ad has an i7 @ 3.0 GHz.

Both machines have the latest drivers.

If I force on for either of them, the problem comes right back.

Edit: Now the M.A.R.S game has the complete opposite behavior. When I force off, it shoots to 50%, when I force on, it is normal around 15%.

 1   2 


Go to: