Ejemplo n.º 1
0
        public void UniformBuffer()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (ShaderProgram sp = Device.CreateShaderProgram(
                           ShaderSources.PassThroughVertexShader(),
                           ShaderSources.RedUniformBlockFragmentShader()))
                    using (UniformBuffer uniformBuffer = Device.CreateUniformBuffer(BufferHint.DynamicDraw, sp.UniformBlocks["RedBlock"].SizeInBytes))
                    {
                        Assert.IsFalse(sp.Log.Contains("warning"));

                        UniformBlock       redBlock = sp.UniformBlocks["RedBlock"];
                        UniformBlockMember red      = redBlock.Members["red"];

                        //
                        // Verify creating uniform buffer
                        //
                        Assert.IsNotNull(uniformBuffer);
                        Assert.AreEqual(BufferHint.DynamicDraw, uniformBuffer.UsageHint);
                        Assert.AreEqual(redBlock.SizeInBytes, uniformBuffer.SizeInBytes);

                        redBlock.Bind(uniformBuffer);

                        //
                        // Verify copying into red member
                        //
                        float redIntensity = 0.5f;
                        uniformBuffer.CopyFromSystemMemory(new[] { redIntensity }, red.OffsetInBytes);

                        float[] redIntensity2 = uniformBuffer.CopyToSystemMemory <float>(red.OffsetInBytes, sizeof(float));
                        Assert.AreEqual(redIntensity, redIntensity2[0]);
                    }
        }
Ejemplo n.º 2
0
        public void UniformBlock()
        {
            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (ShaderProgram sp = Device.CreateShaderProgram(
                           ShaderSources.PassThroughVertexShader(),
                           ShaderSources.RedUniformBlockFragmentShader()))
                {
                    Assert.IsFalse(sp.Log.Contains("warning"));
                    Assert.IsEmpty(sp.Uniforms);
                    Assert.AreEqual(1, sp.UniformBlocks.Count);

                    UniformBlock redBlock = sp.UniformBlocks["RedBlock"];
                    Assert.AreEqual("RedBlock", redBlock.Name);
                    Assert.GreaterOrEqual(redBlock.SizeInBytes, 4);
                    Assert.AreEqual(1, redBlock.Members.Count);

                    UniformBlockMember red = redBlock.Members["red"];
                    Assert.AreEqual("red", red.Name);
                    Assert.AreEqual(0, red.OffsetInBytes);
                    Assert.AreEqual(UniformType.Float, red.Datatype);
                }
        }