Exemple #1
0
 public void RenderLines(List <VertexTypePC> linelist, DepthStencilMode dsmode = DepthStencilMode.DisableAll)
 {
     shaders.SetRasterizerMode(context, RasterizerMode.Solid);
     shaders.SetDepthStencilMode(context, dsmode);
     shaders.SetDefaultBlendState(context);
     shaders.Lines.RenderLines(context, linelist, camera);
 }
 public TextureCreateInfo(
     int width,
     int height,
     int depth,
     int levels,
     int samples,
     int blockWidth,
     int blockHeight,
     int bytesPerPixel,
     Format format,
     DepthStencilMode depthStencilMode,
     Target target,
     SwizzleComponent swizzleR,
     SwizzleComponent swizzleG,
     SwizzleComponent swizzleB,
     SwizzleComponent swizzleA)
 {
     Width            = width;
     Height           = height;
     Depth            = depth;
     Levels           = levels;
     Samples          = samples;
     BlockWidth       = blockWidth;
     BlockHeight      = blockHeight;
     BytesPerPixel    = bytesPerPixel;
     Format           = format;
     DepthStencilMode = depthStencilMode;
     Target           = target;
     SwizzleR         = swizzleR;
     SwizzleG         = swizzleG;
     SwizzleB         = swizzleB;
     SwizzleA         = swizzleA;
 }
Exemple #3
0
        public void RenderGeometry(DepthStencilMode dsmode = DepthStencilMode.DisableAll)
        {
            shaders.SetRasterizerMode(context, RasterizerMode.Solid);
            shaders.SetDepthStencilMode(context, dsmode);
            shaders.SetDefaultBlendState(context);

            if (LineVerts.Count > 0)
            {
                shaders.Lines.RenderLines(context, LineVerts, camera);
            }
            if (TriVerts.Count > 0)
            {
                //shaders.Lines.RenderTriangles(context, TriVerts, camera);
            }
        }
        public static All Convert(this DepthStencilMode mode)
        {
            switch (mode)
            {
            case DepthStencilMode.Depth:
                return(All.DepthComponent);

            case DepthStencilMode.Stencil:
                return(All.StencilIndex);
            }

            Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(DepthStencilMode)} enum value: {mode}.");

            return(All.Depth);
        }
        public void Draw(RenderContext11 renderContext, float opacity, Color color)
        {
            if (glyphCache == null || glyphCache.Version > glyphVersion)
            {
                PrepareBatch();
            }


            Color col = Color.FromArgb((int)(color.A * opacity), (int)(color.R * opacity), (int)(color.G * opacity), (int)(color.B * opacity));


            SimpleGeometryShader11.Color = col;

            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            SimpleGeometryShader11.WVPMatrix = mat;


            renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);

            BlendMode        bm = renderContext.BlendMode;
            DepthStencilMode dm = renderContext.DepthStencilMode;

            //renderContext.DepthStencilMode = DepthStencilMode.ZReadOnly;
            renderContext.BlendMode = BlendMode.Alpha;

            SimpleGeometryShader11.Use(renderContext.devContext);

            renderContext.MainTexture = glyphCache.Texture;
            // Debug to get Glyhph textures and caches
            //        SharpDX.Direct3D11.Texture2D.ToFile(renderContext.devContext, glyphCache.Texture.Texture, SharpDX.Direct3D11.ImageFileFormat.Png, "c:\\temp\\texture2.png");

            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.devContext.Draw(vertexBuffer.Count, 0);

            renderContext.DepthStencilMode = dm;

            renderContext.BlendMode = bm;

            //dump cache

            //          glyphCache.SaveToXML("c:\\temp\\glyphCache.xml");
        }
