Пример #1
0
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglSwapBuffers(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong surface_ptr) {
    EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
    EGLSurface surface = (EGLSurface)(intptr_t)surface_ptr;

    return eglSwapBuffers(dpy, surface);
}
Пример #2
0
static void gfx_ctx_qnx_swap_buffers(void *data)
{
   (void)data;
   eglSwapBuffers(g_egl_dpy, g_egl_surf);
}
Пример #3
0
// Show the current FPS
void cInterfaceEGL::Swap()
{
	eglSwapBuffers(egl_dpy, egl_surf);
}
Пример #4
0
int main(int argc, char **argv)
{
	EGLDisplay display;
	EGLConfig ecfg;
	EGLint num_config;
	EGLint attr[] = {       // some attributes to set up our egl-interface
		EGL_BUFFER_SIZE, 32,
		EGL_RENDERABLE_TYPE,
		EGL_OPENGL_ES2_BIT,
		EGL_NONE
	};
	EGLSurface surface;
	EGLint ctxattr[] = {
	EGL_CONTEXT_CLIENT_VERSION, 2,
		EGL_NONE
	};
	EGLContext context;

	EGLBoolean rv;

	display = eglGetDisplay(NULL);
	assert(eglGetError() == EGL_SUCCESS);
	assert(display != EGL_NO_DISPLAY);

	rv = eglInitialize(display, 0, 0);
	assert(eglGetError() == EGL_SUCCESS);
	assert(rv == EGL_TRUE);

	eglChooseConfig((EGLDisplay) display, attr, &ecfg, 1, &num_config);
	assert(eglGetError() == EGL_SUCCESS);
	assert(rv == EGL_TRUE);

	surface = eglCreateWindowSurface((EGLDisplay) display, ecfg, (EGLNativeWindowType)NULL, NULL);
	assert(eglGetError() == EGL_SUCCESS);
	assert(surface != EGL_NO_SURFACE);

	context = eglCreateContext((EGLDisplay) display, ecfg, EGL_NO_CONTEXT, ctxattr);
	assert(eglGetError() == EGL_SUCCESS);
	assert(context != EGL_NO_CONTEXT);

	assert(eglMakeCurrent((EGLDisplay) display, surface, surface, context) == EGL_TRUE);

	const char *version = (const char *)glGetString(GL_VERSION);
	assert(version);
	printf("%s\n",version);


	GLuint vertexShader   = load_shader ( vertex_src , GL_VERTEX_SHADER  );     // load vertex shader
	GLuint fragmentShader = load_shader ( fragment_src , GL_FRAGMENT_SHADER );  // load fragment shader

	GLuint shaderProgram  = glCreateProgram ();                 // create program object
	glAttachShader ( shaderProgram, vertexShader );             // and attach both...
	glAttachShader ( shaderProgram, fragmentShader );           // ... shaders to it

	glLinkProgram ( shaderProgram );    // link the program
	glUseProgram  ( shaderProgram );    // and select it for usage

	//// now get the locations (kind of handle) of the shaders variables
	position_loc  = glGetAttribLocation  ( shaderProgram , "position" );
	phase_loc     = glGetUniformLocation ( shaderProgram , "phase"    );
	offset_loc    = glGetUniformLocation ( shaderProgram , "offset"   );
	if ( position_loc < 0  ||  phase_loc < 0  ||  offset_loc < 0 ) {
		return 1;
	}

	//glViewport ( 0 , 0 , 800, 600); // commented out so it uses the initial window dimensions
	glClearColor ( 1. , 1. , 1. , 1.);    // background color
	float phase = 0;
	int i;
	for (i=0; i<3*60; ++i) {
		glClear(GL_COLOR_BUFFER_BIT);
		glUniform1f ( phase_loc , phase );  // write the value of phase to the shaders phase
		phase  =  fmodf ( phase + 0.5f , 2.f * 3.141f );    // and update the local variable

		glUniform4f ( offset_loc  ,  offset_x , offset_y , 0.0 , 0.0 );

		glVertexAttribPointer ( position_loc, 3, GL_FLOAT, GL_FALSE, 0, vertexArray );
		glEnableVertexAttribArray ( position_loc );
		glDrawArrays ( GL_TRIANGLE_STRIP, 0, 5 );

		eglSwapBuffers ( (EGLDisplay) display, surface );  // get the rendered buffer to the screen
	}

	printf("stop\n");

#if 0
(*egldestroycontext)((EGLDisplay) display, context);
    printf("destroyed context\n");

    (*egldestroysurface)((EGLDisplay) display, surface);
    printf("destroyed surface\n");
    (*eglterminate)((EGLDisplay) display);
    printf("terminated\n");
    android_dlclose(baz);
#endif
}
Пример #5
0
int main(void) {
    EGLDisplay m_eglDisplay;
    EGLContext m_eglContext;
    EGLSurface m_eglSurface;
    EGLint attributeList[] = { EGL_RED_SIZE, 1, EGL_DEPTH_SIZE, 1, EGL_NONE };
    EGLint		aEGLAttributes[] = {
        EGL_RED_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_BLUE_SIZE, 8,
        EGL_DEPTH_SIZE, 16,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
        EGL_NONE
    };
    EGLint		aEGLContextAttributes[] = {
        EGL_CONTEXT_CLIENT_VERSION, 1,
        EGL_NONE
    };
    EGLConfig m_eglConfig[1];
    EGLint nConfigs;
    unsigned char mIndices[] = { 0, 1, 2 };
    signed short mVertices[] = {
        -50, -29, 0,
        50, -29, 0,
        0,  58, 0
    };
    HWND hwnd;
    HDC hdc;
    MSG sMessage;
    int bDone = 0;

    // Platform init.
    platform(&hwnd, 640, 480);
    ShowWindow(hwnd, SW_SHOW);
    SetForegroundWindow(hwnd);
    SetFocus(hwnd);

    // EGL init.
    hdc = GetDC(hwnd);
    m_eglDisplay = eglGetDisplay(hdc);
    eglInitialize(m_eglDisplay, NULL, NULL);
    eglChooseConfig(m_eglDisplay, aEGLAttributes, m_eglConfig, 1, &nConfigs);
    printf("EGLConfig = %p\n", m_eglConfig[0]);
    m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig[0], (NativeWindowType)hwnd, 0);
    m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig[0], EGL_NO_CONTEXT, aEGLContextAttributes);
    printf("EGLContext = %p\n", m_eglContext);
    eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_SHORT, 0, mVertices);

    /* Set projection matrix so screen extends to (-160, -120) at bottom left 
    * and to (160, 120) at top right, with -128..128 as Z buffer. */

    glMatrixMode(GL_PROJECTION);
    glOrthox(-160<<16, 160<<16, -120<<16, 120<<16, -128<<16, 128<<16);

    glMatrixMode(GL_MODELVIEW);

    glClearColorx(0x10000, 0x10000, 0, 0);
    glColor4x(0x10000, 0, 0, 0);

    // Main event loop
    while(!bDone)
    {
        // Do Windows stuff:
        if(PeekMessage(&sMessage, NULL, 0, 0, PM_REMOVE))
        {
            if(sMessage.message == WM_QUIT)
            {
                bDone = 1;
            }
            else 
            {
                TranslateMessage(&sMessage);
                DispatchMessage(&sMessage);
            }
        }

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, mIndices);
        glRotatex(2<<16, 0, 0, 0x10000);
        eglSwapBuffers(m_eglDisplay, m_eglSurface);
        Sleep(30);
    }

    // Exit.
    eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroyContext(m_eglDisplay, m_eglContext);
    eglDestroySurface(m_eglDisplay, m_eglSurface);
    eglTerminate(m_eglDisplay);

    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);


    return 0;
}
Пример #6
0
void cXInterface::SwapBuffers()
{
	eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}
