blob: f898e5e5cf6012187990a4982a05b5859c37ec6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "../base/SRC_FIRST.hpp"
#include "qgl_render_context.hpp"
#include "../base/assert.hpp"
#include "../base/logging.hpp"
#include <QtOpenGL/QGLContext>
#include <QtOpenGL/QGLWidget>
#include <QtOpenGL/QGLFramebufferObject>
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<graphics::RenderContext> RenderContext::createShared()
{
shared_ptr<graphics::gl::RenderContext> res(new RenderContext(this));
res->setResourceManager(resourceManager());
return res;
}
void RenderContext::endThreadDrawing(unsigned threadSlot)
{
m_context.reset();
graphics::gl::RenderContext::endThreadDrawing(threadSlot);
}
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;
}
}
}
|