Beispiel #1
0
        public void Draw(RenderContext11 renderContext, float Opacity, Color drawColor)
        {
            if (glyphCache == null || glyphCache.Version > glyphVersion)
            {
                PrepareBatch();
            }


            //todo11 Use Shader

            renderContext.SetupBasicEffect(BasicEffect.TextureColorOpacity, Opacity, drawColor);
            renderContext.MainTexture = glyphCache.Texture;
            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            renderContext.PreDraw();


            if (layout == null)
            {
                layout = new SharpDX.Direct3D11.InputLayout(renderContext.Device, renderContext.Shader.InputSignature, new[]
                {
                    new SharpDX.Direct3D11.InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0),
                    new SharpDX.Direct3D11.InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 12, 0),
                });
            }
            renderContext.Device.ImmediateContext.InputAssembler.InputLayout = layout;


            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.devContext.Draw(vertexBuffer.Count, 0);
        }
Beispiel #2
0
        // Set up render context state required for drawing ground overlays when shaders
        // are enabled.
        public void SetupGroundOverlays(RenderContext11 renderContext)
        {
            // A shader should be set up already
            if (renderContext.Shader == null)
            {
                renderContext.SetupBasicEffect(BasicEffect.TextureOnly, 1.0f, Color.White);
            }

            // Count the number of overlays so that we can choose the appropriate shader
            int overlayCount = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                if (overlay.Icon.Texture != null)
                {
                    ++overlayCount;
                }
            }

            overlayCount = Math.Min(PlanetShader11.MaxOverlayTextures, overlayCount);
            if (overlayCount == 0)
            {
                // No work to do
                return;
            }

            // Get a shader identical to the one currently in use, but which supports
            // the required number of overlays.
            PlanetShaderKey key = renderContext.Shader.Key;

            key.overlayTextureCount = overlayCount;
            PlanetShader11 overlayShader = PlanetShader11.GetPlanetShader(renderContext.Device, key);

            renderContext.Shader = overlayShader;
            renderContext.Shader.DiffuseColor = new SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            SharpDX.Direct3D11.DeviceContext devContext = renderContext.Device.ImmediateContext;
            int overlayIndex = 0;

            foreach (KmlGroundOverlay overlay in GroundOverlays)
            {
                Texture11 texture = overlay.Icon.Texture;
                if (texture != null)
                {
                    if (overlayIndex < PlanetShader11.MaxOverlayTextures)
                    {
                        renderContext.Shader.SetOverlayTextureMatrix(overlayIndex, overlay.GetMatrix().Matrix11);
                        renderContext.Shader.SetOverlayTextureColor(overlayIndex, overlay.color);
                        renderContext.Shader.SetOverlayTexture(overlayIndex, texture.ResourceView);
                    }
                    ++overlayIndex;
                }
            }
        }