Пример #7
0
void enddraw(int x, int y, int width, int height)
{
    eglSwapBuffers(display, surface);
}
Пример #8
0
int main(int argc, char **argv)
{
	wrt = (struct warp_runtime *)malloc(sizeof(struct warp_runtime));
	assert(NULL != wrt);

	memset(wrt, 0, sizeof(struct warp_runtime));

	create_warp_runtime(wrt);

	glViewport(0, 0, 500, 500);

	/* setup shader & program */
	GLchar message[512];
	GLint status;
	GLchar *source = NULL;

	GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
	load_shader_from_file("shaders/es3_indexdraw_rect.vert", &source);
	glShaderSource(vertex_shader, 1, (const GLchar * const*)&source, NULL);
	glCompileShader(vertex_shader);

	glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &status);
	if (!status) {
		glGetShaderInfoLog(vertex_shader, 512, NULL, message);
		printf("%s\n", message);
	}

	GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
	free(source);
	load_shader_from_file("shaders/es3_indexdraw_rect.frag", &source);
	glShaderSource(fragment_shader, 1, (const GLchar * const*)&source, NULL);
	glCompileShader(fragment_shader);

	glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &status);
	if (!status) {
		glGetShaderInfoLog(fragment_shader, 512, NULL, message);
		printf("%s\n", message);
	}

	GLuint prog = glCreateProgram();
	glAttachShader(prog, vertex_shader);
	glAttachShader(prog, fragment_shader);
	glLinkProgram(prog);

	glGetProgramiv(prog, GL_LINK_STATUS, &status);
	if (!status) {
		glGetProgramInfoLog(prog, 512, NULL, message);
		printf("%s\n", message);
	}

	glUseProgram(prog);

	/* set up resource */
	GLfloat pos_buf[] = {
			-0.25f, 0.25f, 0.0f,
			0.25f, -0.25f, 0.0f,
			-0.25f, -0.25f, 0.0f,
			0.25f, 0.25f, 0.0f
	};

	GLfloat color_buf[] = {
			1.0f, 0.0f, 0.0f, 0.0f,
			0.0f, 1.0f, 0.0f, 0.0f,
			0.0f, 0.0f, 1.0f, 0.0f,
			1.0f, 1.0f, 0.0f, 0.0f,
	};

	GLushort index_buf[] = {
			0, 1, 2,
			0, 3, 1
	};

	GLuint vao;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	/* setup array buffer for position and color
	 */
	GLuint vbo_pos;
	glGenBuffers(1, &vbo_pos);
	glBindBuffer(GL_ARRAY_BUFFER, vbo_pos);
	glBufferData(GL_ARRAY_BUFFER, sizeof(pos_buf), pos_buf, GL_STATIC_DRAW);

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);

	GLuint vbo_color;
	glGenBuffers(1, &vbo_color);
	glBindBuffer(GL_ARRAY_BUFFER, vbo_color);
	glBufferData(GL_ARRAY_BUFFER, sizeof(color_buf), color_buf, GL_STATIC_DRAW);

	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid *)0);

	/* setup index buffer for index
	 */
	GLuint vbo_index;
	glGenBuffers(1, &vbo_index);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_index);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(index_buf), index_buf, GL_STATIC_DRAW);

	/* game loop */
	while (1) {

		XNextEvent(wrt->x11_display, &(wrt->event));

		switch(wrt->event.type) {
		case Expose:
			/* do the render */
			glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);

			glBindVertexArray(vao);
			glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (void*)0);
			glBindVertexArray(0);

			eglSwapBuffers(wrt->egl_display, wrt->egl_surface);
			break;
		case ButtonPress:
		case KeyPress:
			goto finish;
		default:
			break;
		}
	}

finish:
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	glDeleteProgram(prog);
	glDeleteBuffers(1, &vbo_pos);
	glDeleteBuffers(1, &vbo_color);
	glDeleteBuffers(1, &vbo_index);
	glDeleteVertexArrays(1, &vao);
	destroy_warp_runtime(wrt);
	return 0;
}
Пример #9
0
void CoreWindow::SwapBuffer()
{
    eglSwapBuffers(esContext.eglDisplay, esContext.eglSurface);
//    glXSwapBuffers(m_display, g_win->m_imp->m_win);
}
Пример #10
0
//=================================================================================================================================
///
/// Callback function for this simple ES app.
///
/// \param hWnd handle For this window.
/// \param uMsg message for this window.
/// \param wParam additional message info.
/// \param lParam additional message info.
///
/// \return void
//=================================================================================================================================
LRESULT CALLBACK WndProc( HWND      hWnd, UINT      uMsg, WPARAM    wParam, LPARAM    lParam)
{
   switch ( uMsg )      // Check For Windows Messages
   {
   case WM_ACTIVATE:
      {
         if ( ! HIWORD( wParam ) )     // Check Minimization State
         {
            g_active = TRUE;
         }
         else
         {
            g_active = FALSE;
         }
         return 0;
      }

   case WM_SYSCOMMAND:
      {
         if ( ( wParam == SC_SCREENSAVE ) ||
              ( wParam == SC_MONITORPOWER ) )
         {
            return 0;
         }
         break;
      }

   case WM_CLOSE:
      {
         PostQuitMessage( 0 );
         return 0;
      }

   case WM_KEYDOWN:
      {
        g_keys[wParam] = TRUE;
        if(wParam == 8)
        {
            // Backspace is pressed then undo
            g_scene->undoLastMove();
        } 
        else if(wParam == 13)
        {
            g_scene->start();
        }
        else if(wParam == 32)
        {
            g_scene->end();
        }
        return 0;
      }

   case WM_KEYUP:
      {
         g_keys[wParam] = FALSE;
         return 0;
      }

   case WM_LBUTTONDOWN:
       {
           g_scene->mouseClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), MS_BOX_SHIFT_DOWN);
           return 0;
       }

   case WM_SIZE:
      {
         ResizeScene( LOWORD( lParam ), HIWORD( lParam ) );  // LoWord=Width, HiWord=Height
         return 0;
      }

   case WM_TIMER: 

       switch (wParam) 
       { 
       case 43: 
           
#ifdef PERFORMANCE_TUNING
           double newstart = static_cast <double> (clock ());

           double time = frameCount / ( (newstart - start) / static_cast <double> (CLOCKS_PER_SEC));    

           printf("%f.2\r\n", time);

           frameCount = 0;
           start = newstart;
#else
            // process the 60fps timer
            DrawScene();

            eglSwapBuffers( g_egl.dsp, g_egl.surf );
#endif


           return 0;      
       } 
   }

   // Pass All Unhandled Messages To DefWindowProc
   return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
