From 8c587d2243884d85bbe5fadac64258ac246617b4 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 2 Mar 2013 20:20:32 +0000 Subject: Version C++ qui arrive a initialiser OpenCL sans trop de merdouilles specifiques. Un dur labeur... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reste à retourner les pointeurs où il faut, faire la partie VBO, l'affichage du VBO et lancer un premier kernel git-svn-id: file:///var/svn/2013-gpudataviz/trunk@16 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d --- src/boring_parts.cc | 188 +++++++++++++++++++++++++++------------------------- src/boring_parts.h | 6 +- src/gpudataviz.cc | 36 +++++++--- 3 files changed, 129 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/src/boring_parts.cc b/src/boring_parts.cc index bc25f8f..27ead8b 100644 --- a/src/boring_parts.cc +++ b/src/boring_parts.cc @@ -1,7 +1,5 @@ #include "boring_parts.h" - - // TODO : only need OpenGL things, not GTK ones for now //#include "gtk_includes.h" @@ -20,22 +18,52 @@ } \ } while(0) -int initLibs() { - -#ifdef HAS_OPENCL - RETURN_IF_FAIL( initOpenCL() ); -#endif /*HAS_OPENCL*/ - return 0; -} +/* From http://stackoverflow.com/questions/4317062/opengl-how-to-check-if-the-user-supports-glgenbuffers +#ifndef STRINGIFY + #define STRINGIFY(x) #x +#endif +#ifdef WIN32 + #include + #define glGetProcAddress(a) wglGetProcAddress(a) +#endif +#ifdef X11 + #define glGetProcAddress(a) glXGetProcAddress ( \ + reinterpret_cast(a) \ + ) +#endif + +#ifndef GetExtension + #define GetExtension(Type, ExtenName) \ + ExtenName = (Type) \ + glGetProcAddress(STRINGIFY(ExtenName)); \ + if(!ExtenName) \ + { \ + std:cout << "Your Computer Does Not " \ + << "Support GL Extension: " \ + << STRINGIFY(ExtenName) \ + << std::endl; \ + exit(1); \ + } \ + else \ + { \ + std::cout << "Loaded Extension: " \ + << STRINGIFY(ExtenName) \ + << std::endl; \ + } +#endif +*/ #ifdef HAS_OPENCL -int initOpenCL() { +int initOpenCL(intptr_t gl_display, intptr_t gl_context, intptr_t gl_vbo) { cl_uint id, numPlatforms, numDevices; char pbuf[100]; std::string dTypeStr; cl_platform_id *platforms, platform; - cl_device_id *devices, device; + cl_device_id /* *devices, */device; + cl_context cl_ctx; + cl_command_queue cl_commandQueue; + bool usableDeviceFound=false; // Get platform count CL_RETURN_VAL_IF_FAIL(1, @@ -55,97 +83,77 @@ int initOpenCL() { // Enumerate platforms and grab informations for(id=0;id 0 ) ) return 12; - - // Allocate room for all devices IDs - devices = new cl_device_id[numDevices]; - - // Get devices IDs - CL_RETURN_VAL_IF_FAIL(13, - clGetDeviceIDs(platform,CL_DEVICE_TYPE_ALL,numDevices,devices,&numDevices) - ); - // Enumerate devices and grab informations - for(id=0;id /* Must included before X11/Xlib.h */ //#include /* Seems included by GL/glxew.h */ -#include /* For GLXContext, must appear before gl.h, includes X11/Xlib.h */ +//#include /* For GLXContext, must appear before gl.h, includes X11/Xlib.h */ #include /* Includes a GL/gl.h (the right one ??) */ //#include -//#include +#include //#include int initLibs(); #ifdef HAS_OPENCL #include -int initOpenCL(); +int initOpenCL(intptr_t gl_display, intptr_t gl_context, intptr_t gl_vbo); #else // Quick and dirty cl_float4 replacement typedef union { diff --git a/src/gpudataviz.cc b/src/gpudataviz.cc index e6e4ca5..fbc1852 100644 --- a/src/gpudataviz.cc +++ b/src/gpudataviz.cc @@ -7,6 +7,8 @@ #include "gtk_win_main.h" #include "my_gtk_gl_scene_widget.h" +#include // X11 specific + // Macro to make things readable in main() function #define EXIT_IF_FAIL(val, expr) do { \ if ( ! (expr) ) { \ @@ -39,18 +41,15 @@ int main(int argc, char* argv[]) { Glib::RefPtr glconfig; EXIT_IF_FAIL(2, glconfig=Gdk::GL::Config::create(glMode) ); - // Initialize OpenCL (if available) - EXIT_IF_FAIL(3, initLibs()==0 ); // See boring_parts.cc - - // Initialize host work memory (array for all the vertex coordinates computed by OpenCL and displayed by OpenGL) - cl_float4 *hostWorkMem = (cl_float4 *) calloc(meshWidth * meshHeight, sizeof(cl_float4)); - EXIT_IF_FAIL(4, hostWorkMem); - // Initialize the OpenGL scene MyGTKGLSceneWidget glScene(glconfig); - // Instantiate and run the GTK app + // Instantiate the GTK app GTKWinMain gtkwinmain(glScene); + + // Initialize OpenCL (only after the MyGTKGLSceneWidget realize) + //EXIT_IF_FAIL(3, initLibs()==0 ); // See boring_parts.cc + gtkKit.run(gtkwinmain); return 0; @@ -88,6 +87,27 @@ void MyGTKGLSceneWidget::on_realize() { return; } + // TODO : GL_ARB_vertex_buffer_object + intptr_t gl_vbo=0; + +#ifdef HAS_OPENCL + static bool isOpenCLInitialized=false; + + if (! isOpenCLInitialized) { +// #ifdef X11 + intptr_t gl_context = (intptr_t)glXGetCurrentContext(); + intptr_t gl_display = (intptr_t)glXGetCurrentDisplay(); + + std::cerr << "DEBUG : begin initOpenCL()" << std::endl; + initOpenCL(gl_display, gl_context, gl_vbo); /* See boring_parts.cc */ + isOpenCLInitialized=true; +// #else +// #error initOpenCL works only for X11 systems for now +// #endif + } +#endif + + // Programmatically create rendering lists : opengl will able to replay that efficiently GLUquadricObj* qobj = gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); -- cgit v1.2.3