Пример #1
0
        public RayCastedGlobe(Context context)
        {
            Verify.ThrowIfNull(context);

            _renderState = new RenderState();
            _renderState.FacetCulling.Face = CullFace.Front;
            string vs = EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.GlobeVS.glsl");

            ShaderProgram sp = Device.CreateShaderProgram(vs, EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.GlobeFS.glsl"));

            _cameraEyeSquared = (Uniform <Vector3F>)sp.Uniforms["u_cameraEyeSquared"];
            _useAverageDepth  = (Uniform <bool>)sp.Uniforms["u_useAverageDepth"];

            ShaderProgram solidSP = Device.CreateShaderProgram(vs, EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.SolidShadedGlobeFS.glsl"));

            _cameraEyeSquaredSolid = (Uniform <Vector3F>)solidSP.Uniforms["u_cameraEyeSquared"];
            _useAverageDepthSolid  = (Uniform <bool>)solidSP.Uniforms["u_useAverageDepth"];

            _drawState      = new DrawState(_renderState, sp, null);
            _drawStateSolid = new DrawState(_renderState, solidSP, null);

            Shape     = Ellipsoid.ScaledWgs84;
            Shade     = true;
            ShowGlobe = true;
        }
Пример #2
0
        public BillboardCollection(Context context, int capacity)
        {
            Verify.ThrowIfNull(context);

            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity");
            }

            ///////////////////////////////////////////////////////////////////

            _billboards      = new List <Billboard>(capacity);
            _dirtyBillboards = new List <Billboard>();

            ///////////////////////////////////////////////////////////////////

            RenderState renderState = new RenderState();

            renderState.FacetCulling.Enabled            = false;
            renderState.Blending.Enabled                = true;
            renderState.Blending.SourceRGBFactor        = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor      = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor   = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.BillboardCollection.Shaders.BillboardsVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.BillboardCollection.Shaders.BillboardsGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.BillboardCollection.Shaders.BillboardsFS.glsl"));

            _drawState = new DrawState(renderState, sp, null);

            Show = true;
        }
Пример #3
0
        public void Set(Context context, Mesh mesh)
        {
            Verify.ThrowIfNull(context);

            if (mesh == null)
            {
                throw new ArgumentNullException("mesh");
            }

            if (mesh.PrimitiveType != PrimitiveType.Lines &&
                mesh.PrimitiveType != PrimitiveType.LineLoop &&
                mesh.PrimitiveType != PrimitiveType.LineStrip)
            {
                throw new ArgumentException("mesh.PrimitiveType must be Lines, LineLoop, or LineStrip.", "mesh");
            }

            if (!mesh.Attributes.Contains("position") &&
                !mesh.Attributes.Contains("color"))
            {
                throw new ArgumentException("mesh.Attributes should contain attributes named \"position\" and \"color\".", "mesh");
            }

            if (_drawState.ShaderProgram == null)
            {
                _drawState.ShaderProgram = Device.CreateShaderProgram(
                    EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Polyline.Polyline.PolylineVS.glsl"),
                    EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Polyline.Polyline.PolylineGS.glsl"),
                    EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Polyline.Polyline.PolylineFS.glsl"));
                _fillDistance = (Uniform <float>)_drawState.ShaderProgram.Uniforms["u_fillDistance"];
            }

            ///////////////////////////////////////////////////////////////////
            _drawState.VertexArray = context.CreateVertexArray(mesh, _drawState.ShaderProgram.VertexAttributes, BufferHint.StaticDraw);
            _primitiveType         = mesh.PrimitiveType;
        }
Пример #4
0
        public HeadsUpDisplay()
        {
            RenderState renderState = new RenderState();

            renderState.FacetCulling.Enabled            = false;
            renderState.DepthTest.Enabled               = false;
            renderState.Blending.Enabled                = true;
            renderState.Blending.SourceRGBFactor        = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor      = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor   = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayFS.glsl"));

            _colorUniform       = (Uniform <Vector3F>)sp.Uniforms["u_color"];
            _originScaleUniform = (Uniform <Vector2F>)sp.Uniforms["u_originScale"];

            _drawState = new DrawState(renderState, sp, null);

            Color            = Color.White;
            HorizontalOrigin = HorizontalOrigin.Left;
            VerticalOrigin   = VerticalOrigin.Bottom;
            _positionDirty   = true;
        }
Пример #5
0
        public ClipmapUpdater(Context context, ClipmapLevel[] clipmapLevels)
        {
            ShaderVertexAttributeCollection vertexAttributes = new ShaderVertexAttributeCollection();

            vertexAttributes.Add(new ShaderVertexAttribute("position", VertexLocations.Position, ShaderVertexAttributeType.FloatVector2, 1));

            Mesh unitQuad = RectangleTessellator.Compute(new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0)), 1, 1);

            _unitQuad = context.CreateVertexArray(unitQuad, vertexAttributes, BufferHint.StaticDraw);
            _unitQuadPrimitiveType = unitQuad.PrimitiveType;
            _sceneState            = new SceneState();
            _framebuffer           = context.CreateFramebuffer();

            _updateShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateFS.glsl"));
            _updateTexelOutput = _updateShader.FragmentOutputs["texelOutput"];
            _updateDrawState   = new DrawState(new RenderState(), _updateShader, _unitQuad);
            _updateDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _updateDrawState.RenderState.DepthTest.Enabled = false;
            _updateDestinationOffset = (Uniform <Vector2F>)_updateShader.Uniforms["u_destinationOffset"];
            _updateUpdateSize        = (Uniform <Vector2F>)_updateShader.Uniforms["u_updateSize"];
            _updateSourceOrigin      = (Uniform <Vector2F>)_updateShader.Uniforms["u_sourceOrigin"];

            _upsampleShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleFS.glsl"));
            _upsampleTexelOutput = _upsampleShader.FragmentOutputs["texelOutput"];
            _upsampleDrawState   = new DrawState(new RenderState(), _upsampleShader, _unitQuad);
            _upsampleDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _upsampleDrawState.RenderState.DepthTest.Enabled = false;
            _upsampleSourceOrigin       = (Uniform <Vector2F>)_upsampleShader.Uniforms["u_sourceOrigin"];
            _upsampleUpdateSize         = (Uniform <Vector2F>)_upsampleShader.Uniforms["u_updateSize"];
            _upsampleDestinationOffset  = (Uniform <Vector2F>)_upsampleShader.Uniforms["u_destinationOffset"];
            _upsampleOneOverTextureSize = (Uniform <Vector2F>)_upsampleShader.Uniforms["u_oneOverTextureSize"];

            _computeNormalsShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsFS.glsl"));
            _normalOutput            = _computeNormalsShader.FragmentOutputs["normalOutput"];
            _computeNormalsDrawState = new DrawState(new RenderState(), _computeNormalsShader, _unitQuad);
            _computeNormalsDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _computeNormalsDrawState.RenderState.DepthTest.Enabled = false;
            _computeNormalsOrigin               = (Uniform <Vector2F>)_computeNormalsShader.Uniforms["u_origin"];
            _computeNormalsUpdateSize           = (Uniform <Vector2F>)_computeNormalsShader.Uniforms["u_updateSize"];
            _computeNormalsOneOverHeightMapSize = (Uniform <Vector2F>)_computeNormalsShader.Uniforms["u_oneOverHeightMapSize"];
            _heightExaggeration = (Uniform <float>)_computeNormalsShader.Uniforms["u_heightExaggeration"];
            _postDelta          = (Uniform <float>)_computeNormalsShader.Uniforms["u_postDelta"];

            HeightExaggeration = 1.0f;

            ClipmapLevel levelZero = clipmapLevels[0];

            InitializeRequestThreads(context, _terrain, levelZero, levelZero.Terrain);
            InitializeRequestThreads(context, _imagery, levelZero, levelZero.Imagery);
        }