Пример #11
0
//=================================================================================================================================
///
/// WinMain function for this simple ES app.
///
/// \param hInstance instance.
/// \param hPrevInstance previous instance.
/// \param lpCmdLine command line parameters.
/// \param nCmdShow window show state.
///
/// \return void
//=================================================================================================================================
int WINAPI WinMain( HINSTANCE  hInstance,
                    HINSTANCE  hPrevInstance,
                    LPSTR      lpCmdLine,
                    int        nCmdShow)
{
    UINT res = WinExec ("C:\\Program Files (x86)\\NVIDIA Corporation\\win_x86_es2emu\\ait\\esTriangle\\copy.bat", SW_SHOWNORMAL);

   MSG  msg;
   BOOL done=FALSE;

   g_scene = new msScene();
   
   // redirect stdin/stdout to a console window
   RedirectIOToConsole();

   // unit tests
   //msBox::unitTest();   
   //msAnimation::unitTest();
   //msAnimationBundle::unitTest();
  // msBoxGrid::unitTest();
 //  return 0;

   MainFuncInit();

   HWND hWnd = CreateWind( SCR_WIDTH, SCR_HEIGHT ) ;

   if ( !hWnd )
   {
      return 0;
   }

   string *uniformsPath = new string("\\data\\uniforms.txt");
   msMapDataFileName(*uniformsPath);

   g_scene->loadData(*uniformsPath); 

   delete uniformsPath;

   g_scene->init();
   
#ifdef PERFORMANCE_TUNING
   SetTimer(hWnd,             // handle to main window 
       43,            // timer identifier 
      2000,
       (TIMERPROC) NULL);     // no timer callback 
#else
   SetTimer(hWnd,             // handle to main window 
       43,            // timer identifier 
       FRAME_INTERVAL,                 // 10-second interval 
       (TIMERPROC) NULL);     // no timer callback 
#endif

   while ( ! done )
   {
      if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )  // Is There A Message Waiting?
      {
         if ( msg.message == WM_QUIT )
         {
            done=TRUE;
         }
         else
         {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
         }
      }
      else
      {
#ifdef PERFORMANCE_TUNING
          if ( ( g_active && !DrawScene() ) || g_keys[VK_ESCAPE] )
          {
              done=TRUE;  // ESC or DrawGLScene Signalled A Quit
          }
          else
          {
              eglSwapBuffers( g_egl.dsp, g_egl.surf );

              frameCount ++;
          }
#else
         if ( ( g_active && FALSE ) || g_keys[VK_ESCAPE] )
         {
            done=TRUE;  // ESC or DrawGLScene Signalled A Quit
         }
#endif
      }
   }

   eglDestroyContext( g_egl.dsp, g_egl.cxt );
   eglDestroySurface( g_egl.dsp, g_egl.surf );
   eglTerminate( g_egl.dsp );

   delete g_scene;

#ifdef WINDOWS_GL
   _CrtDumpMemoryLeaks();
#endif
   
   return 0;
}
Пример #12
0
int ngi_context_egl_swap(ngi_context* ctx) {
    return eglSwapBuffers(ctx->platform.egl.edpy, ctx->platform.egl.esfc);
}
Пример #13
0
/**
 * Just the current frame in the display.
 */
static void engine_draw_frame(struct engine* engine) {
    engine->kiwiApp->render();
    eglSwapBuffers(engine->display, engine->surface);
}
Пример #14
0
static void gfx_ctx_swap_buffers(void)
{
   eglSwapBuffers(g_egl_dpy, g_egl_surf);
}
int main(int argc, char **argv)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (argc > 1)
	{
		nRetVal = g_Context.Init();
		CHECK_RC(nRetVal, "Init");
		nRetVal = g_Context.OpenFileRecording(argv[1], g_Player);
		if (nRetVal != XN_STATUS_OK)
		{
			printf("Can't open recording %s: %s\n", argv[1], xnGetStatusString(nRetVal));
			return 1;
		}
	}
	else
	{
		xn::EnumerationErrors errors;
		nRetVal = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, g_scriptNode, &errors);
		if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
		{
			XnChar strError[1024];
			errors.ToString(strError, 1024);
			printf("%s\n", strError);
			return (nRetVal);
		}
		else if (nRetVal != XN_STATUS_OK)
		{
			printf("Open failed: %s\n", xnGetStatusString(nRetVal));
			return (nRetVal);
		}
	}

	nRetVal = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator);
	if (nRetVal != XN_STATUS_OK)
	{
		printf("No depth generator found. Using a default one...");
		xn::MockDepthGenerator mockDepth;
		nRetVal = mockDepth.Create(g_Context);
		CHECK_RC(nRetVal, "Create mock depth");

		// set some defaults
		XnMapOutputMode defaultMode;
		defaultMode.nXRes = 320;
		defaultMode.nYRes = 240;
		defaultMode.nFPS = 30;
		nRetVal = mockDepth.SetMapOutputMode(defaultMode);
		CHECK_RC(nRetVal, "set default mode");

		// set FOV
		XnFieldOfView fov;
		fov.fHFOV = 1.0225999419141749;
		fov.fVFOV = 0.79661567681716894;
		nRetVal = mockDepth.SetGeneralProperty(XN_PROP_FIELD_OF_VIEW, sizeof(fov), &fov);
		CHECK_RC(nRetVal, "set FOV");

		XnUInt32 nDataSize = defaultMode.nXRes * defaultMode.nYRes * sizeof(XnDepthPixel);
		XnDepthPixel* pData = (XnDepthPixel*)xnOSCallocAligned(nDataSize, 1, XN_DEFAULT_MEM_ALIGN);

		nRetVal = mockDepth.SetData(1, 0, nDataSize, pData);
		CHECK_RC(nRetVal, "set empty depth map");

		g_DepthGenerator = mockDepth;
	}

	nRetVal = g_Context.FindExistingNode(XN_NODE_TYPE_USER, g_UserGenerator);
	if (nRetVal != XN_STATUS_OK)
	{
		nRetVal = g_UserGenerator.Create(g_Context);
		CHECK_RC(nRetVal, "Find user generator");
	}

	XnCallbackHandle hUserCallbacks, hCalibrationStart, hCalibrationComplete, hPoseDetected, hCalibrationInProgress, hPoseInProgress;
	if (!g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_SKELETON))
	{
		printf("Supplied user generator doesn't support skeleton\n");
		return 1;
	}
	nRetVal = g_UserGenerator.RegisterUserCallbacks(User_NewUser, User_LostUser, NULL, hUserCallbacks);
	CHECK_RC(nRetVal, "Register to user callbacks");
	nRetVal = g_UserGenerator.GetSkeletonCap().RegisterToCalibrationStart(UserCalibration_CalibrationStart, NULL, hCalibrationStart);
	CHECK_RC(nRetVal, "Register to calibration start");
	nRetVal = g_UserGenerator.GetSkeletonCap().RegisterToCalibrationComplete(UserCalibration_CalibrationComplete, NULL, hCalibrationComplete);
	CHECK_RC(nRetVal, "Register to calibration complete");

	XnCallbackHandle hUserExitCB, hUserReenterCB;
	nRetVal = g_UserGenerator.RegisterToUserExit(User_Exit, NULL, hUserExitCB);
	CHECK_RC(nRetVal, "Register to user exit");
	nRetVal = g_UserGenerator.RegisterToUserReEnter(User_ReEnter, NULL, hUserReenterCB);
	CHECK_RC(nRetVal, "Register to user re-enter");

	if (g_UserGenerator.GetSkeletonCap().NeedPoseForCalibration())
	{
		g_bNeedPose = TRUE;
		if (!g_UserGenerator.IsCapabilitySupported(XN_CAPABILITY_POSE_DETECTION))
		{
			printf("Pose required, but not supported\n");
			return 1;
		}
		nRetVal = g_UserGenerator.GetPoseDetectionCap().RegisterToPoseDetected(UserPose_PoseDetected, NULL, hPoseDetected);
		CHECK_RC(nRetVal, "Register to Pose Detected");
		g_UserGenerator.GetSkeletonCap().GetCalibrationPose(g_strPose);

		nRetVal = g_UserGenerator.GetPoseDetectionCap().RegisterToPoseInProgress(MyPoseInProgress, NULL, hPoseInProgress);
		CHECK_RC(nRetVal, "Register to pose in progress");
	}

	g_UserGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL);

	nRetVal = g_UserGenerator.GetSkeletonCap().RegisterToCalibrationInProgress(MyCalibrationInProgress, NULL, hCalibrationInProgress);
	CHECK_RC(nRetVal, "Register to calibration in progress");

	nRetVal = g_Context.StartGeneratingAll();
	CHECK_RC(nRetVal, "StartGenerating");

#ifndef USE_GLES
	glInit(&argc, argv);
	glutMainLoop();
