Example #1
0
        public override IObservable <TSource> Process <TSource>(IObservable <TSource> source)
        {
            return(Observable.Defer(() =>
            {
                FramebufferState framebuffer = null;
                return source.CombineEither(
                    ShaderManager.WindowSource.Do(window =>
                {
                    framebuffer = new FramebufferState(window, framebufferConfiguration);
                }),
                    (input, window) =>
                {
                    foreach (var state in renderState)
                    {
                        state.Execute(window);
                    }

                    framebuffer.Bind();
                    foreach (var shader in window.Shaders)
                    {
                        shader.Dispatch();
                    }

                    framebuffer.Unbind();
                    return input;
                }).Finally(() =>
                {
                    if (framebuffer != null)
                    {
                        framebuffer.Dispose();
                    }
                });
            }));
        }
Example #2
0
        public ShaderState(
            Shader shaderTarget,
            ResourceManager resourceManager,
            IEnumerable <StateConfiguration> renderStateConfiguration,
            IEnumerable <UniformConfiguration> shaderUniforms,
            IEnumerable <BufferBindingConfiguration> bufferBindingConfiguration,
            FramebufferConfiguration framebufferConfiguration)
        {
            if (shaderTarget == null)
            {
                throw new ArgumentNullException("shaderTarget");
            }

            if (resourceManager == null)
            {
                throw new ArgumentNullException("resourceManager");
            }

            if (renderStateConfiguration == null)
            {
                throw new ArgumentNullException("renderStateConfiguration");
            }

            if (shaderUniforms == null)
            {
                throw new ArgumentNullException("shaderUniforms");
            }

            if (bufferBindingConfiguration == null)
            {
                throw new ArgumentNullException("bufferBindingConfiguration");
            }

            if (framebufferConfiguration == null)
            {
                throw new ArgumentNullException("framebufferConfiguration");
            }

            shader          = shaderTarget;
            renderState     = renderStateConfiguration.ToList();
            uniformBindings = shaderUniforms.Select(configuration => new UniformBinding(shader, configuration)).ToList();
            bufferBindings  = bufferBindingConfiguration.Select(configuration => configuration.CreateBufferBinding(shader, resourceManager)).ToList();
            framebuffer     = new FramebufferState(shader.Window, framebufferConfiguration);
        }