Пример #6
0
        public PolylineOnTerrain()
        {
            _wallSP = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainWallVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainWallGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainWallFS.glsl"));

            _shadowVolumeSP = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainShadowVolumeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainShadowVolumeGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.PolylineOnTerrain.Shaders.PolylineOnTerrainShadowVolumeFS.glsl"));
        }
        public LatitudeLongitudeGridGlobe(Context context)
        {
            Verify.ThrowIfNull(context);

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.LatitudeLongitudeGrid.Shaders.GlobeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.LatitudeLongitudeGrid.Shaders.GlobeFS.glsl"));

            _gridWidth                = (Uniform <Vector2F>)sp.Uniforms["u_gridLineWidth"];
            _gridResolution           = (Uniform <Vector2F>)sp.Uniforms["u_gridResolution"];
            _globeOneOverRadiiSquared = (Uniform <Vector3F>)sp.Uniforms["u_globeOneOverRadiiSquared"];

            _drawState = new DrawState();
            _drawState.ShaderProgram = sp;

            Shape = Ellipsoid.ScaledWgs84;
        }
Пример #8
0
        public DoubleViewportQuad(Context context)
        {
            Verify.ThrowIfNull(context);

            RenderState renderState = new RenderState();

            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled    = false;

            _drawState               = new DrawState();
            _drawState.RenderState   = renderState;
            _drawState.ShaderProgram = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.ViewportQuad.Shaders.DoubleViewportQuadVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.ViewportQuad.Shaders.DoubleViewportQuadFS.glsl"));

            _geometry = new DoubleViewportQuadGeometry();
        }
