Esempio n. 1
0
bool initDevice(HINSTANCE hInstance, HWND hWnd)
{
	if(!initD3DDevice(hWnd))
		return false;
	if(!initDIDevice(hInstance, hWnd))
		return false;
	initShader();
	return true;
}
Esempio n. 2
0
void gep::Renderer::initialize()
{
    m_pDebugRenderer = new DebugRenderer();
    createWindow();
    initD3DDevice();

    g_globalManager.getLogging()->logMessage("Using DirectX Version: %d.%d sdk %d", D3D11_MAJOR_VERSION, D3D11_MINOR_VERSION, D3D11_SDK_VERSION);

    // Create the dummy 2d texture
    {
        m_pDummyTexture = createTexture2D("dummy texture 2d", new DummyTexture2DLoader(), TextureMode::Static);
        m_pDummyTexture->createEmpty(4, 4, ImageFormat::RGBA8);
        auto& dummyData = m_pDummyTexture->getImageData().getData()[0];
        for(uint32 i = 0; i < 4 * 4 * 4; i+=4)
        {
            dummyData[i] = 0xFF;   //R
            dummyData[i+1] = 0;    //G
            dummyData[i+2] = 0xFF; //B
            dummyData[i+3] = 0xFF; //A
        }
        m_pDummyTexture->setHasData(true);
        m_pDummyTexture->finalize();
        g_globalManager.getResourceManager()->registerResourceType("Texture2D", m_pDummyTexture);
    }

    // Creates the dummy shader
    {
        m_pDummyShader = createShader();
        m_pDummyShader->setLoader(new ShaderFileLoader("data/base/dummy.fx"));
        m_pDummyShader->getLoader()->loadResource(m_pDummyShader);
        m_pDummyShader->finalize();
        g_globalManager.getResourceManager()->registerResourceType("Shader", m_pDummyShader);
    }

    // Register the font resource type (no fallback)
    g_globalManager.getResourceManager()->registerResourceType("Font", nullptr);

    // load engine resources
    m_pDefaultFont = g_globalManager.getResourceManager()->loadResource<Font>(FontFileLoader("data/base/dejavusans.ttf", 11), LoadAsync::No);
    m_pFontShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/base/font.fx"), LoadAsync::No);

    g_globalManager.getResourceManager()->finalizeResourcesWithFlags(ResourceFinalize::FromRenderer);

    m_fontPosition = ShaderConstant<vec2>("position", m_pFontShader);
    m_fontColor = ShaderConstant<Color>("color", m_pFontShader);
    m_fontScreenSize = ShaderConstant<vec2>("targetSize", m_pFontShader);
    m_fontTexture = ShaderConstant<Texture2D>("diffuse", m_pFontShader);
    m_fontScreenSize.set(vec2((float)m_settings.screenResolution.x,
                              (float)m_settings.screenResolution.y));

    // text billboard
    m_pTextBillboardShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/base/fontBillboard.fx"), LoadAsync::No);
    m_textBillboardView = ShaderConstant<mat4>("View", m_pTextBillboardShader);
    m_textBillboardProjection = ShaderConstant<mat4>("Projection", m_pTextBillboardShader);
    m_textBillboardPosition = ShaderConstant<vec3>("position", m_pTextBillboardShader);
    m_textBillboardColor = ShaderConstant<Color>("color", m_pTextBillboardShader);
    m_textBillboardTexture = ShaderConstant<Texture2D>("diffuse", m_pTextBillboardShader);
    m_textBillboardScreenSize = ShaderConstant<vec2>("targetSize", m_pTextBillboardShader);
    m_textBillboardScreenSize.set(vec2((float)m_settings.screenResolution.x,
                                       (float)m_settings.screenResolution.y));
    {
        auto aspectRatio = float(m_settings.screenResolution.x) / float(m_settings.screenResolution.y);
        m_projection = mat4::projectionMatrix(60.0f, aspectRatio, 0.1f, 10000.0f);
    }
    m_view = mat4::lookAtMatrix(vec3(300, 0, 205), vec3(0, 0, 150), vec3(0,0,1));

    {
        Vertexbuffer::DataChannel dataChannels[] =
        { Vertexbuffer::DataChannel::POSITION_2D,
        Vertexbuffer::DataChannel::TEXCOORD0 };
        m_pFontBuffer = new Vertexbuffer(m_pd3dDevice, dataChannels, Vertexbuffer::Primitive::Triangle, Vertexbuffer::Usage::Dynamic);
    }

    {
        Vertexbuffer::DataChannel dataChannels[] =
        {
            Vertexbuffer::DataChannel::POSITION
        };
        m_pLinesBuffer = new Vertexbuffer(m_pd3dDevice, dataChannels, Vertexbuffer::Primitive::Line, Vertexbuffer::Usage::Dynamic);
    }

    {
        Vertexbuffer::DataChannel dataChannels[] =
        {
            Vertexbuffer::DataChannel::POSITION_2D
        };
        m_pLines2DBuffer = new Vertexbuffer(m_pd3dDevice, dataChannels, Vertexbuffer::Primitive::Line, Vertexbuffer::Usage::Dynamic);
    }

    {
        m_pDummyModel = createModel();
        m_pDummyModel->loadFile("data/base/dummy.thModel");
        m_pDummyModel->setLoader(ModelDummyLoader().moveToHeap());
        m_pDummyModel->getLoader()->loadResource(m_pDummyModel);
        m_pDummyModel->getMaterial(0).setShader(m_pDummyShader->makeResourcePtrFromThis<Shader>());
        m_pDummyModel->finalize();
        g_globalManager.getResourceManager()->registerResourceType("Model", m_pDummyModel);
    }

    //Loading additional resources
    m_pLightingShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/shaders/lighting.fx"));
    m_pLightingAnimatedShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/shaders/lightingAnimated.fx"));
    m_pLinesShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/base/lines.fx"));
    m_pWireframeShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/shaders/wireframe.fx"));
    m_lineColor = ShaderConstant<Color>("Color", m_pLinesShader);
    m_lineView = ShaderConstant<mat4>("View", m_pLinesShader);
    m_lineProjection = ShaderConstant<mat4>("Projection", m_pLinesShader);

    m_pLines2DShader = g_globalManager.getResourceManager()->loadResource<Shader>(ShaderFileLoader("data/base/lines2D.fx"));
    m_line2DColor = ShaderConstant<Color>("Color", m_pLines2DShader);
    m_lines2DScreenSize = ShaderConstant<vec2>("targetSize", m_pLines2DShader);
    m_lines2DScreenSize.set(vec2((float)m_settings.screenResolution.x,
                                 (float)m_settings.screenResolution.y));

    #ifdef _DEBUG
    const GUID ID_ID3DUserDefinedAnnotation = { 0xb2daad8b, 0x03d4, 0x4dbf, { 0x95, 0xeb,  0x32,  0xab,  0x4b,  0x63,  0xd0,  0xab } };
    m_pDeviceContext->QueryInterface(ID_ID3DUserDefinedAnnotation, (void**)&m_pUserDefinedAnnotation);
    if(m_pUserDefinedAnnotation == nullptr || !m_pUserDefinedAnnotation->GetStatus())
    {
        GEP_RELEASE_AND_NULL(m_pUserDefinedAnnotation);
        HMODULE pModule = LoadLibraryA("d3d9.dll");
        D3DPREF_BeginEvent = (D3DPERF_BeginEvent_Func)GetProcAddress(pModule, "D3DPERF_BeginEvent");
        D3DPREF_EndEvent = (D3DPERF_EndEvent_Func)GetProcAddress(pModule, "D3DPERF_EndEvent");
    }
    #endif

}
int main(int argc, char *argv[])
{
  try
  {
    QCommandLineParser parser;
    parser.setApplicationDescription("Plex Media Player");
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addOptions({{{"l", "licenses"}, "Show license information"}});
    parser.addOptions({{{"a", "from-auto-update"}, "When invoked from auto-update"}});

    char **newArgv = appendCommandLineArguments(argc, argv, g_qtFlags);
    argc += g_qtFlags.size();

    // Suppress SSL related warnings on OSX
    // See https://bugreports.qt.io/browse/QTBUG-43173 for more info
    //
#ifdef Q_OS_MAC
    qputenv("QT_LOGGING_RULES", "qt.network.ssl.warning=false");
#endif

    // Qt calls setlocale(LC_ALL, "") in a bunch of places, which breaks
    // float/string processing in mpv and ffmpeg.
#ifdef Q_OS_UNIX
    qputenv("LC_ALL", "C");
    qputenv("LC_NUMERIC", "C");
#endif

    detectOpenGLEarly();

    preinitQt();

    QGuiApplication app(argc, newArgv);
    app.setWindowIcon(QIcon(":/images/icon.png"));

    // Get the arguments from the app, this is the parsed version of newArgc and newArgv
    QStringList args = app.arguments();

    // Remove the qt flags above so that our command line parser doesn't get cranky.
    for (auto flag : g_qtFlags)
      args.removeAll(flag);

    // Now parse the command line.
    parser.process(args);

    if (parser.isSet("licenses"))
    {
      ShowLicenseInfo();
      return EXIT_SUCCESS;
    }

    // init breakpad.
    setupCrashDumper();

    UniqueApplication* uniqueApp = new UniqueApplication();
    if (!uniqueApp->ensureUnique())
      return EXIT_SUCCESS;

#ifdef Q_OS_UNIX
    // install signals handlers for proper app closing.
    SignalManager signalManager(&app);
    Q_UNUSED(signalManager);
#endif

    Log::Init();

    // Quit app and apply update if we find one.
    if (UpdateManager::CheckForUpdates())
    {
      app.quit();
      return 0;
    }

    detectOpenGLLate();

#ifdef Q_OS_WIN32
    initD3DDevice();
#endif

    Codecs::preinitCodecs();

    // Initialize all the components. This needs to be done
    // early since most everything else relies on it
    //
    ComponentManager::Get().initialize();

    // enable remote inspection if we have the correct setting for it.
    if (SettingsComponent::Get().value(SETTINGS_SECTION_MAIN, "remoteInspector").toBool())
      qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "0.0.0.0:9992");

    QtWebEngine::initialize();

    // start our helper
    HelperLauncher::Get().connectToHelper();

    // load QtWebChannel so that we can register our components with it.
    QQmlApplicationEngine *engine = Globals::Engine();

    KonvergoWindow::RegisterClass();
    Globals::SetContextProperty("components", &ComponentManager::Get().getQmlPropertyMap());

    // the only way to detect if QML parsing fails is to hook to this signal and then see
    // if we get a valid object passed to it. Any error messages will be reported on stderr
    // but since no normal user should ever see this it should be fine
    //
    QObject::connect(engine, &QQmlApplicationEngine::objectCreated, [=](QObject* object, const QUrl& url)
    {
      Q_UNUSED(url);

      if (object == nullptr)
        throw FatalException(QObject::tr("Failed to parse application engine script."));

      KonvergoWindow* window = Globals::MainWindow();

      QObject* webChannel = qvariant_cast<QObject*>(window->property("webChannel"));
      Q_ASSERT(webChannel);
      ComponentManager::Get().setWebChannel(qobject_cast<QWebChannel*>(webChannel));

      QObject::connect(uniqueApp, &UniqueApplication::otherApplicationStarted, window, &KonvergoWindow::otherAppFocus);
    });
    engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml")));

    Log::UpdateLogLevel();

    // run our application
    int ret = app.exec();

    delete uniqueApp;
    Globals::EngineDestroy();

    Log::Uninit();
    return ret;
  }
  catch (FatalException& e)
  {
    QLOG_FATAL() << "Unhandled FatalException:" << qPrintable(e.message());
    QApplication errApp(argc, argv);

    auto  msg = new ErrorMessage(e.message(), true);
    msg->show();

    errApp.exec();

    Log::Uninit();
    return 1;
  }
}