void D3D11FrameBuffer::swapBuffers() { HRESULT result; if(Context::Instance().getCfg().render_cfg.vsync) { result = mGraphicDevice->getSwapChain()->Present(1, 0); } else { result = mGraphicDevice->getSwapChain()->Present(0, 0); } if(FAILED(result)) { MIST_THROW_EXCEPTION(L"unable to present framebuffer"); } }
AppLauncher& AppLauncher::create(const UknString& cfgname) { if(!mInited) { mist::File::DeleteFile(L"ukn_log.txt"); mInited = true; Context::Instance().loadCfgFile(cfgname); doCreate(); } else { MIST_THROW_EXCEPTION(L"app already created"); } return *this; }
AppLauncher& AppLauncher::create(const ContextCfg& cfg) { if(!mInited) { mist::File::DeleteFile(L"ukn_log.txt"); mInited = true; Context::Instance().setCfg(cfg); FrameCounter::Instance().setDesiredFps(cfg.desired_fps); doCreate(); } else { MIST_THROW_EXCEPTION(L"app already created"); } return *this; }
GLWindow::GLWindow(const UknString& name, const RenderSettings& settings): mFrameBuffer(new GLFrameBuffer(false)), Window(name) { glfwSetErrorCallback(ErrorCallback); glfwInit(); switch(settings.color_fmt) { case EF_RGBA8: glfwWindowHint(GLFW_RED_BITS, 8); glfwWindowHint(GLFW_BLUE_BITS, 8); glfwWindowHint(GLFW_GREEN_BITS, 8); glfwWindowHint(GLFW_ALPHA_BITS, 8); break; default: // error break; } switch(settings.depth_stencil_fmt) { case EF_D16: glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_STENCIL_BITS, 0); mFrameBuffer->mIsDepthBuffered = true; mFrameBuffer->mDepthBits = 16; mFrameBuffer->mStencilBits = 0; break; case EF_D24S8: glfwWindowHint(GLFW_DEPTH_BITS, 24); glfwWindowHint(GLFW_STENCIL_BITS, 8); mFrameBuffer->mIsDepthBuffered = true; mFrameBuffer->mDepthBits = 24; mFrameBuffer->mStencilBits = 8; break; default: glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_STENCIL_BITS, 0); mFrameBuffer->mIsDepthBuffered = false; mFrameBuffer->mDepthBits = 0; mFrameBuffer->mStencilBits = 0; break; } if(settings.sample_quality > 0) { glfwWindowHint(GLFW_SAMPLES, settings.sample_quality); } glfwWindowHint(GLFW_RESIZABLE, settings.resizable); /* maybe there are bugs... let glfw decide the best version */ /* glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, UKN_OPENGL_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, UKN_OPENGL_VERSION_MINOR); if(UKN_OPENGL_VERSION_MAJOR >= 3) { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #if defined(MIST_OS_OSX) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #else glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); #endif } */ if(!settings.native_window_handle) { if((mGlfwWindow = glfwCreateWindow(settings.width, settings.height, string::WStringToString(name).c_str(), settings.full_screen ? glfwGetPrimaryMonitor() : 0, 0)) == 0) { MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error opening window"); } } else { if((mGlfwWindow = glfwCreateWindowSlave((void*)settings.native_window_handle, 0)) == 0) { MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error creating slave window on native handle"); } } glfwMakeContextCurrent(mGlfwWindow); #if !defined(UKN_OSX_REQUEST_OPENGL_32_CORE_PROFILE) GLenum err = glewInit(); if (GLEW_OK != err) { MIST_THROW_EXCEPTION(mist::string::StringToWString(format_string("GLWindow::GLWindow: error initializing glew profilem, error; %s", glewGetErrorString(err)))); } #endif // if wnd pos is (0, 0), then put it in the center of current screen int32 wndPosX = settings.left, wndPosY = settings.top; if(wndPosX == 0 && wndPosY == 0) { Array<SystemInformation::DesktopMode> desktop_modes = SystemInformation::EnumDesktopMode(); wndPosX = (desktop_modes[0].width - settings.width) / 2; wndPosY = (desktop_modes[0].height - settings.height) / 2; } glfwSetWindowPos(mGlfwWindow, wndPosX, wndPosY); glfwSetWindowUserPointer(mGlfwWindow, this); glfwSetErrorCallback(ErrorFunc); glfwSetWindowSizeCallback(mGlfwWindow, WindowSizeFunc); glfwSetWindowCloseCallback(mGlfwWindow, WindowCloseFunc); glfwSetWindowRefreshCallback(mGlfwWindow, WindowRefreshFunc); glfwSetWindowFocusCallback(mGlfwWindow, WindowFocusFunc); glfwSetWindowIconifyCallback(mGlfwWindow, WindowIconifyFunc); glfwSetKeyCallback(mGlfwWindow, KeyFunc); glfwSetCursorPosCallback(mGlfwWindow, MousePosFunc); glfwSetMouseButtonCallback(mGlfwWindow, MouseButtonFunc); glfwSetScrollCallback(mGlfwWindow, ScrollFunc); glfwSetCharCallback(mGlfwWindow, CharFunc); // to do with joysticks glfwSwapInterval(0); mFrameBuffer->attach(ATT_Color0, RenderViewPtr(new GLScreenColorRenderView(settings.width, settings.height, settings.color_fmt))); mFrameBuffer->attach(ATT_DepthStencil, RenderViewPtr(new GLScreenDepthStencilRenderView(settings.width, settings.height, settings.depth_stencil_fmt))); onResize() += Bind(this, &GLWindow::onWindowResize); updateWindowProperties(wndPosX, wndPosY, settings.width, settings.height); }