Пример #9
0
        public TessellatedGlobe()
        {
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.Tessellated.Shaders.GlobeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.Tessellated.Shaders.GlobeFS.glsl"));

            _textured                 = (Uniform <bool>)sp.Uniforms["u_Textured"];
            _logarithmicDepth         = (Uniform <bool>)sp.Uniforms["u_logarithmicDepth"];
            _logarithmicDepthConstant = (Uniform <float>)sp.Uniforms["u_logarithmicDepthConstant"];
            LogarithmicDepthConstant  = 1;

            _drawState = new DrawState();
            _drawState.ShaderProgram = sp;

            Shape = Ellipsoid.ScaledWgs84;
            NumberOfSlicePartitions = 32;
            NumberOfStackPartitions = 16;
        }
Пример #10
0
        public RayCastedTerrainTile(TerrainTile tile)
        {
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.RayCastedTerrainTile.TerrainVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.RayCastedTerrainTile.TerrainFS.glsl"));

            _tileResolution     = tile.Resolution;
            _tileMinimumHeight  = tile.MinimumHeight;
            _tileMaximumHeight  = tile.MaximumHeight;
            _tileAABBLowerLeft  = Vector3D.Zero;            // TEXEL_SPACE_TODO
            _tileAABBUpperRight = new Vector3D(tile.Resolution.X, tile.Resolution.Y,
                                               tile.MaximumHeight - tile.MinimumHeight);

            _heightExaggeration = (Uniform <float>)sp.Uniforms["u_heightExaggeration"];
            _minimumHeight      = (Uniform <float>)sp.Uniforms["u_minimumHeight"];
            _maximumHeight      = (Uniform <float>)sp.Uniforms["u_maximumHeight"];
            _aabbLowerLeft      = (Uniform <Vector3F>)sp.Uniforms["u_aabbLowerLeft"];
            _aabbUpperRight     = (Uniform <Vector3F>)sp.Uniforms["u_aabbUpperRight"];
            _shadingAlgorithm   = (Uniform <int>)sp.Uniforms["u_shadingAlgorithm"];

            HeightExaggeration = 1;

            ///////////////////////////////////////////////////////////////////

            _drawState = new DrawState();
            _drawState.RenderState.FacetCulling.Face = CullFace.Front;
            _drawState.ShaderProgram = sp;

            //
            // Upload height map as a one channel floating point texture
            //
            WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                                                                         sizeof(float) * tile.Heights.Length);

            pixelBuffer.CopyFromSystemMemory(tile.Heights);

            _texture = Device.CreateTexture2DRectangle(new Texture2DDescription(
                                                           tile.Resolution.X, tile.Resolution.Y, TextureFormat.Red32f));
            _texture.CopyFromBuffer(pixelBuffer, ImageFormat.Red, ImageDatatype.Float);

            ShowTerrain = true;
        }
Пример #11
0
        public Wireframe(Context context, Mesh mesh)
        {
            RenderState renderState = new RenderState();

            renderState.Blending.Enabled                   = true;
            renderState.Blending.SourceRGBFactor           = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor         = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor      = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor    = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;
            renderState.DepthTest.Function                 = DepthTestFunction.LessThanOrEqual;

            //
            // This implementation is based on the 2006 SIGGRAPH Sketch:
            //
            //    Single-pass Wireframe Rendering
            //    http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/4884/pdf/imm4884.pdf
            //
            // NVIDIA published a white paper with some enhancements we can consider:
            //
            //    Solid Wireframe
            //    http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf
            //
            // More recent work, which I was not aware of at the time, is:
            //
            //    Two Methods for Antialiased Wireframe Drawing with Hidden Line Removal
            //    http://orbit.dtu.dk/getResource?recordId=219956&objectId=1&versionId=1
            //
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeFS.glsl"));

            _lineWidth = (Uniform <float>)sp.Uniforms["u_halfLineWidth"];
            Width      = 1;

            _colorUniform = (Uniform <Vector3F>)sp.Uniforms["u_color"];
            Color         = Color.Black;

            _drawState     = new DrawState(renderState, sp, context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw));
            _primitiveType = mesh.PrimitiveType;
        }
Пример #12
0
        public DayNightViewportQuad(Context context)
        {
            Verify.ThrowIfNull(context);

            RenderState renderState = new RenderState();

            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled    = false;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.ViewportQuadVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.ViewportQuadFS.glsl"));

            _dayNightOutput = (Uniform <int>)sp.Uniforms["u_DayNightOutput"];

            _drawState               = new DrawState();
            _drawState.RenderState   = renderState;
            _drawState.ShaderProgram = sp;

            _geometry = new ViewportQuadGeometry();
        }
Пример #13
0
        public DayNightGlobe(Context context)
        {
            Verify.ThrowIfNull(context);

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.GlobeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.GlobeFS.glsl"));

            _cameraEyeSquaredSP = (Uniform <Vector3F>)sp.Uniforms["u_cameraEyeSquared"];
            _useAverageDepth    = (Uniform <bool>)sp.Uniforms["u_useAverageDepth"];

            float blendDurationScale = 0.1f;

            ((Uniform <float>)sp.Uniforms["u_blendDuration"]).Value      = blendDurationScale;
            ((Uniform <float>)sp.Uniforms["u_blendDurationScale"]).Value = 1 / (2 * blendDurationScale);

            _drawState = new DrawState();
            _drawState.ShaderProgram = sp;

            Shape     = Ellipsoid.ScaledWgs84;
            ShowGlobe = true;
        }
