Пример #1
0
 protected void SetDrawAutomaticUniforms(Context context, DrawState drawState, SceneState sceneState)
 {
     for (int i = 0; i < _drawAutomaticUniforms.Count; ++i)
     {
         _drawAutomaticUniforms[i].Set(context, drawState, sceneState);
     }
 }
Пример #2
0
 public void Render(Context context, SceneState sceneState)
 {
     _pointSize.Value = (float)(8.0 * sceneState.HighResolutionSnapScale);
     
     context.Draw(PrimitiveType.Triangles, 0, 6, _drawState, sceneState);
     context.Draw(PrimitiveType.Points, 6, 1, _drawState, sceneState);
 }
Пример #3
0
 public static void ThrowIfNull(Context context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
 }
Пример #4
0
        private void Clean(Context context)
        {
            if (_dirty)
            {
                if (_va != null)
                {
                    _va.Dispose();
                    _va = null;
                    _drawState.VertexArray = null;
                    _drawStateSolid.VertexArray = null;
                }

                Mesh mesh = BoxTessellator.Compute(2 * _shape.Radii);
                _va = context.CreateVertexArray(mesh, _drawState.ShaderProgram.VertexAttributes, BufferHint.StaticDraw);
                _drawState.VertexArray = _va;
                _drawStateSolid.VertexArray = _va;
                _primitiveType = mesh.PrimitiveType;

                _renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;

                ((Uniform<Vector3F>)_drawState.ShaderProgram.Uniforms["u_globeOneOverRadiiSquared"]).Value = _shape.OneOverRadiiSquared.ToVector3F();
                ((Uniform<Vector3F>)_drawStateSolid.ShaderProgram.Uniforms["u_globeOneOverRadiiSquared"]).Value = _shape.OneOverRadiiSquared.ToVector3F();

                if (_wireframe != null)
                {
                    _wireframe.Dispose();
                    _wireframe = null;
                }
                _wireframe = new Wireframe(context, mesh);
                _wireframe.FacetCullingFace = CullFace.Front;
                _wireframe.Width = 3;

                _dirty = false;
            }
        }
Пример #5
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;
        }
Пример #6
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            Clean(context);

            if (ShowGlobe)
            {
                Vector3D eye = sceneState.Camera.Eye;
                Vector3F cameraEyeSquared = eye.MultiplyComponents(eye).ToVector3F();

                if (Shade)
                {
                    context.TextureUnits[0].Texture = Texture;
                    context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
                    _cameraEyeSquared.Value = cameraEyeSquared;
                    context.Draw(_primitiveType, _drawState, sceneState);
                }
                else
                {
                    _cameraEyeSquaredSolid.Value = cameraEyeSquared;
                    context.Draw(_primitiveType, _drawStateSolid, sceneState);
                }
            }

            if (ShowWireframeBoundingBox)
            {
                _wireframe.Render(context, sceneState);
            }
        }
Пример #7
0
        public ShapefileRenderer(
            string filename, 
            Context context, 
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Shapefile shapefile = new Shapefile(filename);

            switch (shapefile.ShapeType)
            {
                case ShapeType.Point:
                    PointShapefile pointShapefile = new PointShapefile(shapefile, context, globeShape, appearance);
                    pointShapefile.DepthWrite = false;
                    _shapefileGraphics = pointShapefile;
                    break;
                case ShapeType.Polyline:
                    PolylineShapefile polylineShapefile = new PolylineShapefile(shapefile, context, globeShape, appearance);
                    polylineShapefile.DepthWrite = false;
                    _shapefileGraphics = polylineShapefile;
                    break;
                case ShapeType.Polygon:
                    PolygonShapefile polygonShapefile = new PolygonShapefile(shapefile, context, globeShape, appearance);
                    polygonShapefile.DepthWrite = false;
                    _shapefileGraphics = polygonShapefile;
                    break;
                default:
                    throw new NotSupportedException("Rendering is not supported for " + shapefile.ShapeType.ToString() + " shapefiles.");
            }
        }
Пример #8
0
        public PointShapefile(
            Shapefile shapefile, 
            Context context, 
            Ellipsoid globeShape,
            ShapefileAppearance appearance)
        {
            Verify.ThrowIfNull(shapefile);
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(globeShape);
            Verify.ThrowIfNull(appearance);

            _billboards = new BillboardCollection(context);
            _billboards.Texture = Device.CreateTexture2D(appearance.Bitmap, TextureFormat.RedGreenBlueAlpha8, false);
            
            foreach (Shape shape in shapefile)
            {
                if (shape.ShapeType != ShapeType.Point)
                {
                    throw new NotSupportedException("The type of an individual shape does not match the Shapefile type.");
                }

                Vector2D point = ((PointShape)shape).Position;
                Vector3D position = globeShape.ToVector3D(Trig.ToRadians(new Geodetic3D(point.X, point.Y)));

                Billboard billboard = new Billboard();
                billboard.Position = position;
                _billboards.Add(billboard);
            }
        }