#else
	if (!opengles_init(GL_WIN_SIZE_X, GL_WIN_SIZE_Y, &display, &surface, &context))
	{
		printf("Error initializing opengles\n");
		CleanupExit();
	}

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	while (!g_bQuit)
	{
		glutDisplay();
		eglSwapBuffers(display, surface);
	}
	opengles_shutdown(display, surface, context);

	CleanupExit();
#endif
}
Пример #16
0
static DFBResult
InitLocal( AndroidData *android )
{
     /*
      * Here specify the attributes of the desired configuration.
      * Below, we select an EGLConfig with at least 8 bits per color
      * component compatible with on-screen windows
      */
     const EGLint attribs[] = {
             EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
             EGL_BLUE_SIZE, 8,
             EGL_GREEN_SIZE, 8,
             EGL_RED_SIZE, 8,
             EGL_ALPHA_SIZE, 8,
             EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
             EGL_NATIVE_VISUAL_ID, HAL_PIXEL_FORMAT_RGBA_8888,    // DSPF_ARGB
             EGL_NONE
     };

     static const EGLint ctx_attribs[] = {
          EGL_CONTEXT_CLIENT_VERSION, 2,
          EGL_NONE
     };

     EGLint w, h, dummy, format;
     EGLint numConfigs;
     EGLConfig config;
     EGLSurface surface;
     EGLContext context;

     EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

     eglInitialize(display, 0, 0);

     /* Here, the application chooses the configuration it desires. In this
      * sample, we have a very simplified selection process, where we pick
      * the first EGLConfig that matches our criteria */
     eglChooseConfig(display, attribs, &config, 1, &numConfigs);

     /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
      * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
      * As soon as we picked a EGLConfig, we can safely reconfigure the
      * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
     eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

     ANativeWindow_setBuffersGeometry( native_data.app->window, 0, 0, format);

//     ANativeActivity_setWindowFlags( native_data.app->window, AWINDOW_FLAG_FULLSCREEN | AWINDOW_FLAG_KEEP_SCREEN_ON , 0 );

     surface = eglCreateWindowSurface(display, config, native_data.app->window, NULL);
     context = eglCreateContext(display, config, NULL, ctx_attribs);

     if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
         LOGW("Unable to eglMakeCurrent");
         return -1;
     }

     eglQuerySurface(display, surface, EGL_WIDTH, &w);
     eglQuerySurface(display, surface, EGL_HEIGHT, &h);

     android->dpy = display;
     android->ctx = context;
     android->surface = surface;
     android->shared->screen_size.w = w;
     android->shared->screen_size.h = h;     

     if (strstr(glGetString(GL_RENDERER),"SGX"))
          android->shared->native_pixelformat = HAL_PIXEL_FORMAT_RGBA_8888; //ANativeWindow_getFormat(native_data.app->window);
     else
          android->shared->native_pixelformat = ANativeWindow_getFormat(native_data.app->window);

     // Initialize GL state.
//     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
     glEnable(GL_CULL_FACE);
//     glShadeModel(GL_SMOOTH);
     glDisable(GL_DEPTH_TEST);



     // Just fill the screen with a color.
     glClearColor( .5, .5, .5, 1 );
     glClear( GL_COLOR_BUFFER_BIT );

     eglSwapBuffers( android->dpy, android->surface );

     return DFB_OK;
}
Пример #17
0
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
{
    eglSwapBuffers(_glfw.egl.display, window->egl.surface);
}
Пример #18
0
void Interface::draw()
{
    //printf("draw\n");
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

#ifdef USE_OPENGL
    /*glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1., 1., -1., 1., 1., 30.);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();*/
    gluLookAt(0., 0., 21., 0., 0., 0., 0., 1., 0.);

    glColor3f(1., 1., 1.);
    draw_quad(this->m_textures[LAYER_BG], LAYER_BG);
    //draw_quad(this->m_textures[LAYER_BG_OVERLAY_0], LAYER_BG_OVERLAY_0);
    //draw_quad(this->m_textures[LAYER_BG_OVERLAY_1], LAYER_BG_OVERLAY_1);
    //draw_quad(this->m_textures[LAYER_BG_OVERLAY_2], LAYER_BG_OVERLAY_2);

    draw_quad(this->m_textures[LAYER_TITLE_BASE], LAYER_TITLE_BASE);

    draw_quad(this->m_textures[LAYER_MENU], LAYER_MENU);
    if (!global.menu->in_dlg())
    {
        regions_t regions = *global.menu->get_regions();
        int count = regions.size();
        for (int i=0 ; i<count ; i++)
        {
            region_t *region = regions.at(i);
            region_chip_t *chip = region->chip;
            if ((region->state != MENU_DEFAULT) && (chip))
            {
                glBindTexture(GL_TEXTURE_2D, this->m_textures[LAYER_MENU_OVERLAY]);
                glBegin(GL_QUADS);
                    glTexCoord2f(chip->x1, chip->y1); glVertex3f(region->x1, region->y1, LAYER_MENU_OVERLAY);
                    glTexCoord2f(chip->x2, chip->y1); glVertex3f(region->x2, region->y1, LAYER_MENU_OVERLAY);
                    glTexCoord2f(chip->x2, chip->y2); glVertex3f(region->x2, region->y2, LAYER_MENU_OVERLAY);
                    glTexCoord2f(chip->x1, chip->y2); glVertex3f(region->x1, region->y2, LAYER_MENU_OVERLAY);
                glEnd();
            }
        }
    }

    //draw_quad(this->m_textures[LAYER_SYS_BASE], LAYER_SYS_BASE);
    if (global.menu->in_dlg())
    {
        draw_quad(this->m_textures[LAYER_DLG], LAYER_DLG);
        region_t *dlg_regions = global.menu->get_dlg_regions();
        for (int i=0 ; i<2 ; i++)
        {
            region_t *region = &dlg_regions[i];
            region_chip_t *chip = region->chip;
            if ((region->state != MENU_DEFAULT) && (chip))
            {
                glBindTexture(GL_TEXTURE_2D, this->m_textures[LAYER_DLG_OVERLAY]);
                glBegin(GL_QUADS);
                    glTexCoord2f(chip->x1, chip->y1); glVertex3f(region->x1, region->y1, LAYER_DLG_OVERLAY);
                    glTexCoord2f(chip->x2, chip->y1); glVertex3f(region->x2, region->y1, LAYER_DLG_OVERLAY);
                    glTexCoord2f(chip->x2, chip->y2); glVertex3f(region->x2, region->y2, LAYER_DLG_OVERLAY);
                    glTexCoord2f(chip->x1, chip->y2); glVertex3f(region->x1, region->y2, LAYER_DLG_OVERLAY);
                glEnd();
            }
        }
    }
    //for (int i=0 ; i<LAYERS_COUNT ; i++)
        //draw_quad(this->m_textures[i], i);

    if (this->m_fade_color != -1)
    {
        glColor4d(this->m_fade_color, this->m_fade_color, this->m_fade_color, this->m_fade);
        if (this->m_fade_color)
            draw_quad(this->m_texture_white, LAYER_OVERLAY);
        else
            draw_quad(this->m_texture_black, LAYER_OVERLAY);
    }

#ifdef _WIN32
    SwapBuffers(this->m_dc);
#elif defined __unix__
    glXSwapBuffers(this->m_dpy, this->m_win);
#else
    #error here!
#endif

#else

    glViewport(0, 0, this->m_gwa.width, this->m_gwa.height);
    for (int i=0 ; i<=LAYERS_COUNT ; i++)
        if (this->m_textures[i] != uint32_t(-1))
        {
            glBindTexture(GL_TEXTURE_2D, this->m_textures[i]);

            GLint box[] =
            {
                -1, -1, i,
                1, -1, i,
                1,  1, i,
                -1,  1, i
            };
            GLfloat tex[] =
            {
                0.0, 1.0,
                1.0, 1.0,
                1.0, 0.0,
                0.0, 0.0
            };

            glVertexAttribPointer(attr_pos, 3, GL_INT, GL_FALSE, 0, box);
            glVertexAttribPointer(attr_color, 2, GL_FLOAT, GL_FALSE, 0, tex);
            glEnableVertexAttribArray(attr_pos);
            glEnableVertexAttribArray(attr_color);

            //glVertexPointer(3, GL_FLOAT, 0, box);
            //glTexCoordPointer(2, GL_FLOAT, 0, tex);

            glDrawArrays(GL_TRIANGLES, 0, 3);

            glDisableVertexAttribArray(attr_pos);
            glDisableVertexAttribArray(attr_color);
        }

    eglSwapBuffers(this->m_dpy, this->m_surf);
#endif

}
Пример #19
0
void SwapBuffers( void ) {
	int err, i;
	int t;
	int size[2];
	int pos[2];

	t = Sys_Milliseconds();

	if (!setup_vert)
	{
		vert = (GLfloat*)malloc(2*(NUM_VERT+2) * sizeof(GLfloat));

		vert[0] = 0;
		vert[1] = 0;

		for (i = 0; i < NUM_VERT+1; i+=2)
		{
			vert[i+2] = (GLfloat)(sinf(2 * PI / NUM_VERT * i)) * 600 / 768;
			vert[i+3] = (GLfloat)(cosf(2 * PI / NUM_VERT * i));
		}

		setup_vert = 1;
	}

	if (cls.state == CA_ACTIVE)
	{
		if ( !backEnd.projection2D )
			RB_SetGL2D();

		glDisable(GL_TEXTURE_2D);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);

		if (!uis.activemenu)
			drawControls();

		glEnable(GL_TEXTURE_2D);
	}

