From dcbaaf5bb09caf07f27c03f3c3db196542668b4a Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 3 Mar 2013 13:56:50 +0000 Subject: Standardisation des extensions. Avancee sur l'initialisation des VBO mais je galere a trouver un (bon) moyen de charger les fonctions OpenGL qui vont bien. git-svn-id: file:///var/svn/2013-gpudataviz/trunk@17 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d --- src/boring_parts.cpp | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 src/boring_parts.cpp (limited to 'src/boring_parts.cpp') diff --git a/src/boring_parts.cpp b/src/boring_parts.cpp new file mode 100644 index 0000000..0f4ee1a --- /dev/null +++ b/src/boring_parts.cpp @@ -0,0 +1,179 @@ +#include "boring_parts.hpp" + +// TODO : only need OpenGL things, not GTK ones for now +//#include "gtk_includes.hpp" + +#define RETURN_IF_FAIL(expr) do { \ + int res=(expr); \ + if ( res != 0 ) return res; \ +} while(0) + +// TODO : print streamsdk::getOpenCLErrorCodeStr(res) +#define CL_RETURN_VAL_IF_FAIL(val, expr) do { \ + cl_int res=(expr); \ + if ( res != CL_SUCCESS ) { \ + std::cerr << "file " << __FILE__ << ": line " << __LINE__ << " (" << __PRETTY_FUNCTION__ \ + << "): '" << "expr" << "' failed (return code : " << res << ")" << std::endl; \ + return val; \ + } \ +} while(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(intptr_t gl_display, intptr_t gl_context, intptr_t gl_vbo) { + cl_uint id, numPlatforms; + char pbuf[100]; + std::string dTypeStr; + cl_platform_id *platforms, platform; + 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, + clGetPlatformIDs(0, NULL, &numPlatforms) + ); + + std::cout << "Detected " << numPlatforms << " platform(s)" << std::endl; + if ( ! ( numPlatforms > 0 ) ) return 2; + + // Allocate room for all platform IDs + platforms = new cl_platform_id[numPlatforms]; + + // Get platform IDs + CL_RETURN_VAL_IF_FAIL(3, + clGetPlatformIDs(numPlatforms, platforms, &numPlatforms) + ); + + // Enumerate platforms and grab informations + for(id=0;id glCtx, Glib::RefPtr glWin, int width, int height) { + + GLdouble aspect = (GLdouble) width/height; + + // *** OpenGL BEGIN *** + if (!glWin->gl_begin(glCtx)) return false; + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, aspect, 0.1, 10.0); + glMatrixMode(GL_MODELVIEW); + + glWin->gl_end(); + // *** OpenGL END *** + + return true; + +} + -- cgit v1.2.3