Exemple #6
0
 /// <summary>
 /// Constructs the texture information structure.
 /// </summary>
 /// <param name="cpuAddress">The CPU address of the texture</param>
 /// <param name="gpuAddress">The GPU address of the texture</param>
 /// <param name="width">The width of the texture</param>
 /// <param name="height">The height or the texture</param>
 /// <param name="depthOrLayers">The depth or layers count of the texture</param>
 /// <param name="levels">The amount of mipmap levels of the texture</param>
 /// <param name="samplesInX">The number of samples in the X direction for multisample textures, should be 1 otherwise</param>
 /// <param name="samplesInY">The number of samples in the Y direction for multisample textures, should be 1 otherwise</param>
 /// <param name="stride">The stride for linear textures</param>
 /// <param name="isLinear">Whenever the texture is linear or block linear</param>
 /// <param name="gobBlocksInY">Number of GOB blocks in the Y direction</param>
 /// <param name="gobBlocksInZ">Number of GOB blocks in the Z direction</param>
 /// <param name="gobBlocksInTileX">Number of GOB blocks per tile in the X direction</param>
 /// <param name="target">Texture target type</param>
 /// <param name="formatInfo">Texture format information</param>
 /// <param name="depthStencilMode">Depth-stencil mode</param>
 /// <param name="swizzleR">Swizzle for the red color channel</param>
 /// <param name="swizzleG">Swizzle for the green color channel</param>
 /// <param name="swizzleB">Swizzle for the blue color channel</param>
 /// <param name="swizzleA">Swizzle for the alpha color channel</param>
 public TextureInfo(
     ulong cpuAddress,
     ulong gpuAddress,
     int width,
     int height,
     int depthOrLayers,
     int levels,
     int samplesInX,
     int samplesInY,
     int stride,
     bool isLinear,
     int gobBlocksInY,
     int gobBlocksInZ,
     int gobBlocksInTileX,
     Target target,
     FormatInfo formatInfo,
     DepthStencilMode depthStencilMode = DepthStencilMode.Depth,
     SwizzleComponent swizzleR         = SwizzleComponent.Red,
     SwizzleComponent swizzleG         = SwizzleComponent.Green,
     SwizzleComponent swizzleB         = SwizzleComponent.Blue,
     SwizzleComponent swizzleA         = SwizzleComponent.Alpha)
 {
     Address          = cpuAddress;
     GpuAddress       = gpuAddress;
     Width            = width;
     Height           = height;
     DepthOrLayers    = depthOrLayers;
     Levels           = levels;
     SamplesInX       = samplesInX;
     SamplesInY       = samplesInY;
     Stride           = stride;
     IsLinear         = isLinear;
     GobBlocksInY     = gobBlocksInY;
     GobBlocksInZ     = gobBlocksInZ;
     GobBlocksInTileX = gobBlocksInTileX;
     Target           = target;
     FormatInfo       = formatInfo;
     DepthStencilMode = depthStencilMode;
     SwizzleR         = swizzleR;
     SwizzleG         = swizzleG;
     SwizzleB         = swizzleB;
     SwizzleA         = swizzleA;
 }
Exemple #7
0
        public static ImageAspectFlags ConvertAspectFlags(this GAL.Format format, DepthStencilMode depthStencilMode)
        {
            switch (format)
            {
            case GAL.Format.D16Unorm:
            case GAL.Format.D24X8Unorm:
            case GAL.Format.D32Float:
                return(ImageAspectFlags.ImageAspectDepthBit);

            case GAL.Format.S8Uint:
                return(ImageAspectFlags.ImageAspectStencilBit);

            case GAL.Format.D24UnormS8Uint:
            case GAL.Format.D32FloatS8Uint:
                return(depthStencilMode == DepthStencilMode.Stencil ? ImageAspectFlags.ImageAspectStencilBit : ImageAspectFlags.ImageAspectDepthBit);

            default:
                return(ImageAspectFlags.ImageAspectColorBit);
            }
        }
Exemple #8
0
        public void SetDepthStencilMode(DeviceContext context, DepthStencilMode mode)
        {
            switch (mode)
            {
            default:
            case DepthStencilMode.Enabled:
                context.OutputMerger.DepthStencilState = dsEnabled;
                break;

            case DepthStencilMode.DisableWrite:
                context.OutputMerger.DepthStencilState = dsDisableWrite;
                break;

            case DepthStencilMode.DisableComp:
                context.OutputMerger.DepthStencilState = dsDisableComp;
                break;

            case DepthStencilMode.DisableAll:
                context.OutputMerger.DepthStencilState = dsDisableAll;
                break;
            }
        }
 public abstract SwapChainBase CreateSwapChain(WindowBase window, int bufferCount, bool fullscreen, bool ensureSizeMatchesWindowSize, SwapChainFormat format, SwapChainType type, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, SwapChainVSyncMode vSyncMode);
