Пример #1
0
bool CEGLWrapper::GetSurfaceSize(EGLDisplay display, EGLSurface surface, EGLint *width, EGLint *height)
{
  if (!width || !height)
    return false;

  const bool failedToQuerySurfaceSize =
    !eglQuerySurface(display, surface, EGL_WIDTH, width) ||
    !eglQuerySurface(display, surface, EGL_HEIGHT, height);
  const bool invalidSurfaceSize =
    *width <= 0 || *height <= 0;

  if (failedToQuerySurfaceSize || invalidSurfaceSize)
    return false;

  return true;
}
Пример #2
0
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
{
    if (g_egl_dpy)
    {
        EGLint gl_width, gl_height;
        eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &gl_width);
        eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &gl_height);
        *width  = gl_width;
        *height = gl_height;
    }
    else
    {
        *width  = 0;
        *height = 0;
    }
}
bool GLHelper::makeCurrent(EGLSurface surface) {
    EGLint result;

    result = eglMakeCurrent(mDisplay, surface, surface, mContext);
    if (result != EGL_TRUE) {
        fprintf(stderr, "eglMakeCurrent error: %#x\n", eglGetError());
        return false;
    }

    EGLint w, h;
    eglQuerySurface(mDisplay, surface, EGL_WIDTH, &w);
    eglQuerySurface(mDisplay, surface, EGL_HEIGHT, &h);
    glViewport(0, 0, w, h);

    return true;
}
Пример #4
0
static unsigned gfx_ctx_get_resolution_width(unsigned resolution_id)
{
    int gl_width;
    eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &gl_width);

    return gl_width;
}
Пример #5
0
int initialize()
{
    //Query width and height of the window surface created by utility code
    EGLint surface_width, surface_height;

	int dpi = bbutil_calculate_dpi(screen_cxt);

	font = bbutil_load_font("/usr/fonts/font_repository/monotype/tahoma.ttf", 6, dpi);
	if (!font)
		return EXIT_FAILURE;

	localDraw.SetFont(font);
	localDraw.SetScreenSize(width, height);

	eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
    eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);

    width = surface_width;
    height = surface_height;

    // calculate the position of the next/prev buttons in world coordinates
    centerPrev.x = width / 2 - 88;
    centerNext.x = width / 2 + 88;
    centerPrev.y = height / 10;
    centerNext.y = height / 10;
    radius = 24;

	EGLint err = eglGetError();
	if (err != 0x3000)
	{
		fprintf(stderr, "Unable to query egl surface dimensions\n");
		return EXIT_FAILURE;
	}

    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClearDepthf(1.0);

    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glEnable(GL_BLEND);
    glEnable(GL_LINE_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    Resize(width, height);

	return EXIT_SUCCESS;
}
Пример #6
0
//  esCreateWindow()
//
//      title - name for title bar of window
//      width - width of window to create
//      height - height of window to create
//      flags  - bitwise or of window creation flags 
//          ES_WINDOW_ALPHA       - specifies that the framebuffer should have alpha
//          ES_WINDOW_DEPTH       - specifies that a depth buffer should be created
//          ES_WINDOW_STENCIL     - specifies that a stencil buffer should be created
//          ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char* title, GLint width, GLint height, GLuint flags )
{
   EGLint attribList[] =
   {
       EGL_RED_SIZE,       5,
       EGL_GREEN_SIZE,     6,
       EGL_BLUE_SIZE,      5,
       EGL_ALPHA_SIZE,     (flags & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE,
       EGL_DEPTH_SIZE,     (flags & ES_WINDOW_DEPTH) ? 24 : EGL_DONT_CARE,
       EGL_STENCIL_SIZE,   (flags & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE,
       EGL_SAMPLE_BUFFERS, (flags & ES_WINDOW_MULTISAMPLE) ? 1 : 0,
       EGL_NONE
   };
   
   if ( esContext == NULL )
   {
      return GL_FALSE;
   }

// create window (only for windows)
#ifdef _WIN32
   esContext->width = width;
   esContext->height = height;

   if ( !WinCreate ( esContext, title) )
   {
      return GL_FALSE;
   }
#endif

   if ( !CreateEGLContext ( esContext->hWnd,
                            &esContext->eglDisplay,
                            &esContext->eglContext,
                            &esContext->eglSurface,
                            attribList) )
   {
      return GL_FALSE;
   }

#ifdef __ANDROID__
	// get size
	eglQuerySurface(esContext->eglDisplay, esContext->eglSurface, EGL_WIDTH, &esContext->width);
	eglQuerySurface(esContext->eglDisplay, esContext->eglSurface, EGL_HEIGHT, & esContext->height);
#endif

   return GL_TRUE;
}
Пример #7
0
/**
 * デバイスに対してのEGLコンテキストの初期化
 */
static int engine_init_display(struct engine* engine) {
    // OepGL ES と EGLの初期化

    const EGLint attribs[] =
            { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8,
                    EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, 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);

    eglChooseConfig(display, attribs, &config, 1, &numConfigs);

    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

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

    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);

    engine->display = display;
    engine->context = context;
    engine->surface = surface;
    engine->width = w;
    engine->height = h;
    engine->state.angle = 0;

    // ボックス表示の初期化
    initBox(engine);

    return 0;
}
Пример #8
0
void QWebOSGLContext::createSurface()
{
    m_eglSurface = eglCreateWindowSurface(s_eglDisplay, m_eglConfig,
                                          m_platformWindow->getEglWindow(),
                                          NULL);

    if (m_eglSurface == EGL_NO_SURFACE) {
        qDebug("Could not create the egl surface: error = 0x%x\n", eglGetError());
        eglTerminate(s_eglDisplay);
        qFatal("EGL error");
    }

    EGLint w, h;
    eglQuerySurface(s_eglDisplay, m_eglSurface, EGL_WIDTH, &w);
    eglQuerySurface(s_eglDisplay, m_eglSurface, EGL_HEIGHT, &h);
    m_surfaceSize = QSize(w,h);
}
Пример #9
0
static void gfx_ctx_qnx_get_video_size(void *data, unsigned *width, unsigned *height)
{
   EGLint gl_width, gl_height;

   (void)data;

   *width  = 0;
   *height = 0;

   if (!g_egl_dpy)
      return;

   eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &gl_width);
   eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &gl_height);
   *width  = gl_width;
   *height = gl_height;
}
GUI::UInt32
CAndroidGLESWindowContext::GetWidth( void ) const
{GUCEF_TRACE;

    EGLint width = 0;
    eglQuerySurface( m_display, m_surface, EGL_WIDTH, &width );
    return width;
}
Пример #11
0
void initializeWindow()
{
	const EGLint attribs[] =
	{
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
		EGL_BLUE_SIZE, 8,
		EGL_GREEN_SIZE, 8,
		EGL_RED_SIZE, 8,
		EGL_NONE
	};
	EGLint w, h, dummy, format;
	EGLint numConfigs;
	EGLConfig config;
	EGLSurface surface;
	EGLContext context;

	//-- get the display
	EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(display, 0, 0);
	//-- choose config for the display
	eglChooseConfig(display, attribs, &config, 1, &numConfigs);
	//-- get format attributes to pass to the native window
	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
	//-- set format for the native window
	ANativeWindow_setBuffersGeometry(_device.app->window, 0, 0, format);

	//-- create a surface and context to draw on
	surface = eglCreateWindowSurface(display, config, _device.app->window, NULL);
	context = eglCreateContext(display, config, NULL, NULL);

	//-- get the display dimensions
	eglQuerySurface(display, surface, EGL_WIDTH, &w);
	eglQuerySurface(display, surface, EGL_HEIGHT, &h);


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

	_device.Display.display = display;
	_device.Display.context = context;
	_device.Display.surface = surface;
	_device.Display.width = w;
	_device.Display.height = h;
}
GUI::UInt32
CAndroidGLESWindowContext::GetHeight( void ) const
{GUCEF_TRACE;

    EGLint height = 0;
    eglQuerySurface( m_display, m_surface, EGL_HEIGHT, &height );
    return height;
}
Пример #13
0
EGLint GLContext::Resume( ANativeWindow* window )
{
    if( egl_context_initialized_ == false )
    {
        Init( window );
        return EGL_SUCCESS;
    }

    int32_t original_widhth = screen_width_;
    int32_t original_height = screen_height_;

    //Create surface
    window_ = window;
    surface_ = eglCreateWindowSurface( display_, config_, window_, NULL );
    eglQuerySurface( display_, surface_, EGL_WIDTH, &screen_width_ );
    eglQuerySurface( display_, surface_, EGL_HEIGHT, &screen_height_ );

    if( screen_width_ != original_widhth || screen_height_ != original_height )
    {
        //Screen resized
        LOGI( "Screen resized" );
    }

    if( eglMakeCurrent( display_, surface_, surface_, context_ ) == EGL_TRUE )
        return EGL_SUCCESS;

    EGLint err = eglGetError();
    LOGW( "Unable to eglMakeCurrent %d", err );

    if( err == EGL_CONTEXT_LOST )
    {
        //Recreate context
        LOGI( "Re-creating egl context" );
        InitEGLContext();
    }
    else
    {
        //Recreate surface
        Terminate();
        InitEGLSurface();
        InitEGLContext();
    }

    return err;

}
Пример #14
0
///
// Draw a triangle using the shader pair created in Init()
//
void Draw(Example *example)
{
    UserData *userData = (UserData *)example->userptr;

    // Set the viewport
    EGLint width = 0; 
    EGLint height = 0;
    eglQuerySurface(example->egl.display, example->egl.surface, EGL_WIDTH, &width);
    eglQuerySurface(example->egl.display, example->egl.surface, EGL_HEIGHT, &height);
    glViewport(0, 0, width, height);

    // Clear the color buffer
    glClear(GL_COLOR_BUFFER_BIT);

    // Load the vertex attributes
    glBindBuffer(GL_ARRAY_BUFFER, userData->vertexObject);
    glVertexAttribPointer(userData->lifetimeLoc, 1, GL_FLOAT,
        GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
        (const GLvoid *)0);

    glVertexAttribPointer(userData->endPositionLoc, 3, GL_FLOAT,
        GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
        (const GLvoid *)4);

    glVertexAttribPointer(userData->startPositionLoc, 3, GL_FLOAT,
        GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
        (const GLvoid *)16);


    glEnableVertexAttribArray(userData->lifetimeLoc);
    glEnableVertexAttribArray(userData->endPositionLoc);
    glEnableVertexAttribArray(userData->startPositionLoc);
    // Blend particles
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    // Bind the texture
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, userData->textureId);

    // Set the sampler texture unit to 0
    glUniform1i(userData->samplerLoc, 0);

    glDrawArrays(GL_POINTS, 0, NUM_PARTICLES);
}
Пример #15
0
static void gfx_ctx_vivante_get_video_size(void *data,
      unsigned *width, unsigned *height)
{
   (void)data;

   *width  = 0;
   *height = 0;

   if (g_egl_dpy != EGL_NO_DISPLAY && g_egl_surf != EGL_NO_SURFACE)
   {
      EGLint gl_width, gl_height;

      eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &gl_width);
      eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &gl_height);
      *width  = gl_width;
      *height = gl_height;
   }
}
Пример #16
0
    ::EGLConfig EGLSupport::getGLConfigFromDrawable(::EGLSurface drawable,
                                                    unsigned int *w, unsigned int *h)
    {
        ::EGLConfig glConfig = 0;

        if (eglQuerySurface(mGLDisplay, drawable, EGL_CONFIG_ID, (EGLint *) &glConfig) == EGL_FALSE)
        {
            OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR,
                        "Fail to get config from drawable",
                        __FUNCTION__);
            return 0;
        }

        eglQuerySurface(mGLDisplay, drawable, EGL_WIDTH, (EGLint *) w);
        eglQuerySurface(mGLDisplay, drawable, EGL_HEIGHT, (EGLint *) h);

        return glConfig;
    }