//	if (min || max) {
//		eglMakeCurrent(eglDisplay,
//						EGL_NO_SURFACE,
//						EGL_NO_SURFACE,
//						EGL_NO_CONTEXT);
//		eglMakeCurrent(eglDisplay,
//						eglSurface,
//						eglSurface,
//						eglContext);
//
//		size[0] = glConfig.vidWidth;
//		size[1] = glConfig.vidHeight;
//		screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_SIZE, size);
//
//		if (min) {
//			pos[0] = 0;
//			pos[1] = bz[1] - size[1];
//			min = 0;
//		} else {
//			pos[0] = 0;
//			pos[1] = 0;
//			max = 0;
//		}
//
//		screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_POSITION, pos);
//	}

	eglSwapBuffers(eglDisplay, eglSurface);
	err = eglGetError( );
	if (err != EGL_SUCCESS ) {
		Com_Printf( "Error, eglSwapBuffers failed" );
		PrintEglError( err );
		return;
	}
}
/*!*****************************************************************************************************************************************
 @Function		RenderScene
 @Input			eglDisplay                  The EGLDisplay used by the application
 @Input			eglSurface					The EGLSurface created from the native window.
 @Input			nativeWindow                A native window, used to display error messages
 @Return		Whether the function succeeds or not.
 @Description	Renders the scene to the framebuffer. Usually called within a loop.
*******************************************************************************************************************************************/
bool RenderScene( EGLDisplay eglDisplay, EGLSurface eglSurface, HWND nativeWindow ) 
{
	// The message handler setup for the window system will signal this variable when the window is closed, so close the application.
	if (g_hasUserQuit)
	{
		return false;
	}

	/*	Set the clear color
		At the start of a frame, generally you clear the image to tell OpenGL ES that you're done with whatever was there before and want to
		draw a new frame. In order to do that however, OpenGL ES needs to know what colour to set in the image's place. glClearColor
		sets this value as 4 floating point values between 0.0 and 1.x, as the Red, Green, Blue and Alpha channels. Each value represents
		the intensity of the particular channel, with all 0.0 being transparent black, and all 1.x being opaque white. Subsequent calls to
		glClear with the colour bit will clear the frame buffer to this value.
		The functions glClearDepth and glClearStencil allow an application to do the same with depth and stencil values respectively.
	*/
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	/*	Clears the color buffer.
		glClear is used here with the Colour Buffer to clear the colour. It can also be used to clear the depth or stencil buffer using 
		GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT, respectively.
	*/
	glClear(GL_COLOR_BUFFER_BIT);
	
	// Enable the vertex array
	glEnableClientState(GL_VERTEX_ARRAY);

	// Sets the vertex data to this attribute index, with the number of floats in each position
	glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), (GLvoid*)0);
	if (!TestGLError(nativeWindow, "glVertexAttribPointer"))
	{
		return false;
	}

	// Set a color to render
	glColor4f(1.0f, 1.0f, 0.66, 1.0f);

	/*	Draw the triangle
		glDrawArrays is a draw call, and executes the shader program using the vertices and other state set by the user. Draw calls are the
		functions which tell OpenGL ES when to actually draw something to the framebuffer given the current state.
		glDrawArrays causes the vertices to be submitted sequentially from the position given by the "first" argument until it has processed
		"count" vertices. Other draw calls exist, notably glDrawElements which also accepts index data to allow the user to specify that
		some vertices are accessed multiple times, without copying the vertex multiple times.
		Others include versions of the above that allow the user to draw the same object multiple times with slightly different data, and
		a version of glDrawElements which allows a user to restrict the actual indices accessed.
	*/
	glDrawArrays(GL_TRIANGLES, 0, 3);
	if (!TestGLError(nativeWindow, "glDrawArrays"))
	{
		return false;
	}

	/*	Present the display data to the screen.
		When rendering to a Window surface, OpenGL ES is double buffered. This means that OpenGL ES renders directly to one frame buffer, 
		known as the back buffer, whilst the display reads from another - the front buffer. eglSwapBuffers signals to the windowing system
		that OpenGL ES 1.x has finished rendering a scene, and that the display should now draw to the screen from the new data. At the same
		time, the front buffer is made available for OpenGL ES 1.x to start rendering to. In effect, this call swaps the front and back 
		buffers.
	*/
	if (!eglSwapBuffers(eglDisplay, eglSurface) )
	{
		TestEGLError(nativeWindow, "eglSwapBuffers");
		return false;
	}

	// Check for messages from the windowing system. These will pass through the callback registered earlier.
	MSG eventMessage;
	PeekMessage(&eventMessage, nativeWindow, NULL, NULL, PM_REMOVE);
	TranslateMessage(&eventMessage);
	DispatchMessage(&eventMessage);

	return true;
}
Пример #21
0
bool CEGLManager::swapBuffers()
{
    return (eglSwapBuffers(EglDisplay, EglSurface)==EGL_TRUE);
}
Пример #22
0
void WebView::swapBuffers()
{
    eglSwapBuffers(m_glContextData->eglDisplay, m_glContextData->surface);
}
Пример #23
0
int main(int argc, char *argv[]) {
	std::string app_name;
	std::string app_name_nice;
	bool landscape;
	NativeGetAppInfo(&app_name, &app_name_nice, &landscape);

	net::Init();
#ifdef __APPLE__
	// Make sure to request a somewhat modern GL context at least - the
	// latest supported by MacOSX (really, really sad...)
	// Requires SDL 2.0
	// We really should upgrade to SDL 2.0 soon.
	//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
#endif

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) {
		fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
#ifdef EGL
	if (EGL_Open())
		return 1;
#endif

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

	int mode;
#ifdef USING_GLES2
	mode = SDL_SWSURFACE | SDL_FULLSCREEN;
#else
	mode = SDL_OPENGL;
	for (int i = 1; i < argc; i++)
		if (!strcmp(argv[i],"--fullscreen"))
			mode |= SDL_FULLSCREEN;
#endif
	if (mode & SDL_FULLSCREEN) {
		const SDL_VideoInfo* info = SDL_GetVideoInfo();
		pixel_xres = info->current_w;
		pixel_yres = info->current_h;
		g_Config.bFullScreen = true;
	} else {
		// set a sensible default resolution (2x)
		pixel_xres = 480 * 2;
		pixel_yres = 272 * 2;
		g_Config.bFullScreen = false;
	}
	dp_xres = (float)pixel_xres;
	dp_yres = (float)pixel_yres;

	if (SDL_SetVideoMode(pixel_xres, pixel_yres, 0, mode) == NULL) {
		fprintf(stderr, "SDL SetVideoMode failed: Unable to create OpenGL screen: %s\n", SDL_GetError());
		SDL_Quit();
		return(2);
	}
#ifdef EGL
	EGL_Init();
#endif

	SDL_WM_SetCaption((app_name_nice + " " + PPSSPP_GIT_VERSION).c_str(), NULL);
#ifdef MAEMO
	SDL_ShowCursor(SDL_DISABLE);
#endif


#ifndef USING_GLES2
	if (GLEW_OK != glewInit()) {
		printf("Failed to initialize glew!\n");
		return 1;
	}

	if (GLEW_VERSION_2_0) {
		printf("OpenGL 2.0 or higher.\n");
	} else {
		printf("Sorry, this program requires OpenGL 2.0.\n");
		return 1;
	}
#endif

#ifdef _MSC_VER
	// VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\"));
	TCHAR path[MAX_PATH];
	SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path);
	PathAppend(path, (app_name + "\\").c_str());
