Beispiel #1
0
        public void SetUp()
        {
            texture = new Mock<ITexture>();
            texture.SetupGet(t => t.Width).Returns(200);
            texture.SetupGet(t => t.Height).Returns(50);
            var textureRegion = new TextureRegion(2, 2, 15, 20);

            spriteSheet = new Mock<ISpriteSheet>();
            spriteSheet.SetupGet(s => s.Texture)
                       .Returns(texture.Object);
            spriteSheet.Setup(s => s.GetRegion(It.IsAny<int>()))
                       .Returns(textureRegion);
            spriteSheet.SetupGet(s => s.TextureRegions)
                       .Returns(new TextureRegion[] { textureRegion });

            shaderProgram = new Mock<IShaderProgram>();
            var mvpUniform = new ShaderUniform("mvp", 4, 16, ActiveUniformType.FloatMat4);
            var uniforms = new Dictionary<string, ShaderUniform>()
            {
                {"mvp", mvpUniform}
            };
            shaderProgram.SetupGet(s => s.Uniforms).Returns(uniforms);
            vao = new Mock<IVertexArrayObject>();
            vbo = new Mock<IVertexBuffer<VertexPositionColourTexture>>();
            vbo.SetupGet(v => v.VertexDeclaration).Returns(declaration);
            adapter = new Mock<IDrawAdapter>();

            spriteBatch = new SpriteBatch(
                spriteSheet.Object,
                shaderProgram.Object,
                vao.Object,
                vbo.Object,
                adapter.Object
            );
        }
        public void Constructor_CorrectlyInitialises_Instance()
        {
            var uniform = new ShaderUniform("model", 0, 64, ActiveUniformType.FloatMat4);

            uniform.ShouldSatisfyAllConditions(
                () => uniform.Name.ShouldBe("model"),
                () => uniform.Location.ShouldBe(0),
                () => uniform.Size.ShouldBe(64),
                () => uniform.UniformType.ShouldBe(ActiveUniformType.FloatMat4)
            );
        }
Beispiel #3
0
 public void SetMatrix4(ShaderUniform uniform, ref Matrix4 matrix, bool transpose)
 {
     if (uniform == null)
     {
         throw new ArgumentNullException(nameof(uniform));
     }
     if (!uniforms.ContainsKey(uniform.Name))
     {
         throw new ArgumentException(
             "The given uniform must be in the invoking shader program"
         );
     }
     if (uniform.UniformType != ActiveUniformType.FloatMat4)
     {
         throw new ArgumentException(
             $"The given uniform must be of type {nameof(ActiveUniformType.FloatMat4)}"
         );
     }
     adapter.UniformMatrix4(uniform.Location, false, ref matrix);
 }
        private void GivenProgramHasUniform(
            string name,
            int expectedLocation = 2,
            ActiveUniformType type = ActiveUniformType.FloatMat4)
        {
            var uniform = new ShaderUniform(name, expectedLocation, 8, type);
            adapter.Setup(a => a.GetUniformLocation(program.Handle, name))
                   .Returns(expectedLocation);
            adapter.Setup(a => a.GetActiveUniform(program.Handle, expectedLocation, It.IsAny<int>()))
                   .Returns(uniform);

            program.Link();
            program.GetUniformLocation(name);
        }
        public void SetMatrix4_ThrowsArgumentException_OnUniformNotInShaderProgram()
        {
            var matrix = Matrix4.Identity;
            var uniform = new ShaderUniform("mvp", 4, 16, ActiveUniformType.FloatMat4);
            Action action = () => program.SetMatrix4(uniform, ref matrix, false);

            action.ShouldThrow<ArgumentException>().Message.ShouldContain(
                "The given uniform must be in the invoking shader program"
            );
        }