qmlfrontend/engine_instance.cpp
changeset 14303 00b56ec8b7df
parent 14299 21be7838a127
child 14377 b6824a53d4b1
equal deleted inserted replaced
14302:a6c5ce147530 14303:00b56ec8b7df
     1 #include "engine_instance.h"
     1 #include "engine_instance.h"
     2 
     2 
     3 extern "C" void (*getProcAddress())(const char* fn) { return nullptr; }
     3 #include <QDebug>
       
     4 #include <QOpenGLFunctions>
       
     5 #include <QSurface>
       
     6 
       
     7 static QOpenGLContext* currentOpenglContext = nullptr;
       
     8 extern "C" void (*getProcAddress(const char* fn))() {
       
     9   if (!currentOpenglContext)
       
    10     return nullptr;
       
    11   else
       
    12     return currentOpenglContext->getProcAddress(fn);
       
    13 }
     4 
    14 
     5 EngineInstance::EngineInstance(QObject* parent)
    15 EngineInstance::EngineInstance(QObject* parent)
     6     : QObject(parent), m_instance(Engine::start_engine()) {}
    16     : QObject(parent), m_instance(Engine::start_engine()) {}
     7 
    17 
     8 EngineInstance::~EngineInstance() { Engine::cleanup(m_instance); }
    18 EngineInstance::~EngineInstance() { Engine::cleanup(m_instance); }
    12     Engine::send_ipc(m_instance, reinterpret_cast<uint8_t*>(b.data()),
    22     Engine::send_ipc(m_instance, reinterpret_cast<uint8_t*>(b.data()),
    13                      static_cast<size_t>(b.size()));
    23                      static_cast<size_t>(b.size()));
    14   }
    24   }
    15 }
    25 }
    16 
    26 
    17 void EngineInstance::advance(quint32 ticks) {}
    27 void EngineInstance::advance(quint32 ticks) {
       
    28   Engine::advance_simulation(m_instance, ticks);
       
    29 }
    18 
    30 
    19 void EngineInstance::renderFrame() {}
    31 void EngineInstance::renderFrame() { Engine::render_frame(m_instance); }
    20 
    32 
    21 void EngineInstance::setOpenGLContext(QOpenGLContext* context) {
    33 void EngineInstance::setOpenGLContext(QOpenGLContext* context) {
    22   Engine::setup_current_gl_context(m_instance, 0, 0, &getProcAddress);
    34   currentOpenglContext = context;
       
    35 
       
    36   auto size = context->surface()->size();
       
    37   Engine::setup_current_gl_context(
       
    38       m_instance, static_cast<quint16>(size.width()),
       
    39       static_cast<quint16>(size.height()), &getProcAddress);
    23 }
    40 }
    24 
    41 
    25 Engine::PreviewInfo EngineInstance::generatePreview() {
    42 Engine::PreviewInfo EngineInstance::generatePreview() {
    26   Engine::PreviewInfo pinfo;
    43   Engine::PreviewInfo pinfo;
    27 
    44