| 509 | } |
| 510 | |
| 511 | void NativeEngine::DoFrame() { |
| 512 | // prepare to render (create context, surfaces, etc, if needed) |
| 513 | if (!PrepareToRender()) { |
| 514 | // not ready |
| 515 | VLOGD("NativeEngine: preparation to render failed."); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | SceneManager* mgr = SceneManager::GetInstance(); |
| 520 | |
| 521 | // how big is the surface? We query every frame because it's cheap, and some |
| 522 | // strange devices out there change the surface size without calling any |
| 523 | // callbacks... |
| 524 | int width, height; |
| 525 | eglQuerySurface(mEglDisplay, mEglSurface, EGL_WIDTH, &width); |
| 526 | eglQuerySurface(mEglDisplay, mEglSurface, EGL_HEIGHT, &height); |
| 527 | |
| 528 | if (width != mSurfWidth || height != mSurfHeight) { |
| 529 | // notify scene manager that the surface has changed size |
| 530 | LOGD("NativeEngine: surface changed size %dx%d --> %dx%d", mSurfWidth, |
| 531 | mSurfHeight, width, height); |
| 532 | mSurfWidth = width; |
| 533 | mSurfHeight = height; |
| 534 | mgr->SetScreenSize(mSurfWidth, mSurfHeight); |
| 535 | glViewport(0, 0, mSurfWidth, mSurfHeight); |
| 536 | } |
| 537 | |
| 538 | // if this is the first frame, install the welcome scene |
| 539 | if (mIsFirstFrame) { |
| 540 | mIsFirstFrame = false; |
| 541 | mgr->RequestNewScene(new WelcomeScene()); |
| 542 | } |
| 543 | |
| 544 | // render! |
| 545 | mgr->DoFrame(); |
| 546 | |
| 547 | // swap buffers |
| 548 | if (EGL_FALSE == eglSwapBuffers(mEglDisplay, mEglSurface)) { |
| 549 | // failed to swap buffers... |
| 550 | LOGW("NativeEngine: eglSwapBuffers failed, EGL error %d", eglGetError()); |
| 551 | HandleEglError(eglGetError()); |
| 552 | } |
| 553 | |
| 554 | // print out GL errors, if any |
| 555 | GLenum e; |
| 556 | static int errorsPrinted = 0; |
| 557 | while ((e = glGetError()) != GL_NO_ERROR) { |
| 558 | if (errorsPrinted < MAX_GL_ERRORS) { |
| 559 | _log_opengl_error(e); |
| 560 | ++errorsPrinted; |
| 561 | if (errorsPrinted >= MAX_GL_ERRORS) { |
| 562 | LOGE("*** NativeEngine: TOO MANY OPENGL ERRORS. NO LONGER PRINTING."); |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | android_app* NativeEngine::GetAndroidApp() { return mApp; } |
nothing calls this directly
no test coverage detected