summaryrefslogtreecommitdiff
path: root/src/boring_parts.cc
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-03 13:56:50 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-03 13:56:50 +0000
commitdcbaaf5bb09caf07f27c03f3c3db196542668b4a (patch)
tree3d74622e716c3bc58ceeefdb422c5c1c68b4e4a9 /src/boring_parts.cc
parent8c587d2243884d85bbe5fadac64258ac246617b4 (diff)
download2013-gpudataviz-dcbaaf5bb09caf07f27c03f3c3db196542668b4a.tar.gz
2013-gpudataviz-dcbaaf5bb09caf07f27c03f3c3db196542668b4a.tar.bz2
2013-gpudataviz-dcbaaf5bb09caf07f27c03f3c3db196542668b4a.zip
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
Diffstat (limited to 'src/boring_parts.cc')
-rw-r--r--src/boring_parts.cc179
1 files changed, 0 insertions, 179 deletions
diff --git a/src/boring_parts.cc b/src/boring_parts.cc
deleted file mode 100644
index 27ead8b..0000000
--- a/src/boring_parts.cc
+++ /dev/null
@@ -1,179 +0,0 @@
-#include "boring_parts.h"
-
-// TODO : only need OpenGL things, not GTK ones for now
-//#include "gtk_includes.h"
-
-#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 <windows.h>
- #define glGetProcAddress(a) wglGetProcAddress(a)
-#endif
-#ifdef X11
- #define glGetProcAddress(a) glXGetProcAddress ( \
- reinterpret_cast<const unsigned char*>(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, numDevices;
- 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<numPlatforms;id++) {
- cl_int res;
- platform=platforms[id];
-
- CL_RETURN_VAL_IF_FAIL(4,
- clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL)
- );
- std::cout << "Platform " << id << " : " << pbuf << std::endl;
-
- // Dynamically get the function pointer for clGetGLConetextInfoKHR
- clGetGLContextInfoKHR_fn clGetGLContextInfoKHR_proc = (clGetGLContextInfoKHR_fn) clGetExtensionFunctionAddressForPlatform(platform, "clGetGLContextInfoKHR");
- if (!clGetGLContextInfoKHR_proc) {
- std::cerr << "clGetExtensionFunctionAddressForPlatform(platform, clGetGLContextInfoKHR) failed" << std::endl;
- continue;
- }
-
- // Try to get the device corresponding to the GL context/display on this platform
- cl_context_properties cpsGL[] = {
- CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
- CL_GLX_DISPLAY_KHR, gl_display,
- CL_GL_CONTEXT_KHR, gl_context,
- 0
- };
-
- std::cout << "cl_context_properties :" << std::endl;
- std::cout << "\tCL_CONTEXT_PLATFORM :" << (void *)cpsGL[1] << std::endl;
- std::cout << "\tCL_GLX_DISPLAY_KHR :" << (void *)cpsGL[3] << std::endl;
- std::cout << "\tCL_GL_CONTEXT_KHR :" << (void *)cpsGL[5] << std::endl;
-
- size_t deviceSize=0;
- // get deviceSize (should be 1*sizeof(cl_device_id) with CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR)
- res=clGetGLContextInfoKHR_proc(cpsGL,CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,0,NULL,&deviceSize);
- if ( res!=CL_SUCCESS || deviceSize!=1*sizeof(cl_device_id)) {
- std::cerr << "clGetGLContextInfoKHR_proc(cpsGL,CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,0,...) failed" << std::endl;
- std::cerr << " (return code : " << res << ")" << std::endl;
- continue;
- }
-
- device=0;
- res=clGetGLContextInfoKHR_proc(cpsGL,CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,deviceSize,&device,NULL);
- if ( res!=CL_SUCCESS || device==0 ) {
- std::cerr << "clGetGLContextInfoKHR_proc(cpsGL,CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,...) failed" << std::endl;
- std::cerr << " (return code : " << res << ")" << std::endl;
- continue;
- }
-
- std::cout << "cl_device :" << (void *)device << std::endl;
-
- cl_ctx = clCreateContext(cpsGL,1,&device,0,0,&res);
- if ( res!=CL_SUCCESS ) {
- std::cerr << "clCreateContext() failed" << std::endl;
- std::cerr << " (return code : " << res << ")" << std::endl;
- continue;
- }
-
- cl_commandQueue = clCreateCommandQueue(cl_ctx,device,0,&res);
- if ( res!=CL_SUCCESS ) {
- std::cerr << "clCreateCommandQueue() failed" << std::endl;
- std::cerr << " (return code : " << res << ")" << std::endl;
- continue;
- }
-
- usableDeviceFound=true;
- break;
- }
-
- if (! usableDeviceFound) {
- std::cerr << "No OpenCL device has been successfully initialized" << std::endl;
- return 1;
- }
- std::cout << "OpenCL initialization done." << std::endl;
- return 0;
-}
-#endif /*HAS_OPENCL*/
-
-bool updateGLProjectionMatrix(Glib::RefPtr<Gdk::GL::Context> glCtx, Glib::RefPtr<Gdk::GL::Window> 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;
-
-}
-