Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-06-27 14:32:21 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-06-28 18:04:46 +0300
commitfa65b1a203134bec37371fe818067f9ae7c821c8 (patch)
tree57406af369ecd9c6535b971d065701bcbe9b6123 /qt_tstfrm
parent68f4e87b2cd1ab60484d2802f6a4da6bb56a07a2 (diff)
Added shaders library
Diffstat (limited to 'qt_tstfrm')
-rw-r--r--qt_tstfrm/test_main_loop.cpp78
-rw-r--r--qt_tstfrm/test_main_loop.hpp10
2 files changed, 71 insertions, 17 deletions
diff --git a/qt_tstfrm/test_main_loop.cpp b/qt_tstfrm/test_main_loop.cpp
index cfd37fdb98..961a4fff7a 100644
--- a/qt_tstfrm/test_main_loop.cpp
+++ b/qt_tstfrm/test_main_loop.cpp
@@ -3,38 +3,38 @@
#include <QtCore/QTimer>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
+#include <QtGui/QOffscreenSurface>
+#include <QtGui/QOpenGLContext>
#include "base/scope_guard.hpp"
-#include "std/cstring.hpp"
+#include <cstring>
+#include <memory>
namespace
{
-
class MyWidget : public QWidget
{
public:
- MyWidget(TRednerFn const & fn)
- : m_fn(fn)
- {
- }
+ explicit MyWidget(RenderFunction && fn)
+ : m_fn(std::move(fn))
+ {}
protected:
- void paintEvent(QPaintEvent * e)
+ void paintEvent(QPaintEvent * e) override
{
m_fn(this);
}
private:
- TRednerFn m_fn;
+ RenderFunction m_fn;
};
+} // namespace
-} // namespace
-
-void RunTestLoop(char const * testName, TRednerFn const & fn, bool autoExit)
+void RunTestLoop(char const * testName, RenderFunction && fn, bool autoExit)
{
- char * buf = (char *)malloc(strlen(testName) + 1);
- MY_SCOPE_GUARD(argvFreeFun, [&buf](){ free(buf); });
+ auto buf = new char[strlen(testName) + 1];
+ MY_SCOPE_GUARD(argvFreeFun, [&buf](){ delete [] buf; });
strcpy(buf, testName);
int argc = 1;
@@ -42,10 +42,60 @@ void RunTestLoop(char const * testName, TRednerFn const & fn, bool autoExit)
if (autoExit)
QTimer::singleShot(3000, &app, SLOT(quit()));
- MyWidget * widget = new MyWidget(fn);
+ auto widget = new MyWidget(std::move(fn));
widget->setWindowTitle(testName);
widget->show();
app.exec();
delete widget;
}
+
+void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3,
+ TestFunction const & fn)
+{
+ auto buf = new char[strlen(testName) + 1];
+ MY_SCOPE_GUARD(argvFreeFun, [&buf](){ delete [] buf; });
+ strcpy(buf, testName);
+
+ int argc = 1;
+ QApplication app(argc, &buf);
+
+ QSurfaceFormat fmt;
+ fmt.setAlphaBufferSize(8);
+ fmt.setBlueBufferSize(8);
+ fmt.setGreenBufferSize(8);
+ fmt.setRedBufferSize(8);
+ fmt.setStencilBufferSize(0);
+ fmt.setSamples(0);
+ fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ fmt.setSwapInterval(1);
+ fmt.setDepthBufferSize(16);
+ if (apiOpenGLES3)
+ {
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+ fmt.setVersion(3, 2);
+ }
+ else
+ {
+ fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
+ fmt.setVersion(2, 1);
+ }
+
+ auto surface = std::make_unique<QOffscreenSurface>();
+ surface->setFormat(fmt);
+ surface->create();
+
+ auto context = std::make_unique<QOpenGLContext>();
+ context->setFormat(fmt);
+ context->create();
+ context->makeCurrent(surface.get());
+
+ if (fn)
+ fn(apiOpenGLES3);
+
+ context->doneCurrent();
+ surface->destroy();
+
+ QTimer::singleShot(0, &app, SLOT(quit()));
+ app.exec();
+}
diff --git a/qt_tstfrm/test_main_loop.hpp b/qt_tstfrm/test_main_loop.hpp
index db102c218e..00c330e50e 100644
--- a/qt_tstfrm/test_main_loop.hpp
+++ b/qt_tstfrm/test_main_loop.hpp
@@ -1,7 +1,11 @@
#pragma once
-#include "std/function.hpp"
+#include <functional>
class QPaintDevice;
-typedef function<void (QPaintDevice *)> TRednerFn;
-void RunTestLoop(char const * testName, TRednerFn const & fn, bool autoExit = true);
+using RenderFunction = std::function<void (QPaintDevice *)>;
+using TestFunction = std::function<void (bool apiOpenGLES3)>;
+
+extern void RunTestLoop(char const * testName, RenderFunction && fn, bool autoExit = true);
+
+extern void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3, TestFunction const & fn);