#else
	// Mac / Linux
	char path[512];
	const char *the_path = getenv("HOME");
	if (!the_path) {
		struct passwd* pwd = getpwuid(getuid());
		if (pwd)
			the_path = pwd->pw_dir;
	}
	strcpy(path, the_path);
	if (path[strlen(path)-1] != '/')
		strcat(path, "/");
#endif

#ifdef _WIN32
	NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE");
#else
	NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE");
#endif

	pixel_in_dps = (float)pixel_xres / dp_xres;

	float dp_xscale = (float)dp_xres / pixel_xres;
	float dp_yscale = (float)dp_yres / pixel_yres;

	g_dpi_scale = dp_xres / (float)pixel_xres;

	printf("Pixels: %i x %i\n", pixel_xres, pixel_yres);
	printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres);
	NativeInitGraphics();

	SDL_AudioSpec fmt;
	fmt.freq = 44100;
	fmt.format = AUDIO_S16;
	fmt.channels = 2;
	fmt.samples = 2048;
	fmt.callback = &mixaudio;
	fmt.userdata = (void *)0;

	if (SDL_OpenAudio(&fmt, NULL) < 0)
		ELOG("Failed to open audio: %s", SDL_GetError());

	// Audio must be unpaused _after_ NativeInit()
	SDL_PauseAudio(0);
#ifdef PANDORA
	int numjoys = SDL_NumJoysticks();
	// Joysticks init, we the nubs if setup as Joystick
	if (numjoys > 0) {
		ljoy = SDL_JoystickOpen(0);
		if (numjoys > 1)
			rjoy = SDL_JoystickOpen(1);
	}
#else
	joystick = new SDLJoystick();
#endif
	EnableFZ();

	int framecount = 0;
	float t = 0;
	float lastT = 0;
	while (true) {
		input_state.accelerometer_valid = false;
		input_state.mouse_valid = true;
		int quitRequested = 0;

		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			float mx = event.motion.x * dp_xscale;
			float my = event.motion.y * dp_yscale;

			switch (event.type) {
			case SDL_QUIT:
				quitRequested = 1;
				break;
			case SDL_KEYDOWN:
				{
					int k = event.key.keysym.sym;
					KeyInput key;
					key.flags = KEY_DOWN;
					key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
					key.deviceId = DEVICE_ID_KEYBOARD;
					NativeKey(key);
					break;
				}
			case SDL_KEYUP:
				{
					int k = event.key.keysym.sym;
					KeyInput key;
					key.flags = KEY_UP;
					key.keyCode = KeyMapRawSDLtoNative.find(k)->second;
					key.deviceId = DEVICE_ID_KEYBOARD;
					NativeKey(key);
					break;
				}
			case SDL_MOUSEBUTTONDOWN:
				switch (event.button.button) {
				case SDL_BUTTON_LEFT:
					{
						input_state.pointer_x[0] = mx;
						input_state.pointer_y[0] = my;
						//input_state.mouse_buttons_down = 1;
						input_state.pointer_down[0] = true;
						input_state.mouse_valid = true;
						TouchInput input;
						input.x = mx;
						input.y = my;
						input.flags = TOUCH_DOWN;
						input.id = 0;
						NativeTouch(input);
						KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_DOWN);
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_RIGHT:
					{
						KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_DOWN);
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_WHEELUP:
					{
						KeyInput key;
						key.deviceId = DEVICE_ID_MOUSE;
						key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
						key.flags = KEY_DOWN;
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_WHEELDOWN:
					{
						KeyInput key;
						key.deviceId = DEVICE_ID_MOUSE;
						key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
						key.flags = KEY_DOWN;
						NativeKey(key);
					}
					break;
				}
				break;
			case SDL_MOUSEMOTION:
				if (input_state.pointer_down[0]) {
					input_state.pointer_x[0] = mx;
					input_state.pointer_y[0] = my;
					input_state.mouse_valid = true;
					TouchInput input;
					input.x = mx;
					input.y = my;
					input.flags = TOUCH_MOVE;
					input.id = 0;
					NativeTouch(input);
				}
				break;
			case SDL_MOUSEBUTTONUP:
				switch (event.button.button) {
				case SDL_BUTTON_LEFT:
					{
						input_state.pointer_x[0] = mx;
						input_state.pointer_y[0] = my;
						input_state.pointer_down[0] = false;
						input_state.mouse_valid = true;
						//input_state.mouse_buttons_up = 1;
						TouchInput input;
						input.x = mx;
						input.y = my;
						input.flags = TOUCH_UP;
						input.id = 0;
						NativeTouch(input);
						KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_1, KEY_UP);
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_RIGHT:
					{
						KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_2, KEY_UP);
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_WHEELUP:
					{
						KeyInput key;
						key.deviceId = DEVICE_ID_DEFAULT;
						key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP;
						key.flags = KEY_UP;
						NativeKey(key);
					}
					break;
				case SDL_BUTTON_WHEELDOWN:
					{
						KeyInput key;
						key.deviceId = DEVICE_ID_DEFAULT;
						key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN;
						key.flags = KEY_UP;
						NativeKey(key);
					}
					break;
				}
				break;
			default:
				joystick->ProcessInput(event);
				break;
			}
		}

		if (quitRequested)
			break;

		const uint8 *keys = (const uint8 *)SDL_GetKeyState(NULL);
		SimulateGamepad(keys, &input_state);
		UpdateInputState(&input_state);
		NativeUpdate(input_state);
		NativeRender();
#ifndef MAEMO
		if (lastUIState != globalUIState) {
			lastUIState = globalUIState;
			if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !g_Config.bShowTouchControls)
				SDL_ShowCursor(SDL_DISABLE);
			if (lastUIState != UISTATE_INGAME && g_Config.bFullScreen)
				SDL_ShowCursor(SDL_ENABLE);
		}
#endif

		EndInputState(&input_state);

		if (framecount % 60 == 0) {
			// glsl_refresh(); // auto-reloads modified GLSL shaders once per second.
		}

#ifdef EGL
		eglSwapBuffers(g_eglDisplay, g_eglSurface);