Пример #14
0
        public Plane(Context context)
        {
            Verify.ThrowIfNull(context);

            RenderState lineRS = new RenderState();

            lineRS.FacetCulling.Enabled = false;

            ShaderProgram lineSP = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Plane.Shaders.LineVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Plane.Shaders.LineGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Plane.Shaders.LineFS.glsl"));

            _lineLogarithmicDepth         = (Uniform <bool>)lineSP.Uniforms["u_logarithmicDepth"];
            _lineLogarithmicDepthConstant = (Uniform <float>)lineSP.Uniforms["u_logarithmicDepthConstant"];
            _lineFillDistance             = (Uniform <float>)lineSP.Uniforms["u_fillDistance"];
            _lineColorUniform             = (Uniform <Vector3F>)lineSP.Uniforms["u_color"];

            OutlineWidth = 1;
            OutlineColor = Color.Gray;

            ///////////////////////////////////////////////////////////////////

            RenderState fillRS = new RenderState();

            fillRS.FacetCulling.Enabled            = false;
            fillRS.Blending.Enabled                = true;
            fillRS.Blending.SourceRGBFactor        = SourceBlendingFactor.SourceAlpha;
            fillRS.Blending.SourceAlphaFactor      = SourceBlendingFactor.SourceAlpha;
            fillRS.Blending.DestinationRGBFactor   = DestinationBlendingFactor.OneMinusSourceAlpha;
            fillRS.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            ShaderProgram fillSP = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Plane.Shaders.FillVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Plane.Shaders.FillFS.glsl"));

            _fillLogarithmicDepth         = (Uniform <bool>)fillSP.Uniforms["u_logarithmicDepth"];
            _fillLogarithmicDepthConstant = (Uniform <float>)fillSP.Uniforms["u_logarithmicDepthConstant"];
            _fillColorUniform             = (Uniform <Vector3F>)fillSP.Uniforms["u_color"];
            _fillAlphaUniform             = (Uniform <float>)fillSP.Uniforms["u_alpha"];

            LogarithmicDepthConstant = 1;
            FillColor        = Color.Gray;
            FillTranslucency = 0.5f;

            ///////////////////////////////////////////////////////////////////

            _positionBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, 2 * 4 * SizeInBytes <Vector3F> .Value);

            ushort[] indices = new ushort[]
            {
                0, 1, 2, 3,                             // Line loop
                0, 1, 2, 0, 2, 3                        // Triangles
            };
            IndexBuffer indexBuffer = Device.CreateIndexBuffer(BufferHint.StaticDraw, indices.Length * sizeof(ushort));

            indexBuffer.CopyFromSystemMemory(indices);

            int stride = 2 * SizeInBytes <Vector3F> .Value;

            _va = context.CreateVertexArray();
            _va.Attributes[VertexLocations.PositionHigh] =
                new VertexBufferAttribute(_positionBuffer, ComponentDatatype.Float, 3, false, 0, stride);
            _va.Attributes[VertexLocations.PositionLow] =
                new VertexBufferAttribute(_positionBuffer, ComponentDatatype.Float, 3, false, SizeInBytes <Vector3F> .Value, stride);
            _va.IndexBuffer = indexBuffer;

            Show        = true;
            ShowOutline = true;
            ShowFill    = true;

            ///////////////////////////////////////////////////////////////////

            _drawStateLine = new DrawState(lineRS, lineSP, _va);
            _drawStateFill = new DrawState(fillRS, fillSP, _va);

            Origin = Vector3D.Zero;
            XAxis  = Vector3D.UnitX;
            YAxis  = Vector3D.UnitY;
        }