Exemple #10
0
        /// <summary>
        /// Gets texture information from a texture descriptor.
        /// </summary>
        /// <param name="descriptor">The texture descriptor</param>
        /// <returns>The texture information</returns>
        private TextureInfo GetInfo(TextureDescriptor descriptor)
        {
            ulong address = Context.MemoryManager.Translate(descriptor.UnpackAddress());

            int width         = descriptor.UnpackWidth();
            int height        = descriptor.UnpackHeight();
            int depthOrLayers = descriptor.UnpackDepth();
            int levels        = descriptor.UnpackLevels();

            TextureMsaaMode msaaMode = descriptor.UnpackTextureMsaaMode();

            int samplesInX = msaaMode.SamplesInX();
            int samplesInY = msaaMode.SamplesInY();

            int stride = descriptor.UnpackStride();

            TextureDescriptorType descriptorType = descriptor.UnpackTextureDescriptorType();

            bool isLinear = descriptorType == TextureDescriptorType.Linear;

            Target target = descriptor.UnpackTextureTarget().Convert((samplesInX | samplesInY) != 1);

            // We use 2D targets for 1D textures as that makes texture cache
            // management easier. We don't know the target for render target
            // and copies, so those would normally use 2D targets, which are
            // not compatible with 1D targets. By doing that we also allow those
            // to match when looking for compatible textures on the cache.
            if (target == Target.Texture1D)
            {
                target = Target.Texture2D;
                height = 1;
            }
            else if (target == Target.Texture1DArray)
            {
                target = Target.Texture2DArray;
                height = 1;
            }

            uint format = descriptor.UnpackFormat();
            bool srgb   = descriptor.UnpackSrgb();

            if (!FormatTable.TryGetTextureFormat(format, srgb, out FormatInfo formatInfo))
            {
                if ((long)address > 0L && (int)format > 0)
                {
                    Logger.Error?.Print(LogClass.Gpu, $"Invalid texture format 0x{format:X} (sRGB: {srgb}).");
                }

                formatInfo = FormatInfo.Default;
            }

            int gobBlocksInY = descriptor.UnpackGobBlocksInY();
            int gobBlocksInZ = descriptor.UnpackGobBlocksInZ();

            int gobBlocksInTileX = descriptor.UnpackGobBlocksInTileX();

            SwizzleComponent swizzleR = descriptor.UnpackSwizzleR().Convert();
            SwizzleComponent swizzleG = descriptor.UnpackSwizzleG().Convert();
            SwizzleComponent swizzleB = descriptor.UnpackSwizzleB().Convert();
            SwizzleComponent swizzleA = descriptor.UnpackSwizzleA().Convert();

            DepthStencilMode depthStencilMode = GetDepthStencilMode(
                formatInfo.Format,
                swizzleR,
                swizzleG,
                swizzleB,
                swizzleA);

            if (formatInfo.Format.IsDepthOrStencil())
            {
                swizzleR = SwizzleComponent.Red;
                swizzleG = SwizzleComponent.Red;
                swizzleB = SwizzleComponent.Red;

                if (depthStencilMode == DepthStencilMode.Depth)
                {
                    swizzleA = SwizzleComponent.One;
                }
                else
                {
                    swizzleA = SwizzleComponent.Red;
                }
            }

            return(new TextureInfo(
                       address,
                       width,
                       height,
                       depthOrLayers,
                       levels,
                       samplesInX,
                       samplesInY,
                       stride,
                       isLinear,
                       gobBlocksInY,
                       gobBlocksInZ,
                       gobBlocksInTileX,
                       target,
                       formatInfo,
                       depthStencilMode,
                       swizzleR,
                       swizzleG,
                       swizzleB,
                       swizzleA));
        }
Exemple #11
0
 public override SwapChainBase CreateSwapChain(WindowBase window, int bufferCount, bool fullscreen, bool ensureSizeMatchesWindowSize, SwapChainFormat format, SwapChainType type, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, SwapChainVSyncMode vSyncMode)
 {
     return(primaryDevice.CreateSwapChain(window, bufferCount, fullscreen, ensureSizeMatchesWindowSize, format, type, stencilUsage, depthStencilFormat, depthStencilMode, vSyncMode));
 }