#else
		if (!keys[SDLK_TAB] || t - lastT >= 1.0/60.0)
		{
			SDL_GL_SwapBuffers();
			lastT = t;
		}
#endif
		time_update();
		t = time_now();
		framecount++;
	}
#ifndef PANDORA
	delete joystick;
	joystick = NULL;
#endif
	// Faster exit, thanks to the OS. Remove this if you want to debug shutdown
	// The speed difference is only really noticable on Linux. On Windows you do notice it though
#ifdef _WIN32
	exit(0);
#endif
	NativeShutdownGraphics();
	SDL_PauseAudio(1);
	SDL_CloseAudio();
	NativeShutdown();
#ifdef EGL
	EGL_Close();
#endif
	SDL_Quit();
	net::Shutdown();
	exit(0);
	return 0;
}
Пример #24
0
void GraphicsAdapter::swapBuffers() const
{
	eglSwapBuffers(_display, _surface);
}
TEST_F(SurfaceTextureGLToGLTest, TexturingFromGLFilledRGBABufferPow2) {
    const int texWidth = 64;
    const int texHeight = 64;

    mST->setDefaultBufferSize(texWidth, texHeight);

    // This test requires 3 buffers to complete run on a single thread.
    mST->setDefaultMaxBufferCount(3);

    // Do the producer side of things
    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
            mProducerEglSurface, mProducerEglContext));
    ASSERT_EQ(EGL_SUCCESS, eglGetError());

    // This is needed to ensure we pick up a buffer of the correct size.
    eglSwapBuffers(mEglDisplay, mProducerEglSurface);

    glClearColor(0.6, 0.6, 0.6, 0.6);
    glClear(GL_COLOR_BUFFER_BIT);

    glEnable(GL_SCISSOR_TEST);
    glScissor(4, 4, 4, 4);
    glClearColor(1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glScissor(24, 48, 4, 4);
    glClearColor(0.0, 1.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glScissor(37, 17, 4, 4);
    glClearColor(0.0, 0.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    eglSwapBuffers(mEglDisplay, mProducerEglSurface);

    // Do the consumer side of things
    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
            mEglContext));
    ASSERT_EQ(EGL_SUCCESS, eglGetError());

    glDisable(GL_SCISSOR_TEST);

    // Skip the first frame, which was empty
    ASSERT_EQ(NO_ERROR, mST->updateTexImage());
    ASSERT_EQ(NO_ERROR, mST->updateTexImage());

    glClearColor(0.2, 0.2, 0.2, 0.2);
    glClear(GL_COLOR_BUFFER_BIT);

    glViewport(0, 0, texWidth, texHeight);
    drawTexture();

    EXPECT_TRUE(checkPixel( 0,  0, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(63,  0, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153));

    EXPECT_TRUE(checkPixel( 4,  7, 255,   0,   0, 255));
    EXPECT_TRUE(checkPixel(25, 51,   0, 255,   0, 255));
    EXPECT_TRUE(checkPixel(40, 19,   0,   0, 255, 255));
    EXPECT_TRUE(checkPixel(29, 51, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel( 5, 32, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(13,  8, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(46,  3, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(30, 33, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel( 6, 52, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(55, 33, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(16, 29, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel( 1, 30, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(41, 37, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(46, 29, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel(15, 25, 153, 153, 153, 153));
    EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153));
}
Пример #26
0
static void *render_thread_run(void *data) {
    struct render_thread *render_thread = data;

    EGLDisplay egl_display = NULL;
    EGLSurface egl_surface = NULL;
    EGLContext egl_context = NULL;
    // Gather egl params and bind to mpv opengl_cb
    {
        pthread_mutex_lock(&render_thread->lock);

        egl_display = render_thread->egl_display;
        egl_surface = render_thread->egl_surface;
        egl_context = render_thread->egl_context;

        eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
        eglSwapInterval(egl_display, 0);

        int res = mpv_opengl_cb_init_gl(render_thread->opengl_cb_context, NULL,
                                        mpv_get_proc_address, NULL);
        if (res < 0) {
            log_mpv_error("mpv_opengl_cb_init_gl failed", res);
        }

        mpv_opengl_cb_set_update_callback(render_thread->opengl_cb_context,
                                          update_callback, render_thread);

        // TODO: after the first uninit the video track is reset to 0 (none)
        // Setting this to 1 restarts the playback though and messes up the time the video
        // was playing at.
        uint64_t on = 1;
        mpv_set_property(render_thread->mpv, "vid", MPV_FORMAT_INT64, &on);

        render_thread->running = 1;
        pthread_cond_broadcast(&render_thread->ready);

        pthread_mutex_unlock(&render_thread->lock);
    }

    int64_t last_time = mpv_get_time_us(render_thread->mpv);
    int frames = 0;

    while (1) {
        // Wait for available frames
        {
            pthread_mutex_lock(&render_thread->frame_wait_lock);
            while (!render_thread->frame_available) {
                pthread_cond_wait(&render_thread->frame_wait, &render_thread->frame_wait_lock);
            }
            render_thread->frame_available = 0;
            pthread_mutex_unlock(&render_thread->frame_wait_lock);
        }

        // Check if still running
        int run, width, height;
        {
            pthread_mutex_lock(&render_thread->lock);
            run = render_thread->running;
            width = render_thread->width;
            height = render_thread->height;
            pthread_mutex_unlock(&render_thread->lock);
        }
        if (!run) {
            break;
        }

//        int64_t draw_start = mpv_get_time_us(render_thread->mpv);
        mpv_opengl_cb_draw(render_thread->opengl_cb_context, 0, width, -height);
//        LOGI("Render time %ld", (mpv_get_time_us(render_thread->mpv) - draw_start));
        if (!eglSwapBuffers(egl_display, egl_surface)) {
            LOGE("eglSwapBuffers failed %d", eglGetError());
        }
//        mpv_opengl_cb_report_flip(render_thread->opengl_cb_context, 0);

        frames++;

        int64_t now = mpv_get_time_us(render_thread->mpv);
        if (now - last_time >= 1000 * 1000) {
            // last_time += 1000 * 1000;
            last_time = now; // Don't play catch-up
            LOGI("Render fps %d", frames);
            frames = 0;
        }
    }

    // Release egl params and unbind from mpv opengl_cb
    {
        pthread_mutex_lock(&render_thread->lock);

        int res = mpv_opengl_cb_uninit_gl(render_thread->opengl_cb_context);
        if (res < 0) {
            log_mpv_error("mpv_opengl_cb_uninit_gl failed", res);
        }

        eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

        pthread_mutex_unlock(&render_thread->lock);
    }

    return NULL;
}
Пример #27
0
/**
 * Just the current frame in the display.
 */
static void engine_draw_frame(struct engine* engine)
{
	if (engine->display == NULL)
	{
		// No display.
		return;
	}

	glViewport(0, 0, static_cast<int32_t>(engine->width), static_cast<int32_t>(engine->height));

	// Just fill the screen with a color.
	glClearColor(0.95f, 0.95f, 0.95f, 1);
	glClear(GL_COLOR_BUFFER_BIT);

	// Use the program object
	glUseProgram(engine->programObject);

	glEnableVertexAttribArray(POSITION_PARAMETER_INDEX);
	glEnableVertexAttribArray(COLOR_PARAMETER_INDEX);

	const float z = 0.0f;
	const float buttonColor[] = {0.25f, 0.25f, 0.25f, 1.0f};
	GLfloat leftButton[] = {-0.85f, 0.75f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3],
			-0.9f, 0.8f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3],
			-0.85f,  0.85f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3]};

	// Load the vertex data
	glVertexAttribPointer(POSITION_PARAMETER_INDEX, POSITION_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, leftButton);
	glVertexAttribPointer(COLOR_PARAMETER_INDEX, COLOR_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, &leftButton[3]);
	glDrawArrays(GL_TRIANGLES, 0, TRIANGLE_NUM_VERTICES);

	GLfloat rightButton[] = {0.85f,  0.75f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3],
			0.9f, 0.8f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3],
			0.85f,  0.85f, z,
			buttonColor[0], buttonColor[1], buttonColor[2], buttonColor[3]};

	glVertexAttribPointer(POSITION_PARAMETER_INDEX, POSITION_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, rightButton);
	glVertexAttribPointer(COLOR_PARAMETER_INDEX, COLOR_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, &rightButton[3]);
	glDrawArrays(GL_TRIANGLES, 0, TRIANGLE_NUM_VERTICES);

	float left = engine->playerX - PADDLE_HALF_WIDTH;
	float right = engine->playerX + PADDLE_HALF_WIDTH;
	float top = engine->playerY - PADDLE_HALF_HEIGHT;
	float bottom = engine->playerY + PADDLE_HALF_HEIGHT;
	const float paddleColor[] = {1.0f, 0.0f, 0.0f, 1.0f};
	GLfloat paddle[] = {left, top, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3],
			left, bottom, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3],
			right, top, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3],
			right, top, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3],
			left, bottom, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3],
			right, bottom, z,
			paddleColor[0], paddleColor[1], paddleColor[2], paddleColor[3]};

	glVertexAttribPointer(POSITION_PARAMETER_INDEX, POSITION_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, paddle);
	glVertexAttribPointer(COLOR_PARAMETER_INDEX, COLOR_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, &paddle[3]);
	glDrawArrays(GL_TRIANGLES, 0, QUAD_NUM_VERTICES);

	left = engine->ballX - BALL_HALF_WIDTH;
	right = engine->ballX + BALL_HALF_WIDTH;
	top = engine->ballY - BALL_HALF_HEIGHT;
	bottom = engine->ballY + BALL_HALF_HEIGHT;
	const float ballColor[] = {1.0f, 0.0f, 0.0f, 1.0f};
	GLfloat ball[] = {left,  top, z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3],
			left, bottom,  z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3],
			right,   top, z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3],
			right,   top, z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3],
			left, bottom,  z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3],
			right,  bottom, z,
			ballColor[0], ballColor[1], ballColor[2], ballColor[3]};

	glVertexAttribPointer(POSITION_PARAMETER_INDEX, POSITION_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, ball);
	glVertexAttribPointer(COLOR_PARAMETER_INDEX, COLOR_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, &ball[3]);
	glDrawArrays(GL_TRIANGLES, 0, QUAD_NUM_VERTICES);

	GLfloat blockColors[][4] = { {0.0f, 1.0f, 0.0f, 1.0f},{0.0f, 0.0f, 1.0f, 1.0f} };
	for (int32_t i=0; i<NUM_BLOCKS; ++i)
	{
		block& currentBlock = engine->blocks[i];
		if (currentBlock.isActive)
		{
			const int32_t colorIndex = i % 2;
			const float r = blockColors[colorIndex][0];
			const float g = blockColors[colorIndex][1];
			const float b = blockColors[colorIndex][2];
			const float a = blockColors[colorIndex][3];
			const float left = currentBlock.x - BLOCK_HALF_WIDTH;
			const float right = currentBlock.x + BLOCK_HALF_WIDTH;
			const float top = currentBlock.y + BLOCK_HALF_HEIGHT;
			const float bottom = currentBlock.y - BLOCK_HALF_HEIGHT;
			GLfloat block[] = {left, top, z,
					r, g, b, a,
					left, bottom, z,
					r, g, b, a,
					right, top, z,
					r, g, b, a,
					right, top, z,
					r, g, b, a,
					left, bottom, z,
					r, g, b, a,
					right, bottom, z,
					r, g, b, a};

			glVertexAttribPointer(POSITION_PARAMETER_INDEX, POSITION_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, block);
			glVertexAttribPointer(COLOR_PARAMETER_INDEX, COLOR_NUM_ELEMENTS, GL_FLOAT, GL_FALSE, VERTEX_SIZE, &block[3]);
			glDrawArrays(GL_TRIANGLES, 0, QUAD_NUM_VERTICES);
		}
	}

	glDisableVertexAttribArray(POSITION_PARAMETER_INDEX);
	glDisableVertexAttribArray(COLOR_PARAMETER_INDEX);

	eglSwapBuffers(engine->display, engine->surface);
}
Пример #28
0
/*!
 * \brief GepardGLES2::fillRect
 * \param x  X-axis value of _start_ and _end_ point
 * \param y  Y-axis value of _start_ and _end_ point
 * \param w  size on X-axis
 * \param h  size on Y-axis
 *
 * \todo unimplemented function
 */
