public MoreDrawCallsState(GpuResources res, IRenderDevice device, ref PipelineStateDesc desc, iPipelineStateFactory stateFactory, eShaderMacros macros) : base(res, device, ref desc, stateFactory, macros) { drawCallsBuffer = res.moreDrawCalls; drawCallsBuffer.resized.add(this, (DynamicBuffer buffer, int capacity) => dropResourceBindings()); }
public static CursorTexture load(IRenderDevice renderDevice, byte[] payload, CursorFile.ImageInfo info) { BITMAPINFOHEADER header = new BITMAPINFOHEADER(); int bihSize = Marshal.SizeOf <BITMAPINFOHEADER>(); payload.AsSpan().Slice(0, bihSize).CopyTo(MiscUtils.asSpan(ref header)); if (bihSize == header.biSize) { bool monochrome; ITextureView texture = loadBmp(renderDevice, payload, ref header, info.size, out monochrome); if (monochrome) { return(new MonochromeCursorTexture(texture, info.size, info.hotspot)); } else { return(new StaticCursorTexture(texture, info.size, info.hotspot)); } } if (header.biSize == 0x474E5089) // "‰PNG" magic number { return(new StaticCursorTexture(loadPng(renderDevice, payload), info.size, info.hotspot)); } throw new ArgumentException("LoadCursor.load only supports BMP or PNG images"); }
protected override void createResources(IRenderDevice device) { createPipelineState(device); createVertexBuffer(device); createIndexBuffer(device); context.animation.startDelta(this); }
public static Boolean Validate(this IMediaFeature feature, IRenderDevice device) { var validator = default(IFeatureValidator); AssociatedValidators.TryGetValue(feature, out validator); return(validator?.Validate(feature, device) ?? false); }
public Boolean Validate(IMediaFeature feature, IRenderDevice renderDevice) { var defaultValue = new Length(1.0, Length.Unit.None); var converter = feature.IsMinimum || feature.IsMaximum ? NaturalIntegerConverter : NaturalIntegerConverter.Option(defaultValue); var index = converter.Convert(feature.Value); if (index != null) { var desired = index.AsInt32(); var available = renderDevice.MonochromeBits; if (feature.IsMaximum) { return(available <= desired); } else if (feature.IsMinimum) { return(available >= desired); } return(desired == available); } return(false); }
public AnimatedCursor(Context context, IRenderDevice device, iPipelineStateFactory stateFactory, iShaderFactory shaderFactory, iStorageFolder assets) { constantBuffer = device.CreateDynamicUniformBuffer <AnimatedConstantBuffer>("Animated cursor CB"); PipelineStateDesc desc = createStateDesc(context); desc.premultipliedBlendingMaxAlpha(); initState(stateFactory, shaderFactory, assets, "AniCursorVS.hlsl", "AniCursorPS.hlsl", "Animated cursor"); stateFactory.apply(ref desc); pipelineState = device.CreatePipelineState(ref desc); pipelineState.GetStaticVariableByName(ShaderType.Vertex, "CursorCB").Set(constantBuffer); pipelineState.GetStaticVariableByName(ShaderType.Pixel, "CursorCB").Set(constantBuffer); bindings = pipelineState.CreateShaderResourceBinding(true); textureVariable = bindings.GetVariableByName(ShaderType.Pixel, "g_Texture"); animatedConstants = default; timers = context.animation.timers; lastFrameSwitch = timers[animationTimer]; lastRendered = lastFrameSwitch; frameDuration = default; animationFrames = 0; }
public Boolean Validate(IMediaFeature feature, IRenderDevice renderDevice) { var defaultValue = new Length(1.0, Length.Unit.None); var converter = feature.IsMinimum || feature.IsMaximum ? PositiveIntegerConverter : PositiveIntegerConverter.Option(defaultValue); var color = converter.Convert(feature.Value); if (color != null) { var desired = color.AsInt32(); var available = Math.Pow(renderDevice.ColorBits, 2); if (feature.IsMaximum) { return(available <= desired); } else if (feature.IsMinimum) { return(available >= desired); } return(desired == available); } return(false); }
protected override void createResources(IRenderDevice rd) { var dev = context.drawDevice; // Parse the tiger iStorageFolder resources = StorageFolder.embeddedResources(Assembly.GetExecutingAssembly(), resourceFolder); resources.openRead("Tiger.gz", out Stream stream); SvgSink builder = new SvgSink(); using (stream) SvgParser.parse(stream, builder); image = builder.build(dev); mouseHandler.subscribe(this); mouseHandler.subscribe(rightDragEvent); rightDragEvent.dpiSpeedMultiplier = dev.dpiScaling.mulUnits; rightDragEvent.onDragDelta += onRightMouseDrag; if (radiansPerSecond != 0) { context.animation.startDelta(this); } }
void createVertexBuffer(IRenderDevice device) { // Cube vertices // (-1,+1,+1)________________(+1,+1,+1) // /| /| // / | / | // / | / | // / | / | //(-1,-1,+1) /____|__________/(+1,-1,+1) // | |__________|____| // | /(-1,+1,-1) | /(+1,+1,-1) // | / | / // | / | / // |/ | / // /_______________|/ // (-1,-1,-1) (+1,-1,-1) // Vertex[] CubeVerts = new Vertex[] { vert(float3(-1, -1, -1), float2(0, 1)), vert(float3(-1, +1, -1), float2(0, 0)), vert(float3(+1, +1, -1), float2(1, 0)), vert(float3(+1, -1, -1), float2(1, 1)), vert(float3(-1, -1, -1), float2(0, 1)), vert(float3(-1, -1, +1), float2(0, 0)), vert(float3(+1, -1, +1), float2(1, 0)), vert(float3(+1, -1, -1), float2(1, 1)), vert(float3(+1, -1, -1), float2(0, 1)), vert(float3(+1, -1, +1), float2(1, 1)), vert(float3(+1, +1, +1), float2(1, 0)), vert(float3(+1, +1, -1), float2(0, 0)), vert(float3(+1, +1, -1), float2(0, 1)), vert(float3(+1, +1, +1), float2(0, 0)), vert(float3(-1, +1, +1), float2(1, 0)), vert(float3(-1, +1, -1), float2(1, 1)), vert(float3(-1, +1, -1), float2(1, 0)), vert(float3(-1, +1, +1), float2(0, 0)), vert(float3(-1, -1, +1), float2(0, 1)), vert(float3(-1, -1, -1), float2(1, 1)), vert(float3(-1, -1, +1), float2(1, 1)), vert(float3(+1, -1, +1), float2(0, 1)), vert(float3(+1, +1, +1), float2(0, 0)), vert(float3(-1, +1, +1), float2(1, 0)), }; BufferDesc VertBuffDesc = new BufferDesc(false) { Usage = Usage.Static, BindFlags = BindFlags.VertexBuffer, }; cubeVertexBuffer = device.CreateBuffer(VertBuffDesc, CubeVerts, "Cube vertex buffer"); }
/// <summary>Create buffer with initial content from the specified structure</summary> public static IBuffer CreateBuffer <T>(this IRenderDevice device, BufferDesc desc, ref T data, string name = null) where T : unmanaged { unsafe { fixed(T *pointer = &data) return(device.CreateBuffer(ref desc, name, (IntPtr)pointer, Marshal.SizeOf <T>())); } }
static ITextureView loadPng(IRenderDevice device, byte[] payload) { TextureLoadInfo loadInfo = new TextureLoadInfo(false); var png = new MemoryStream(payload, false); var texture = device.LoadTexture(png, eImageFileFormat.PNG, ref loadInfo, "Mouse cursor"); return(texture.GetDefaultView(TextureViewType.ShaderResource)); }
protected override void createResources(IRenderDevice device) { resources = new TeapotResources(context, device); // context.mouseCursor = eCursor.Arrow; context.mouseCursor = eCursor.Working; mouseHandler.subscribe(this); }
ITextureView iMediaEngine.createFrameTexture(IRenderDevice device, TextureFormat format) { if (presentMode != ePresentMode.None) { throw new ApplicationException("Video present mode can only be set once"); } presentMode = ePresentMode.RGB; return(createOutputTexture(device, format, decodedSize.cropRect.size)); }
public static Boolean Validate(this ICssMedium medium, IRenderDevice device) { if (!String.IsNullOrEmpty(medium.Type) && KnownTypes.Contains(medium.Type) == medium.IsInverse) { return(false); } return(!medium.IsInvalid(device) && !medium.Features.Any(m => m.Validate(device) == medium.IsInverse)); }
public RenderTreeBuilder(IWindow window, IRenderDevice device = null) { var ctx = window.Document.Context; var defaultStyleSheetProvider = ctx.GetServices <ICssDefaultStyleSheetProvider>(); _device = device ?? ctx.GetService <IRenderDevice>(); _defaultSheets = defaultStyleSheetProvider.Select(m => m.Default).Where(m => m != null); _window = window; }
public Nv12State(IRenderDevice device, TextureFormat format, Nv12Texture[] textures, ref sDecodedVideoSize videoSize) { // Create the pipeline state var pso = new PipelineStateDesc(false); pso.GraphicsPipeline.DepthStencilDesc.DepthEnable = false; pso.GraphicsPipeline.RasterizerDesc.CullMode = CullMode.None; pso.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList; pso.GraphicsPipeline.NumRenderTargets = 1; pso.GraphicsPipeline.setRTVFormat(0, format); pso.ResourceLayout.DefaultVariableType = ShaderResourceVariableType.Static; var compiler = device.GetShaderFactory(); iStorageFolder assets = StorageFolder.embeddedResources(System.Reflection.Assembly.GetExecutingAssembly(), resourceFolder); using (var psf = device.CreatePipelineStateFactory()) { psf.setName("Video PSO"); using (var vs = compiler.compileHlslFile(assets, "VideoVS.hlsl", ShaderType.Vertex)) psf.graphicsVertexShader(vs); using (var ps = compilePixelShader(compiler, assets)) psf.graphicsPixelShader(ps); psf.layoutVariable(ShaderType.Pixel, ShaderResourceVariableType.Dynamic, varTexture); var sampler = samplerDesc(); psf.layoutStaticSampler(ShaderType.Pixel, ref sampler, varTexture); psf.apply(ref pso); pipelineState = device.CreatePipelineState(ref pso); } // Create resource binding and cache the variable binding = pipelineState.CreateShaderResourceBinding(true); textureVariable = binding.GetVariableByName(ShaderType.Pixel, varTexture); // Copy views of the textures into array sourceTextures = new ITextureView[textures.Length]; for (int i = 0; i < textures.Length; i++) { sourceTextures[i] = textures[i].view; } // Create GL viewport structure with weird values for cropping the video viewport = new Viewport(false) { TopLeftX = -videoSize.cropRect.left, // TopLeftY = videoSize.cropRect.top, // OpenGL uses opposite Y direction there. TopLeftY = videoSize.cropRect.bottom - videoSize.size.cy, Width = videoSize.size.cx, Height = videoSize.size.cy, }; }
// public SaveTgaFrames dbgSaveTga { get; private set; } public Nv12Texture[] exportTextures(IRenderDevice renderDevice) { var fmt = decodedPixelFormat; var color = colorFormat; decoded.exportTextures(renderDevice, device, ref fmt, ref color); // dbgSaveTga = decoded.dbgMapOutput( device, ref fmt ); return(decoded.textures); }
/// <summary>Create dynamic buffer for shader constants</summary> public static IBuffer CreateDynamicUniformBuffer(this IRenderDevice device, int cb, string name = null) { BufferDesc CBDesc = new BufferDesc(false); CBDesc.uiSizeInBytes = cb; CBDesc.Usage = Usage.Dynamic; CBDesc.BindFlags = BindFlags.UniformBuffer; CBDesc.CPUAccessFlags = CpuAccessFlags.Write; return(device.CreateBuffer(CBDesc, name)); }
protected override void createResources(IRenderDevice device) { iStorageFolder assets = StorageFolder.embeddedResources(Assembly.GetExecutingAssembly(), "RenderSamples/03-Texturing"); createPipelineState(device, assets); createVertexBuffer(device); createIndexBuffer(device); loadTexture(device, assets); animation.startDelta(this); }
/// <summary>Create dynamic buffer for shader constants, sized for the structure passed in generic argument.</summary> public static IBuffer CreateDynamicUniformBuffer <T>(this IRenderDevice device, string name = null) where T : unmanaged { int cb = Marshal.SizeOf <T>(); if (0 != cb % 16) { throw new ArgumentException(); } return(device.CreateDynamicUniformBuffer(cb, name)); }
/// <summary>Export all buffers from V4L2, import them into GLES in Diligent Engine</summary> public void exportTextures(IRenderDevice renderDevice, VideoDevice device, ref sPixelFormatMP pixelFormat, ref ColorFormat color) { iGlesRenderDevice gles = ComLightCast.cast <iGlesRenderDevice>(renderDevice); textures = new Nv12Texture[buffers.Length]; for (int i = 0; i < buffers.Length; i++) { textures[i] = buffers[i].exportNv12(gles, device, ref pixelFormat, ref color); } }
static void compileShaders(IRenderDevice device, iPipelineStateFactory stateFactory, string name, eShaderMacros macros) { var compiler = device.GetShaderFactory(); iStorageFolder src = StorageFolder.embeddedResources(System.Reflection.Assembly.GetExecutingAssembly(), resourceFolder); var defines = macros.defines().ToArray(); stateFactory.graphicsVertexShader(compiler.compileShader(src, name, ShaderType.Vertex, defines)); stateFactory.graphicsPixelShader(compiler.compileShader(src, name, ShaderType.Pixel, defines)); }
static CursorTexture loadStatic(this IRenderDevice renderDevice, string resource, int idealSize) { using (var stm = openResource(resource)) using (var unzip = new GZipStream(stm, CompressionMode.Decompress)) using (var file = new CursorFile(unzip)) { int index = findBestCursor(file, idealSize); return(file.load(renderDevice, index)); } }
/// <summary>Load a binary STL file.</summary> /// <seealso href="https://en.wikipedia.org/wiki/STL_%28file_format%29" /> public static Task <IndexedMesh> loadStlAsync(this IRenderDevice device, Stream stream, float?minCosAngle, string name = null) { if (null == Dispatcher.currentDispatcher) { throw new ApplicationException("You must call loadStlAsync on the GUI thread."); // CPU-bound heavy lifting is offloaded to the pool, however once it all done we have to resume on the thread which can create GPU resources. // To resume on the correct thread, the calling code, here, need to be on the thread with the dispatcher. } return(MeshLoader.loadStlAsync(device, stream, minCosAngle, name)); }
public async Task createAsync(IRenderDevice device) { iStorageFolder resources = StorageFolder.embeddedResources(Assembly.GetExecutingAssembly(), resourcesFolder); resources.openRead("UtahTeapot.stl.gz", out Stream stream); float minCos = MathF.Cos(Angle.degrees(10)); // float minCos = 1.1f; using (stream) mesh = await device.loadStlAsync(stream, minCos, "Teapot"); }
/// <summary>Grab texture from VRAM, encode into 32-bit PNG</summary> public static void saveTexture(IRenderDevice device, IDeviceContext context, ITexture texture, string destinationPath) { string dir = Path.GetDirectoryName(destinationPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } readTexture(device, context, texture, (format, size, mapped) => encodeScreenshot(format, size, mapped, destinationPath)); }
public Boolean Check(IRenderDevice device) { foreach (var condition in _conditions) { if (!condition.Check(device)) { return(false); } } return(true); }
/// <summary>True if the device uses OpenGL or OpenGL ES backend</summary> public static bool isGlDevice(this IRenderDevice device) { var caps = device.GetDeviceCaps(); switch (caps.DevType) { case RenderDeviceType.GL: case RenderDeviceType.GLES: return(true); } return(false); }
public Boolean Validate(IMediaFeature feature, IRenderDevice renderDevice) { var accuracy = PointerAccuracyConverter.Convert(feature.Value); if (accuracy != null) { var desired = accuracy.AsEnum <PointerAccuracy>(); //Nothing yet, so we assume we have a headless browser return(desired == PointerAccuracy.None); } return(false); }
public Boolean Validate(IMediaFeature feature, IRenderDevice device) { var grid = BinaryConverter.Convert(feature.Value); if (grid != null) { var desired = grid.AsBoolean(); var available = device.IsGrid; return(desired == available); } return(false); }