Пример #15
0
        public GlobeClipmapTerrain(Context context, RasterSource terrainSource, EsriRestImagery imagery, Ellipsoid ellipsoid, int clipmapPosts)
        {
            _terrainSource = terrainSource;
            _ellipsoid     = ellipsoid;

            _clipmapPosts    = clipmapPosts;
            _clipmapSegments = _clipmapPosts - 1;

            int clipmapLevels = _terrainSource.Levels.Count;

            _clipmapLevels = new ClipmapLevel[clipmapLevels];

            for (int i = 0; i < _clipmapLevels.Length; ++i)
            {
                _clipmapLevels[i] = new ClipmapLevel();
            }

            for (int i = 0; i < _clipmapLevels.Length; ++i)
            {
                RasterLevel terrainLevel = _terrainSource.Levels[i];
                _clipmapLevels[i].Terrain       = terrainLevel;
                _clipmapLevels[i].HeightTexture = Device.CreateTexture2D(new Texture2DDescription(_clipmapPosts, _clipmapPosts, TextureFormat.Red32f));
                _clipmapLevels[i].NormalTexture = Device.CreateTexture2D(new Texture2DDescription(_clipmapPosts, _clipmapPosts, TextureFormat.RedGreenBlue32f));
                _clipmapLevels[i].CoarserLevel  = i == 0 ? null : _clipmapLevels[i - 1];
                _clipmapLevels[i].FinerLevel    = i == _clipmapLevels.Length - 1 ? null : _clipmapLevels[i + 1];

                // Aim for roughly one imagery texel per geometry texel.
                // Find the first imagery level that meets our resolution needs.
                double      longitudeResRequired = terrainLevel.PostDeltaLongitude;
                double      latitudeResRequired  = terrainLevel.PostDeltaLatitude;
                RasterLevel imageryLevel         = null;
                for (int j = 0; j < imagery.Levels.Count; ++j)
                {
                    imageryLevel = imagery.Levels[j];
                    if (imageryLevel.PostDeltaLongitude <= longitudeResRequired &&
                        imageryLevel.PostDeltaLatitude <= latitudeResRequired)
                    {
                        break;
                    }
                }

                _clipmapLevels[i].Imagery        = imageryLevel;
                _clipmapLevels[i].ImageryWidth   = (int)Math.Ceiling(_clipmapPosts * terrainLevel.PostDeltaLongitude / imageryLevel.PostDeltaLongitude);
                _clipmapLevels[i].ImageryHeight  = (int)Math.Ceiling(_clipmapPosts * terrainLevel.PostDeltaLatitude / imageryLevel.PostDeltaLatitude);
                _clipmapLevels[i].ImageryTexture = Device.CreateTexture2D(new Texture2DDescription(_clipmapLevels[i].ImageryWidth, _clipmapLevels[i].ImageryHeight, TextureFormat.RedGreenBlue8, false));
            }

            _shaderProgram = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.GlobeClipmapVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.GlobeClipmapFS.glsl"));

            _fillPatchPosts    = (clipmapPosts + 1) / 4; // M
            _fillPatchSegments = _fillPatchPosts - 1;

            // Create the MxM block used to fill the ring and the field.
            Mesh fieldBlockMesh = RectangleTessellator.Compute(
                new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(_fillPatchSegments, _fillPatchSegments)),
                _fillPatchSegments, _fillPatchSegments);

            _fillPatch = context.CreateVertexArray(fieldBlockMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            // Create the Mx3 block used to fill the space between the MxM blocks in the ring
            Mesh ringFixupHorizontalMesh = RectangleTessellator.Compute(
                new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(_fillPatchSegments, 2.0)),
                _fillPatchSegments, 2);

            _horizontalFixupPatch = context.CreateVertexArray(ringFixupHorizontalMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            // Create the 3xM block used to fill the space between the MxM blocks in the ring
            Mesh ringFixupVerticalMesh = RectangleTessellator.Compute(
                new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(2.0, _fillPatchSegments)),
                2, _fillPatchSegments);

            _verticalFixupPatch = context.CreateVertexArray(ringFixupVerticalMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            Mesh offsetStripHorizontalMesh = RectangleTessellator.Compute(
                new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(2 * _fillPatchPosts, 1.0)),
                2 * _fillPatchPosts, 1);

            _horizontalOffsetPatch = context.CreateVertexArray(offsetStripHorizontalMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            Mesh offsetStripVerticalMesh = RectangleTessellator.Compute(
                new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(1.0, 2 * _fillPatchPosts - 1)),
                1, 2 * _fillPatchPosts - 1);

            _verticalOffsetPatch = context.CreateVertexArray(offsetStripVerticalMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            Mesh centerMesh = RectangleTessellator.Compute(new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(2.0, 2.0)), 2, 2);

            _centerPatch = context.CreateVertexArray(centerMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            Mesh degenerateTriangleMesh = CreateDegenerateTriangleMesh();

            _degenerateTrianglePatch = context.CreateVertexArray(degenerateTriangleMesh, _shaderProgram.VertexAttributes, BufferHint.StaticDraw);

            _patchOriginInClippedLevel  = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_patchOriginInClippedLevel"];
            _levelScaleFactor           = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_levelScaleFactor"];
            _levelZeroWorldScaleFactor  = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_levelZeroWorldScaleFactor"];
            _levelOffsetFromWorldOrigin = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_levelOffsetFromWorldOrigin"];
            _heightExaggeration         = (Uniform <float>)_shaderProgram.Uniforms["u_heightExaggeration"];
            _viewPosInClippedLevel      = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_viewPosInClippedLevel"];
            _fineLevelOriginInCoarse    = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_fineLevelOriginInCoarse"];
            _unblendedRegionSize        = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_unblendedRegionSize"];
            _oneOverBlendedRegionSize   = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_oneOverBlendedRegionSize"];
            _fineTextureOrigin          = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_fineTextureOrigin"];
            _showBlendRegions           = (Uniform <bool>)_shaderProgram.Uniforms["u_showBlendRegions"];
            _useBlendRegions            = (Uniform <bool>)_shaderProgram.Uniforms["u_useBlendRegions"];
            _oneOverClipmapSize         = (Uniform <float>)_shaderProgram.Uniforms["u_oneOverClipmapSize"];
            _color            = (Uniform <Vector3F>)_shaderProgram.Uniforms["u_color"];
            _blendRegionColor = (Uniform <Vector3F>)_shaderProgram.Uniforms["u_blendRegionColor"];
            _terrainToImageryResolutionRatio = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_terrainToImageryResolutionRatio"];
            _terrainOffsetInImagery          = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_terrainOffsetInImagery"];
            _oneOverImagerySize = (Uniform <Vector2F>)_shaderProgram.Uniforms["u_oneOverImagerySize"];
            _showImagery        = (Uniform <bool>)_shaderProgram.Uniforms["u_showImagery"];
            _lighting           = (Uniform <bool>)_shaderProgram.Uniforms["u_shade"];

            ((Uniform <Vector3F>)_shaderProgram.Uniforms["u_globeRadiiSquared"]).Value =
                ellipsoid.RadiiSquared.ToVector3F();

            _renderState = new RenderState();
            _renderState.FacetCulling.FrontFaceWindingOrder = fieldBlockMesh.FrontFaceWindingOrder;
            _primitiveType = fieldBlockMesh.PrimitiveType;

            float oneOverBlendedRegionSize = (float)(10.0 / _clipmapPosts);

            _oneOverBlendedRegionSize.Value = new Vector2F(oneOverBlendedRegionSize, oneOverBlendedRegionSize);

            float unblendedRegionSize = (float)(_clipmapSegments / 2 - _clipmapPosts / 10.0 - 1);

            _unblendedRegionSize.Value = new Vector2F(unblendedRegionSize, unblendedRegionSize);

            _useBlendRegions.Value = true;
            _showImagery.Value     = true;

            _oneOverClipmapSize.Value = 1.0f / clipmapPosts;

            _updater = new ClipmapUpdater(context, _clipmapLevels);

            HeightExaggeration = 0.00001f;
        }
