// --------------------------------------------------------------------------- // Function: renderGL // Design: Belongs (mostly) to OpenGL component // Purpose: Main rendering of the 3D desktop // Updated: Sep 10, 2012 // TODO: Split into separate functions // --------------------------------------------------------------------------- void renderGL(Desktop3DLocation& loc, double timeDiff_, RendererPlugin *renderer) { static int frame = 0, time, timebase = 0, count = 0; frame++; count++; count %= 360; time = glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { fprintf(stderr, "FPS:%4.2f\n", frame * 1000.0 / (time - timebase)); timebase = time; frame = 0; } if (!initedOpenGL) { initedOpenGL = true; if(renderer->getWindowID()) window = renderer->getWindowID(); if (OGRE3D || IRRLICHT) { if(renderer->getOpenGLContext()) context = renderer->getOpenGLContext(); if(!IRRLICHT && !OGRE3D) { std::cerr << "context: " << context << ", " << glXGetCurrentContext() << std::endl; std::cerr << "dpy: " << dpy << ", window: " << window << std::endl; if(!context) { context = glXGetCurrentContext(); } std::cerr << "context: " << context << ", " << glXGetCurrentContext() << std::endl; bool r = glXMakeCurrent(dpy, window, context); std::cerr << "R: " << r << std::endl; } glewExperimental = true; GLenum err = glewInit(); std::cerr << "Inited GLEW: " << err << std::endl; if (GLEW_OK != err) { // GLEW failed! exit(1); } fbconfig = getFBConfigFromContext(dpy, context); std::cerr << "Got fbconfig: " << fbconfig << std::endl; } if(!OGRE3D) { checkForErrors(); std::cerr << "init_distortion_shader" << std::endl; bool success = init_distortion_shader(); if (!success) { std::cerr << "Failed to init distortion shader!" << std::endl; exit(1); } success = init_distortion_shader_cache(); if (!success) { std::cerr << "Failed to init distortion shader cache!" << std::endl; exit(1); } if (USE_FBO) prep_framebuffers(); } renderer->setDesktopTexture(desktopTexture); getCursorTexture(); } if ((renderToTexture || OGRE3D) && !IRRLICHT) { saveState(); renderDesktopToTexture(); restoreState(); } renderer->step(loc, timeDiff_); if(renderer->needsSwapBuffers()) { glXSwapBuffers(display, window); } }
BuiltinResources::BuiltinResources() { // Set up paths mBuiltinRawDataFolder = Paths::getDataPath() + u8"Raw/"; mBuiltinDataFolder = Paths::getDataPath(); mEngineSkinSpritesFolder = mBuiltinDataFolder + SKIN_FOLDER + SPRITE_FOLDER; mEngineShaderFolder = mBuiltinDataFolder + SHADER_FOLDER; mEngineMeshFolder = mBuiltinDataFolder + MESH_FOLDER; mEngineCursorFolder = mBuiltinDataFolder + CURSOR_FOLDER; ResourceManifestPath = mBuiltinDataFolder + "ResourceManifest.asset"; // Update from raw assets if needed if (FileSystem::exists(mBuiltinRawDataFolder)) { time_t lastUpdateTime; UINT32 modifications = BuiltinResourcesHelper::checkForModifications( mBuiltinRawDataFolder, mBuiltinDataFolder + u8"Timestamp.asset", lastUpdateTime); // Check if manifest needs to be rebuilt if (modifications == 0 && !FileSystem::exists(ResourceManifestPath)) modifications = 1; if (modifications > 0) { bool fullReimport = modifications == 2; SPtr<ResourceManifest> oldResourceManifest; if (!fullReimport && FileSystem::exists(ResourceManifestPath)) { oldResourceManifest = ResourceManifest::load(ResourceManifestPath, mBuiltinDataFolder); if (oldResourceManifest != nullptr) gResources().registerResourceManifest(oldResourceManifest); } if (oldResourceManifest) mResourceManifest = oldResourceManifest; else { mResourceManifest = ResourceManifest::create("BuiltinResources"); gResources().registerResourceManifest(mResourceManifest); } preprocess(fullReimport, lastUpdateTime); BuiltinResourcesHelper::writeTimestamp(mBuiltinDataFolder + u8"Timestamp.asset"); ResourceManifest::save(mResourceManifest, ResourceManifestPath, mBuiltinDataFolder); } } // Load manifest if (mResourceManifest == nullptr) { if (FileSystem::exists(ResourceManifestPath)) mResourceManifest = ResourceManifest::load(ResourceManifestPath, mBuiltinDataFolder); if (mResourceManifest == nullptr) mResourceManifest = ResourceManifest::create("BuiltinResources"); gResources().registerResourceManifest(mResourceManifest); } if (FileSystem::exists(mBuiltinRawDataFolder)) { // Update shader bytecode for the current render backend, if needed const RenderAPIInfo& apiInfo = ct::RenderAPI::instance().getAPIInfo(); bool supportsBytecodeCaching = apiInfo.isFlagSet(RenderAPIFeatureFlag::ByteCodeCaching); if (supportsBytecodeCaching) { Path dataListsFilePath = mBuiltinRawDataFolder + DATA_LIST_JSON; SPtr<DataStream> dataListStream = FileSystem::openFile(dataListsFilePath); if (dataListStream) { json dataListJSON = json::parse(dataListStream->getAsString().c_str()); json shadersJSON = dataListJSON["Shaders"]; for (auto& entry : shadersJSON) { std::string uuidStr = entry["UUID"]; UUID uuid(uuidStr.c_str()); Path filePath; if (!mResourceManifest->uuidToFilePath(uuid, filePath)) continue; BuiltinResourcesHelper::updateShaderBytecode(filePath); } } } } // Load basic resources mShaderSpriteText = getShader(ShaderSpriteTextFile); mShaderSpriteImage = getShader(ShaderSpriteImageAlphaFile); mShaderSpriteNonAlphaImage = getShader(ShaderSpriteImageNoAlphaFile); mShaderSpriteLine = getShader(ShaderSpriteLineFile); mShaderDiffuse = getShader(ShaderDiffuseFile); mShaderTransparent = getShader(ShaderTransparentFile); mShaderParticlesUnlit = getShader(ShaderParticlesUnlitFile); SPtr<PixelData> dummyPixelData = PixelData::create(2, 2, 1, PF_RGBA8); dummyPixelData->setColorAt(Color::Red, 0, 0); dummyPixelData->setColorAt(Color::Red, 0, 1); dummyPixelData->setColorAt(Color::Red, 1, 0); dummyPixelData->setColorAt(Color::Red, 1, 1); mDummyTexture = Texture::create(dummyPixelData); mWhiteSpriteTexture = getSkinTexture(WhiteTex); mDummySpriteTexture = SpriteTexture::create(mDummyTexture); mFont = gResources().load<Font>(mBuiltinDataFolder + (DefaultFontFilename + u8".asset")); mSkin = gResources().load<GUISkin>(mBuiltinDataFolder + (GUISkinFile + u8".asset")); mEmptySkin = GUISkin::create(); /************************************************************************/ /* CURSOR */ /************************************************************************/ HTexture cursorArrowTex = getCursorTexture(CursorArrowTex); HTexture cursorArrowDragTex = getCursorTexture(CursorArrowDragTex); HTexture cursorArrowLeftRightTex = getCursorTexture(CursorArrowLeftRightTex); HTexture cursorIBeamTex = getCursorTexture(CursorIBeamTex); HTexture cursorDenyTex = getCursorTexture(CursorDenyTex); HTexture cursorWaitTex = getCursorTexture(CursorWaitTex); HTexture cursorSizeNESWTex = getCursorTexture(CursorSizeNESWTex); HTexture cursorSizeNSTex = getCursorTexture(CursorSizeNSTex); HTexture cursorSizeNWSETex = getCursorTexture(CursorSizeNWSETex); HTexture cursorSizeWETex = getCursorTexture(CursorSizeWETex); mCursorArrow = cursorArrowTex->getProperties().allocBuffer(0, 0); cursorArrowTex->readData(mCursorArrow); mCursorArrowDrag = cursorArrowDragTex->getProperties().allocBuffer(0, 0); cursorArrowDragTex->readData(mCursorArrowDrag); mCursorArrowLeftRight = cursorArrowLeftRightTex->getProperties().allocBuffer(0, 0); cursorArrowLeftRightTex->readData(mCursorArrowLeftRight); mCursorIBeam = cursorIBeamTex->getProperties().allocBuffer(0, 0); cursorIBeamTex->readData(mCursorIBeam); mCursorDeny = cursorDenyTex->getProperties().allocBuffer(0, 0); cursorDenyTex->readData(mCursorDeny); mCursorWait = cursorWaitTex->getProperties().allocBuffer(0, 0); cursorWaitTex->readData(mCursorWait); mCursorSizeNESW = cursorSizeNESWTex->getProperties().allocBuffer(0, 0); cursorSizeNESWTex->readData(mCursorSizeNESW); mCursorSizeNS = cursorSizeNSTex->getProperties().allocBuffer(0, 0); cursorSizeNSTex->readData(mCursorSizeNS); mCursorSizeNWSE = cursorSizeNWSETex->getProperties().allocBuffer(0, 0); cursorSizeNWSETex->readData(mCursorSizeNWSE); mCursorSizeWE = cursorSizeWETex->getProperties().allocBuffer(0, 0); cursorSizeWETex->readData(mCursorSizeWE); /************************************************************************/ /* ICON */ /************************************************************************/ Path iconPath = mBuiltinDataFolder + ICON_FOLDER; iconPath.append(String(IconTextureName) + u8".asset"); HTexture iconTex = gResources().load<Texture>(iconPath); mFrameworkIcon = iconTex->getProperties().allocBuffer(0, 0); iconTex->readData(mFrameworkIcon); gCoreThread().submit(true); }