bool csXMLShaderCompiler::Initialize (iObjectRegistry* object_reg) { objectreg = object_reg; wrapperFact = new csWrappedDocumentNodeFactory (this); csRef<iPluginManager> plugin_mgr = csQueryRegistry<iPluginManager> (object_reg); strings = csQueryRegistryTagInterface<iStringSet> ( object_reg, "crystalspace.shared.stringset"); stringsSvName = csQueryRegistryTagInterface<iShaderVarStringSet> ( object_reg, "crystalspace.shader.variablenameset"); string_mixmode_alpha = stringsSvName->Request ("mixmode alpha"); stringLightCount = stringsSvName->Request ("light count"); g3d = csQueryRegistry<iGraphics3D> (object_reg); vfs = csQueryRegistry<iVFS> (object_reg); synldr = csQueryRegistryOrLoad<iSyntaxService> (object_reg, "crystalspace.syntax.loader.service.text"); if (!synldr) return false; docpp = csQueryRegistryOrLoad<CS::DocSystem::iDocumentPreprocessor> (object_reg, "crystalspace.document.preprocessor"); if (!docpp) return false; csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (object_reg)); if (verbosemgr) do_verbose = verbosemgr->Enabled ("renderer.shader"); else do_verbose = false; binDocSys = csLoadPluginCheck<iDocumentSystem> (plugin_mgr, "crystalspace.documentsystem.binary"); xmlDocSys.AttachNew (new csTinyDocumentSystem); csConfigAccess config (object_reg); doDumpXML = config->GetBool ("Video.XMLShader.DumpVariantXML"); doDumpConds = config->GetBool ("Video.XMLShader.DumpConditions"); doDumpValues = config->GetBool ("Video.XMLShader.DumpPossibleValues"); debugInstrProcessing = config->GetBool ("Video.XMLShader.DebugInstructionProcessing"); sharedEvaluator.AttachNew (new csConditionEvaluator (stringsSvName, condConstants)); return true; }
csShaderProgram::csShaderProgram (iObjectRegistry* objectReg) : scfImplementationType (this) { InitCommonTokens (commonTokens); csShaderProgram::objectReg = objectReg; synsrv = csQueryRegistry<iSyntaxService> (objectReg); stringsSvName = csQueryRegistryTagInterface<iShaderVarStringSet> (objectReg, "crystalspace.shader.variablenameset"); csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (objectReg)); if (verbosemgr) doVerbose = verbosemgr->Enabled("renderer.shader"); else doVerbose = false; }
bool DocumentPreprocessor::Initialize (iObjectRegistry* objReg) { objectreg = objReg; csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (objectreg)); if (verbosemgr) do_verbose = verbosemgr->Enabled ("document.preprocessor") // Heritage from being a part of xmlshader || verbosemgr->Enabled ("renderer.shader"); else do_verbose = false; csConfigAccess config (objectreg); debugInstrProcessing = config->GetBool ("Document.Preprocessor.DebugInstructionProcessing") // Heritage from being a part of xmlshader || config->GetBool ("Video.XMLShader.DebugInstructionProcessing"); return true; }
void csGLShader_FIXED::Open() { if(!object_reg) return; if (isOpen) return; config.AddConfig (object_reg, "/config/glshader_fixed.cfg"); if (!(enable && ext)) return; ext->InitGL_ARB_multitexture(); ext->InitGL_EXT_separate_specular_color(); ext->InitGL_EXT_secondary_color(); if (ext->CS_GL_ARB_multitexture) { ext->InitGL_ARB_texture_env_combine (); if (!ext->CS_GL_ARB_texture_env_combine) ext->InitGL_EXT_texture_env_combine (); ext->InitGL_ARB_texture_env_dot3 (); if (!ext->CS_GL_ARB_texture_env_dot3) ext->InitGL_EXT_texture_env_dot3 (); glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &texUnits); enableCombine = ext->CS_GL_ARB_multitexture && (ext->CS_GL_ARB_texture_env_combine || ext->CS_GL_EXT_texture_env_combine); #ifdef FUNNY_TEXTURE_UNIT_COUNT const char* descr = 0; if (texUnits < 2) descr = "unbelievable"; else if (texUnits == 2) descr = "puny"; else if (texUnits <= 4) descr = "moderate"; else if (texUnits <= 6) descr = "acceptable"; else if (texUnits <= 8) descr = "whopping"; else descr = "unseen before"; Report (CS_REPORTER_SEVERITY_NOTIFY, "Multitexture units: %s %d", descr, texUnits); #else Report (CS_REPORTER_SEVERITY_NOTIFY, "Multitexture units: %d", texUnits); #endif int useTextureUnits = config->GetInt ("Video.OpenGL.Shader.Fixed.MaxTextureUnits", texUnits); if (useTextureUnits < texUnits) { Report (CS_REPORTER_SEVERITY_NOTIFY, "Configured to use %d texture units", useTextureUnits); texUnits = useTextureUnits; } ext->InitGL_version_1_4(); if (!ext->CS_GL_version_1_4) ext->InitGL_ARB_texture_env_crossbar(); enableCrossbar = ext->CS_GL_version_1_4 || ext->CS_GL_ARB_texture_env_crossbar; } csRef<iShaderVarStringSet> strings = csQueryRegistryTagInterface<iShaderVarStringSet> (object_reg, "crystalspace.shader.variablenameset"); lsvCache.SetStrings (strings); bool verbose = false; csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (object_reg)); if (verbosemgr) verbose = verbosemgr->Enabled ("renderer.shader"); #define LQUOT "\xe2\x80\x9c" #define RQUOT "\xe2\x80\x9d" fixedFunctionForcefulEnable = config->GetBool ("Video.OpenGL.FixedFunctionForcefulEnable", false); if (verbose) Report (CS_REPORTER_SEVERITY_NOTIFY, LQUOT "Forceful" RQUOT " fixed function enable: %s", fixedFunctionForcefulEnable ? "yes" : "no"); isOpen = true; }
bool csShaderManager::Initialize(iObjectRegistry *objreg) { objectreg = objreg; vc = csQueryRegistry<iVirtualClock> (objectreg); txtmgr = csQueryRegistry<iTextureManager> (objectreg); csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (objectreg)); if (verbosemgr) do_verbose = verbosemgr->Enabled ("renderer.shader"); else do_verbose = false; Frame = csevFrame(objectreg); SystemOpen = csevSystemOpen(objectreg); SystemClose = csevSystemClose(objectreg); csRef<iEventHandlerRegistry> handlerReg = csQueryRegistry<iEventHandlerRegistry> (objectreg); //eventSucc[0] = handlerReg->GetGenericID ("crystalspace.graphics3d"); csRef<iEventQueue> q = csQueryRegistry<iEventQueue> (objectreg); if (q) { csEventID events[] = { Frame, SystemOpen, SystemClose, CS_EVENTLIST_END }; RegisterWeakListener (q, this, events, weakEventHandler); } csRef<iPluginManager> plugin_mgr = csQueryRegistry<iPluginManager> (objectreg); strings = csQueryRegistryTagInterface<iStringSet> ( objectreg, "crystalspace.shared.stringset"); stringsSvName = csQueryRegistryTagInterface<iShaderVarStringSet> ( objectreg, "crystalspace.shader.variablenameset"); { csRef<csNullShader> nullShader; nullShader.AttachNew (new csNullShader (this)); nullShader->SetName ("*null"); RegisterShader (nullShader); } config.AddConfig (objectreg, "/config/shadermgr.cfg"); csRef<iStringArray> classlist = iSCF::SCF->QueryClassList("crystalspace.graphics3d.shadercompiler."); size_t const nmatches = classlist.IsValid() ? classlist->GetSize() : 0; if (nmatches != 0) { size_t i; for (i = 0; i < nmatches; ++i) { const char* classname = classlist->Get(i); csRef<iShaderCompiler> plugin = csLoadPluginCheck<iShaderCompiler> (plugin_mgr, classname); if (plugin) { if (do_verbose) Report (CS_REPORTER_SEVERITY_NOTIFY, "Loaded compiler plugin %s, compiler: %s", classname,plugin->GetName()); RegisterCompiler(plugin); } } } else { Report (CS_REPORTER_SEVERITY_WARNING, "No shader plugins found!"); } csString cfgKey; const csString keyPrefix ("Video.ShaderManager.Tags."); csSet<csString> knownKeys; csRef<iConfigIterator> it (config->Enumerate (keyPrefix)); while (it->HasNext ()) { it->Next(); const char* key = it->GetKey (true); const char* dot = strrchr (key, '.'); cfgKey.Clear (); cfgKey.Append (key, dot - key); if (knownKeys.In ((const char*)cfgKey)) continue; knownKeys.Add ((const char*)cfgKey); const char* tagName = config->GetStr ( keyPrefix + cfgKey + ".TagName", cfgKey); const char* tagPresence = config->GetStr ( keyPrefix + cfgKey + ".Presence", "Neutral"); int tagPriority = config->GetInt ( keyPrefix + cfgKey + ".Priority", 0); csShaderTagPresence presence; if (strcasecmp (tagPresence, "neutral") == 0) { presence = TagNeutral; } else if (strcasecmp (tagPresence, "forbidden") == 0) { presence = TagForbidden; } else if (strcasecmp (tagPresence, "required") == 0) { presence = TagRequired; } else { Report (CS_REPORTER_SEVERITY_WARNING, "Unknown shader tag presence '%s' for tag config '%s'", tagPresence, (const char*)cfgKey); continue; } csStringID tagID = strings->Request (tagName); SetTagOptions (tagID, presence, tagPriority); } sv_time.AttachNew (new csShaderVariable (stringsSvName->Request ("standard time"))); sv_time->SetValue (0.0f); if (config->GetBool ("Video.ShaderManager.EnableShaderCache", false)) { bool redundantRemove = config->GetBool ("Video.ShaderManager.ShaderCache.RedundantRemove", true); shaderCache.AttachNew (new PlexHierarchicalCache (redundantRemove)); csRef<CS::Utility::VfsHierarchicalCache> cache; const char* cachePath; cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.User", "/shadercache/user"); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, csString().Format ("%s/" CS_VERSION_MAJOR "." CS_VERSION_MINOR, cachePath))); shaderCache->AddSubShaderCache (cache, cachePriorityUser); } cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.App", 0); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, cachePath)); cache->SetReadOnly (true); shaderCache->AddSubShaderCache (cache, cachePriorityApp); } cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.Global", "/shadercache/global"); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, cachePath)); cache->SetReadOnly (true); shaderCache->AddSubShaderCache (cache, cachePriorityGlobal); } } return true; }
bool csGraphics2DOpenGL::Open () { if (is_open) return true; csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (object_reg)); if (verbosemgr) detector.SetVerbose (verbosemgr->Enabled ("renderer.windows.gldriver")); // create the window. if (FullScreen) { SwitchDisplayMode (false); } int pixelFormat = -1; csGLPixelFormatPicker picker (this); /* Check if the WGL pixel format check should be used at all. It appears that some drivers take "odd" choices when using the WGL pixel format path (e.g. returning Accum-capable formats even if none was requested). */ bool doWGLcheck = false; { GLPixelFormat format; if (picker.GetNextFormat (format)) { doWGLcheck = (format[glpfvMultiSamples] != 0); picker.Reset (); } } if (doWGLcheck) pixelFormat = FindPixelFormatWGL (picker); m_bActivated = true; int wwidth = fbWidth; int wheight = fbHeight; DWORD exStyle = 0; DWORD style = WS_POPUP | WS_SYSMENU; int xpos = 0; int ypos = 0; if (FullScreen) { /*exStyle |= WS_EX_TOPMOST;*/ } else { style |= WS_CAPTION | WS_MINIMIZEBOX; if (AllowResizing) style |= WS_THICKFRAME | WS_MAXIMIZEBOX; wwidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME); wheight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME) + GetSystemMetrics (SM_CYCAPTION); xpos = (GetSystemMetrics (SM_CXSCREEN) - wwidth) / 2; ypos = (GetSystemMetrics (SM_CYSCREEN) - wheight) / 2; } m_hWnd = m_piWin32Assistant->CreateCSWindow (this, exStyle, style, xpos, ypos, wwidth, wheight); if (!m_hWnd) SystemFatalError (L"Cannot create Crystal Space window", GetLastError()); SetTitle (win_title); // Subclass the window if (IsWindowUnicode (m_hWnd)) { m_OldWndProc = (WNDPROC)SetWindowLongPtrW (m_hWnd, GWLP_WNDPROC, (LONG_PTR) WindowProc); SetWindowLongPtrW (m_hWnd, GWLP_USERDATA, (LONG_PTR)this); } else { m_OldWndProc = (WNDPROC)SetWindowLongPtrA (m_hWnd, GWLP_WNDPROC, (LONG_PTR) WindowProc); SetWindowLongPtrA (m_hWnd, GWLP_USERDATA, (LONG_PTR)this); } hDC = GetDC (m_hWnd); if (pixelFormat == -1) { picker.Reset(); pixelFormat = FindPixelFormatGDI (hDC, picker); } PIXELFORMATDESCRIPTOR pfd; if (DescribePixelFormat (hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd) == 0) SystemFatalError (L"DescribePixelFormat failed.", GetLastError()); if (SetPixelFormat (hDC, pixelFormat, &pfd) != TRUE) { HRESULT spfErr = (HRESULT)GetLastError(); SystemFatalError (L"SetPixelFormat failed.", spfErr); } currentFormat[glpfvColorBits] = pfd.cColorBits; currentFormat[glpfvAlphaBits] = pfd.cAlphaBits; currentFormat[glpfvDepthBits] = pfd.cDepthBits; currentFormat[glpfvStencilBits] = pfd.cStencilBits; currentFormat[glpfvAccumColorBits] = pfd.cAccumBits; currentFormat[glpfvAccumAlphaBits] = pfd.cAccumAlphaBits; Depth = pfd.cColorBits; hardwareAccelerated = !(pfd.dwFlags & PFD_GENERIC_FORMAT) || (pfd.dwFlags & PFD_GENERIC_ACCELERATED); hGLRC = wglCreateContext (hDC); wglMakeCurrent (hDC, hGLRC); UpdateWindow (m_hWnd); ShowWindow (m_hWnd, m_nCmdShow); SetForegroundWindow (m_hWnd); SetFocus (m_hWnd); /* Small hack to emit "no HW acceleration" message on both GDI Generic and * sucky Direct3D default OpenGL */ hardwareAccelerated &= (strncmp ((char*)glGetString (GL_VENDOR), "Microsoft", 9) != 0); if (!hardwareAccelerated) { Report (CS_REPORTER_SEVERITY_WARNING, "No hardware acceleration!"); } detector.DoDetection (m_hWnd, hDC); Report (CS_REPORTER_SEVERITY_NOTIFY, "GL driver: %s %s", detector.GetDriverDLL(), detector.GetDriverVersion() ? detector.GetDriverVersion() : "<version unknown>"); if (FullScreen) { /* * from the Windows Shell docs: * "It is possible to cover the taskbar by explicitly setting the size * of the window rectangle equal to the size of the screen with * SetWindowPos." */ SetWindowPos (m_hWnd, CS_WINDOW_Z_ORDER, 0, 0, fbWidth, fbHeight, 0); } if (!csGraphics2DGLCommon::Open ()) return false; ext.InitWGL_EXT_swap_control (hDC); if (ext.CS_WGL_EXT_swap_control) { ext.wglSwapIntervalEXT (vsync ? 1 : 0); vsync = (ext.wglGetSwapIntervalEXT() != 0); Report (CS_REPORTER_SEVERITY_NOTIFY, "VSync is %s.", vsync ? "enabled" : "disabled"); } return true; }