2 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #include "SampleApplication.h"
10 SampleApplication::SampleApplication(const std::string& name, size_t width, size_t height,
11 EGLint glesMajorVersion, EGLint requestedRenderer)
15 mEGLWindow.reset(new EGLWindow(width, height, glesMajorVersion, requestedRenderer));
16 mTimer.reset(CreateTimer());
17 mOSWindow.reset(CreateOSWindow());
19 mEGLWindow->setConfigRedBits(8);
20 mEGLWindow->setConfigGreenBits(8);
21 mEGLWindow->setConfigBlueBits(8);
22 mEGLWindow->setConfigAlphaBits(8);
23 mEGLWindow->setConfigDepthBits(24);
24 mEGLWindow->setConfigStencilBits(8);
27 mEGLWindow->setSwapInterval(0);
30 SampleApplication::~SampleApplication()
34 bool SampleApplication::initialize()
39 void SampleApplication::destroy()
43 void SampleApplication::step(float dt, double totalTime)
47 void SampleApplication::draw()
51 void SampleApplication::swap()
56 OSWindow *SampleApplication::getWindow() const
58 return mOSWindow.get();
61 EGLConfig SampleApplication::getConfig() const
63 return mEGLWindow->getConfig();
66 EGLDisplay SampleApplication::getDisplay() const
68 return mEGLWindow->getDisplay();
71 EGLSurface SampleApplication::getSurface() const
73 return mEGLWindow->getSurface();
76 EGLContext SampleApplication::getContext() const
78 return mEGLWindow->getContext();
81 int SampleApplication::run()
83 if (!mOSWindow->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight()))
88 if (!mEGLWindow->initializeGL(mOSWindow.get()))
103 double prevTime = 0.0;
107 double elapsedTime = mTimer->getElapsedTime();
108 double deltaTime = elapsedTime - prevTime;
110 step(static_cast<float>(deltaTime), elapsedTime);
112 // Clear events that the application did not process from this frame
114 while (popEvent(&event))
116 // If the application did not catch a close event, close now
117 if (event.Type == Event::EVENT_CLOSED)
131 mOSWindow->messageLoop();
133 prevTime = elapsedTime;
137 mEGLWindow->destroyGL();
138 mOSWindow->destroy();
143 void SampleApplication::exit()
148 bool SampleApplication::popEvent(Event *event)
150 return mOSWindow->popEvent(event);