Exemple #12
0
 public override DepthStencilBase CreateDepthStencil(int width, int height, DepthStencilFormat format, StencilUsage stencilUsage, DepthStencilMode mode, MSAALevel msaaLevel)
 {
     return(activeDevice.CreateDepthStencil(width, height, format, stencilUsage, mode, msaaLevel));
 }
Exemple #13
0
 public override Texture2DBase CreateRenderTexture2D(int width, int height, TextureFormat format, RenderTextureUsage usage, byte[] data, TextureMode mode, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, bool allowRandomAccess, MultiGPUNodeResourceVisibility nodeVisibility)
 {
     return(activeDevice.CreateRenderTexture2D(width, height, format, usage, data, mode, stencilUsage, depthStencilFormat, depthStencilMode, allowRandomAccess, nodeVisibility));
 }
Exemple #14
0
        /// <summary>
        /// Gets texture information from a texture descriptor.
        /// </summary>
        /// <param name="descriptor">The texture descriptor</param>
        /// <param name="layerSize">Layer size for textures using a sub-range of mipmap levels, otherwise 0</param>
        /// <returns>The texture information</returns>
        private TextureInfo GetInfo(TextureDescriptor descriptor, out int layerSize)
        {
            int width         = descriptor.UnpackWidth();
            int height        = descriptor.UnpackHeight();
            int depthOrLayers = descriptor.UnpackDepth();
            int levels        = descriptor.UnpackLevels();

            TextureMsaaMode msaaMode = descriptor.UnpackTextureMsaaMode();

            int samplesInX = msaaMode.SamplesInX();
            int samplesInY = msaaMode.SamplesInY();

            int stride = descriptor.UnpackStride();

            TextureDescriptorType descriptorType = descriptor.UnpackTextureDescriptorType();

            bool isLinear = descriptorType == TextureDescriptorType.Linear;

            Target target = descriptor.UnpackTextureTarget().Convert((samplesInX | samplesInY) != 1);

            // We use 2D targets for 1D textures as that makes texture cache
            // management easier. We don't know the target for render target
            // and copies, so those would normally use 2D targets, which are
            // not compatible with 1D targets. By doing that we also allow those
            // to match when looking for compatible textures on the cache.
            if (target == Target.Texture1D)
            {
                target = Target.Texture2D;
                height = 1;
            }
            else if (target == Target.Texture1DArray)
            {
                target = Target.Texture2DArray;
                height = 1;
            }

            uint format = descriptor.UnpackFormat();
            bool srgb   = descriptor.UnpackSrgb();

            ulong gpuVa = descriptor.UnpackAddress();

            if (!FormatTable.TryGetTextureFormat(format, srgb, out FormatInfo formatInfo))
            {
                if (Context.MemoryManager.IsMapped(gpuVa) && (int)format > 0)
                {
                    Logger.Error?.Print(LogClass.Gpu, $"Invalid texture format 0x{format:X} (sRGB: {srgb}).");
                }

                formatInfo = FormatInfo.Default;
            }

            int gobBlocksInY = descriptor.UnpackGobBlocksInY();
            int gobBlocksInZ = descriptor.UnpackGobBlocksInZ();

            int gobBlocksInTileX = descriptor.UnpackGobBlocksInTileX();

            layerSize = 0;

            int minLod = descriptor.UnpackBaseLevel();
            int maxLod = descriptor.UnpackMaxLevelInclusive();

            // Linear textures don't support mipmaps, so we don't handle this case here.
            if ((minLod != 0 || maxLod + 1 != levels) && target != Target.TextureBuffer && !isLinear)
            {
                int depth  = TextureInfo.GetDepth(target, depthOrLayers);
                int layers = TextureInfo.GetLayers(target, depthOrLayers);

                SizeInfo sizeInfo = SizeCalculator.GetBlockLinearTextureSize(
                    width,
                    height,
                    depth,
                    levels,
                    layers,
                    formatInfo.BlockWidth,
                    formatInfo.BlockHeight,
                    formatInfo.BytesPerPixel,
                    gobBlocksInY,
                    gobBlocksInZ,
                    gobBlocksInTileX);

                layerSize = sizeInfo.LayerSize;

                if (minLod != 0 && minLod < levels)
                {
                    // If the base level is not zero, we additionally add the mip level offset
                    // to the address, this allows the texture manager to find the base level from the
                    // address if there is a overlapping texture on the cache that can contain the new texture.
                    gpuVa += (ulong)sizeInfo.GetMipOffset(minLod);

                    width  = Math.Max(1, width >> minLod);
                    height = Math.Max(1, height >> minLod);

                    if (target == Target.Texture3D)
                    {
                        depthOrLayers = Math.Max(1, depthOrLayers >> minLod);
                    }

                    (gobBlocksInY, gobBlocksInZ) = SizeCalculator.GetMipGobBlockSizes(height, depth, formatInfo.BlockHeight, gobBlocksInY, gobBlocksInZ);
                }

                levels = (maxLod - minLod) + 1;
            }

            SwizzleComponent swizzleR = descriptor.UnpackSwizzleR().Convert();
            SwizzleComponent swizzleG = descriptor.UnpackSwizzleG().Convert();
            SwizzleComponent swizzleB = descriptor.UnpackSwizzleB().Convert();
            SwizzleComponent swizzleA = descriptor.UnpackSwizzleA().Convert();

            DepthStencilMode depthStencilMode = GetDepthStencilMode(
                formatInfo.Format,
                swizzleR,
                swizzleG,
                swizzleB,
                swizzleA);

            if (formatInfo.Format.IsDepthOrStencil())
            {
                swizzleR = SwizzleComponent.Red;
                swizzleG = SwizzleComponent.Red;
                swizzleB = SwizzleComponent.Red;

                if (depthStencilMode == DepthStencilMode.Depth)
                {
                    swizzleA = SwizzleComponent.One;
                }
                else
                {
                    swizzleA = SwizzleComponent.Red;
                }
            }

            return(new TextureInfo(
                       gpuVa,
                       width,
                       height,
                       depthOrLayers,
                       levels,
                       samplesInX,
                       samplesInY,
                       stride,
                       isLinear,
                       gobBlocksInY,
                       gobBlocksInZ,
                       gobBlocksInTileX,
                       target,
                       formatInfo,
                       depthStencilMode,
                       swizzleR,
                       swizzleG,
                       swizzleB,
                       swizzleA));
        }
 public bool Init(int width, int height, TextureFormat format, byte[] data, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, bool allowRandomAccess, MultiGPUNodeResourceVisibility nodeVisibility)
 {
     depthStencil = new DepthStencil(deviceD3D12, stencilUsage, depthStencilMode);
     if (!depthStencil.Init(width, height, depthStencilFormat, MSAALevel.Disabled))
     {
         return(false);
     }
     return(Init(width, height, format, data, true, allowRandomAccess, MSAALevel.Disabled, nodeVisibility));
 }
 private static extern IntPtr Orbital_Video_D3D12_DepthStencil_Create(IntPtr device, DepthStencilMode mode);
