OGLContextFactory + Qt impl.

This commit is contained in:
Dmitry Kunin 2013-12-25 15:10:50 +03:00 committed by Alex Zolotarev
parent 1fb2f88afd
commit 6476b1cfea
7 changed files with 62 additions and 10 deletions

View file

@ -25,3 +25,6 @@ OTHER_FILES += \
shaders/texturing_vertex_shader.vsh \
shaders/shader_index.txt \
shaders/texturing_fragment_shader.fsh
HEADERS += \
oglcontextfactory.hpp

View file

@ -0,0 +1,9 @@
#pragma once
#include "oglcontext.hpp"
class OGLContextFactory
{
virtual OGLContext * getDrawContext() = 0;
virtual OGLContext * getResourcesUploadContext() = 0;
};

View file

@ -24,12 +24,14 @@ HEADERS += \
mainwindow.hpp \
glwidget.hpp \
qtoglcontext.hpp \
qtoglcontextfactory.hpp
SOURCES += \
mainwindow.cpp \
main.cpp \
glwidget.cpp \
qtoglcontext.cpp \
qtoglcontextfactory.cpp
FORMS += \
mainwindow.ui

View file

@ -2,21 +2,15 @@
#include "../base/assert.hpp"
QtOGLContext::QtOGLContext(QWindow * surface)
{
m_isContextCreated = false;
m_surface = surface;
m_nativeContext = new QOpenGLContext(m_surface);
m_nativeContext->setFormat(m_surface->requestedFormat());
}
QtOGLContext::QtOGLContext(QWindow * surface, QtOGLContext * contextToShareWith)
{
m_isContextCreated = false;
m_surface = surface;
m_nativeContext = new QOpenGLContext(m_surface);
m_nativeContext->setFormat(m_surface->requestedFormat());
m_nativeContext->setShareContext(contextToShareWith->m_nativeContext);
if (contextToShareWith != NULL)
m_nativeContext->setShareContext(contextToShareWith->m_nativeContext);
}
void QtOGLContext::makeCurrent()

View file

@ -8,7 +8,6 @@
class QtOGLContext: public OGLContext
{
public:
QtOGLContext(QWindow * surface);
QtOGLContext(QWindow *surface, QtOGLContext * contextToShareWith);
virtual void present();

View file

@ -0,0 +1,25 @@
#include "qtoglcontextfactory.hpp"
#include "../base/assert.hpp"
QtOGLContextFactory::QtOGLContextFactory(QWindow * surface)
: m_surface(surface)
, m_drawContext(NULL)
, m_uploadContext(NULL)
{}
OGLContext * QtOGLContextFactory::getDrawContext()
{
if (m_drawContext == NULL)
m_drawContext = new QtOGLContext(m_surface, m_uploadContext);
return m_drawContext;
}
OGLContext * QtOGLContextFactory::getResourcesUploadContext()
{
if (m_uploadContext != NULL)
m_uploadContext = new QtOGLContext(m_surface, m_drawContext);
return m_uploadContext;
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "../../drape/oglcontextfactory.hpp"
#include "qtoglcontext.hpp"
#include <QtGui/QWindow>
class QtOGLContextFactory
{
public:
QtOGLContextFactory(QWindow * surface);
virtual OGLContext * getDrawContext();
virtual OGLContext * getResourcesUploadContext();
private:
QWindow * m_surface;
QtOGLContext * m_drawContext;
QtOGLContext * m_uploadContext;
};