Пример #9
0
        private void Update(Context context)
        {
            if (_dirtyLength)
            {
                VertexAttributeDoubleVector3 positionAttribute = new VertexAttributeDoubleVector3("position", 6);
                positionAttribute.Values.Add(new Vector3D(0, 0, 0));
                positionAttribute.Values.Add(new Vector3D(_length, 0, 0));
                positionAttribute.Values.Add(new Vector3D(0, 0, 0));
                positionAttribute.Values.Add(new Vector3D(0, _length, 0));
                positionAttribute.Values.Add(new Vector3D(0, 0, 0));
                positionAttribute.Values.Add(new Vector3D(0, 0, _length));

                VertexAttributeRGBA colorAttribute = new VertexAttributeRGBA("color", 6);
                colorAttribute.AddColor(Color.Red);
                colorAttribute.AddColor(Color.Red);
                colorAttribute.AddColor(Color.Green);
                colorAttribute.AddColor(Color.Green);
                colorAttribute.AddColor(Color.Blue);
                colorAttribute.AddColor(Color.Blue);

                Mesh mesh = new Mesh();
                mesh.PrimitiveType = PrimitiveType.Lines;
                mesh.Attributes.Add(positionAttribute);
                mesh.Attributes.Add(colorAttribute);

                _polyline.Set(context, mesh);

                _dirtyLength = false;
            }

            _polyline.Width = Width;
        }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     //
     // viewport.Bottom should really be used but Rectangle goes top to botom, not bottom to top.
     //
     Rectangle viewport = context.Viewport;
     _uniform.Value = new Vector2F(1.0f / (float)viewport.Width, 1.0f / (float)viewport.Height);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = new Vector4F(
         sceneState.DiffuseIntensity,
         sceneState.SpecularIntensity,
         sceneState.AmbientIntensity,
         sceneState.Shininess);
 }
Пример #12
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            _lineWidth.Value = (float)(0.5 * Width * sceneState.HighResolutionSnapScale);

            context.Draw(_primitiveType, _drawState, sceneState);
        }
        private void Update(Context context, SceneState sceneState)
        {
            if (_meshBuffers != null)
            {
                if (_drawState.VertexArray != null)
                {
                    _drawState.VertexArray.Dispose();
                    _drawState.VertexArray = null;
                }

                _drawState.VertexArray = context.CreateVertexArray(_meshBuffers);
                _meshBuffers = null;
            }

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

            int width = (int)Math.Ceiling(Width * sceneState.HighResolutionSnapScale);
            int outlineWidth = (int)Math.Ceiling(OutlineWidth * sceneState.HighResolutionSnapScale);

            int textureWidth = width + outlineWidth + outlineWidth + 2;

            if ((_texture == null) || (_texture.Description.Width != textureWidth))
            {
                int textureResolution = textureWidth * 2;

                float[] texels = new float[textureResolution];

                int k = 3;
                for (int i = 1; i < textureWidth - 1; ++i)
                {
                    texels[k] = 1;                  // Alpha (stored in Green channel)
                    k += 2;
                }

                int j = (outlineWidth + 1) * 2;
                for (int i = 0; i < width; ++i)
                {
                    texels[j] = 1;                  // Fill/Outline (stored in Red channel)
                    j += 2;
                }

                WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                    sizeof(float) * textureResolution);
                pixelBuffer.CopyFromSystemMemory(texels);

                if (_texture != null)
                {
                    _texture.Dispose();
                    _texture = null;
                }

                // TODO:  Why does only Float or HalfFloat work here?
                _texture = Device.CreateTexture2D(new Texture2DDescription(textureWidth, 1, TextureFormat.RedGreen8));
                _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreen, ImageDatatype.Float);
            }
        }
Пример #14
0
        /// <summary>
        /// Creates a frame buffer with a 1x1 RGB color attachment.
        /// </summary>
        public static Framebuffer CreateFramebuffer(Context context)
        {
            Framebuffer framebuffer = context.CreateFramebuffer();
            framebuffer.ColorAttachments[0] = Device.CreateTexture2D(
                new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8, false));
            framebuffer.DepthAttachment = Device.CreateTexture2D(
                new Texture2DDescription(1, 1, TextureFormat.Depth24, false));

            return framebuffer;
        }
