Results 1 to 15 of 15

Thread: Help! Overlay, Layered, Threading Issue, Heavy CPU

  1. #1
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default Help! Overlay, Layered, Threading Issue, Heavy CPU

    This issue has been resolved.
    Solution as of ClanLib 2.2.9
    • Wait for next stable release -or- grab next version up from svn: Solves thread issue.
    • Don't try and make a 1440x900 layered window - keep it small: Solves CPU issue.






    My goal is to create an overlay. That is, a window with sprites/images with a transparent background. It displays nicely, thousands of frames per second unthrottled. However, I am having heavy CPU usage due to creating/closing threads by the window.flip() call.

    I found this related thread but didn't want to necro.

    Can someone explain this or provide a code example?

    So to get it to work with OpenGL 1.3 and higher, we create a shadow window that is rendered to. Then we use OpenGL to get the pixel buffer and copy it to the real window.
    Output from Visual Studio 2010 on Windows 7 x64
    Code:
    The thread 'void (__thiscall CL_Win32Window' (0x1470) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1238) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x14b4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x5a8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xc9c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xb44) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe3c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xfe4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1084) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x15a0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xec4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x17c8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x12f0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1514) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1098) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13f8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xc08) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1494) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x12d0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xd78) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x578) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1650) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1088) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x5f8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13ec) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x6a4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1500) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe44) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13e8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe28) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xdf0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x728) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xa90) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1220) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xc10) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xc34) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x55c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xd88) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1330) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x129c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe94) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1688) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xd5c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe7c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1214) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1144) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xdf8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xf68) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x6e8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13f4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x15e8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x41c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x11c8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x260) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1484) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1434) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x169c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x7f0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1414) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe74) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x924) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1768) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xf54) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x16c0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe9c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x17a0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xc68) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1708) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1740) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13b8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x11a0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x14cc) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xd6c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe90) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe30) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xddc) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xdd8) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x8a4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x57c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1568) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1560) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xd48) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1318) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x310) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1078) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x124c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1534) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1598) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x1114) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x13b0) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x434) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x158c) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0x16f4) has exited with code 0 (0x0).
    The thread 'void (__thiscall CL_Win32Window' (0xe64) has exited with code 0 (0x0).
    ... etc until the app is closed
    Project Source - using ClanLib Win32 2.2.9
    Code:
    #include <ClanLib/core.h>
    #include <ClanLib/application.h>
    #include <ClanLib/display.h>
    #include <ClanLib/gl1.h>
    
    #include <cmath>
    #include <cstdlib>
    
    using namespace std;
    #define CLIENTWIDTH 1440 // <-- this is a problem for the cpu, decrease the resolution
    #define	CLIENTHEIGHT 900 // <-- this is a problem for the cpu, decrease the resolution
    
    class App
    {
    public:
    	int start(const std::vector<CL_String> &args);
    private:
    	void on_window_close(CL_DisplayWindow *window);
    	bool quit;
    };
    
    /************************************************************
    						Program Class
     ************************************************************/
    class Program
    {
    public:
    	static int main(const std::vector<CL_String> &args)
    	{
    		// Initialize ClanLib base components
    		CL_SetupCore setup_core;
    
    		// Initialize the ClanLib display component
    		CL_SetupDisplay setup_display;
    
    		// Initilize the OpenGL drivers
    		CL_SetupGL1 setup_gl1;
    
    		// Start the Application
    		App app;
    		int retval = app.start(args);
    		return retval;
    	}
    };
    
    // Instantiate CL_ClanApplication, informing it where the Program is located
    CL_ClanApplication app(&Program::main);
    
    // The start of the Application
    int App::start(const std::vector<CL_String> &args)
    {
    	quit = false;
    
    	try
    	{
    		// Set the window description
    		CL_DisplayWindowDescription desc_window;
    		desc_window.set_title("Layered Test");
    		desc_window.set_allow_resize(false);
    		desc_window.set_decorations(false);
    		desc_window.set_position(CL_Rect(0, 0, CLIENTWIDTH, CLIENTHEIGHT), false);
    #ifdef WIN32
    		desc_window.set_layered(true);
    #else
    		desc_window.set_layered(false);
    #endif
    		//Open the main window
    		CL_DisplayWindow window(desc_window);
    
    		// Set up the sig slots & keyboard
    		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close, &window);
    		CL_InputDevice keyboard = window.get_ic().get_keyboard();
    
    		// Set up the graphic context
    		CL_GraphicContext gc = window.get_gc();
    		gc.set_translate(0.0f, 0.0f);
    
    		// Load resource manager
    		CL_ResourceManager res_main("./assets/main.xml");
    
    		// Load Sprite
    		CL_Sprite Sprite_Ball(gc, "ball", &res_main);
    
    		while (!quit)
    		{
    			// Check for exit request
    			if(keyboard.get_keycode(CL_KEY_ESCAPE) == true)
    				quit = true;
    
    			// transparent clearing
    			gc.clear(CL_Colorf(0.0f,0.0f,0.0f, 0.0f));
    
    			// Draw Ball
    			Sprite_Ball.draw(gc, 20.0f, 20.0f);
    
    			window.flip(0); // <-- Creates and Destroys CL_Win32Window threads like crazy
    			CL_KeepAlive::process();
    			CL_System::sleep(50);
    		}
    	}
    	catch(CL_Exception &exception)
    	{
    		// Create a console window for text-output if not available
    		CL_ConsoleWindow console("Console", 80, 160);
    		CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace());
    		console.display_close_message();
    
    		return -1;
    	}
    
    	return 0;
    
    };
    
    void App::on_window_close(CL_DisplayWindow *window)
    {
    	quit = true;
    }
    Last edited by Jarett Langton; 06-28-2011 at 12:18 AM.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Quote Originally Posted by Jarett Langton View Post
    However, I am having heavy CPU usage due to creating/closing threads by the window.flip() call.
    [/code]
    Ah, my mistake.

    The "flip() function spawns a seperate thread to process the layered windows.

    Recreating threads each frame is slow (and causes lots of debugging messages)

    The thread should be created once, and "paused" when processing is complete and "resumed" on the next flip()

  3. #3
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Ah, great - Not my bad code then? If not, is this something you will be able to fix and I can continue with my project?

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    It has now been fixed for ClanLib 2.2 SVN and ClanLib 2.3 SVN

    (It will be in the ClanLib 2.2.10 release)

    For reference, attached is the patch (created from ClanLib 2.2.9)

    In the GUI_Layered Example, Frames-Per-Second increased slighty from 97-98 fps to 103-104 fps

    LayeredWindow.patch
    Last edited by rombust; 06-27-2011 at 07:51 AM. Reason: forgot to add the patch

  5. #5
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Awesome! Thank you.

  6. #6
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Solution as of ClanLib 2.2.9

    • Wait for next stable release -or- grab next version up from svn: Solves thread issue.
    • Don't try and make a 1920x1080 layered window: Solves CPU issue.

    Thanks to rombust, and the other people on IRC who put up with me.

  7. #7
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Here's a quick look at what you guys helped me create.

    Screw youtube - posted it here.
    Last edited by Jarett Langton; 07-10-2011 at 07:33 AM. Reason: removed youtube, added link

  8. #8
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Hmm, the video won't play in Japan, maybe a copyright issue with the music?
    Seth A. Robinson
    Robinson Technologies

  9. #9
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Quote Originally Posted by Seth View Post
    Hmm, the video won't play in Japan, maybe a copyright issue with the music?
    Yah, stupid Youtube - It's not even able to play in my country (Canada) but an audioswap is underway so it should be available soon.

  10. #10
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Here's an alternate link to the video on my server.

  11. #11
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Also, here's just the intros made by looking through the examples in the particle stuff.
    I like the second one, AionTool, the best... It's the most recent one I did.

  12. #12
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I am a bit confused why you posted the video links to this "layered window" thread.

    I assume you are not using layered windows now, and that you are using a borderless window instead?

  13. #13
    Lesser Knight
    Join Date
    Nov 2010
    Location
    Winfield, BC Canada
    Posts
    32

    Default

    Quote Originally Posted by rombust View Post
    I am a bit confused why you posted the video links to this "layered window" thread.

    I assume you are not using layered windows now, and that you are using a borderless window instead?
    Sorry, it's not obvious in the video but layered window is an option in the program.

    Last edited by Jarett Langton; 07-10-2011 at 03:34 PM.

  14. #14
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    That, I do like

  15. #15
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Very fancy and original use of ClanLib

Similar Threads

  1. New Layered Window Example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 8
    Last Post: 10-12-2009, 03:24 PM
  2. Layered windows now available in the gui example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-08-2009, 10:37 AM
  3. Graphic Overlay Issue
    By jmguy02 in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 04-07-2009, 02:53 AM
  4. Threading Libraries?
    By Chambers in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 05-11-2007, 03:31 AM

Bookmarks

Bookmarks

Posting Permissions

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