diff options
-rw-r--r-- | qt/qt.pro | 1 | ||||
-rw-r--r-- | qt/widgets.cpp | 48 | ||||
-rw-r--r-- | qt_tstfrm/gl_test_widget.hpp | 212 | ||||
-rw-r--r-- | qt_tstfrm/gui_test_widget.hpp | 101 | ||||
-rw-r--r-- | qt_tstfrm/macros.hpp | 217 | ||||
-rw-r--r-- | qt_tstfrm/main_tester.cpp | 44 | ||||
-rw-r--r-- | qt_tstfrm/main_tester.hpp | 18 | ||||
-rw-r--r-- | qt_tstfrm/qt_tstfrm.pro | 10 | ||||
-rw-r--r-- | qt_tstfrm/tstwidgets.cpp | 226 | ||||
-rw-r--r-- | qt_tstfrm/tstwidgets.hpp | 25 | ||||
-rw-r--r-- | qt_tstfrm/widgets.hpp | 50 | ||||
-rw-r--r-- | qt_tstfrm/widgets_impl.hpp | 27 |
12 files changed, 426 insertions, 553 deletions
@@ -70,7 +70,6 @@ macx* { SOURCES += \ main.cpp \ mainwindow.cpp \ - widgets.cpp \ draw_widget.cpp \ proxystyle.cpp \ slider_ctrl.cpp \ diff --git a/qt/widgets.cpp b/qt/widgets.cpp deleted file mode 100644 index 903663b2bf..0000000000 --- a/qt/widgets.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*#include "widgets.hpp" - -#include "../qt_tstfrm/widgets_impl.hpp" - -#include "../map/drawer.hpp" - -#include "../platform/platform.hpp" - -#include "../graphics/rendercontext.hpp" -#include "../graphics/internal/opengl.hpp" - - -namespace qt -{ - template class GLDrawWidgetT<Drawer>; - - GLDrawWidget::GLDrawWidget(QWidget * pParent) - : base_type(pParent) - { - } - - shared_ptr<GLDrawWidget::drawer_t> const & GLDrawWidget::GetDrawer() const - { - return m_p; - } - - GLDrawWidget::~GLDrawWidget() - { - makeCurrent(); - m_p.reset(); - doneCurrent(); - } - - void GLDrawWidget::initializeGL() - { - } - - shared_ptr<graphics::gl::RenderContext> const & GLDrawWidget::renderContext() - { - return m_renderContext; - } - - shared_ptr<graphics::ResourceManager> const & GLDrawWidget::resourceManager() - { - return m_resourceManager; - } -} -*/ diff --git a/qt_tstfrm/gl_test_widget.hpp b/qt_tstfrm/gl_test_widget.hpp new file mode 100644 index 0000000000..51f9d083ed --- /dev/null +++ b/qt_tstfrm/gl_test_widget.hpp @@ -0,0 +1,212 @@ +#pragma once + +#include "tstwidgets.hpp" + +#include "../../testing/testing.hpp" +#include "../../map/qgl_render_context.hpp" + +#include <QtGui/QApplication> + +template<class T, bool (T::*)(QKeyEvent *)> +struct key_event_fn_bind +{ + typedef T type; +}; + +template <class T, bool (T::*)(QMouseEvent*)> +struct mouse_event_fn_bind +{ + typedef T type; +}; + +template <class T, void (T::*)()> +struct void_fn_bind +{ + typedef T type; +}; + +template <class T, class RC, void (T::*)(shared_ptr<RC>)> +struct init_with_context_fn_bind +{ + typedef T type; +}; + +template<class T, class U> +struct has_on_keypress +{ + static const bool value = false; +}; + +template<class T> +struct has_on_keypress<T, typename key_event_fn_bind<T, &T::OnKeyPress>::type> +{ + static const bool value = true; +}; + +template <class T, class U> +struct has_on_mousemove +{ + static const bool value = false; +}; + +template <class T> +struct has_on_mousemove<T, typename mouse_event_fn_bind<T, &T::OnMouseMove>::type > +{ + static const bool value = true; +}; + +template <class T, class U> +struct has_on_mousepress +{ + static bool const value = false; +}; + +template <class T> +struct has_on_mousepress<T, typename mouse_event_fn_bind<T, &T::OnMousePress>::type > +{ + static const bool value = true; +}; + +template <class T, class U> +struct has_init +{ + static bool const value = false; +}; + +template <class T> +struct has_init<T, typename void_fn_bind<T, &T::Init>::type > +{ + static const bool value = true; +}; + +template <class T, class U, class RC> +struct has_init_with_context +{ + static bool const value = false; +}; + +template <class T, class RC> +struct has_init_with_context<T, typename init_with_context_fn_bind<T, RC, &T::Init>::type, RC > +{ + static const bool value = true; +}; + +template <bool T> +struct bool_tag{}; + +template <typename TTest> +class GLTestWidget : public tst::GLDrawWidget +{ +public: + + TTest test; + + typedef tst::GLDrawWidget base_type; + + virtual void DoDraw(shared_ptr<graphics::Screen> const & p) + { + p->beginFrame(); + p->clear(graphics::Color(182, 182, 182, 255)); + test.DoDraw(p); + p->endFrame(); + } + + virtual void DoResize(int, int) + { + } + + bool keyPressEventImpl(QKeyEvent * ev, bool_tag<true> const &) + { + return test.OnKeyPress(ev); + } + + bool keyPressEventImpl(QKeyEvent *, bool_tag<false> const & ) + { + return false; + } + + virtual void keyPressEvent(QKeyEvent * ev) + { + if (keyPressEventImpl(ev, bool_tag<has_on_keypress<TTest, TTest>::value >())) + repaint(); + } + + bool mousePressEventImpl(QMouseEvent * ev, bool_tag<true> const &) + { + return test.OnMousePress(ev); + } + + bool mousePressEventImpl(QMouseEvent *, bool_tag<false> const &) + { + return false; + } + + virtual void mousePressEvent(QMouseEvent * ev) + { + if (mousePressEventImpl(ev, bool_tag<has_on_mousepress<TTest, TTest>::value >())) + repaint(); + } + + bool mouseMoveEventImpl(QMouseEvent * ev, bool_tag<true> const &) + { + return test.OnMouseMove(ev); + } + + bool mouseMoveEventImpl(QMouseEvent *, bool_tag<false> const &) + { + return false; + } + + void mouseMoveEvent(QMouseEvent * ev) + { + if (mouseMoveEventImpl(ev, bool_tag<has_on_mousemove<TTest, TTest>::value >())) + repaint(); + } + + void InitImpl(bool_tag<true> const & ) + { + test.Init(); + } + + void InitImpl(bool_tag<false> const & ) + {} + + void Init() + { + InitImpl(bool_tag<has_init<TTest, TTest>::value >()); + } + + void InitWithContextImpl(bool_tag<true> const &) + { + test.Init(shared_ptr<qt::gl::RenderContext>(new qt::gl::RenderContext(this))); + } + + void InitWithContextImpl(bool_tag<false> const &) + {} + + void initializeGL() + { + tst::GLDrawWidget::initializeGL(); + InitWithContextImpl(bool_tag<has_init_with_context<TTest, TTest, qt::gl::RenderContext>::value>()); + } +}; + +template <class Test> QWidget * create_widget() +{ + GLTestWidget<Test> * w = new GLTestWidget<Test>(); + w->Init(); + return w; +} + +#define UNIT_TEST_GL(name)\ + void UnitTestGL_##name();\ + TestRegister g_TestRegister_##name("Test::"#name, __FILE__, &UnitTestGL_##name);\ + void UnitTestGL_##name()\ + {\ + char * argv[] = { const_cast<char *>(#name) };\ + int argc = 1;\ + QApplication app(argc, argv);\ + QWidget * w = create_widget<name>();\ + w->show();\ + app.exec();\ + } diff --git a/qt_tstfrm/gui_test_widget.hpp b/qt_tstfrm/gui_test_widget.hpp new file mode 100644 index 0000000000..0cfb1c8511 --- /dev/null +++ b/qt_tstfrm/gui_test_widget.hpp @@ -0,0 +1,101 @@ +#pragma once + +#include "gl_test_widget.hpp" +#include "../../gui/controller.hpp" + +template <class T, void (T::*)(gui::Controller*)> +struct init_with_controller_fn_bind +{ + typedef T type; +}; + +template <class T, class U> +struct has_init_with_controller +{ + static bool const value = false; +}; + +template <class T> +struct has_init_with_controller<T, typename init_with_controller_fn_bind<T, &T::Init>::type> +{ + static bool const value = true; +}; + +template <typename TTest> +class GUITestWidget : public GLTestWidget<TTest> +{ +private: + + typedef GLTestWidget<TTest> base_t; + + shared_ptr<gui::Controller> m_controller; + shared_ptr<graphics::Screen> m_cacheScreen; + +public: + + void initializeGL() + { + base_t::initializeGL(); + + m_controller.reset(new gui::Controller()); + + gui::Controller::RenderParams rp; + + graphics::Screen::Params cp; + + cp.m_doUnbindRT = false; + cp.m_threadSlot = 0; + cp.m_storageType = graphics::ESmallStorage; + cp.m_textureType = graphics::ESmallTexture; + cp.m_skinName = "basic_mdpi.skn"; + cp.m_isSynchronized = false; + cp.m_resourceManager = base_t::m_resourceManager; + cp.m_renderContext = base_t::m_primaryContext; + + m_cacheScreen = make_shared_ptr(new graphics::Screen(cp)); + + rp.m_CacheScreen = m_cacheScreen.get(); + rp.m_GlyphCache = base_t::m_resourceManager->glyphCache(0); + rp.m_InvalidateFn = bind(&QGLWidget::update, this); + rp.m_VisualScale = 1.0; + + InitImpl(m_controller, bool_tag<has_init_with_controller<TTest, TTest>::value >()); + + m_controller->SetRenderParams(rp); + } + + void InitImpl(shared_ptr<gui::Controller> const & c, bool_tag<true> const &) + { + base_t::test.Init(c.get()); + } + + void InitImpl(shared_ptr<gui::Controller> const & c, bool_tag<false> const &) + {} + + void DoDraw(shared_ptr<graphics::Screen> const & s) + { + base_t::DoDraw(s); + m_controller->UpdateElements(); + m_controller->DrawFrame(s.get()); + } +}; + +template <class Test> QWidget * create_gui_test_widget() +{ + GUITestWidget<Test> * w = new GUITestWidget<Test>(); + w->Init(); + return w; +} + +#define UNIT_TEST_GUI(name)\ + void UnitTestGUI_##name();\ + TestRegister g_TestRegisterGUI_##name("Test::"#name, __FILE__, &UnitTestGUI_##name);\ + void UnitTestGUI_##name()\ + {\ + char * argv[] = { const_cast<char *>(#name) };\ + int argc = 1;\ + QApplication app(argc, argv);\ + QWidget * w = create_gui_test_widget<name>();\ + w->show();\ + app.exec();\ + } diff --git a/qt_tstfrm/macros.hpp b/qt_tstfrm/macros.hpp index 5e8f4696ea..58e097ba2f 100644 --- a/qt_tstfrm/macros.hpp +++ b/qt_tstfrm/macros.hpp @@ -1,218 +1,3 @@ #pragma once -#include "widgets.hpp" -#include "main_tester.hpp" -#include "tstwidgets.hpp" - -#include "../../testing/testing.hpp" -#include "../../map/qgl_render_context.hpp" - -#include <QtOpenGL/QGLContext> -#include <QtOpenGL/QGLPixelBuffer> -#include <QtGui/QApplication> - -//#include <iostream> - -template<class T, bool (T::*)(QKeyEvent *)> -struct key_event_fn_bind -{ - typedef T type; -}; - -template <class T, bool (T::*)(QMouseEvent*)> -struct mouse_event_fn_bind -{ - typedef T type; -}; - -template <class T, void (T::*)()> -struct void_fn_bind -{ - typedef T type; -}; - -template <class T, class RC, void (T::*)(shared_ptr<RC>)> -struct init_with_context_fn_bind -{ - typedef T type; -}; - -template<class T, class U> -struct has_on_keypress -{ - static const bool value = false; -}; - -template<class T> -struct has_on_keypress<T, typename key_event_fn_bind<T, &T::OnKeyPress>::type> -{ - static const bool value = true; -}; - -template <class T, class U> -struct has_on_mousemove -{ - static const bool value = false; -}; - -template <class T> -struct has_on_mousemove<T, typename mouse_event_fn_bind<T, &T::OnMouseMove>::type > -{ - static const bool value = true; -}; - -template <class T, class U> -struct has_on_mousepress -{ - static bool const value = false; -}; - -template <class T> -struct has_on_mousepress<T, typename mouse_event_fn_bind<T, &T::OnMousePress>::type > -{ - static const bool value = true; -}; - -template <class T, class U> -struct has_init -{ - static bool const value = false; -}; - -template <class T> -struct has_init<T, typename void_fn_bind<T, &T::Init>::type > -{ - static const bool value = true; -}; - -template <class T, class U, class RC> -struct has_init_with_context -{ - static bool const value = false; -}; - -template <class T, class RC> -struct has_init_with_context<T, typename init_with_context_fn_bind<T, RC, &T::Init>::type, RC > -{ - static const bool value = true; -}; - -template <bool T> -struct bool_tag{}; - -template <typename TTest> -class GLTestWidget : public tst::GLDrawWidget -{ - TTest test; - - typedef tst::GLDrawWidget base_type; - -public: - - virtual void DoDraw(shared_ptr<graphics::Screen> p) - { - test.DoDraw(p); - } - virtual void DoResize(int, int) - { - } - - bool keyPressEventImpl(QKeyEvent * ev, bool_tag<true> const &) - { - return test.OnKeyPress(ev); - } - - bool keyPressEventImpl(QKeyEvent *, bool_tag<false> const & ) - { - return false; - } - - virtual void keyPressEvent(QKeyEvent * ev) - { - if (keyPressEventImpl(ev, bool_tag<has_on_keypress<TTest, TTest>::value >())) - repaint(); - } - - bool mousePressEventImpl(QMouseEvent * ev, bool_tag<true> const &) - { - return test.OnMousePress(ev); - } - - bool mousePressEventImpl(QMouseEvent *, bool_tag<false> const &) - { - return false; - } - - virtual void mousePressEvent(QMouseEvent * ev) - { - if (mousePressEventImpl(ev, bool_tag<has_on_mousepress<TTest, TTest>::value >())) - repaint(); - } - - bool mouseMoveEventImpl(QMouseEvent * ev, bool_tag<true> const &) - { - return test.OnMouseMove(ev); - } - - bool mouseMoveEventImpl(QMouseEvent *, bool_tag<false> const &) - { - return false; - } - - void mouseMoveEvent(QMouseEvent * ev) - { - if (mouseMoveEventImpl(ev, bool_tag<has_on_mousemove<TTest, TTest>::value >())) - repaint(); - } - - void InitImpl(bool_tag<true> const & ) - { - test.Init(); - } - - void InitImpl(bool_tag<false> const & ) - {} - - void Init() - { - InitImpl(bool_tag<has_init<TTest, TTest>::value >()); - } - - void InitWithContextImpl(bool_tag<true> const &) - { - test.Init(shared_ptr<qt::gl::RenderContext>(new qt::gl::RenderContext(this))); - } - - void InitWithContextImpl(bool_tag<false> const &) - {} - - void initializeGL() - { - tst::GLDrawWidget::initializeGL(); - InitWithContextImpl(bool_tag<has_init_with_context<TTest, TTest, qt::gl::RenderContext>::value>()); - } -}; - -template <class Test> QWidget * create_widget() -{ - GLTestWidget<Test> * w = new GLTestWidget<Test>(); - w->Init(); - return w; -} - -#define GL_TEST_START \ - int argc = 0; \ - QApplication app(argc, 0); \ - QGLWidget * buf = new QGLWidget(); \ - QGLContext ctx(QGLFormat::defaultFormat(), buf); \ - ctx.create(); \ - ctx.makeCurrent(); - -#define UNIT_TEST_GL(name)\ - void UnitTestGL_##name();\ - TestRegister g_TestRegister_##name("Test::"#name, __FILE__, &UnitTestGL_##name);\ - void UnitTestGL_##name()\ - {\ - tst::BaseTester tester;\ - tester.Run(#name, &create_widget<name>);\ - } +#include "gl_test_widget.hpp" diff --git a/qt_tstfrm/main_tester.cpp b/qt_tstfrm/main_tester.cpp deleted file mode 100644 index b0a36c45cf..0000000000 --- a/qt_tstfrm/main_tester.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "main_tester.hpp" - -#include <QtGui/QApplication> -#include <QtGui/QFrame> -#include <QtGui/QBoxLayout> - - -namespace tst -{ - class MainWindow : public QFrame - { - public: - MainWindow(QWidget * pWidget) - { - QHBoxLayout * pMainLayout = new QHBoxLayout(); - pMainLayout->setContentsMargins(0, 0, 0, 0); - - pMainLayout->addWidget(pWidget); - - setLayout(pMainLayout); - - setWindowTitle(tr("Testing Framework Form")); - - pWidget->setFocus(); - - resize(640, 480); - } - }; - -int BaseTester::Run(char const * name, function<QWidget * (void)> const & fn) -{ - char * argv[] = { const_cast<char *>(name) }; - int argc = 1; - - QApplication app(argc, argv); - - MainWindow wnd(fn()); - wnd.setWindowTitle(name); - wnd.show(); - - return app.exec(); -} - -} diff --git a/qt_tstfrm/main_tester.hpp b/qt_tstfrm/main_tester.hpp deleted file mode 100644 index c72bec542e..0000000000 --- a/qt_tstfrm/main_tester.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "../std/function.hpp" - -class QWidget; - -namespace tst -{ - /// Base tester. Can work with any widgets from widgets.hpp - /// Works in screen coordinates with user defined widget. - class BaseTester - { - public: - - /// Main run function. - int Run(char const * name, function<QWidget * (void)> const & fn); - }; -} diff --git a/qt_tstfrm/qt_tstfrm.pro b/qt_tstfrm/qt_tstfrm.pro index d9b39b5609..a69f3a6a1f 100644 --- a/qt_tstfrm/qt_tstfrm.pro +++ b/qt_tstfrm/qt_tstfrm.pro @@ -10,16 +10,12 @@ include($$ROOT_DIR/common.pri) QT *= core gui opengl HEADERS += \ - main_tester.hpp \ tstwidgets.hpp \ - widgets.hpp \ - widgets_impl.hpp \ - screen_qt.hpp \ - macros.hpp + macros.hpp \ + gl_test_widget.hpp \ + gui_test_widget.hpp SOURCES += \ - main_tester.cpp \ tstwidgets.cpp \ - screen_qt.cpp \ diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp index ead01139e2..3325509d2b 100644 --- a/qt_tstfrm/tstwidgets.cpp +++ b/qt_tstfrm/tstwidgets.cpp @@ -1,6 +1,4 @@ #include "tstwidgets.hpp" -#include "widgets_impl.hpp" -#include "screen_qt.hpp" #include "../graphics/screen.hpp" #include "../graphics/resource_manager.hpp" @@ -12,161 +10,141 @@ #include "../platform/platform.hpp" - -template class qt::GLDrawWidgetT<graphics::Screen>; - -namespace tst { - -GLDrawWidget::GLDrawWidget() : base_type(0) -{ -} - -GLDrawWidget::~GLDrawWidget() +namespace tst { -} - -void GLDrawWidget::initializeGL() -{ - try + void GLDrawWidget::initializeGL() { - graphics::gl::InitExtensions(); - graphics::gl::CheckExtensionSupport(); - } - catch (graphics::gl::platform_unsupported & e) - { - /// TODO: Show "Please Update Drivers" dialog and close the program. - } + try + { + graphics::gl::InitExtensions(); + graphics::gl::CheckExtensionSupport(); + } + catch (graphics::gl::platform_unsupported & e) + { + /// TODO: Show "Please Update Drivers" dialog and close the program. + } - m_primaryContext = make_shared_ptr(new qt::gl::RenderContext(this)); + m_primaryContext = make_shared_ptr(new qt::gl::RenderContext(this)); - graphics::ResourceManager::Params rmp; + graphics::ResourceManager::Params rmp; - rmp.m_rtFormat = graphics::Data8Bpp; - rmp.m_texFormat = graphics::Data8Bpp; + rmp.m_rtFormat = graphics::Data8Bpp; + rmp.m_texFormat = graphics::Data8Bpp; - rmp.m_videoMemoryLimit = 20 * 1024 * 1024; + rmp.m_videoMemoryLimit = 20 * 1024 * 1024; - graphics::ResourceManager::StoragePoolParams spp; - graphics::ResourceManager::TexturePoolParams tpp; + graphics::ResourceManager::StoragePoolParams spp; + graphics::ResourceManager::TexturePoolParams tpp; - spp = graphics::ResourceManager::StoragePoolParams(30000 * sizeof(graphics::gl::Vertex), - sizeof(graphics::gl::Vertex), - 50000 * sizeof(unsigned short), - sizeof(unsigned short), - 20, - graphics::ELargeStorage, - false); + spp = graphics::ResourceManager::StoragePoolParams(30000 * sizeof(graphics::gl::Vertex), + sizeof(graphics::gl::Vertex), + 50000 * sizeof(unsigned short), + sizeof(unsigned short), + 1, + graphics::ELargeStorage, + true); - rmp.m_storageParams[graphics::ELargeStorage] = spp; + rmp.m_storageParams[graphics::ELargeStorage] = spp; - spp = graphics::ResourceManager::StoragePoolParams(3000 * sizeof(graphics::gl::Vertex), - sizeof(graphics::gl::Vertex), - 5000 * sizeof(unsigned short), - sizeof(unsigned short), - 100, - graphics::EMediumStorage, - false); + spp = graphics::ResourceManager::StoragePoolParams(3000 * sizeof(graphics::gl::Vertex), + sizeof(graphics::gl::Vertex), + 5000 * sizeof(unsigned short), + sizeof(unsigned short), + 1, + graphics::EMediumStorage, + true); - rmp.m_storageParams[graphics::EMediumStorage] = spp; + rmp.m_storageParams[graphics::EMediumStorage] = spp; - spp = graphics::ResourceManager::StoragePoolParams(500 * sizeof(graphics::gl::Vertex), - sizeof(graphics::gl::Vertex), - 500 * sizeof(unsigned short), - sizeof(unsigned short), - 10, - graphics::ESmallStorage, - false); + spp = graphics::ResourceManager::StoragePoolParams(500 * sizeof(graphics::gl::Vertex), + sizeof(graphics::gl::Vertex), + 500 * sizeof(unsigned short), + sizeof(unsigned short), + 1, + graphics::ESmallStorage, + true); - rmp.m_storageParams[graphics::ESmallStorage] = spp; + rmp.m_storageParams[graphics::ESmallStorage] = spp; - tpp = graphics::ResourceManager::TexturePoolParams(512, - 512, - 10, - rmp.m_texFormat, - graphics::ELargeTexture, - false); + spp = graphics::ResourceManager::StoragePoolParams(500 * sizeof(graphics::gl::Vertex), + sizeof(graphics::gl::Vertex), + 500 * sizeof(unsigned short), + sizeof(unsigned short), + 1, + graphics::ETinyStorage, + true); - rmp.m_textureParams[graphics::ELargeTexture] = tpp; + rmp.m_storageParams[graphics::ETinyStorage] = spp; - tpp = graphics::ResourceManager::TexturePoolParams(512, - 256, - 5, - rmp.m_texFormat, - graphics::ESmallTexture, - false); - rmp.m_textureParams[graphics::ESmallTexture]; + tpp = graphics::ResourceManager::TexturePoolParams(512, + 512, + 1, + rmp.m_texFormat, + graphics::ELargeTexture, + true); - rmp.m_glyphCacheParams = graphics::ResourceManager::GlyphCacheParams("unicode_blocks.txt", - "fonts_whitelist.txt", - "fonts_blacklist.txt", - 2 * 1024 * 1024); + rmp.m_textureParams[graphics::ELargeTexture] = tpp; - rmp.m_threadSlotsCount = 1; - rmp.m_renderThreadsCount = 0; + tpp = graphics::ResourceManager::TexturePoolParams(256, + 256, + 1, + rmp.m_texFormat, + graphics::EMediumTexture, + true); - rmp.m_useSingleThreadedOGL = false; + rmp.m_textureParams[graphics::EMediumTexture] = tpp; - m_resourceManager.reset(new graphics::ResourceManager(rmp)); + tpp = graphics::ResourceManager::TexturePoolParams(128, + 128, + 1, + rmp.m_texFormat, + graphics::ESmallTexture, + true); - m_primaryContext->setResourceManager(m_resourceManager); - m_primaryContext->startThreadDrawing(0); + rmp.m_textureParams[graphics::ESmallTexture] = tpp; - Platform::FilesList fonts; - GetPlatform().GetFontNames(fonts); - m_resourceManager->addFonts(fonts); - m_frameBuffer = make_shared_ptr(new graphics::gl::FrameBuffer()); + rmp.m_glyphCacheParams = graphics::ResourceManager::GlyphCacheParams("unicode_blocks.txt", + "fonts_whitelist.txt", + "fonts_blacklist.txt", + 2 * 1024 * 1024); - Drawer::Params params; - params.m_resourceManager = m_resourceManager; - params.m_frameBuffer = m_frameBuffer; - params.m_threadSlot = m_resourceManager->guiThreadSlot(); - params.m_renderContext = m_primaryContext; - params.m_skinName = "basic_mdpi.skn"; + rmp.m_threadSlotsCount = 1; + rmp.m_renderThreadsCount = 0; - m_p = make_shared_ptr(new graphics::Screen(params)); + rmp.m_useSingleThreadedOGL = false; - m_primaryFrameBuffer = make_shared_ptr(new graphics::gl::FrameBuffer(true)); + m_resourceManager.reset(new graphics::ResourceManager(rmp)); - params.m_frameBuffer = m_primaryFrameBuffer; - m_primaryScreen = make_shared_ptr(new graphics::Screen(params)); -} - -void GLDrawWidget::resizeGL(int w, int h) -{ - m_p->onSize(w, h); - m_primaryScreen->onSize(w, h); + m_primaryContext->setResourceManager(m_resourceManager); + m_primaryContext->startThreadDrawing(0); - m_frameBuffer->onSize(w, h); - m_primaryFrameBuffer->onSize(w, h); + Platform::FilesList fonts; + GetPlatform().GetFontNames(fonts); + m_resourceManager->addFonts(fonts); - m_depthBuffer.reset(); - m_depthBuffer = make_shared_ptr(new graphics::gl::RenderBuffer(w, h, true)); - m_frameBuffer->setDepthBuffer(m_depthBuffer); + Drawer::Params params; - m_renderTarget.reset(); - m_renderTarget = make_shared_ptr(new graphics::gl::RGBA8Texture(w, h)); - m_p->setRenderTarget(m_renderTarget); -} - -void GLDrawWidget::paintGL() -{ -// m_renderTarget->dump("renderTarget.png"); + m_primaryFrameBuffer = make_shared_ptr(new graphics::gl::FrameBuffer(true)); - m_p->beginFrame(); - m_p->clear(graphics::Color(182, 182, 182, 255)); - DoDraw(m_p); - m_p->endFrame(); + params.m_frameBuffer = m_primaryFrameBuffer; + params.m_resourceManager = m_resourceManager; + params.m_threadSlot = m_resourceManager->guiThreadSlot(); + params.m_renderContext = m_primaryContext; + params.m_skinName = "basic_mdpi.skn"; - m_primaryScreen->beginFrame(); + m_primaryScreen = make_shared_ptr(new graphics::Screen(params)); + } - m_primaryScreen->immDrawTexturedRect( - m2::RectF(0, 0, m_renderTarget->width(), m_renderTarget->height()), - m2::RectF(0, 0, 1, 1), - m_renderTarget - ); + void GLDrawWidget::resizeGL(int w, int h) + { + m_primaryScreen->onSize(w, h); + m_primaryFrameBuffer->onSize(w, h); + } - m_primaryScreen->endFrame(); -} + void GLDrawWidget::paintGL() + { + DoDraw(m_primaryScreen); + } } diff --git a/qt_tstfrm/tstwidgets.hpp b/qt_tstfrm/tstwidgets.hpp index a55e0680e3..0f05ccf074 100644 --- a/qt_tstfrm/tstwidgets.hpp +++ b/qt_tstfrm/tstwidgets.hpp @@ -1,7 +1,5 @@ #pragma once -#include "widgets.hpp" - #include "../graphics/opengl/texture.hpp" #include "../graphics/opengl/renderbuffer.hpp" @@ -12,43 +10,34 @@ #include "../std/shared_ptr.hpp" +#include <QtOpenGL/QGLWidget> namespace graphics { - class Skin; namespace gl { class Screen; } } -namespace qt { class Screen; } - namespace tst { - class GLDrawWidget : public qt::GLDrawWidgetT<graphics::Screen> + class GLDrawWidget : public QGLWidget { - protected: - typedef qt::GLDrawWidgetT<graphics::Screen> base_type; + public: shared_ptr<graphics::ResourceManager> m_resourceManager; shared_ptr<graphics::gl::FrameBuffer> m_primaryFrameBuffer; - shared_ptr<graphics::gl::FrameBuffer> m_frameBuffer; - shared_ptr<graphics::gl::RGBA8Texture> m_renderTarget; - shared_ptr<graphics::gl::RenderBuffer> m_depthBuffer; - shared_ptr<graphics::Skin> m_skin; shared_ptr<qt::gl::RenderContext> m_primaryContext; shared_ptr<graphics::Screen> m_primaryScreen; - public: - - GLDrawWidget(); - virtual ~GLDrawWidget(); - - protected: virtual void initializeGL(); virtual void resizeGL(int w, int h); virtual void paintGL(); + + public: + + virtual void DoDraw(shared_ptr<graphics::Screen> const & screen) = 0; }; } diff --git a/qt_tstfrm/widgets.hpp b/qt_tstfrm/widgets.hpp deleted file mode 100644 index eb67d83af1..0000000000 --- a/qt_tstfrm/widgets.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include <QtOpenGL/qgl.h> - -#include "../map/drawer.hpp" - -#include "../std/shared_ptr.hpp" - -namespace qt -{ - template <class TScreen, class TBase> class BaseDrawWidget : public TBase - { - typedef TBase base_type; - - public: - typedef TScreen screen_t; - - BaseDrawWidget(QWidget * pParent) : base_type(pParent) - { - } - - protected: - /// Override this function to make drawing and additional resize processing. - //@{ - virtual void DoDraw(shared_ptr<screen_t> p) = 0; - virtual void DoResize(int w, int h) = 0; - //@} - }; - - /// Widget uses our graphics library for drawing. - template <class T> class GLDrawWidgetT : public BaseDrawWidget<T, QGLWidget> - { - typedef BaseDrawWidget<T, QGLWidget> base_type; - - protected: - shared_ptr<T> m_p; - - public: - GLDrawWidgetT(QWidget * pParent) : base_type(pParent){} - virtual ~GLDrawWidgetT(); - - protected: - /// Overriden from QGLWidget. - //@{ - virtual void initializeGL() = 0; - virtual void paintGL(); - virtual void resizeGL(int w, int h); - //@} - }; -} diff --git a/qt_tstfrm/widgets_impl.hpp b/qt_tstfrm/widgets_impl.hpp deleted file mode 100644 index 0d16b8c937..0000000000 --- a/qt_tstfrm/widgets_impl.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "widgets.hpp" - -namespace qt -{ - template <class T> - GLDrawWidgetT<T>::~GLDrawWidgetT() - {} - - template <class T> - void GLDrawWidgetT<T>::paintGL() - { - if (m_p) - this->DoDraw(m_p); - } - - template <class T> - void GLDrawWidgetT<T>::resizeGL(int w, int h) - { - if (m_p) - { - m_p->onSize(w, h); - this->DoResize(w, h); - } - } -} |