Пример #15
0
        private void CreateVertexArray(Context context)
        {
            // TODO:  Buffer hint.
            _positionBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, SizeInBytes<Vector2F>.Value);

            VertexBufferAttribute positionAttribute = new VertexBufferAttribute(
                _positionBuffer, ComponentDatatype.Float, 2);

            _drawState.VertexArray = context.CreateVertexArray();
            _drawState.VertexArray.Attributes[_drawState.ShaderProgram.VertexAttributes["position"].Location] = positionAttribute;
         }
Пример #16
0
        public static VertexArray CreateVertexArray(Context context, int positionLocation)
        {
            Vector4F[] positions = new[] { new Vector4F(0, 0, 0, 1) };
            VertexBuffer positionsBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, ArraySizeInBytes.Size(positions));
            positionsBuffer.CopyFromSystemMemory(positions);
            
            VertexArray va = context.CreateVertexArray();
            va.Attributes[positionLocation] = new VertexBufferAttribute(positionsBuffer, ComponentDatatype.Float, 4);
            va.DisposeBuffers = true;

            return va;
        }
Пример #17
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);
        }
Пример #18
0
        private void Update(Context context)
        {
            if (_positionDirty)
            {
                DisposeVertexArray();
                CreateVertexArray(context);

                Vector2F[] positions = new Vector2F[] { _position.ToVector2F() };
                _positionBuffer.CopyFromSystemMemory(positions);

                _positionDirty = false;
            }
        }
Пример #19
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            _geometry.Update(context, _drawState.ShaderProgram);

            context.TextureUnits[0].Texture = Texture;
            context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
            _drawState.VertexArray = _geometry.VertexArray;

            context.Draw(PrimitiveType.TriangleStrip, _drawState, sceneState);
        }
Пример #20
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowInvalidOperationIfNull(Texture, "Texture");

            Update(context);

            if (_drawState.VertexArray != null)
            {
                context.TextureUnits[0].Texture = Texture;
                context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
                context.Draw(PrimitiveType.Points, _drawState, sceneState);
            }
        }
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            if (_drawState.ShaderProgram != null)
            {
                double fillDistance = Width * 0.5 * sceneState.HighResolutionSnapScale;
                _fillDistance.Value = (float)(fillDistance);
                _outlineDistance.Value = (float)(fillDistance + (OutlineWidth * sceneState.HighResolutionSnapScale));

                context.Draw(_primitiveType, _drawState, sceneState);
            }
        }
Пример #22
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);
            Verify.ThrowIfNull(sceneState);

            if (Show)
            {
                if (_drawState.ShaderProgram != null)
                {
                    _fillDistance.Value = (float)(Width * 0.5 * sceneState.HighResolutionSnapScale);

                    context.Draw(_primitiveType, _drawState, sceneState);
                }
            }
        }
        public HighResolutionSnapFramebuffer(Context context, double widthInInches, int dotsPerInch, double aspectRatio)
        {
            _widthInInches = widthInInches;
            _dotsPerInch = dotsPerInch;
            _aspectRatio = aspectRatio;

            Texture2DDescription colorDescription = new Texture2DDescription(WidthInPixels, HeightInPixels, TextureFormat.RedGreenBlue8, false);
            _colorTexture = Device.CreateTexture2D(colorDescription);

            Texture2DDescription depthDescription = new Texture2DDescription(WidthInPixels, HeightInPixels, TextureFormat.Depth24, false);
            _depthTexture = Device.CreateTexture2D(depthDescription);

            _framebuffer = context.CreateFramebuffer();
            _framebuffer.ColorAttachments[0] = _colorTexture;
            _framebuffer.DepthAttachment = _depthTexture;
        }
Пример #24
0
        public ViewportQuad(Context context, string fs)
        {
            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.ViewportQuadVS.glsl"),
                fs == null ? EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.ViewportQuad.Shaders.ViewportQuadFS.glsl") : fs);

            _geometry = new ViewportQuadGeometry();
        }
Пример #25
0
        public void Render(Context context, SceneState sceneState)
        {
            Verify.ThrowIfNull(context);

            Clean(context);

            if (_textured.Value)
            {
                Verify.ThrowInvalidOperationIfNull(Texture, "Texture");
                context.TextureUnits[0].Texture = Texture;
                context.TextureUnits[0].TextureSampler = Device.TextureSamplers.LinearClamp;
            }

            _drawState.RenderState.RasterizationMode = Wireframe ? RasterizationMode.Line : RasterizationMode.Fill;

            context.Draw(_primitiveType, _drawState, sceneState);
        }