Пример #16
0
        public Polygon(Context context, Ellipsoid globeShape, IEnumerable <Vector3D> positions)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);

            //
            // Pipeline Stage 1a:  Clean up - Remove duplicate positions
            //
            List <Vector3D> cleanPositions = (List <Vector3D>)SimplePolygonAlgorithms.Cleanup(positions);

            //
            // Pipeline Stage 1b:  Clean up - Swap winding order
            //
            EllipsoidTangentPlane  plane            = new EllipsoidTangentPlane(globeShape, cleanPositions);
            ICollection <Vector2D> positionsOnPlane = plane.ComputePositionsOnPlane(cleanPositions);

            if (SimplePolygonAlgorithms.ComputeWindingOrder(positionsOnPlane) == PolygonWindingOrder.Clockwise)
            {
                cleanPositions.Reverse();
                //((List<Vector2D>)positionsOnPlane).Reverse();
            }

            //
            // Pipeline Stage 2:  Triangulate
            //
            IndicesUnsignedInt indices = EarClippingOnEllipsoid.Triangulate(cleanPositions);
            //IndicesInt32 indices = EarClipping.Triangulate(positionsOnPlane);

            //
            // Pipeline Stage 3:  Subdivide
            //
            TriangleMeshSubdivisionResult result = TriangleMeshSubdivision.Compute(cleanPositions, indices, Trig.ToRadians(1));

            //
            // Pipeline Stage 4:  Set height
            //
            VertexAttributeDoubleVector3 positionsAttribute = new VertexAttributeDoubleVector3(
                "position", (result.Indices.Values.Count / 3) + 2);

            foreach (Vector3D position in result.Positions)
            {
                positionsAttribute.Values.Add(globeShape.ScaleToGeocentricSurface(position));
            }

            Mesh mesh = new Mesh();

            mesh.PrimitiveType         = PrimitiveType.Triangles;
            mesh.FrontFaceWindingOrder = WindingOrder.Counterclockwise;
            mesh.Attributes.Add(positionsAttribute);
            mesh.Indices = result.Indices;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Polygon.Shaders.PolygonVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Polygon.Shaders.PolygonFS.glsl"));

            ((Uniform <Vector3F>)sp.Uniforms["u_globeOneOverRadiiSquared"]).Value = globeShape.OneOverRadiiSquared.ToVector3F();
            _colorUniform = (Uniform <Vector4F>)sp.Uniforms["u_color"];

            _drawState = new DrawState();
            _drawState.RenderState.Blending.Enabled                = true;
            _drawState.RenderState.Blending.SourceRGBFactor        = SourceBlendingFactor.SourceAlpha;
            _drawState.RenderState.Blending.SourceAlphaFactor      = SourceBlendingFactor.SourceAlpha;
            _drawState.RenderState.Blending.DestinationRGBFactor   = DestinationBlendingFactor.OneMinusSourceAlpha;
            _drawState.RenderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;
            _drawState.ShaderProgram = sp;
            _meshBuffers             = Device.CreateMeshBuffers(mesh, _drawState.ShaderProgram.VertexAttributes, BufferHint.StaticDraw);

            _primitiveType = mesh.PrimitiveType;

            Color = Color.White;
        }