void GepardGLES2::fillRect(float x, float y, float w, float h)
{
    //! \todo: implement fillRect with GLES2

    eglSwapBuffers(_eglDisplay, _eglSurface);
}
Пример #29
0
static int rpi_init(struct MPGLContext *ctx, int flags)
{
    struct priv *p = ctx->priv;
    struct vo *vo = ctx->vo;

    p->egl.log = vo->log;

    bcm_host_init();

    p->display = vc_dispmanx_display_open(0);
    p->update = vc_dispmanx_update_start(0);
    if (!p->display || !p->update) {
        MP_FATAL(ctx->vo, "Could not get DISPMANX objects.\n");
        goto fail;
    }

    uint32_t w, h;
    if (graphics_get_display_size(0, &w, &h) < 0) {
        MP_FATAL(ctx->vo, "Could not get display size.\n");
        goto fail;
    }

    // dispmanx is like a neanderthal version of Wayland - you can add an
    // overlay any place on the screen. Just use the whole screen.
    VC_RECT_T dst = {.width = w, .height = h};
    VC_RECT_T src = {.width = w << 16, .height = h << 16};
    VC_DISPMANX_ALPHA_T alpha = {
        .flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,
        .opacity = 0xFF,
    };
    p->window = vc_dispmanx_element_add(p->update, p->display, 1, &dst, 0,
                                        &src, DISPMANX_PROTECTION_NONE, &alpha, 0, 0);
    if (!p->window) {
        MP_FATAL(ctx->vo, "Could not add DISPMANX element.\n");
        goto fail;
    }

    vc_dispmanx_update_submit_sync(p->update);

    if (mp_egl_rpi_init(&p->egl, p->window, w, h) < 0)
        goto fail;

    ctx->gl = p->egl.gl;

    vo->dwidth = p->w = w;
    vo->dheight = p->h = h;

    return 0;

fail:
    rpi_uninit(ctx);
    return -1;
}

static int rpi_reconfig(struct MPGLContext *ctx)
{
    struct priv *p = ctx->priv;
    ctx->vo->dwidth = p->w;
    ctx->vo->dheight = p->h;
    return 0;
}

static void rpi_swap_buffers(MPGLContext *ctx)
{
    struct priv *p = ctx->priv;
    eglSwapBuffers(p->egl.egl_display, p->egl.egl_surface);
}

static int rpi_control(MPGLContext *ctx, int *events, int request, void *arg)
{
    return VO_NOTIMPL;
}

const struct mpgl_driver mpgl_driver_rpi = {
    .name           = "rpi",
    .priv_size      = sizeof(struct priv),
    .init           = rpi_init,
    .reconfig       = rpi_reconfig,
    .swap_buffers   = rpi_swap_buffers,
    .control        = rpi_control,
    .uninit         = rpi_uninit,
};
Пример #30
0
bool GLEnv::SwapBuffers() {
  const bool result = eglSwapBuffers(display(), surface()) == EGL_TRUE;
  return !CheckEGLError("eglSwapBuffers") && result;
}