Ejemplo n.º 1
0
void cxAndroid::cxAndroidMain()
{
    vm = activity->vm;
    vm->AttachCurrentThread(&env, nullptr);
    CX_ASSERT(env != nullptr, "attach current thread java env error");
    //startup engine
    cxEngine::Startup(false);
    while(!destroyReq){
        if(ProcessInput()){
            break;
        }
        if(animating) {
            DrawFrame();
        }
    }
    //destroy engine
    cxEngine::Destroy();
    //clear core cache
    cxCore::Instance()->Clear();
    DestroyDisplay();
    if(env != nullptr){
        vm->DetachCurrentThread();
        env = NULL;
    }
}
Ejemplo n.º 2
0
 void AndroidEventLoop::Deactivate()
 {
     if (mEnabled)
     {
     	m_pActivityHandler->onDeactivate();
         mEnabled = false;
     }
     DestroyDisplay();
 }
Ejemplo n.º 3
0
	void Shutdown( void ) {
		console.Print( PrintLevel::Normal, "Shutting down renderer...\n" );

		RenderCommand::Shutdown();
		Font::Shutdown();
		//ShaderProgram::Shutdown();
		Texture::Shutdown();
		Backend::Shutdown();

		DestroyDisplay();
	}
Ejemplo n.º 4
0
		ReturnValue WindowsEventLoop::Run(ActivityHandler* pActivityHandler)
		{
			m_pActivityHandler = pActivityHandler;
			m_isRunning=true;

			InitializeDisplay();
			m_pActivityHandler->onActivate();

			// Global step loop.
			while(m_isRunning)
			{
				ProcessEvents();
				if(m_pActivityHandler->onStep() != RETURN_VALUE_OK)
				{
					m_isRunning=false;
				}
				SwapBuffers();
			}

			m_pActivityHandler->onDeactivate();
			DestroyDisplay();
			return RETURN_VALUE_OK;
		}