Exemple #17
0
        /// <summary>
        /// Gets texture information from a texture descriptor.
        /// </summary>
        /// <param name="descriptor">The texture descriptor</param>
        /// <returns>The texture information</returns>
        private TextureInfo GetInfo(TextureDescriptor descriptor)
        {
            ulong address = Context.MemoryManager.Translate(descriptor.UnpackAddress());

            int width         = descriptor.UnpackWidth();
            int height        = descriptor.UnpackHeight();
            int depthOrLayers = descriptor.UnpackDepth();
            int levels        = descriptor.UnpackLevels();

            TextureMsaaMode msaaMode = descriptor.UnpackTextureMsaaMode();

            int samplesInX = msaaMode.SamplesInX();
            int samplesInY = msaaMode.SamplesInY();

            int stride = descriptor.UnpackStride();

            TextureDescriptorType descriptorType = descriptor.UnpackTextureDescriptorType();

            bool isLinear = descriptorType == TextureDescriptorType.Linear;

            Target target = descriptor.UnpackTextureTarget().Convert((samplesInX | samplesInY) != 1);

            uint format = descriptor.UnpackFormat();
            bool srgb   = descriptor.UnpackSrgb();

            if (!FormatTable.TryGetTextureFormat(format, srgb, out FormatInfo formatInfo))
            {
                if ((long)address > 0L && (int)format > 0)
                {
                    Logger.PrintError(LogClass.Gpu, $"Invalid texture format 0x{format:X} (sRGB: {srgb}).");
                }

                formatInfo = FormatInfo.Default;
            }

            int gobBlocksInY = descriptor.UnpackGobBlocksInY();
            int gobBlocksInZ = descriptor.UnpackGobBlocksInZ();

            int gobBlocksInTileX = descriptor.UnpackGobBlocksInTileX();

            SwizzleComponent swizzleR = descriptor.UnpackSwizzleR().Convert();
            SwizzleComponent swizzleG = descriptor.UnpackSwizzleG().Convert();
            SwizzleComponent swizzleB = descriptor.UnpackSwizzleB().Convert();
            SwizzleComponent swizzleA = descriptor.UnpackSwizzleA().Convert();

            DepthStencilMode depthStencilMode = GetDepthStencilMode(
                formatInfo.Format,
                swizzleR,
                swizzleG,
                swizzleB,
                swizzleA);

            if (IsDepthStencil(formatInfo.Format))
            {
                swizzleR = SwizzleComponent.Red;
                swizzleG = SwizzleComponent.Red;
                swizzleB = SwizzleComponent.Red;

                if (depthStencilMode == DepthStencilMode.Depth)
                {
                    swizzleA = SwizzleComponent.One;
                }
                else
                {
                    swizzleA = SwizzleComponent.Red;
                }
            }

            return(new TextureInfo(
                       address,
                       width,
                       height,
                       depthOrLayers,
                       levels,
                       samplesInX,
                       samplesInY,
                       stride,
                       isLinear,
                       gobBlocksInY,
                       gobBlocksInZ,
                       gobBlocksInTileX,
                       target,
                       formatInfo,
                       depthStencilMode,
                       swizzleR,
                       swizzleG,
                       swizzleB,
                       swizzleA));
        }
 public abstract DepthStencilBase CreateDepthStencil(int width, int height, DepthStencilFormat format, StencilUsage stencilUsage, DepthStencilMode mode, MSAALevel msaaLevel);
 public abstract Texture2DBase CreateRenderTexture2D(int width, int height, TextureFormat format, RenderTextureUsage usage, byte[] data, TextureMode mode, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, bool allowRandomAccess, MultiGPUNodeResourceVisibility nodeVisibility);