Пример #26
0
        public GPURelativeToEye(Context context, Vector3D[] positions, byte[] colors)
        {
            _sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Examples.GPURelativeToEye.Shaders.VS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl"));
            _cameraEyeHigh = (Uniform<Vector3F>)_sp.Uniforms["u_cameraEyeHigh"];
            _cameraEyeLow = (Uniform<Vector3F>)_sp.Uniforms["u_cameraEyeLow"];
            _modelViewPerspectiveMatrixRelativeToEye = (Uniform<Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]);
            _pointSize = (Uniform<float>)_sp.Uniforms["u_pointSize"];

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

            Mesh mesh = new Mesh();
            VertexAttributeFloatVector3 positionsHighAttribute = new VertexAttributeFloatVector3("positionHigh", positions.Length);
            VertexAttributeFloatVector3 positionsLowAttribute = new VertexAttributeFloatVector3("positionLow", positions.Length);
            VertexAttributeRGB colorAttribute = new VertexAttributeRGB("color", positions.Length);
            mesh.Attributes.Add(positionsHighAttribute);
            mesh.Attributes.Add(positionsLowAttribute);
            mesh.Attributes.Add(colorAttribute);

            for (int i = 0; i < positions.Length; ++i)
            {
                Vector3F positionHigh;
                Vector3F positionLow;
                Vector3DToTwoVector3F(positions[i], out positionHigh, out positionLow);

                positionsHighAttribute.Values.Add(positionHigh);
                positionsLowAttribute.Values.Add(positionLow);
            }

            for (int i = 0; i < colors.Length; ++i)
            {
                colorAttribute.Values.Add(colors[i]);
            }

            _va = context.CreateVertexArray(mesh, _sp.VertexAttributes, BufferHint.StaticDraw);

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

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;
            renderState.ProgramPointSize = ProgramPointSize.Enabled;

            _drawState = new DrawState(renderState, _sp, _va);
        }
Пример #27
0
        internal void Update(Context context, ShaderProgram sp)
        {
            if (_va == null)
            {
                VertexBufferAttribute positionAttribute = new VertexBufferAttribute(
                    _positionBuffer, ComponentDatatype.Float, 2);
                VertexBufferAttribute textureCoordinatesAttribute = new VertexBufferAttribute(
                    _textureCoordinatesBuffer, ComponentDatatype.HalfFloat, 2);

                _va = context.CreateVertexArray();
                _va.Attributes[sp.VertexAttributes["position"].Location] = positionAttribute;
                _va.Attributes[sp.VertexAttributes["textureCoordinates"].Location] = textureCoordinatesAttribute;
            }

            if (_viewport != context.Viewport)
            {
                //
                // Bottom and top swapped:  MS -> OpenGL
                //
                float left = context.Viewport.Left;
                float bottom = context.Viewport.Top;
                float right = context.Viewport.Right;
                float top = context.Viewport.Bottom;

                Vector2F[] positions = new Vector2F[] 
                { 
                    new Vector2F(left, bottom), 
                    new Vector2F(right, bottom), 
                    new Vector2F(left, top), 
                    new Vector2F(right, top)
                };
                _positionBuffer.CopyFromSystemMemory(positions);

                Vector2H[] textureCoordinates = new Vector2H[] 
                { 
                    new Vector2H(0, 0), 
                    new Vector2H(1, 0), 
                    new Vector2H(0, 1), 
                    new Vector2H(1, 1)
                };
                _textureCoordinatesBuffer.CopyFromSystemMemory(textureCoordinates);

                _viewport = context.Viewport;
            }
        }
Пример #28
0
        private void InitializeRequestThreads(Context context, RasterDataDetails details, ClipmapLevel clipmapLevelZero, RasterLevel rasterLevelZero)
        {
            details.WorkerWindow = Device.CreateWindow(1, 1);
            context.MakeCurrent();

#if !SingleThreaded
            Thread requestThread = new Thread(RequestThreadEntryPoint);
            requestThread.IsBackground = true;
            requestThread.Start(details);
#endif

            // Preload the entire world at level 0
            RasterTileRegion[] regions = rasterLevelZero.GetTilesInExtent(0, 0, rasterLevelZero.LongitudePosts - 1, rasterLevelZero.LatitudePosts - 1);
            foreach (RasterTileRegion region in regions)
            {
                RequestTileLoad(details, clipmapLevelZero, region.Tile);
            }
        }
Пример #29
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();
        }
Пример #30
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;
        }