Пример #17
0
static int IJK_EGL_getSurfaceHeight(IJK_EGL* egl)
{
    EGLint height = 0;
    if (!eglQuerySurface(egl->display, egl->surface, EGL_HEIGHT, &height)) {
        ALOGE("[EGL] eglQuerySurface(EGL_HEIGHT) returned error %d", eglGetError());
        return 0;
    }

    return height;
}
Пример #18
0
static int IJK_EGL_getSurfaceWidth(IJK_EGL* egl)
{
    EGLint width = 0;
    if (!eglQuerySurface(egl->display, egl->surface, EGL_WIDTH, &width)) {
        ALOGE("[EGL] eglQuerySurface(EGL_WIDTH) returned error %d", eglGetError());
        return 0;
    }

    return width;
}
Пример #19
0
void initialize()
{
	//Initialize vertex and color data
    vertices[0] = -0.25f;
    vertices[1] = -0.25f;

    vertices[2] = 0.25f;
    vertices[3] = -0.25f;

    vertices[4] = -0.25f;
    vertices[5] = 0.25f;

    vertices[6] = 0.25f;
    vertices[7] = 0.25f;

    colors[0] = 1.0f;
    colors[1] = 0.0f;
    colors[2] = 1.0f;
    colors[3] = 1.0f;

    colors[4] = 1.0f;
    colors[5] = 1.0f;
    colors[6] = 0.0f;
    colors[7] = 1.0f;

    colors[8] = 0.0f;
    colors[9] = 1.0f;
    colors[10] = 1.0f;
    colors[11] = 1.0f;

    colors[12] = 0.0f;
    colors[13] = 1.0f;
    colors[14] = 1.0f;
    colors[15] = 1.0f;

    //Query width and height of the window surface created by utility code
    EGLint surface_width, surface_height;

	eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
    eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);

    glTranslatef((float)(surface_width) / (float)(surface_height) / 2, 0.5f, 0.0f);
}
Пример #20
0
	void AndroidEGLWindow::windowMovedOrResized()
	{
        if(mActive)
        {		
			// When using GPU rendering for Android UI the os creates a context in the main thread
			// Now we have 2 choices create OGRE in its own thread or set our context current before doing
			// anything else. I put this code here because this function called before any rendering is done.
			// Because the events for screen rotation / resizing did not worked on all devices it is the best way
			// to query the correct dimensions.
	        mContext->setCurrent(); 
            eglQuerySurface(mEglDisplay, mEglSurface, EGL_WIDTH, (EGLint*)&mWidth);
            eglQuerySurface(mEglDisplay, mEglSurface, EGL_HEIGHT, (EGLint*)&mHeight);
            
            // Notify viewports of resize
            ViewportList::iterator it = mViewportList.begin();
            while( it != mViewportList.end() )
                (*it++).second->_updateDimensions();
        }
	}