Пример #17
0
        public VertexDisplacementMapTerrainTile(Context context, TerrainTile tile)
        {
            //
            // Upload height map as a one channel floating point texture
            //
            WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                                                                         sizeof(float) * tile.Heights.Length);

            pixelBuffer.CopyFromSystemMemory(tile.Heights);

            _texture = Device.CreateTexture2DRectangle(new Texture2DDescription(
                                                           tile.Resolution.X, tile.Resolution.Y, TextureFormat.Red32f));
            _texture.CopyFromBuffer(pixelBuffer, ImageFormat.Red, ImageDatatype.Float);

            ///////////////////////////////////////////////////////////////////

            ShaderProgram spTerrain = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.TerrainVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.TerrainFS.glsl"));

            _heightExaggerationUniform = (Uniform <float>)spTerrain.Uniforms["u_heightExaggeration"];
            ((Uniform <Vector2F>)spTerrain.Uniforms["u_positionToTextureCoordinate"]).Value = new Vector2F(
                (float)(1.0 / (double)(tile.Resolution.X)),
                (float)(1.0 / (double)(tile.Resolution.Y)));
            ((Uniform <Vector2F>)spTerrain.Uniforms["u_positionToRepeatTextureCoordinate"]).Value = new Vector2F(
                (float)(4.0 / (double)tile.Resolution.X),
                (float)(4.0 / (double)tile.Resolution.Y));

            ///////////////////////////////////////////////////////////////////

            ShaderProgram spNormals = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.NormalsVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.NormalsGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.NormalsFS.glsl"));

            _heightExaggerationNormals = (Uniform <float>)spNormals.Uniforms["u_heightExaggeration"];
            _fillDistanceNormals       = (Uniform <float>)spNormals.Uniforms["u_fillDistance"];
            ((Uniform <Vector3F>)spNormals.Uniforms["u_color"]).Value = Vector3F.Zero;

            ///////////////////////////////////////////////////////////////////

            ShaderProgram spWireframe = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.WireframeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.WireframeGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.VertexDisplacementMapTerrainTile.WireframeFS.glsl"));

            _lineWidthWireframe          = (Uniform <float>)spWireframe.Uniforms["u_halfLineWidth"];
            _heightExaggerationWireframe = (Uniform <float>)spWireframe.Uniforms["u_heightExaggeration"];
            ((Uniform <Vector3F>)spWireframe.Uniforms["u_color"]).Value = Vector3F.Zero;

            ///////////////////////////////////////////////////////////////////

            Mesh mesh = RectangleTessellator.Compute(new RectangleD(new Vector2D(0.5, 0.5),
                                                                    new Vector2D((double)tile.Resolution.X - 0.5, (double)tile.Resolution.Y - 0.5)),
                                                     tile.Resolution.X - 1, tile.Resolution.Y - 1);

            _va            = context.CreateVertexArray(mesh, spWireframe.VertexAttributes, BufferHint.StaticDraw);
            _primitiveType = mesh.PrimitiveType;

            ///////////////////////////////////////////////////////////////////

            RenderState rsTerrain = new RenderState();

            rsTerrain.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;

            RenderState rsWireframe = new RenderState();

            rsWireframe.Blending.Enabled                   = true;
            rsWireframe.Blending.SourceRGBFactor           = SourceBlendingFactor.SourceAlpha;
            rsWireframe.Blending.SourceAlphaFactor         = SourceBlendingFactor.SourceAlpha;
            rsWireframe.Blending.DestinationRGBFactor      = DestinationBlendingFactor.OneMinusSourceAlpha;
            rsWireframe.Blending.DestinationAlphaFactor    = DestinationBlendingFactor.OneMinusSourceAlpha;
            rsWireframe.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;
            rsWireframe.DepthTest.Function                 = DepthTestFunction.LessThanOrEqual;

            RenderState rsNormals = new RenderState();

            rsNormals.FacetCulling.Enabled            = false;
            rsNormals.Blending.Enabled                = true;
            rsNormals.Blending.SourceRGBFactor        = SourceBlendingFactor.SourceAlpha;
            rsNormals.Blending.SourceAlphaFactor      = SourceBlendingFactor.SourceAlpha;
            rsNormals.Blending.DestinationRGBFactor   = DestinationBlendingFactor.OneMinusSourceAlpha;
            rsNormals.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            ///////////////////////////////////////////////////////////////////

            _drawStateTerrain   = new DrawState(rsTerrain, spTerrain, _va);
            _drawStateWireframe = new DrawState(rsWireframe, spWireframe, _va);
            _drawStateNormals   = new DrawState(rsNormals, spNormals, _va);

            _tileMinimumHeight = tile.MinimumHeight;
            _tileMaximumHeight = tile.MaximumHeight;

            _heightExaggeration = 1;
            _normalsAlgorithm   = TerrainNormalsAlgorithm.ForwardDifference;
            _showTerrain        = true;
            _dirty = true;
        }
