public unsafe void TestShaderResourcePackage() { ConstantBuffer <Vector4> matColorBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); TextureSampler textureSampler = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes); FragmentShader testFS = new FragmentShader( @"Tests\SimpleFS.cso", new ConstantBufferBinding(0U, "MaterialColor", matColorBuffer), new TextureSamplerBinding(0U, "DefaultSampler") ); Material testMaterial = new Material("Test Material", testFS); testMaterial.SetMaterialConstantValue((ConstantBufferBinding)testFS.GetBindingByIdentifier("MaterialColor"), Vector4.ONE); testMaterial.SetMaterialResource((TextureSamplerBinding)testFS.GetBindingByIdentifier("DefaultSampler"), textureSampler); ShaderResourcePackage shaderResourcePackage = testMaterial.FragmentShaderResourcePackage; Assert.AreEqual(Vector4.ONE, *((Vector4 *)shaderResourcePackage.GetValue((ConstantBufferBinding)testFS.GetBindingByIdentifier("MaterialColor")))); Assert.AreEqual(textureSampler, shaderResourcePackage.GetValue((TextureSamplerBinding)testFS.GetBindingByIdentifier("DefaultSampler"))); testFS.Dispose(); matColorBuffer.Dispose(); testMaterial.Dispose(); textureSampler.Dispose(); }
public void TestSettingMaterialProperties() { ConstantBuffer <Vector4> matColorBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); TextureSampler textureSampler = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes); FragmentShader testFS = new FragmentShader( @"Tests\SimpleFS.cso", new ConstantBufferBinding(0U, "MaterialColor", matColorBuffer), new TextureSamplerBinding(0U, "DefaultSampler") ); Material testMaterial = new Material("Test Material", testFS); testMaterial.SetMaterialConstantValue((ConstantBufferBinding)testFS.GetBindingByIdentifier("MaterialColor"), Vector4.ONE); testMaterial.SetMaterialResource((TextureSamplerBinding)testFS.GetBindingByIdentifier("DefaultSampler"), textureSampler); #if !DEVELOPMENT && !RELEASE ConstantBufferBinding cb = new ConstantBufferBinding(1U, "Test", matColorBuffer); try { testMaterial.SetMaterialConstantValue(cb, Vector4.RIGHT); Assert.Fail(); } catch (AssuranceFailedException) { } finally { (cb as IDisposable).Dispose(); } try { testMaterial.SetMaterialConstantValue((ConstantBufferBinding)testFS.GetBindingByIdentifier("MaterialColor"), Matrix.IDENTITY); Assert.Fail(); } catch (AssuranceFailedException) { } #endif testFS.Dispose(); matColorBuffer.Dispose(); testMaterial.Dispose(); textureSampler.Dispose(); }
public unsafe void TestSetShaderTextureSamplers() { TextureSampler ts0 = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes); TextureSampler ts2 = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes); Shader shader = new FragmentShader( @"Tests\SimpleFS.cso", new TextureSamplerBinding(0U, "TS0"), new TextureSamplerBinding(1U, "TS1"), new TextureSamplerBinding(2U, "TS2") ); Dictionary <TextureSamplerBinding, TextureSampler> tsDict = new Dictionary <TextureSamplerBinding, TextureSampler>(); tsDict[shader.TextureSamplerBindings[0]] = ts0; tsDict[shader.TextureSamplerBindings[2]] = ts2; RenderCommand testCommand = RenderCommand.SetShaderTextureSamplers(shader, tsDict); Assert.AreEqual(RenderCommandInstruction.FSSetSamplers, testCommand.Instruction); ResourceHandle *resHandleArray = (ResourceHandle *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg1, sizeof(long))); Assert.AreEqual(ts0.ResourceHandle, resHandleArray[0]); Assert.AreEqual(ResourceHandle.NULL, resHandleArray[1]); Assert.AreEqual(ts2.ResourceHandle, resHandleArray[2]); Assert.AreEqual((RenderCommandArgument)3U, testCommand.Arg2); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderTextureSamplers(null, tsDict); Assert.Fail(); } catch (AssuranceFailedException) { } try { RenderCommand.SetShaderTextureSamplers(shader, null); Assert.Fail(); } catch (AssuranceFailedException) { } #endif ts0.Dispose(); ts2.Dispose(); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderTextureSamplers(shader, tsDict); Assert.Fail(); } catch (AssuranceFailedException) { } #endif shader.Dispose(); #if !DEVELOPMENT && !RELEASE try { RenderCommand.SetShaderTextureSamplers(shader, new Dictionary <TextureSamplerBinding, TextureSampler>()); Assert.Fail(); } catch (AssuranceFailedException) { } #endif }