// Initialize GL //***************************************************************************** void InitGL(int* argc, char **argv) { // initialize GLUT glutInit(argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition (glutGet(GLUT_SCREEN_WIDTH)/2 - iGraphicsWinWidth/2, glutGet(GLUT_SCREEN_HEIGHT)/2 - iGraphicsWinHeight/2); glutInitWindowSize(iGraphicsWinWidth, iGraphicsWinHeight); iGLUTWindowHandle = glutCreateWindow("OpenCL for GPU RGB Sobel Filter Demo"); #if !(defined (__APPLE__) || defined(MACOSX)) glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif // register glut callbacks glutKeyboardFunc(KeyboardGL); glutDisplayFunc(DisplayGL); glutReshapeFunc(Reshape); glutIdleFunc(Idle); glutTimerFunc(REFRESH_DELAY, timerEvent,0); // create GLUT menu iGLUTMenuHandle = glutCreateMenu(MenuGL); glutAddMenuEntry("Toggle Filter On/Off <spacebar>", ' '); glutAddMenuEntry("Toggle Processing between GPU and CPU [p]", 'p'); glutAddMenuEntry("Toggle between Full Screen and Windowed [f]", 'f'); glutAddMenuEntry("Increase Threshold [+]", '+'); glutAddMenuEntry("Decrease Threshold [-]", '-'); glutAddMenuEntry("Quit <esc>", '\033'); glutAttachMenu(GLUT_RIGHT_BUTTON); // Set clear color glClearColor(0.f, 0.f, 0.f, 0.f); // Zoom with fixed aspect ratio float fAspects[2] = {(float)glutGet(GLUT_WINDOW_WIDTH)/(float)uiImageWidth , (float)glutGet(GLUT_WINDOW_HEIGHT)/(float)uiImageHeight}; fZoom = fAspects[0] > fAspects[1] ? fAspects[1] : fAspects[0]; glPixelZoom(fZoom, fZoom); glewInit(); // Disable vertical sync, if supported #ifdef _WIN32 if (wglewIsSupported("WGL_EXT_swap_control")) { iVsyncState = wglGetSwapIntervalEXT(); wglSwapIntervalEXT(0); } #else #if defined (__APPLE__) || defined(MACOSX) GLint VBL = 0; CGLGetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &iVsyncState); CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); #else if(glxewIsSupported("GLX_SGI_swap_control")) { glXSwapIntervalSGI(0); } #endif #endif }
bool RenderImageImplPBuffer::IsSupported() { // Make sure that GLEW is initialized EnsureGlewInit(); return glxewIsSupported("GLX_SGIX_pbuffer"); }
void setSwapInterval(int interval) { if (glxewIsSupported("GLX_EXT_swap_control")) { Display *dpy = glXGetCurrentDisplay(); GLXDrawable drawable = glXGetCurrentDrawable(); glXSwapIntervalEXT(dpy, drawable, interval); } }
const bool GPUQuery::extensionSupported(const char * extension) { bool supported = glewIsSupported(extension) ? true : false; if(!supported) #ifdef WIN32 return wglewIsSupported(extension) ? true : false; #else return glxewIsSupported(extension) ? true : false; #endif return supported; }
const bool GPUQuery::extensionSupported(const char * extension) { if(isCoreProfile()) return false; bool supported = glewIsSupported(extension) ? true : false; if(!supported) #ifdef WIN32 return wglewIsSupported(extension) ? true : false; #elif defined(LINUX) return glxewIsSupported(extension) ? true : false; #else return supported; #endif return supported; }
// Setup function for GLUT parameters and loop //***************************************************************************** void InitGL(int* argc, char **argv) { // init GLUT glutInit(argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowPosition (glutGet(GLUT_SCREEN_WIDTH)/2 - iGraphicsWinWidth/2, glutGet(GLUT_SCREEN_HEIGHT)/2 - iGraphicsWinHeight/2); glutInitWindowSize(iGraphicsWinWidth, iGraphicsWinHeight); iGLUTWindowHandle = glutCreateWindow("OpenCL for GPU Nbody Demo"); #if !(defined (__APPLE__) || defined(MACOSX) || defined(__EMSCRIPTEN__)) glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif // init GLEW #ifndef __EMSCRIPTEN__ glewInit(); GLboolean bGlew = glewIsSupported("GL_VERSION_2_0 " "GL_VERSION_1_5 " "GL_ARB_multitexture " "GL_ARB_vertex_buffer_object"); oclCheckErrorEX(bGlew, shrTRUE, pCleanup); #endif glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 1.0); renderer = new ParticleRenderer(); // check GL errors GLenum error; while ((error = glGetError()) != GL_NO_ERROR) { #ifdef __EMSCRIPTEN__ shrLog("InitGL: error - %d\n", error); #else shrLog("InitGL: error - %s\n", (char *)gluErrorString(error)); #endif } // Disable vertical sync, if supported #ifdef _WIN32 if (wglewIsSupported("WGL_EXT_swap_control")) { iVsyncState = wglGetSwapIntervalEXT(); wglSwapIntervalEXT(0); } #else #if defined (__APPLE__) || defined(MACOSX) GLint VBL = 0; CGLGetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &iVsyncState); CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); #elif __EMSCRIPTEN__ #else if(glxewIsSupported("GLX_SGI_swap_control")) { glXSwapIntervalSGI(0); } #endif #endif // create a new parameter list paramlist = new ParamListGL("sliders"); paramlist->bar_col_outer[0] = 0.8f; paramlist->bar_col_outer[1] = 0.8f; paramlist->bar_col_outer[2] = 0.0f; paramlist->bar_col_inner[0] = 0.8f; paramlist->bar_col_inner[1] = 0.8f; paramlist->bar_col_inner[2] = 0.0f; // add parameters to the list // Point Size paramlist->AddParam(new Param<float>("Point Size", activeParams.m_pointSize, 0.0f, 10.0f, 0.01f, &activeParams.m_pointSize)); // Velocity Damping paramlist->AddParam(new Param<float>("Velocity Damping", activeParams.m_damping, 0.5f, 1.0f, .0001f, &(activeParams.m_damping))); // Softening Factor paramlist->AddParam(new Param<float>("Softening Factor", activeParams.m_softening, 0.001f, 1.0f, .0001f, &(activeParams.m_softening))); // Time step size paramlist->AddParam(new Param<float>("Time Step", activeParams.m_timestep, 0.0f, 1.0f, .0001f, &(activeParams.m_timestep))); // Cluster scale (only affects starting configuration paramlist->AddParam(new Param<float>("Cluster Scale", activeParams.m_clusterScale, 0.0f, 10.0f, 0.01f, &(activeParams.m_clusterScale))); // Velocity scale (only affects starting configuration) paramlist->AddParam(new Param<float>("Velocity Scale", activeParams.m_velocityScale, 0.0f, 1000.0f, 0.1f, &activeParams.m_velocityScale)); }