Exemple #20
0
        public override DepthStencilBase CreateDepthStencil(int width, int height, DepthStencilFormat format, StencilUsage stencilUsage, DepthStencilMode mode, MSAALevel msaaLevel)
        {
            var abstraction = new DepthStencil(this, stencilUsage, mode);

            if (!abstraction.Init(width, height, format, msaaLevel))
            {
                abstraction.Dispose();
                throw new Exception("Failed to create DepthStencil");
            }
            return(abstraction);
        }
Exemple #21
0
        public override Texture2DBase CreateRenderTexture2D(int width, int height, TextureFormat format, RenderTextureUsage usage, byte[] data, TextureMode mode, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, bool allowRandomAccess, MultiGPUNodeResourceVisibility nodeVisibility)
        {
            var abstraction = new RenderTexture2D(this, usage, mode);

            if (!abstraction.Init(width, height, format, data, stencilUsage, depthStencilFormat, depthStencilMode, allowRandomAccess, nodeVisibility))
            {
                abstraction.Dispose();
                throw new Exception("Failed to create RenderTexture2D");
            }
            return(abstraction);
        }
Exemple #22
0
        public override SwapChainBase CreateSwapChain(WindowBase window, int bufferCount, bool fullscreen, bool ensureSizeMatchesWindowSize, SwapChainFormat format, SwapChainType type, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, SwapChainVSyncMode vSyncMode)
        {
            var abstraction = new SwapChain(this, ensureSizeMatchesWindowSize, type);

            if (!abstraction.Init(window, bufferCount, fullscreen, format, stencilUsage, depthStencilFormat, depthStencilMode, vSyncMode))
            {
                abstraction.Dispose();
                throw new Exception("Failed to create SwapChain");
            }
            return(abstraction);
        }
 public DepthStencil(Device device, StencilUsage usage, DepthStencilMode mode)
     : base(device, usage)
 {
     deviceD3D12 = device;
     handle      = Orbital_Video_D3D12_DepthStencil_Create(device.handle, mode);
 }
 public override SwapChainBase CreateSwapChain(WindowBase window, int bufferCount, bool fullscreen, bool ensureSizeMatchesWindowSize, SwapChainFormat format, SwapChainType type, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, SwapChainVSyncMode vSyncMode)
 {
     throw new NotImplementedException();
 }
 public override Texture2DBase CreateRenderTexture2D(int width, int height, TextureFormat format, RenderTextureUsage usage, byte[] data, TextureMode mode, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, bool allowRandomAccess, MultiGPUNodeResourceVisibility nodeVisibility)
 {
     throw new NotImplementedException();
 }
 public override DepthStencilBase CreateDepthStencil(int width, int height, DepthStencilFormat format, StencilUsage stencilUsage, DepthStencilMode mode, MSAALevel msaaLevel)
 {
     throw new NotImplementedException();
 }