Пример #21
0
QImage* QMeeGoLivePixmapData::lock(EGLSyncKHR fenceSync)
{
    QGLShareContextScope ctx(qt_gl_share_widget()->context());
    QMeeGoExtensions::ensureInitialized();

    if (fenceSync) {
        QMeeGoExtensions::eglClientWaitSyncKHR(QEgl::display(),
                                               fenceSync,
                                               EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
                                               EGL_FOREVER_KHR);
    }

    void *data = 0;
    int pitch = 0;
    EGLSurface surface = 0;
    QImage::Format format;
    lockedImage = QImage();

    surface = getSurfaceForBackingPixmap();
    if (! QMeeGoExtensions::eglLockSurfaceKHR(QEgl::display(), surface, lock_attribs)) {
        qWarning("Failed to lock surface (live texture)!");
        return &lockedImage;
    }

    eglQuerySurface(QEgl::display(), surface, EGL_BITMAP_POINTER_KHR, (EGLint*) &data);
    eglQuerySurface(QEgl::display(), surface, EGL_BITMAP_PITCH_KHR, (EGLint*) &pitch);

    // Ok, here we know we just support those two formats. Real solution would be:
    // uqery also the format.
    if (backingX11Pixmap->depth() > 16)
        format = QImage::Format_ARGB32_Premultiplied;
    else
        format = QImage::Format_RGB16;

    if (data == NULL || pitch == 0) {
        qWarning("Failed to query the live texture!");
        return &lockedImage;
    }

    lockedImage = QImage((uchar *) data, width(), height(), format);
    return &lockedImage;
}
Пример #22
0
	void OGLESRenderWindow::WindowMovedOrResized(Window const & win)
	{
#if defined KLAYGE_PLATFORM_WINDOWS
		UNREF_PARAM(win);

		::RECT rect;
		::GetClientRect(hWnd_, &rect);

		uint32_t new_left = rect.left;
		uint32_t new_top = rect.top;
		if ((new_left != left_) || (new_top != top_))
		{
			this->Reposition(new_left, new_top);
		}

		uint32_t new_width = rect.right - rect.left;
		uint32_t new_height = rect.bottom - rect.top;
#elif defined KLAYGE_PLATFORM_LINUX
		int screen = DefaultScreen(x_display_);
		uint32_t new_width = DisplayWidth(x_display_, screen);
		uint32_t new_height = DisplayHeight(x_display_, screen);
#elif defined KLAYGE_PLATFORM_ANDROID
		uint32_t new_left = win.Left() / 2;
		uint32_t new_top = win.Top() / 2;
		if ((new_left != left_) || (new_top != top_))
		{
			this->Reposition(new_left, new_top);
		}

		EGLint new_width, new_height;
		eglQuerySurface(display_, surf_, EGL_WIDTH, &new_width);
		eglQuerySurface(display_, surf_, EGL_HEIGHT, &new_height);

		new_width -= new_left;
		new_height -= new_top;
#endif

		if ((new_width != width_) || (new_height != height_))
		{
			Context::Instance().RenderFactoryInstance().RenderEngineInstance().Resize(new_width, new_height);
		}
	}
