HRESULT DXManager::initializeRenderTarget() { HRESULT hr = S_OK; ID3D11Texture2D* pBackBuffer; hr = mPSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); if (FAILED(hr)) { showErrorMessageBox(L"No backbuffer texture!", L"Error", mHWnd); return hr; } hr = mPd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &mPRenderTargetView); pBackBuffer->Release(); pBackBuffer = 0; if (FAILED(hr)) { showErrorMessageBox(L"Render target creation failed!", L"Error", mHWnd); return hr; } D3D11_DEPTH_STENCIL_VIEW_DESC descDSV; // Initailze DepthStencilView ZeroMemory(&descDSV, sizeof(descDSV)); descDSV.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDSV.ViewDimension = (mMuntisampleCount > 1) ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; descDSV.Flags = 0; hr = mPd3dDevice->CreateDepthStencilView(pDepthStencil, &descDSV, &mPDepthStencilView); if (FAILED(hr)) { showErrorMessageBox(L"Depth-Stencil view creation failed!", L"Error", mHWnd); return hr; }//END Initialize DepthStencilView mPd3dDeviceContext->OMSetRenderTargets(1, &mPRenderTargetView, mPDepthStencilView); return S_OK; }
void QDesigner::initialize() { // initialize the sub components QStringList files; QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); parseCommandLineArgs(files, resourceDir); QTranslator *translator = new QTranslator(this); QTranslator *qtTranslator = new QTranslator(this); const QString localSysName = QLocale::system().name(); QString translatorFileName = QStringLiteral("designer_"); translatorFileName += localSysName; translator->load(translatorFileName, resourceDir); translatorFileName = QStringLiteral("qt_"); translatorFileName += localSysName; qtTranslator->load(translatorFileName, resourceDir); installTranslator(translator); installTranslator(qtTranslator); if (QLibraryInfo::licensedProducts() == QStringLiteral("Console")) { QMessageBox::information(0, tr("Qt Designer"), tr("This application cannot be used for the Console edition of Qt")); QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); return; } m_workbench = new QDesignerWorkbench(); emit initialized(); previousMessageHandler = qInstallMessageHandler(designerMessageHandler); // Warn when loading faulty forms Q_ASSERT(previousMessageHandler); m_suppressNewFormShow = m_workbench->readInBackup(); if (!files.empty()) { const QStringList::const_iterator cend = files.constEnd(); for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it) { // Ensure absolute paths for recent file list to be unique QString fileName = *it; const QFileInfo fi(fileName); if (fi.exists() && fi.isRelative()) fileName = fi.absoluteFilePath(); m_workbench->readInForm(fileName); } } if ( m_workbench->formWindowCount()) m_suppressNewFormShow = true; // Show up error box with parent now if something went wrong if (m_initializationErrors.isEmpty()) { if (!m_suppressNewFormShow && QDesignerSettings(m_workbench->core()).showNewFormOnStartup()) QTimer::singleShot(100, this, SLOT(callCreateForm())); // won't show anything if suppressed } else { showErrorMessageBox(m_initializationErrors); m_initializationErrors.clear(); } }
void QDesigner::showErrorMessage(const char *message) { // strip the prefix const QString qMessage = QString::fromUtf8(message + qstrlen(designerWarningPrefix)); // If there is no main window yet, just store the message. // The QErrorMessage would otherwise be hidden by the main window. if (m_mainWindow) { showErrorMessageBox(qMessage); } else { const QMessageLogContext emptyContext; previousMessageHandler(QtWarningMsg, emptyContext, message); // just in case we crash m_initializationErrors += qMessage; m_initializationErrors += QLatin1Char('\n'); } }
void QDesigner::showErrorMessage(const char *message) { // strip the prefix const QString qMessage = QString::fromUtf8(message + qstrlen(designerWarningPrefix)); // If there is no main window yet, just store the message. // The QErrorMessage would otherwise be hidden by the main window. if (m_mainWindow) { showErrorMessageBox(qMessage); } else { qInstallMsgHandler(0); qt_message_output(QtWarningMsg, message); // just in case we crash qInstallMsgHandler (designerMessageHandler); m_initializationErrors += qMessage; m_initializationErrors += QLatin1Char('\n'); } }
HRESULT DXManager::initializeDepthBufferDesc() { HRESULT hr = S_OK; D3D11_TEXTURE2D_DESC descDepth; ZeroMemory(&descDepth, sizeof(descDepth)); descDepth.Width = m_ScreenWidth; descDepth.Height = m_ScreenHeight; descDepth.MipLevels = 1; descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;; descDepth.SampleDesc.Count = mMuntisampleCount; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D11_USAGE_DEFAULT; descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; hr = mPd3dDevice->CreateTexture2D(&descDepth, nullptr, &pDepthStencil); if (FAILED(hr)) { showErrorMessageBox(L"Depth-Stencil buffer creation failed!", L"Error", mHWnd); return hr; } return S_OK; }
void game::MainLoop(void) { r3dOutToLog("Starting updater, v:%s, cmd:%s\n", UPDATER_VERSION, __r3dCmdLine); CUpdater updater; // parse command line int argc = 0; char** argv = CommandLineToArgvA(__r3dCmdLine, &argc); for(int i=0; i<argc; i++) { /*if(strcmp(argv[i], "-steam") == 0 && (i + 0) < argc) { r3dOutToLog("Trying to init steam\n"); gSteam.InitSteam(); continue; }*/ } if(g_isConsoleUpdater) { cmdLine_MainLoop(updater); return; } updater.Start(); win32_input_Flush(); if(g_taskbar) g_taskbar->SetProgressState(win::hWnd, TBPF_NORMAL); r3dStartFrame(); while(1) { r3dEndFrame(); r3dStartFrame(); g_mb = 0; g_hCursor = gCursorArrow; tempDoMsgLoop(); ::Sleep(1); r3dRenderer->StartRender(); r3dRenderer->StartFrame(); r3dRenderer->SetRenderingMode(R3D_BLEND_ALPHA | R3D_BLEND_NZ); r3dSetFiltering(R3D_POINT); r3dDrawBox2D(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(64, 64, 64)); #if 0 updater.status_ = CUpdater::STATUS_TimeExpired; updater.showProgress_ = false; updater.prgTotal_.cur = 100; updater.prgTotal_.total = 100; r3dscpy(updater.updMsg1_, "Xxxxxxx"); #endif switch(updater.status_) { default: r3d_assert(0); case CUpdater::STATUS_Checking: g_bkgStarting->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); break; case CUpdater::STATUS_NeedLogin: g_bkgLogin->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); drawLoginButtons(updater); break; case CUpdater::STATUS_SerialCheck: g_bkgSerialCheck->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); drawSerialCheckButtons(updater); break; case CUpdater::STATUS_NeedRegister: g_bkgRegister->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); drawRegisterButtons(updater); break; case CUpdater::STATUS_TimeExpired: g_bkgExpired->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); drawTimeExpiredButtons(updater); break; case CUpdater::STATUS_Updating: g_bkgUpdate->draw(0, 0, r3dRenderer->ScreenW, r3dRenderer->ScreenH, r3dColor(255, 255, 255)); drawUpdateButtons(updater); drawServerStatus(updater); drawNews(updater); break; } drawProgressBar(updater); drawCloseButton(); r3dRenderer->EndFrame(); r3dRenderer->EndRender(true); // if exit requested by control-f4 if(g_bExit) { updater.RequestStop(); break; } // activate updater window if other instance requested it if(WaitForSingleObject(g_updaterEvt, 0) == WAIT_OBJECT_0) { SwitchToThisWindow(win::hWnd, TRUE); } // try to remove mouse lock because of // win::HandleActivate code that will lock mouse inside window ClipCursor(NULL); // if signalled to play game if(g_bStartGame) break; if(updater.result_ != CUpdater::RES_UPDATING && updater.result_ != CUpdater::RES_PLAY) break; // wndclass.hCursor must be NULL for this to work //SetCursor(g_hCursor); } updater.Stop(); if(g_taskbar) g_taskbar->SetProgressState(win::hWnd, TBPF_NOPROGRESS); switch(updater.result_) { default: r3d_assert(0); case CUpdater::RES_STOPPED: break; case CUpdater::RES_PLAY: startGame(updater); break; case CUpdater::RES_ERROR: showErrorMessageBox(updater); break; } gHwInfoPoster.Stop(); TerminateProcess(GetCurrentProcess(), 0); return; }
Application::Application(int& argc, char** argv, GameLogic* gameLogic, IgnoredConfigWarningMode ignoredConfigWarningMode) :QApplication(argc, argv) ,mFPSDialog(0) ,mGraphicsSettingsWidget(0) ,mOgreWidget(0) ,mSettingsDialog(0) ,mInternalOgreLog(0) ,mInternalOgreLogManager(0) ,mLogManager(0) ,mOgreLog(0) ,mSystemLog(0) ,mActiveRenderSystem(0) ,mOpenGLRenderSystem(0) ,mDirect3D9RenderSystem(0) ,mRoot(0) ,mFrameCounter(0) ,mGameLogic(gameLogic) ,mAutoUpdateTimer(0) ,mSettings(0) ,mAutoUpdateEnabled(true) ,mIsInitialised(false) ,mIgnoredConfigWarningMode(ignoredConfigWarningMode) { if(mGameLogic != 0) { mGameLogic->mApplication = this; } //Initialise the resources. initQtResources(); //Sanity check for config files if(mIgnoredConfigWarningMode == WarnAboutIgnoredConfigs) { QDirIterator it("."); while (it.hasNext()) { it.next(); if(QString::compare(it.fileInfo().suffix(), "cfg", Qt::CaseInsensitive) == 0) { if( (QString::compare(it.fileInfo().baseName(), "plugins", Qt::CaseInsensitive) != 0) && (QString::compare(it.fileInfo().baseName(), "plugins_d", Qt::CaseInsensitive) != 0) && (QString::compare(it.fileInfo().baseName(), "resources", Qt::CaseInsensitive) != 0)) { //We have found a file with the .cfg extension but which is not //'plugins.cfg' or 'resources.cfg'. Warn the user about this. warnAboutIgnoredConfigFile(it.fileInfo().fileName()); } } } } mAutoUpdateTimer = new QTimer; QObject::connect(mAutoUpdateTimer, SIGNAL(timeout()), this, SLOT(update())); //On the test system, a value of one here gives a high frame rate and still allows //event processing to take place. A value of 0 doubles the frame rate but the mouse //becomes jumpy. This property is configerable via setAutoUpdateInterval(). mAutoUpdateTimer->setInterval(1); //Load the settings file. If it doesn't exist it is created. mSettings = new QSettings("settings.ini", QSettings::IniFormat); mOgreWidget = new EventHandlingOgreWidget(0, 0); //Logging should be initialised ASAP, and before Ogre::Root is created. initialiseLogging(); //Create the Ogre::Root object. qDebug("Creating Ogre::Root object..."); try { #ifdef QT_DEBUG mRoot = new Ogre::Root("plugins_d.cfg"); #else mRoot = new Ogre::Root("plugins.cfg"); #endif qDebug("Ogre::Root created successfully."); } catch(Ogre::Exception& e) { QString error ( "Failed to create the Ogre::Root object. This is a fatal error and the " "application will now exit. There are a few known reasons why this can occur:\n\n" " 1) Ensure your plugins.cfg has the correct path to the plugins.\n" " 2) In plugins.cfg, use unix style directorary serperators. I.e '/' rather than '\\'.\n" " 3) If your plugins.cfg is trying to load the Direct3D plugin, make sure you have DirectX installed on your machine.\n\n" "The message returned by Ogre was:\n\n" ); error += QString::fromStdString(e.getFullDescription().c_str()); qCritical(error.toAscii()); showErrorMessageBox(error); //Not much else we can do here... std::exit(1); } //Load the render system plugins. We do that here so that we know what //render systems are available by the time we show the settings dialog. //Note that the render system is not initialised until the user selects one. mOpenGLRenderSystem = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); mDirect3D9RenderSystem = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem"); if(!(mOpenGLRenderSystem || mDirect3D9RenderSystem)) { qCritical("No rendering subsystems found"); showErrorMessageBox("No rendering subsystems found. Please ensure that your 'plugins.cfg' (or 'plugins_d.cfg') is correct and can be found by the executable."); } mSettingsDialog = new SettingsDialog(mSettings, mOgreWidget); mGraphicsSettingsWidget = new GraphicsSettingsWidget; mSettingsDialog->addSettingsWidget("Graphics", mGraphicsSettingsWidget); }
HRESULT DXManager::initializeDevice(bool fullscreen) { HRESULT hr = S_OK; UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevel; featureLevel = D3D_FEATURE_LEVEL_11_0; DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(sd)); sd.BufferCount = 1; sd.BufferDesc.Width = m_ScreenWidth; sd.BufferDesc.Height = m_ScreenHeight; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; if (m_vsync_enabled) { sd.BufferDesc.RefreshRate.Numerator = mNumerator; sd.BufferDesc.RefreshRate.Denominator = mDenominator; } else { sd.BufferDesc.RefreshRate.Numerator = 0; sd.BufferDesc.RefreshRate.Denominator = 1; } sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.OutputWindow = mHWnd; sd.SampleDesc.Count = mMuntisampleCount; sd.SampleDesc.Quality = 0; if (fullscreen) { sd.Windowed = false; } else { sd.Windowed = true; } sd.Flags = 0; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_REFERENCE, D3D_DRIVER_TYPE_SOFTWARE, }; UINT numDriverTypes = sizeof(driverTypes) / sizeof(driverTypes[0]); for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; ++driverTypeIndex) { mDriverType = driverTypes[driverTypeIndex]; hr = D3D11CreateDeviceAndSwapChain(nullptr, mDriverType, nullptr, createDeviceFlags, &featureLevel, 1, D3D11_SDK_VERSION, &sd, &mPSwapChain, &mPd3dDevice, nullptr, &mPd3dDeviceContext); if (SUCCEEDED(hr)) { if (mDriverType != D3D_DRIVER_TYPE_HARDWARE) showWarningMessageBox(L"No hardware Direct3D here.", L"Warning", mHWnd); break; } } if (FAILED(hr)) { showErrorMessageBox(L"Device and swap chain creation failed!", L"Error", mHWnd); return hr; } return S_OK; }