Exemple #1
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;
        }
        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);
        }
        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;
        }
        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;
        }
        private void CreateDepthAndSilhouetteData(Context context)
        {
            if ((_depthTexture == null) || (_depthTexture.Description.Width != context.Viewport.Width) ||
                (_depthTexture.Description.Height != context.Viewport.Height))
            {
                //
                // Dispose as necessary
                //
                if (_depthTexture != null)
                {
                    _depthTexture.Dispose();
                }
                if (_silhouetteTexture != null)
                {
                    _silhouetteTexture.Dispose();
                }
                if (_colorTexture != null)
                {
                    _colorTexture.Dispose();
                }

                //
                // Textures
                //
                _depthTexture = Device.CreateTexture2D(new Texture2DDescription(context.Viewport.Width, context.Viewport.Height, TextureFormat.Depth24));
                _silhouetteTexture = Device.CreateTexture2D(new Texture2DDescription(context.Viewport.Width, context.Viewport.Height, TextureFormat.Red8));
                _colorTexture = Device.CreateTexture2D(new Texture2DDescription(context.Viewport.Width, context.Viewport.Height, TextureFormat.RedGreenBlue8));

                //
                // Terrain FBO
                //
                if (_terrainFramebuffer == null)
                {
                    _terrainFramebuffer = context.CreateFramebuffer();
                }
                _terrainFramebuffer.DepthAttachment = _depthTexture;
                _terrainFramebuffer.ColorAttachments[0] = _colorTexture;

                //
                // Silhouette FBO
                //
                if (_silhouetteFramebuffer == null)
                {
                    _silhouetteFramebuffer = context.CreateFramebuffer();
                }
                _silhouetteFramebuffer.DepthAttachment = _depthTexture;
                _silhouetteFramebuffer.ColorAttachments[0] = _silhouetteTexture;
            }
        }