Exemple #27
0
        public bool Init(WindowBase window, int bufferCount, bool fullscreen, SwapChainFormat format, StencilUsage stencilUsage, DepthStencilFormat depthStencilFormat, DepthStencilMode depthStencilMode, SwapChainVSyncMode vSyncMode)
        {
            var size = window.GetSize(WindowSizeType.WorkingArea);

            depthStencilD3D12 = new DepthStencil(deviceD3D12, stencilUsage, depthStencilMode);
            depthStencil      = depthStencilD3D12;
            if (!depthStencilD3D12.Init(size.width, size.height, depthStencilFormat, MSAALevel.Disabled))
            {
                return(false);
            }
            return(Init(window, bufferCount, fullscreen, format, vSyncMode));
        }
Exemple #28
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (bufferIsFlat != flat)
            {
                CleanUp();
                bufferIsFlat = flat;
            }

            if (!CleanAndReady)
            {
                PrepVertexBuffer(opacity);
            }

            Matrix3d oldWorld = renderContext.World;

            if (astronomical && !bufferIsFlat)
            {
                double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
                renderContext.World = Matrix3d.RotationX(ecliptic) * renderContext.World;
            }


            if (triangleList2d != null)
            {
                triangleList2d.Decay      = decay;
                triangleList2d.Sky        = this.Astronomical;
                triangleList2d.TimeSeries = timeSeries;
                triangleList2d.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise);
            }

            if (triangleList != null)
            {
                triangleList.Decay      = decay;
                triangleList.Sky        = this.Astronomical;
                triangleList.TimeSeries = timeSeries;
                triangleList.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise);
            }

            if (lineList != null)
            {
                lineList.Sky        = this.Astronomical;
                lineList.Decay      = decay;
                lineList.TimeSeries = timeSeries;

                lineList.DrawLines(renderContext, opacity * Opacity);
            }

            if (lineList2d != null)
            {
                lineList2d.Sky         = !this.Astronomical;
                lineList2d.Decay       = decay;
                lineList2d.TimeSeries  = timeSeries;
                lineList2d.ShowFarSide = ShowFarSide;
                lineList2d.DrawLines(renderContext, opacity * Opacity);
            }

            if (textBatch != null)
            {
                DepthStencilMode mode = renderContext.DepthStencilMode;

                renderContext.DepthStencilMode = DepthStencilMode.Off;

                textBatch.Draw(renderContext, 1, Color.White);
                renderContext.DepthStencilMode = mode;
            }

            if (astronomical && !bufferIsFlat)
            {
                renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
            }
            else
            {
                renderContext.DepthStencilMode = DepthStencilMode.Off;
            }

            DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);

            renderContext.setRasterizerState(TriangleCullMode.Off);

            Vector3 cam           = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311;
            float   adjustedScale = scaleFactor;

            if (flat && astronomical && (markerScale == MarkerScales.World))
            {
                adjustedScale = (float)(scaleFactor / (Earth3d.MainWindow.ZoomFactor / 360));
            }

            Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;

            matrixWVP.Transpose();
            switch (plotType)
            {
            default:
            case PlotTypes.Gaussian:
                renderContext.BlendMode = BlendMode.Additive;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView);
                break;

            case PlotTypes.Circle:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, CircleTexture.ResourceView);
                break;

            case PlotTypes.Point:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PointTexture.ResourceView);
                break;

            case PlotTypes.Square:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, SquareTexture.ResourceView);
                break;

            case PlotTypes.Target1:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target1Texture.ResourceView);
                break;

            case PlotTypes.Target2:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target2Texture.ResourceView);
                break;

            case PlotTypes.PushPin:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PushPin.GetPushPinTexture(markerIndex).ResourceView);
                break;
            }

            columnChartsActivate.TargetState = plotType == PlotTypes.Column;

            if (shapeFileVertex != null)
            {
                if (plotType == PlotTypes.Column && !RenderContext11.Downlevel) // column chart mode
                {
                    columnChartsActivate.TargetState = true;

                    renderContext.BlendMode = BlendMode.Alpha;
                    renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
                    renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null);
                    renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
                    TimeSeriesColumnChartShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    TimeSeriesColumnChartShader11.Constants.JNow           = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
                    TimeSeriesColumnChartShader11.Constants.Decay          = timeSeries ? decay : 0f;
                    TimeSeriesColumnChartShader11.Constants.Scale          = (float)(adjustedScale);
                    TimeSeriesColumnChartShader11.Constants.Sky            = astronomical ? -1 : 1;
                    TimeSeriesColumnChartShader11.Constants.Opacity        = opacity * this.Opacity;
                    TimeSeriesColumnChartShader11.Constants.ShowFarSide    = ShowFarSide ? 1f : 0f;
                    TimeSeriesColumnChartShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesColumnChartShader11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesColumnChartShader11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesColumnChartShader11.Use(renderContext.devContext);
                }
                else if (plotType == PlotTypes.Cylinder && !RenderContext11.Downlevel)
                {
                    renderContext.BlendMode = BlendMode.Alpha;
                    renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
                    renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null);
                    renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
                    TimeSeriesColumnChartShaderNGon11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    TimeSeriesColumnChartShaderNGon11.Constants.JNow           = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
                    TimeSeriesColumnChartShaderNGon11.Constants.Decay          = timeSeries ? decay : 0f;
                    TimeSeriesColumnChartShaderNGon11.Constants.Scale          = (float)(adjustedScale);
                    TimeSeriesColumnChartShaderNGon11.Constants.Sky            = astronomical ? -1 : 1;
                    TimeSeriesColumnChartShaderNGon11.Constants.Opacity        = opacity * this.Opacity;
                    TimeSeriesColumnChartShaderNGon11.Constants.ShowFarSide    = ShowFarSide ? 1f : 0f;
                    TimeSeriesColumnChartShaderNGon11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesColumnChartShaderNGon11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesColumnChartShaderNGon11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesColumnChartShaderNGon11.Use(renderContext.devContext);
                }
                else
                {
                    TimeSeriesPointSpriteShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    double jBase = SpaceTimeController.UtcToJulian(baseDate);
                    TimeSeriesPointSpriteShader11.Constants.JNow        = (float)(SpaceTimeController.JNow - jBase);
                    TimeSeriesPointSpriteShader11.Constants.Decay       = timeSeries ? decay : 0f;
                    TimeSeriesPointSpriteShader11.Constants.Scale       = ((markerScale == MarkerScales.World) ? ((float)adjustedScale) : (-(float)adjustedScale));
                    TimeSeriesPointSpriteShader11.Constants.Sky         = astronomical ? -1 : 1;
                    TimeSeriesPointSpriteShader11.Constants.Opacity     = opacity * this.Opacity;
                    TimeSeriesPointSpriteShader11.Constants.ShowFarSide = ShowFarSide ? 1f : 0f;
                    TimeSeriesPointSpriteShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesPointSpriteShader11.ViewportScale     = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesPointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10.0f);
                    if (shapeFileVertex.Downlevel)
                    {
                        DownlevelTimeSeriesPointSpriteShader.Use(renderContext.devContext, shapeFileVertex.Instanced);
                    }
                    else
                    {
                        TimeSeriesPointSpriteShader11.Use(renderContext.devContext);
                    }
                }


                shapeFileVertex.Draw(renderContext, shapeFileVertex.Count, null, 1.0f);
            }
            renderContext.Device.ImmediateContext.GeometryShader.Set(null);
            renderContext.BlendMode = BlendMode.Alpha;


            renderContext.World = oldWorld;

            return(true);
        }