コード例 #1
0
        internal TypelessBufferAsRenderTarget(TypelessBuffer buffer, PixelFormat fmt, ulong offset, uint width)
        {
            this.buffer = buffer;
            this.format = fmt;
            this.offset = offset;
            this.width  = width;

            buffer.AddRef();
        }
コード例 #2
0
        internal TypelessBufferAsTexture(PixelFormat format, ulong offset, uint width, TypelessBuffer buffer)
        {
            this.format = format;
            this.offset = offset;
            this.buffer = buffer;
            this.width  = width;

            buffer.AddRef();

            // We try to bind to device.
            if (this.buffer.Device != null)
            {
                // We bind to device.
                BindToDevice(buffer.Device);
            }
        }
コード例 #3
0
        void Dispose(bool fin)
        {
            // Already disposed.
            if (cacheableState == SharpMedia.Caching.CacheableState.Disposed)
            {
                return;
            }

            buffer.Release();

            if (this.view != null)
            {
                view.Dispose();
            }

            if (!fin)
            {
                GC.SuppressFinalize(this);
                buffer = null;
            }

            cacheableState = SharpMedia.Caching.CacheableState.Disposed;
        }
コード例 #4
0
        public unsafe GraphicsCanvas([NotNull] GraphicsDevice device,
                                     [NotNull] RenderTargetView renderTarget,
                                     Vector2f canvasUnits)
        {
            info = new GraphicsCanvasInfo(this);

            // Initialize shaders.
            Initialize();

            this.unitSize     = canvasUnits;
            this.device       = device;
            this.renderTarget = renderTarget;

            this.batch = Geometry.CreateBatch(VertexData.Format, new IndexFormat(true),
                                              MaxVerticesInBatch, MaxIndicesInBatch, CyclicBufferCount);

            // We also immediatelly bind it to device.
            this.batch.BindToDevice(device);

            // We create vertex constants buffer.
            {
                TypelessBuffer vertexConstBuffer = new TypelessBuffer(Usage.Dynamic, BufferUsage.ConstantBuffer,
                                                                      CPUAccess.Write, GraphicsLocality.DeviceOrSystemMemory, 16 * 4 * 2);
                vertexConstBuffer.DisposeOnViewDispose = true;

                ConstantBufferLayoutBuilder vertexBufferLayout = new ConstantBufferLayoutBuilder();
                vertexBufferLayout.AppendElement("PositionTransform", PinFormat.Float4x4);
                vertexBufferLayout.AppendElement("TextureTransform", PinFormat.Float4x4);

                vertexConstants = vertexConstBuffer.CreateConstantBuffer(vertexBufferLayout.CreateLayout());
            }

            // We create pixel constants buffer.
            pixelConstants = new TypelessBuffer(Usage.Dynamic, BufferUsage.ConstantBuffer, CPUAccess.Write,
                                                GraphicsLocality.DeviceOrSystemMemory, ConstantBufferView.MaxSize);
        }
コード例 #5
0
        void Initialize()
        {
            // 1) We create vertex shader first.
            {
                vertexShader = new ShaderCode(BindingStage.VertexShader);
                vertexShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx2);



                // We now extend position
                ExpandOperation expandPositionOp = new ExpandOperation(PinFormat.Floatx4, ExpandType.AddOnesAtW);
                expandPositionOp.BindInputs(vertexShader.InputOperation.PinAsOutput(PinComponent.Position));
                Pin position = expandPositionOp.Outputs[0];

                // We now output position.
                vertexShader.OutputOperation.AddComponentAndLink(PinComponent.Position, position);
            }

            vertexShader.Immutable = true;

            // 2) We create pixel shader.
            {
                pixelShader = new ShaderCode(BindingStage.PixelShader);
                pixelShader.InputOperation.AddInput(PinComponent.Position, PinFormat.Floatx4);

                // We first use only XY.
                SwizzleOperation swizzleOp = new SwizzleOperation(SwizzleMask.XY);
                swizzleOp.BindInputs(pixelShader.InputOperation.PinAsOutput(PinComponent.Position));

                ConstantOperation constant = vertexShader.CreateConstant("Offset", PinFormat.Floatx2);

                // We first offset.
                SubstractOperation subOp = new SubstractOperation();
                subOp.BindInputs(swizzleOp.Outputs[0], constant.Outputs[0]);

                ConstantOperation interfaceOp = pixelShader.CreateConstant("Composite", PinFormat.Interface, Pin.DynamicArray);

                // We use the compositing operation.
                CompositingOperation op = new CompositingOperation();
                op.BindInputs(subOp.Outputs[0],
                              interfaceOp.Outputs[0]);

                // Compositing is bound to output.
                pixelShader.OutputOperation.AddComponentAndLink(PinComponent.RenderTarget0, op.Outputs[0]);
            }

            pixelShader.Immutable = true;

            // 3) Initialize states.

            // Depth-stencil state.
            depthStencilState = new DepthStencilState();
            depthStencilState.DepthTestEnabled  = false;
            depthStencilState.DepthWriteEnabled = false;

            // Blend state (no blending default).
            blendState = new BlendState();


            // Rasterization state.
            rasterizationState                      = new RasterizationState();
            rasterizationState.FrontFacing          = Facing.CCW;
            rasterizationState.CullMode             = CullMode.None;
            rasterizationState.FillMode             = FillMode.Solid;
            rasterizationState.MultiSamplingEnabled = true;


            // We intern all states.
            depthStencilState  = StateManager.Intern(depthStencilState);
            blendState         = StateManager.Intern(blendState);
            rasterizationState = StateManager.Intern(rasterizationState);

            // 4) We create geometry.
            alignedQuad = new Geometry(device);
            alignedQuad.AssociateBuffers = true;

            {
                // We create vertex buffer
                VertexBufferView vertexBuffer = VertexBufferView.Create(device, vertexFormat, Usage.Default,
                                                                        CPUAccess.None, GraphicsLocality.DeviceOrSystemMemory,
                                                                        new Vector2f(-1.0f, -1.0f), new Vector2f(1.0f, -1.0f),
                                                                        new Vector2f(1.0f, 1.0f), new Vector2f(-1.0f, -1.0f),
                                                                        new Vector2f(1.0f, 1.0f), new Vector2f(-1.0f, 1.0f));

                alignedQuad[0] = vertexBuffer;
            }

            // 5) We create pixel typeless buffer for constant buffer.
            pixelTypelessConstantBuffer = new TypelessBuffer(Usage.Dynamic, BufferUsage.ConstantBuffer,
                                                             CPUAccess.Write, GraphicsLocality.DeviceOrSystemMemory, ConstantBufferView.MaxSize);
        }