Пример #23
0
bool GLContext::InitEGLSurface() {
  display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  eglInitialize(display_, 0, 0);

  /*
   * 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_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,  // Request opengl ES2.0
      EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,     EGL_BLUE_SIZE, 8,
      EGL_GREEN_SIZE,      8,                  EGL_RED_SIZE,  8,
      EGL_DEPTH_SIZE,      24,                 EGL_NONE};
  color_size_ = 8;
  depth_size_ = 24;

  EGLint num_configs;
  eglChooseConfig(display_, attribs, &config_, 1, &num_configs);

  if (!num_configs) {
    // Fall back to 16bit depth buffer
    const EGLint attribs[] = {
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,  // Request opengl ES2.0
        EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,     EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE,      8,                  EGL_RED_SIZE,  8,
        EGL_DEPTH_SIZE,      16,                 EGL_NONE};
    eglChooseConfig(display_, attribs, &config_, 1, &num_configs);
    depth_size_ = 16;
  }

  if (!num_configs) {
    LOGW("Unable to retrieve EGL config");
    return false;
  }

  surface_ = eglCreateWindowSurface(display_, config_, window_, NULL);
  eglQuerySurface(display_, surface_, EGL_WIDTH, &screen_width_);
  eglQuerySurface(display_, surface_, EGL_HEIGHT, &screen_height_);

  return true;
}
Пример #24
0
int size_eglpbuffer(const eglpbuffer_t eglpbuf, struct opengl_display_t * egldisp, /*out*/uint32_t * width, /*out*/uint32_t * height)
{
   int err;
   EGLint attr_value;
   static_assert(sizeof(EGLint) <= sizeof(uint32_t), "attribute type can be converted to returned type");
   if (!eglQuerySurface(egldisp, eglpbuf, EGL_WIDTH, &attr_value)) {
      goto ONERR;
   }
   *width = (uint32_t) attr_value;
   if (!eglQuerySurface(egldisp, eglpbuf, EGL_HEIGHT, &attr_value)) {
      goto ONERR;
   }
   *height = (uint32_t) attr_value;

   return 0;
ONERR:
   err = convert2errno_egl(eglGetError());
   TRACEEXIT_ERRLOG(err);
   return err;
}
Пример #25
0
int initialize()
{
	EGLint surface_width, surface_height;

	eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
	EGLint err = eglGetError();
	if (err != 0x3000) {
		return EXIT_FAILURE;
	}

	eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);
	err = eglGetError();
	if (err != 0x3000) {
		return EXIT_FAILURE;
	}

    glClearDepthf(1.0f);
    glClearColor(0.0f,0.0f,0.0f,1.0f);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);

	glViewport(0, 0, surface_width, surface_height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	float nearClip = -2.0f;
	float farClip  = 2.0f;
	float yFOV  = 75.0f;
	float yMax = nearClip * tan(yFOV*M_PI/360.0f);
	float aspect = surface_width/surface_height;
	float xMin = -yMax * aspect;
	float xMax = yMax *aspect;

	glFrustumf(xMin, xMax, -yMax, yMax, nearClip, farClip);
	glScalef((float)surface_height/(float)surface_width, 1.0f, 1.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	return EXIT_SUCCESS;
}
Пример #26
0
int init(engine* e) {
	const EGLint attribs[] = {
		EGL_BLUE_SIZE,       8,
		EGL_GREEN_SIZE,      8,
		EGL_RED_SIZE,        8,
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
		EGL_NONE
	};
	const EGLint contextAttribs[] = {
		EGL_CONTEXT_CLIENT_VERSION, 2,
		EGL_NONE
	};

	EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(display, 0, 0);

	EGLConfig config;
	EGLint numConfigs;
	eglChooseConfig(display, attribs, &config, 1, &numConfigs);

	EGLint format;
	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
	ANativeWindow_setBuffersGeometry(e->app->window, 0, 0, format);

	EGLSurface surface = eglCreateWindowSurface(display, config, e->app->window, NULL);
	EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);

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

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

	e->display = display;
	e->surface = surface;

	glViewport(0, 0, w, h);

}
/* XXX: Lock eglgles context? */
gboolean
gst_egl_adaptation_update_surface_dimensions (GstEglAdaptationContext * ctx)
{
  gint width, height;

  /* Save surface dims */
  eglQuerySurface (gst_egl_display_get (ctx->display),
      ctx->eglglesctx->surface, EGL_WIDTH, &width);
  eglQuerySurface (gst_egl_display_get (ctx->display),
      ctx->eglglesctx->surface, EGL_HEIGHT, &height);

  if (width != ctx->surface_width || height != ctx->surface_height) {
    ctx->surface_width = width;
    ctx->surface_height = height;
    GST_INFO_OBJECT (ctx->element, "Got surface of %dx%d pixels", width,
        height);
    return TRUE;
  }

  return FALSE;
}
/* EGLBoolean eglQuerySurface ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value ) */
static jboolean
android_eglQuerySurface
  (JNIEnv *_env, jobject _this, jobject dpy, jobject surface, jint attribute, jintArray value_ref, jint offset) {
    jint _exception = 0;
    const char * _exceptionType = NULL;
    const char * _exceptionMessage = NULL;
    EGLBoolean _returnValue = (EGLBoolean) 0;
    EGLDisplay dpy_native = (EGLDisplay) fromEGLHandle(_env, egldisplayGetHandleID, dpy);
    EGLSurface surface_native = (EGLSurface) fromEGLHandle(_env, eglsurfaceGetHandleID, surface);
    EGLint *value_base = (EGLint *) 0;
    jint _remaining;
    EGLint *value = (EGLint *) 0;

    if (!value_ref) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "value == null";
        goto exit;
    }
    if (offset < 0) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "offset < 0";
        goto exit;
    }
    _remaining = _env->GetArrayLength(value_ref) - offset;
    if (_remaining < 1) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "length - offset < 1 < needed";
        goto exit;
    }
    value_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
    value = value_base + offset;

    _returnValue = eglQuerySurface(
        (EGLDisplay)dpy_native,
        (EGLSurface)surface_native,
        (EGLint)attribute,
        (EGLint *)value
    );

