コード例 #1
0
        public OpenGLSceneProcessor(IServiceProvider serviceProvider, IRenderWindow renderWindow, SceneGraph sceneGraph)
        {
            _serviceProvider          = serviceProvider;
            _cancellationTokenManager = _serviceProvider.GetRequiredService <CancellationTokenSource>();
            _logger         = _serviceProvider.GetRequiredService <ILogger <RenderWindow> >();
            _shaderCompiler = _serviceProvider.GetRequiredService <IShaderCompiler>();
            _textureLoader  = _serviceProvider.GetRequiredService <ITextureLoader>();

            _renderWindow   = renderWindow; // This cannot be passed via the service provider otherwise there will be a cycle in the DI graph
            _sceneGraph     = sceneGraph;
            _renderList     = new LinkedList <IRenderCommand>();
            _renderInfo     = new RenderInfo();
            _requestPicking = null;

            GL.LoadBindings(new GLFWBindingsContext());

            // Get human readable log messages during debugging
            if (Debugger.IsAttached)
            {
                GL.Enable(EnableCap.DebugOutput);
                _debugProc = DebugMessageCallback;
                _gcHandle  = GCHandle.Alloc(_debugProc);
                GL.DebugMessageCallback(_debugProc, IntPtr.Zero);
            }

            GL.Enable(EnableCap.DepthTest);

            // Save default frame buffer id for later blitting
            GL.GetInteger(GetPName.FramebufferBinding, out _defaultFrameBufferId);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _defaultFrameBufferId);

            InitFrameBuffer(640, 360);
        }
コード例 #2
0
ファイル: BufferManager.cs プロジェクト: WCoetser/TRL-3D
        public BufferManager(SceneGraph sceneGraph, ILogger <BufferManager> logger, IShaderCompiler shaderCompiler, ITextureLoader textureLoader)
        {
            _sceneGraph     = sceneGraph;
            _logger         = logger;
            _shaderCompiler = shaderCompiler;
            _textureLoader  = textureLoader;

            _objectToGeometryBuffers = new Dictionary <ObjectIdentityBase, HashSet <ObjectIdentityBase> >();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: TLeonardUK/VulkanEngine
        public void MonitorAndCompileChanges()
        {
            System.Console.ForegroundColor = ConsoleColor.DarkGray;

            string outputDirectory = Path.GetFullPath("../Temp/Assets/");
            string inputDirectory  = Path.GetFullPath("../Assets/");

            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.IncludeSubdirectories = true;
            watcher.Path         = inputDirectory;
            watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.Filter       = "*.*";
            watcher.Changed     += new FileSystemEventHandler((object sender, FileSystemEventArgs e) =>
            {
                if (m_shaderFileWatchedExtensions.Contains(Path.GetExtension(e.FullPath)))
                {
                    m_filesChangedEvent.Set();
                }
            });
            watcher.EnableRaisingEvents = true;

            IShaderCompiler compiler = MakeShaderCompiler();

            compiler.RootPath = inputDirectory;

            while (true)
            {
                m_filesChangedEvent.WaitOne();

                bool bSuccess = CompileAllShaders(compiler, outputDirectory, inputDirectory);
                if (bSuccess)
                {
                    System.Console.ForegroundColor = ConsoleColor.Green;
                    System.Console.WriteLine("Compile success.");
                }
                else
                {
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("Compilation failed.");
                }

                System.Console.WriteLine();

                m_filesChangedEvent.Reset();
            }
        }
コード例 #4
0
ファイル: TriangleBuffer.cs プロジェクト: WCoetser/TRL-3D
        /// <summary>
        /// Builds a buffer based on the given triangles for the given scene graph
        /// </summary>
        /// <param name="sceneGraph">The scene graph for the entire world model.</param>
        /// <param name="triangleAssertionsToRender">The triangles for which a buffer needs to be constructed.</param>
        public TriangleBuffer(SceneGraph sceneGraph,
                              BufferManager bufferManager,
                              IEnumerable <Core.Scene.Triangle> triangleAssertionsToRender,
                              ILogger logger,
                              IShaderCompiler shaderCompiler,
                              ITextureLoader textureLoader) : base()
        {
            _logger         = logger;
            _shaderCompiler = shaderCompiler;
            _textureLoader  = textureLoader;
            _sceneGraph     = sceneGraph;
            _bufferManager  = bufferManager;

            _triangleAssertionsToRender = triangleAssertionsToRender.ToArray();

            _vertexBuffer      = new Lazy <float[]>(() => new float[_triangleAssertionsToRender.Length * VerticesPerTriangle * ComponentsPerVertex]);
            _vertexIndexBuffer = new Lazy <uint[]>(() => new uint[_triangleAssertionsToRender.Length * VerticesPerTriangle]);

            _textureObjectIdToShaderIndex = new EqualityComparerMapper <ulong>(EqualityComparer <ulong> .Default);

            BuildBuffer();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: TLeonardUK/VulkanEngine
        public bool CompileAllShaders(IShaderCompiler compiler, string outputDirectory, string inputDirectory)
        {
            List <string> shaders = GatherShaders(compiler.RootPath, m_shaderFileExtensions);

            bool bSuccess = true;

            foreach (string shaderPath in shaders)
            {
                System.Console.ForegroundColor = ConsoleColor.White;
                System.Console.WriteLine("Compiling: " + shaderPath);
                System.Console.ForegroundColor = ConsoleColor.DarkGray;

                Shader shader = compiler.Compile(shaderPath);

                System.Console.ForegroundColor = shader.CompileFailed ? ConsoleColor.Red : ConsoleColor.DarkGray;
                System.Console.WriteLine(shader.Output);
                System.Console.ForegroundColor = ConsoleColor.DarkGray;

                if (shader.CompileFailed)
                {
                    bSuccess = false;
                }
                else
                {
                    string outputFile = outputDirectory + shaderPath.Substring(compiler.RootPath.Length) + ".spirv";
                    if (!shader.Save(outputFile))
                    {
                        System.Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine("Failed to save output to: " + outputFile);
                        System.Console.ForegroundColor = ConsoleColor.DarkGray;

                        bSuccess = false;
                    }
                }
            }

            return(bSuccess);
        }
コード例 #6
0
 private void Initialize(IShaderCompiler compiler)
 {
     _parameters = compiler.Parameters.ToDictionary(x => x.Name);
 }
コード例 #7
0
 public ShaderCompilerArguments(IShaderCompiler compiler, IDictionary <string, string> dictionary)
     : base(dictionary)
 {
     Initialize(compiler);
 }
コード例 #8
0
 public ShaderCompilerArguments(IShaderCompiler compiler)
     : base()
 {
     Initialize(compiler);
 }
コード例 #9
0
ファイル: IShaderEffect.cs プロジェクト: fealty/Frost
 public void Compile(IShaderCompiler compiler)
 {
     Contract.Requires(compiler != null);
 }