Пример #18
0
        public TriangleMeshTerrainTile(Context context, TerrainTile tile)
        {
            ShaderProgram silhouetteSP = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteFS.glsl"));

            Uniform <float> fillDistance = (Uniform <float>)silhouetteSP.Uniforms["u_fillDistance"];

            fillDistance.Value            = 1.5f;
            _silhouetteHeightExaggeration = (Uniform <float>)silhouetteSP.Uniforms["u_heightExaggeration"];

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.TerrainVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.TerrainFS.glsl"));

            _tileMinimumHeight = tile.MinimumHeight;
            _tileMaximumHeight = tile.MaximumHeight;

            _heightExaggeration = (Uniform <float>)sp.Uniforms["u_heightExaggeration"];
            _minimumHeight      = (Uniform <float>)sp.Uniforms["u_minimumHeight"];
            _maximumHeight      = (Uniform <float>)sp.Uniforms["u_maximumHeight"];
            HeightExaggeration  = 1;

            ///////////////////////////////////////////////////////////////////

            Mesh mesh = new Mesh();

            mesh.PrimitiveType         = PrimitiveType.Triangles;
            mesh.FrontFaceWindingOrder = WindingOrder.Counterclockwise;

            int numberOfPositions = tile.Resolution.X * tile.Resolution.Y;
            VertexAttributeDoubleVector3 positionsAttribute = new VertexAttributeDoubleVector3("position", numberOfPositions);
            IList <Vector3D>             positions          = positionsAttribute.Values;

            mesh.Attributes.Add(positionsAttribute);

            int numberOfPartitionsX    = tile.Resolution.X - 1;
            int numberOfPartitionsY    = tile.Resolution.Y - 1;
            int numberOfIndices        = (numberOfPartitionsX * numberOfPartitionsY) * 6;
            IndicesUnsignedInt indices = new IndicesUnsignedInt(numberOfIndices);

            mesh.Indices = indices;

            //
            // Positions
            //
            Vector2D lowerLeft    = tile.Extent.LowerLeft;
            Vector2D toUpperRight = tile.Extent.UpperRight - lowerLeft;

            int heightIndex = 0;

            for (int y = 0; y <= numberOfPartitionsY; ++y)
            {
                double deltaY   = y / (double)numberOfPartitionsY;
                double currentY = lowerLeft.Y + (deltaY * toUpperRight.Y);

                for (int x = 0; x <= numberOfPartitionsX; ++x)
                {
                    double deltaX   = x / (double)numberOfPartitionsX;
                    double currentX = lowerLeft.X + (deltaX * toUpperRight.X);
                    positions.Add(new Vector3D(currentX, currentY, tile.Heights[heightIndex++]));
                }
            }

            //
            // Indices
            //
            int rowDelta = numberOfPartitionsX + 1;
            int i        = 0;

            for (int y = 0; y < numberOfPartitionsY; ++y)
            {
                for (int x = 0; x < numberOfPartitionsX; ++x)
                {
                    indices.AddTriangle(new TriangleIndicesUnsignedInt(i, i + 1, rowDelta + (i + 1)));
                    indices.AddTriangle(new TriangleIndicesUnsignedInt(i, rowDelta + (i + 1), rowDelta + i));
                    i += 1;
                }
                i += 1;
            }

            _drawState = new DrawState();
            _drawState.RenderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;
            _drawState.ShaderProgram = sp;
            _drawState.VertexArray   = context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw);

            _silhouetteDrawState = new DrawState();
            _silhouetteDrawState.RenderState.FacetCulling.Enabled = false;
            _silhouetteDrawState.RenderState.DepthMask            = false;
            _silhouetteDrawState.VertexArray   = _drawState.VertexArray;
            _silhouetteDrawState.ShaderProgram = silhouetteSP;

            _primitiveType = mesh.PrimitiveType;

            _clearColor         = new ClearState();
            _clearColor.Buffers = ClearBuffers.ColorBuffer;

            //
            // Only depth needs to be cleared but include stencil for speed.
            //
            _clearDepthStencil         = new ClearState();
            _clearDepthStencil.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer;
        }