Revision: 1511
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1511&view=rev
Author:   rorthomas
Date:     2010-08-11 09:44:05 +0000 (Wed, 11 Aug 2010)

Log Message:
-----------
windows: added late-loading of OpenCL.dll making rorconfig work on non-opencl 
platforms

Modified Paths:
--------------
    trunk/source/configurator/CMakeLists.txt
    trunk/source/configurator/configurator.cpp

Modified: trunk/source/configurator/CMakeLists.txt
===================================================================
--- trunk/source/configurator/CMakeLists.txt    2010-08-08 20:32:30 UTC (rev 
1510)
+++ trunk/source/configurator/CMakeLists.txt    2010-08-11 09:44:05 UTC (rev 
1511)
@@ -34,6 +34,16 @@
    # warning C4305: 'initializing' : truncation from 'double' to 'const float'
    add_definitions("/wd4305 /wd4244")
 
+   
+   #now: delay loading for opencl
+   if(ROR_USE_OPENCL)
+      set(CMAKE_EXE_LINKER_FLAGS_DEBUG          
"${CMAKE_EXE_LINKER_FLAGS_DEBUG}          /DELAYLOAD:OpenCL.dll")
+      set(CMAKE_EXE_LINKER_FLAGS_RELEASE        
"${CMAKE_EXE_LINKER_FLAGS_RELEASE}        /DELAYLOAD:OpenCL.dll")
+      set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL     
"${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}     /DELAYLOAD:OpenCL.dll")
+      set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO 
"${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /DELAYLOAD:OpenCL.dll")
+      set(OS_LIBS ${OS_LIBS} Delayimp.lib)
+   endif(ROR_USE_OPENCL)
+
 ELSEIF(UNIX)
    find_package(PkgConfig)
    PKG_CHECK_MODULES  (GTK gtk+-2.0 REQUIRED)

Modified: trunk/source/configurator/configurator.cpp
===================================================================
--- trunk/source/configurator/configurator.cpp  2010-08-08 20:32:30 UTC (rev 
1510)
+++ trunk/source/configurator/configurator.cpp  2010-08-11 09:44:05 UTC (rev 
1511)
@@ -115,9 +115,11 @@
 
 std::map<std::string, std::string> settings;
 
+#ifdef USE_OPENCL
+#include <delayimp.h>
+#endif // USE_OPENCL
 
 
-
 #ifdef __WXGTK__
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
@@ -350,6 +352,8 @@
 //     wxTextCtrl *p2pport;
 #endif
 
+       void tryLoadOpenCL();
+       int openCLAvailable;
        //Joysticks *joy;
 //     wxTextCtrl *deadzone;
 //     wxGauge *joygauges[256];
@@ -1568,7 +1572,7 @@
 // ----------------------------------------------------------------------------
 
 // frame constructor
-MyDialog::MyDialog(const wxString& title, MyApp *_app) : wxDialog(NULL, 
wxID_ANY, title,  wxPoint(100, 100), wxSize(500, 580), 
wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
+MyDialog::MyDialog(const wxString& title, MyApp *_app) : wxDialog(NULL, 
wxID_ANY, title,  wxPoint(100, 100), wxSize(500, 580), 
wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), openCLAvailable(0)
 {
        app=_app;
 
@@ -3402,19 +3406,63 @@
 #include "ocl_bwtest.h"
 #endif // USE_OPENCL
 
+
+#ifdef USE_OPENCL
+// late loading DLLs
+// see http://msdn.microsoft.com/en-us/library/8yfshtha.aspx
+int tryLoadOpenCL2()
+{
+#ifdef WIN32
+       bool failed = false;
+       __try
+       {
+               failed = FAILED(__HrLoadAllImportsForDll("OpenCL.dll"));
+       } __except (EXCEPTION_EXECUTE_HANDLER)
+       {
+               failed = true;
+       }
+
+       if(failed)
+               return -1;
+       return 1;
+#else // WIN32
+       // TODO: implement late loading under different OSs
+#endif // WIN32
+}
+
+void MyDialog::tryLoadOpenCL()
+{
+       if(openCLAvailable != 0) return;
+       
+       openCLAvailable = tryLoadOpenCL2();
+       if(openCLAvailable != 1)
+       {
+               wxMessageDialog *msg=new wxMessageDialog(this, "OpenCL.dll not 
found\nAre the Display drivers up to date?", "OpenCL.dll not found", wxOK | 
wxICON_ERROR );
+               msg->ShowModal();
+
+               gputext->SetValue("failed to load OpenCL.dll");
+       }
+}
+#endif // USE_OPENCL
+
+
 void MyDialog::OnButCheckOpenCLBW(wxCommandEvent& event)
 {
 #ifdef USE_OPENCL
+       tryLoadOpenCL();
+       if(openCLAvailable != 1) return;
        gputext->SetValue("");
        ostream tstream(gputext);
        OpenCLTestBandwidth bw_test(tstream);
-
 #endif // USE_OPENCL
 }
 
+
 void MyDialog::OnButCheckOpenCL(wxCommandEvent& event)
 {
 #ifdef USE_OPENCL
+       tryLoadOpenCL();
+       if(openCLAvailable != 1) return;
        gputext->SetValue("");
        ostream tstream(gputext);
     bool bPassed = true;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to