diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2010-12-05 19:24:16 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-22 22:33:57 +0300 |
commit | d6e12b7ce4bcbf0ccd1c07eb25de143422913c34 (patch) | |
tree | a7e910c330ce4da9b4f2d8be76067adece2561c4 /map/qgl_render_context.cpp |
One Month In Minsk. Made in Belarus.
Diffstat (limited to 'map/qgl_render_context.cpp')
-rw-r--r-- | map/qgl_render_context.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/map/qgl_render_context.cpp b/map/qgl_render_context.cpp new file mode 100644 index 0000000000..ce7f40ab87 --- /dev/null +++ b/map/qgl_render_context.cpp @@ -0,0 +1,69 @@ +#include "../base/SRC_FIRST.hpp" + +#include "qgl_render_context.hpp" + +#include "../base/assert.hpp" +#include "../base/logging.hpp" +#include "../base/ptr_utils.hpp" + +#include <QtOpenGL/QGLContext> +#include <QtOpenGL/QGLWidget> +#include <QtOpenGL/QGLFramebufferObject> + +#include "../base/start_mem_debug.hpp" + +namespace qt +{ + namespace gl + { + struct null_deleter + { + template <typename T> void operator()(T*) {} + }; + + /// Create compatible render context + RenderContext::RenderContext(QGLWidget * widget) + { + /// Dirty hack, but we'll use it with caution, I promise. + m_context = shared_ptr<QGLContext>(const_cast<QGLContext*>(widget->context()), null_deleter()); + } + + void RenderContext::makeCurrent() + { + m_context->makeCurrent(); + } + + shared_ptr<yg::gl::RenderContext> RenderContext::createShared() + { + return shared_ptr<yg::gl::RenderContext>(new RenderContext(this)); + } + + void RenderContext::endThreadDrawing() + { + m_context.reset(); + } + + RenderContext::RenderContext(RenderContext * renderContext) + { + QGLFormat const format = renderContext->context()->format(); + m_parent = make_shared_ptr(new QWidget()); + m_context = shared_ptr<QGLContext>(new QGLContext(format, m_parent.get())); + bool sharedContextCreated = m_context->create(renderContext->context().get()); + bool isSharing = m_context->isSharing(); + ASSERT(sharedContextCreated && isSharing, ("cannot create shared opengl context")); + if (!sharedContextCreated || !isSharing) + m_context.reset(); + } + + RenderContext::~RenderContext() + { + m_context.reset(); + m_parent.reset(); + } + + shared_ptr<QGLContext> RenderContext::context() const + { + return m_context; + } + } +} |