Ejemplo n.º 5
0
void *VolumeRendererShell::ThreadFunction(void* ptr) {

#ifdef SAGE

  // Swap buffer observer class for SAGE
  class SwapBuffers : public VolumeRendererCommand {

  public:

    // Constructor
    SwapBuffers(int width, int height, 
                Display* display, GLXPbufferSGIX pbuffer,
                char* hostname, int port,
                float left, float right, float bottom, float top,
                int rank, int numberOfNodes, int* level) {

      // Current level
      _level = level;

      // Display variables
      _xDisplay = display;
      _glXPBuffer = pbuffer;      
      _height = height;
      _width = width;

      // Initialize synchronizer
      _synchronizerClient.Init(hostname, port);

      // Setup SAGE viewport
      _sageImageMap.left = left;
      _sageImageMap.right = right;
      _sageImageMap.bottom = bottom;
      _sageImageMap.top = top;

      // SAGE parameters
      _sageConfig.init("VRA.conf");
      _sageConfig.setAppName("VRA");
      _sageConfig.rank = rank;
      _sageConfig.nodeNum = numberOfNodes - 1;
      _sageConfig.resX = _width;
      _sageConfig.resY = _height;
      _sageConfig.imageMap = _sageImageMap;
      _sageConfig.pixFmt = PIXFMT_888;
      _sageConfig.rowOrd = BOTTOM_TO_TOP;
      _sageConfig.master = false;
      _sageConfig.rendering = true;

      // Initialize SAGE
      _sageInf.init(_sageConfig);

      // Check buffer
      _image = NULL;
      if (_image != NULL)
        delete [] _image;

      // Get buffer from SAGE
      _image = (GLubyte*) _sageInf.getBuffer();

    }

    // Destructor
    ~SwapBuffers() {
      
      // Finalize synchronizer
      _synchronizerClient.Finalize();
      
    }

    // Execute callback
    bool Execute(int value) { 

      // Setup readback
      glReadBuffer(GL_FRONT);
      glPixelStorei(GL_PACK_ALIGNMENT, 1);

      // Synchronize with other nodes
      _synchronizerClient.Barrier(*_level);

      // Swap buffer
      if (value == 0) {
        glXSwapBuffers(_xDisplay, _glXPBuffer);
        glReadPixels(0, 0, _width, _height, 
                     GL_RGB, GL_UNSIGNED_BYTE, _image);
        _sageInf.swapBuffer();
        _image = (GLubyte*) _sageInf.getBuffer();
        return true;
      }

      // Send current buffer
      else {
        glReadPixels(0, 0, _width, _height, 
                     GL_RGB, GL_UNSIGNED_BYTE, _image);
        _sageInf.swapBuffer();
        _image = (GLubyte*) _sageInf.getBuffer();
        return false;
      }

    }

  private:

    // Current level
    int* _level;

    // Display variables
    Display* _xDisplay;
    GLXPbufferSGIX _glXPBuffer;
    GLubyte* _image;
    int _height;
    int _width;
    
    // SAGE variables
    sageRect _sageImageMap;
    sail _sageInf;
    sailConfig _sageConfig;

    // Synchronizer
    SynchronizerClient _synchronizerClient;

  };

#else

  // Swap buffer observer class for SDL
  class SwapBuffers : public VolumeRendererCommand {

  public:

    // Constructor
    SwapBuffers(char* hostname, int port, int* level) {

      // Current level
      _level = level;

      // Initialize synchronizer
      _synchronizerClient.Init(hostname, port);

    }

    // Destructor
    ~SwapBuffers() {
 
      // Finalize synchronizer
      _synchronizerClient.Finalize();
 
    }

    // Execute callback
    virtual bool Execute(int value) {

      // Synchronizer with other nodes
      _synchronizerClient.Barrier(*_level);

      // Swap buffer
      if (value == 0) {
        SDL_GL_SwapBuffers();
        return true;
      }

      return false;

    }

  private:

    // Current level
    int* _level;

    // Synchronizer
    SynchronizerClient _synchronizerClient;

  };

#endif

  // Progress observer class
  class ProgressUpdate : public VolumeRendererCommand {
  public:
    ProgressUpdate(int* level) {
      _level = level;
    }
    virtual bool Execute(int value) {
      *_level = value;
      return true;
    }
  private:
    int* _level;
  };

  // Abort check observer class
  class AbortCheck : public VolumeRendererCommand {
  public:
    AbortCheck(VolumeRendererThreadInfo* info) {
      _info = info;
    }
    virtual bool Execute(int value) {
      if (_info -> _abortFlag == true) {
        _info -> _abortFlag = false;
        return true;
      }
      return false;
    }
  private:
    VolumeRendererThreadInfo* _info;
  };

  // Current level
  int level = 0;

  // Cast thread info class
  VolumeRendererThreadInfo* info = (VolumeRendererThreadInfo*) ptr;

  // Initialize display
  InitDisplay(info -> _displaySize[0], 
              info -> _displaySize[1],
              info -> _fullScreenFlag,
              info -> _normalCoordinates[0],
              info -> _normalCoordinates[1],
              info -> _normalCoordinates[2],
              info -> _normalCoordinates[3]);

  // Initialize volume renderer
  VolumeRenderer* renderer = new VolumeRenderer;
  renderer -> Init();

  // Abort render observer
  VolumeRendererCommand* ac = new AbortCheck(info);
  renderer -> SetAbortRenderObserver(ac);  

  // Progress observer
  VolumeRendererCommand* pu = new ProgressUpdate(&level);
  renderer -> SetProgressObserver(pu);  

#ifdef SAGE

  // Swap buffer observer
  VolumeRendererCommand* sb = 
    new SwapBuffers(info -> _displaySize[0], 
                    info -> _displaySize[1],
                    _xDisplay, _glXPBuffer,
                    info -> _synchronizationHostname,
                    info -> _synchronizationPort,
                    info -> _normalCoordinates[0],
                    info -> _normalCoordinates[1],
                    info -> _normalCoordinates[2],
                    info -> _normalCoordinates[3],
                    info -> _rank,
                    info -> _numberOfNodes,
                    &level);
  renderer -> SetSwapBuffersObserver(sb);

#else

  // Swap buffer observer
  VolumeRendererCommand* sb = 
    new SwapBuffers(info -> _synchronizationHostname,
                    info -> _synchronizationPort,
                    &level);
  renderer -> SetSwapBuffersObserver(sb);

#endif

  // Get mutex and condition variables
  pthread_mutex_t* conditionMutex = info -> _conditionMutex;
  pthread_cond_t* conditionCond = info -> _conditionCond;

  // Thread loop
  while(info -> _exitFlag == false) {

    // Wait on condition variable
    pthread_mutex_lock(conditionMutex);
    while(info -> _renderFlag == false) {
      pthread_cond_wait(conditionCond, conditionMutex);
    }
    pthread_mutex_unlock(conditionMutex);
 
    // Check exit flag
    if (info -> _exitFlag == true) {
      continue;
    }

    // Check for update axis flag
    if (info -> _updateAxis == true) {
      if (info -> _axisOnFlag == true) {
        renderer -> SetAxisOn();
      }
      else {
        renderer -> SetAxisOff();
      }
      renderer -> SetAxisPosition(info -> _axisPosition[0], 
                                  info -> _axisPosition[1], 
                                  info -> _axisPosition[2]);
      info -> _updateAxis = false;
    }

    // Check for update brick box flag
    if (info -> _updateBrickBox == true) {
      if (info -> _brickBoxOnFlag == true) {
        renderer -> SetBrickBoxOn();
      }
      else {
        renderer -> SetBrickBoxOff();
      }
    }

    // Check for update bounding box flag
    if (info -> _updateBoundingBox == true) {
      if (info -> _boundingBoxOnFlag == true) {
        renderer -> SetBoundingBoxOn();
      }
      else {
        renderer -> SetBoundingBoxOff();
      }
    }

    // Check for update data flag
    if (info -> _updateData == true) {
      renderer -> SetData(info -> _data, info -> _ramSize, info -> _vramSize);
      info -> _updateData = false;
    }

    // Check for update frustum flag
    if (info -> _updateFrustum == true) {
      renderer -> SetFrustum(info -> _frustum[0], info -> _frustum[1],
                             info -> _frustum[2], info -> _frustum[3],
                             info -> _frustum[4], info -> _frustum[5]);
      info -> _updateFrustum = false;
    }

    // Check for update map flag
    if (info -> _updateMap == true) {
      if (info -> _mapType == VOLUME_RENDERER_THREAD_INFO_MAP_8) {
        renderer -> SetMapUnsigned8Int(info -> _map);
      }
      else if (info -> _mapType == VOLUME_RENDERER_THREAD_INFO_MAP_16) {
        renderer -> SetMapUnsigned16Int(info -> _map);
      }
      info -> _updateMap = false;
    }

    // Check for update R flag
    if (info -> _updateR == true) {
      renderer -> SetR(info -> _R);
      info -> _updateR = false;
    }

    // Check for update S flag
    if (info -> _updateS == true) {
      renderer -> SetS(info -> _S);
      info -> _updateS = false;
    }

    // Check for update slice frequency flag
    if (info -> _updateSliceFrequency == true) {
      renderer -> SetSliceFrequency(info -> _sliceFrequency);
      info -> _updateSliceFrequency = false;
    }

    // Check for update T flag
    if (info -> _updateT == true) {
      renderer -> SetT(info -> _T);
      info -> _updateT = false;
    }

    // Check for update viewport flag
    if (info -> _updateViewport == true) {
      renderer -> SetViewport(info -> _viewport[0], info -> _viewport[1],
                              info -> _viewport[2], info -> _viewport[3]);
      info -> _updateViewport = false;
    }

    // Render
    info -> _inRenderFlag = true;
    renderer -> Render();
    info -> _abortFlag = false;
    info -> _inRenderFlag = false;

    // Reset render flag
    info -> _renderFlag = false;

  }

  // Clean up renderer
  delete renderer;

  // Clean up abort render observer
  delete ac;

  // Clean up progress observer
  delete pu;

  // Clean up swap buffer observer
  delete sb;

  // Clean up display
  DestroyDisplay();

}
Ejemplo n.º 6
0
	Status AndroidEventLoop::InitializeDisplay()
	{
		int mWidth, mHeight;

		EGLint lFormat, lNumConfigs, lErrorResult;
		EGLConfig lConfig;

		const EGLint lAttributes[] =
			{
				EGL_RENDERABLE_TYPE, EGL_WINDOW_BIT,
				EGL_RED_SIZE, 8,
				EGL_GREEN_SIZE, 8,
				EGL_BLUE_SIZE, 8,
				EGL_DEPTH_SIZE, 24,
				EGL_NONE
			};
		const EGLint lContextAttrib[] =
		{
			EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE
		};

		// Retrieves a display connection and initializes it.
		mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
		if (mDisplay == EGL_NO_DISPLAY)
		{
			LOGE("EGL_NO_DISPLAY");
			goto ERROR;
		}
		if (!eglInitialize(mDisplay, NULL, NULL))
		{
			LOGE("Unable to initialize display");
			goto ERROR;
		}

		// Selects the first OpenGL configuration found.
		if(!eglChooseConfig(mDisplay, lAttributes, &lConfig, 1, &lNumConfigs) || (lNumConfigs <= 0))
		{
			LOGE("Unable to select display configuration");
			goto ERROR;
		}

		// Reconfigures the Android window with the EGL format.
		if (!eglGetConfigAttrib(mDisplay, lConfig, EGL_NATIVE_VISUAL_ID, &lFormat))
		{
			LOGE("Unable to configure window format");
			goto ERROR;
		}
		ANativeWindow_setBuffersGeometry(Global::pAndroidApp->window, 0, 0, lFormat);
		// Creates the display surface.
		mSurface = eglCreateWindowSurface(mDisplay, lConfig, Global::pAndroidApp->window, NULL);
		if (mSurface == EGL_NO_SURFACE)
		{
			LOGE("EGL_NO_SURFACE");
			goto ERROR;
		}
		mContext = eglCreateContext(mDisplay, lConfig, EGL_NO_CONTEXT, lContextAttrib);
		if (mContext == EGL_NO_CONTEXT)
		{
			LOGE("EGL_NO_CONTEXT");
			goto ERROR;
		}

		// Activates the display surface.
		LOGD("Activating the display.");
		if (!eglMakeCurrent(mDisplay, mSurface, mSurface, mContext)
		 || !eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth)
		 || !eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight)
		 || (mWidth <= 0) || (mHeight <= 0))
		{
			LOGE("Unable to activate display");
			goto ERROR;
		}

		// Displays information about OpenGL.
		LOGI("Starting GraphicsService");
		LOGI("Version  : %s", glGetString(GL_VERSION));
		LOGI("Vendor   : %s", glGetString(GL_VENDOR));
		LOGI("Renderer : %s", glGetString(GL_RENDERER));
		LOGI("Viewport : %d x %d", mWidth, mHeight);

		Render::SetScreenSize(mWidth,mHeight);

		return STATUS_OK;

	ERROR:
		LOGE("Error while starting GraphicsService");
		DestroyDisplay();
		return STATUS_KO;
	}