exit:
    if (value_base) {
        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
            _exception ? JNI_ABORT: 0);
    }
    if (_exception) {
        jniThrowException(_env, _exceptionType, _exceptionMessage);
    }
    return (jboolean)_returnValue;
}
static void android_view_HardwareRenderer_beginFrame(JNIEnv* env, jobject clazz,
        jintArray size) {

    EGLDisplay display = eglGetCurrentDisplay();
    EGLSurface surface = eglGetCurrentSurface(EGL_DRAW);

    if (size) {
        EGLint value;
        jint* storage = env->GetIntArrayElements(size, NULL);

        eglQuerySurface(display, surface, EGL_WIDTH, &value);
        storage[0] = value;

        eglQuerySurface(display, surface, EGL_HEIGHT, &value);
        storage[1] = value;

        env->ReleaseIntArrayElements(size, storage, 0);
    }

    eglBeginFrame(display, surface);
}
Пример #30
0
int _glfwPlatformOpenWindow( int width, int height,
                             const _GLFWwndconfig* wndconfig,
                             const _GLFWfbconfig* fbconfig )
{
    while( _glfwWin.initialized != GL_TRUE ) {
        _glfwPlatformPollEvents();
    }

    {
        const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 16, EGL_NONE };
        EGLint w, h, format;
        EGLint numConfigs;
        EGLConfig config;
        EGLSurface surface;
        EGLContext context;
        EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        eglInitialize(display, 0, 0);
        eglChooseConfig(display, attribs, &config, 1, &numConfigs);
        eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
        ANativeWindow_setBuffersGeometry(_glfwWin.app->window, 0, 0, format
);
        surface = eglCreateWindowSurface(display, config, _glfwWin.app->window, NULL);
        context = eglCreateContext(display, config, NULL, NULL);
        if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
           return GL_FALSE;
        }

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

        _glfwWin.display = display;
        _glfwWin.context = context;
        _glfwWin.surface = surface;
        _glfwWin.width = w;
        _glfwWin.height = h;

        _glfwWin.resized = GL_TRUE;
    }
    return GL_TRUE;
}