// 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
}
Exemple #2
0
int spoutGLDXinterop::GetVerticalSync()
{
	if(!bExtensionsLoaded) bExtensionsLoaded = LoadGLextensions();

	// needed for both sender and receiver
	if(bSWAPavailable) {
		return(wglGetSwapIntervalEXT());
	}
	return 0;
}
Exemple #3
0
	int gl_GetSwapInterval(State& state){
#ifdef __WGLEW_H__
		wglSwapIntervalEXT((int) state.stack->to<int>(1));
		state.stack->push<int>(wglGetSwapIntervalEXT());
#else
#ifdef __GLXEW_H__
		glXSwapIntervalMESA((int) state.stack->to<int>(1));
		state.stack->push<int>(glXGetSwapIntervalMESA());
#endif
#endif
		return 1;
	}
Exemple #4
0
void RenderDevice::Present(bool useVsync)
{
	BOOL success;
	int swapInterval = (useVsync) ? 1 : 0;
	if (wglGetSwapIntervalEXT() != swapInterval)
		wglSwapIntervalEXT(swapInterval);

	HDC dc = GetDC(Window);
	success = SwapBuffers(dc);
	ReleaseDC(Window, dc);

    OVR_ASSERT(success);
}
Exemple #5
0
bool CBaseRendererGL::AdjustMode(TEngineWindow &stNewWin)
{
	bool res = true;

	if (_eMultisampling != stNewWin.eMultisampling)
	{
		res = false;

		if (!WGLEW_ARB_multisample && stNewWin.eMultisampling != MM_NONE)
		{
			stNewWin.eMultisampling = MM_NONE;
			LOG("MSAA is not supported.", LT_WARNING);
		}
		else
		{
			stNewWin.eMultisampling = _eMultisampling;
			LOG("Changing MSAA samples count after initialization is not allowed.", LT_WARNING);
		}
	}

	if (WGLEW_EXT_swap_control)
	{
		int swapint = wglGetSwapIntervalEXT();
		
		if (stNewWin.bVSync)
		{
			if (swapint != 1 || (WGLEW_EXT_swap_control_tear && swapint != -1))
				wglSwapIntervalEXT(WGLEW_EXT_swap_control_tear ? -1 : 1);
		}
		else
			if (swapint != 0)
				wglSwapIntervalEXT(0);

	}
	else 
	{
		res = false;
		stNewWin.bVSync = false;
		LOG("VSync is not supported.", LT_WARNING);
	}

	return res;
}
// 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));
}
 int getSwapInterval() const
 {
     makeActive();
     return wglGetSwapIntervalEXT != nullptr ? wglGetSwapIntervalEXT() : 0;
 }
Exemple #8
0
    QTestWindow() {
        setSurfaceType(QSurface::OpenGLSurface);

        QSurfaceFormat format;
        // Qt Quick may need a depth and stencil buffer. Always make sure these are available.
        format.setDepthBufferSize(16);
        format.setStencilBufferSize(8);
        format.setVersion(4, 5);
        format.setProfile(QSurfaceFormat::OpenGLContextProfile::CompatibilityProfile);
        format.setOption(QSurfaceFormat::DebugContext);

        setFormat(format);

        _context = new QOpenGLContext;
        _context->setFormat(format);
        _context->create();

        show();
        makeCurrent();

        {
            QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this);
            logger->initialize(); // initializes in the current context, i.e. ctx
            logger->enableMessages();
            connect(logger, &QOpenGLDebugLogger::messageLogged, this, [&](const QOpenGLDebugMessage & debugMessage) {
                qDebug() << debugMessage;
            });
            //        logger->startLogging(QOpenGLDebugLogger::SynchronousLogging);
        }
        qDebug() << (const char*)glGetString(GL_VERSION);

#ifdef WIN32
        glewExperimental = true;
        GLenum err = glewInit();
        if (GLEW_OK != err) {
            /* Problem: glewInit failed, something is seriously wrong. */
            const GLubyte * errStr = glewGetErrorString(err);
            qDebug("Error: %s\n", errStr);
        }
        qDebug("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

        if (wglewGetExtension("WGL_EXT_swap_control")) {
            int swapInterval = wglGetSwapIntervalEXT();
            qDebug("V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF"));
        }
        glGetError();
#endif

        _textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false);
        _textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false,
            TextRenderer::SHADOW_EFFECT);
        _textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1,
            false, TextRenderer::OUTLINE_EFFECT);
        _textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24);

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glClearColor(0.2f, 0.2f, 0.2f, 1);
        glDisable(GL_DEPTH_TEST);

        makeCurrent();

        setFramePosition(QPoint(-1000, 0));
        resize(QSize(800, 600));
    }