Exemple #1
0
        /// <summary>
        /// adds a PostProcessor to the scene. Sets the scene field and calls PostProcessor.onAddedToScene so that PostProcessors can load
        /// resources using the scenes ContentManager.
        /// </summary>
        /// <param name="postProcessor">Post processor.</param>
        public T AddPostProcessor <T>(T postProcessor) where T : PostProcessor
        {
            _postProcessors.Add(postProcessor);
            _postProcessors.Sort();
            postProcessor.OnAddedToScene(this);

            // if we already began let the PostProcessor know what size our RenderTarget is
            if (_didSceneBegin)
            {
                postProcessor.OnSceneBackBufferSizeChanged(_sceneRenderTarget.Width, _sceneRenderTarget.Height);
            }

            // lazily create the 2nd RenderTarget for post processing only when a PostProcessor is added
            if (_destinationRenderTarget == null)
            {
                if (_sceneRenderTarget != null)
                {
                    _destinationRenderTarget = RenderTarget.Create(_sceneRenderTarget.Width, _sceneRenderTarget.Height);
                }
                else
                {
                    _destinationRenderTarget = RenderTarget.Create();
                }
            }

            return(postProcessor);
        }
        public void OnSceneBackBufferSizeChanged(int newWidth, int newHeight)
        {
            // dont recreate the mosaic unless we really need to
            if (_lastMosaicScale != _scene.PixelPerfectScale)
            {
                CreateMosaicTexture(_scene.PixelPerfectScale);
                _lastMosaicScale = _scene.PixelPerfectScale;
            }

            if (_mosaicRenderTex != null)
            {
                _mosaicRenderTex.Dispose();
                _mosaicRenderTex = RenderTarget.Create(newWidth * _scene.PixelPerfectScale,
                                                       newHeight * _scene.PixelPerfectScale, DepthFormat.None);
            }
            else
            {
                _mosaicRenderTex = RenderTarget.Create(newWidth * _scene.PixelPerfectScale,
                                                       newHeight * _scene.PixelPerfectScale, DepthFormat.None);
            }

            // based on the look of games by: http://deepnight.net/games/strike-of-rage/
            // use the mosaic to render to a full sized RenderTarget repeating the mosaic
            Core.GraphicsDevice.SetRenderTarget(_mosaicRenderTex);
            Graphics.Instance.Batcher.Begin(BlendState.Opaque, SamplerState.PointWrap, DepthStencilState.None,
                                            RasterizerState.CullNone);
            Graphics.Instance.Batcher.Draw(_mosaicTexture, Vector2.Zero,
                                           new Rectangle(0, 0, _mosaicRenderTex.Width, _mosaicRenderTex.Height), Color.White);
            Graphics.Instance.Batcher.End();

            // let our Effect know about our rendered, full screen mosaic
            _effect.Parameters["_secondTexture"].SetValue(_mosaicRenderTex);
        }
        /// <summary>
        /// 初期化
        /// </summary>
        /// <param name="name">キャラクター名</param>
        /// <param name="screenSize">スクリーンサイズ</param>
        public void Initialize(Util.Math.Point screenSize)
        {
            //!< 初期化
            Initialized = true;
            //!< スクリーンサイズ設定
            _screenSize = screenSize;
            //!< キャラクターをロードする
            CharacterLoad(_babumiConfig.ModelJsonPath);
            //!< Debugの時だけバージョンチェックをする
            if (_babumiConfig.RequiredVersion > GraphicsManager.Instance.GetVersion())
            {
                return; //!< GL4.3以下なので処理をしない
            }
            _bitmapSource = new WriteableBitmap((int)_screenSize.X, (int)_screenSize.Y, 96, 96, PixelFormats.Bgra32, null);
            _sourceRect   = new Int32Rect(0, 0, (int)_screenSize.X - 20, (int)_screenSize.Y - 20);

            _renderTarget = new RenderTarget {
                Width = (uint)_screenSize.X, Height = (uint)_screenSize.Y
            };
            _renderTarget.Create();

            _sssbObject = new SSBObject();
            _sssbObject.Create((int)_screenSize.X * (int)_screenSize.Y * sizeof(uint));

            _computeShader = new Shader();
            _computeShader.CreateShader("Res/computeShader.fx", Shader.Type.ComputeShader);
            _computeShader.Attach();

            GraphicsManager.Instance.SetRenderTarget(_renderTarget);
        }
Exemple #4
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            RenderTarget renderTarget = RenderTarget.Create();

            renderTarget.Window.Title         = string.Format("XPlane {0}", Application.ProductVersion);
            renderTarget.Window.Icon          = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            renderTarget.Window.SurfaceLayout = new SurfaceLayout(true, false, true);

            SGL.Initialize(new Configurator(new BackBuffer(800, 480), new Game1(), renderTarget));
        }
Exemple #5
0
        public override void Load()
        {
            m_render_target = RenderTarget.Create(320, 240, false);

            m_render_target_view = Engine.Canvas.CreateView(Color.Black);
            m_render_target_view.AbsoluteViewport = RectF.FromBox(0, 0, 320, 240);
            m_render_target_view.RenderTarget     = m_render_target;

            m_sprite = new Sprite(Engine.Content.Get <Texture2D>("party"));
            m_sprite.SetPosition(Engine.Canvas.Width / 2, Engine.Canvas.Height / 2);

            m_sprite_target = new Sprite(m_render_target.Texture);

            m_sprite_target.SetPosition(Engine.Canvas.Width / 2, Engine.Canvas.Height / 2);
        }
Exemple #6
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            RenderTarget renderTarget = RenderTarget.Create();

            renderTarget.Window.Icon             = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            renderTarget.Window.Title            = "Flying Bird";
            renderTarget.Window.CursorVisibility = true;
            renderTarget.Window.SurfaceLayout    = new SurfaceLayout(true, false, true);

            SGL.Initialize();

            SGL.Components.Get <GraphicsDevice>().ClearColor = Color.FromArgb(255, 128, 197, 205);
        }
Exemple #7
0
        /// <summary>
        /// Initializes SGL.
        /// </summary>
        public static void Initialize()
        {
            Game         gameInstance = InitializeHelper.GetGameClass();
            RenderTarget renderTarget;

            try
            {
                renderTarget = RenderTarget.Default;
            }
            catch (InvalidOperationException)
            {
                renderTarget = RenderTarget.Create();
            }

            var sglInitializer = new Configurator(gameInstance, renderTarget);

            Initialize(sglInitializer);
        }
Exemple #8
0
        void UpdateResolutionScaler()
        {
            var designSize        = _designResolutionSize;
            var screenSize        = new Point(Screen.Width, Screen.Height);
            var screenAspectRatio = (float)screenSize.X / (float)screenSize.Y;

            var renderTargetWidth  = screenSize.X;
            var renderTargetHeight = screenSize.Y;

            var resolutionScaleX = (float)screenSize.X / (float)designSize.X;
            var resolutionScaleY = (float)screenSize.Y / (float)designSize.Y;

            var rectCalculated = false;

            // calculate the scale used by the PixelPerfect variants
            PixelPerfectScale = 1;
            if (_resolutionPolicy != SceneResolutionPolicy.None)
            {
                if ((float)designSize.X / (float)designSize.Y > screenAspectRatio)
                {
                    PixelPerfectScale = screenSize.X / designSize.X;
                }
                else
                {
                    PixelPerfectScale = screenSize.Y / designSize.Y;
                }

                if (PixelPerfectScale == 0)
                {
                    PixelPerfectScale = 1;
                }
            }

            switch (_resolutionPolicy)
            {
            case SceneResolutionPolicy.None:
                _finalRenderDestinationRect.X      = _finalRenderDestinationRect.Y = 0;
                _finalRenderDestinationRect.Width  = screenSize.X;
                _finalRenderDestinationRect.Height = screenSize.Y;
                rectCalculated = true;
                break;

            case SceneResolutionPolicy.ExactFit:
                // exact design size render texture
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;
                break;

            case SceneResolutionPolicy.NoBorder:
                // exact design size render texture
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;

                resolutionScaleX = resolutionScaleY = Math.Max(resolutionScaleX, resolutionScaleY);
                break;

            case SceneResolutionPolicy.NoBorderPixelPerfect:
                // exact design size render texture
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;

                // we are going to do some cropping so we need to use floats for the scale then round up
                PixelPerfectScale = 1;
                if ((float)designSize.X / (float)designSize.Y < screenAspectRatio)
                {
                    var floatScale = (float)screenSize.X / (float)designSize.X;
                    PixelPerfectScale = Mathf.CeilToInt(floatScale);
                }
                else
                {
                    var floatScale = (float)screenSize.Y / (float)designSize.Y;
                    PixelPerfectScale = Mathf.CeilToInt(floatScale);
                }

                if (PixelPerfectScale == 0)
                {
                    PixelPerfectScale = 1;
                }

                _finalRenderDestinationRect.Width  = Mathf.CeilToInt(designSize.X * PixelPerfectScale);
                _finalRenderDestinationRect.Height = Mathf.CeilToInt(designSize.Y * PixelPerfectScale);
                _finalRenderDestinationRect.X      = (screenSize.X - _finalRenderDestinationRect.Width) / 2;
                _finalRenderDestinationRect.Y      = (screenSize.Y - _finalRenderDestinationRect.Height) / 2;
                rectCalculated = true;

                break;

            case SceneResolutionPolicy.ShowAll:
                resolutionScaleX = resolutionScaleY = Math.Min(resolutionScaleX, resolutionScaleY);

                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;
                break;

            case SceneResolutionPolicy.ShowAllPixelPerfect:
                // exact design size render texture
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;

                _finalRenderDestinationRect.Width  = Mathf.CeilToInt(designSize.X * PixelPerfectScale);
                _finalRenderDestinationRect.Height = Mathf.CeilToInt(designSize.Y * PixelPerfectScale);
                _finalRenderDestinationRect.X      = (screenSize.X - _finalRenderDestinationRect.Width) / 2;
                _finalRenderDestinationRect.Y      = (screenSize.Y - _finalRenderDestinationRect.Height) / 2;
                rectCalculated = true;

                break;

            case SceneResolutionPolicy.FixedHeight:
                resolutionScaleX = resolutionScaleY;
                designSize.X     = Mathf.CeilToInt(screenSize.X / resolutionScaleX);

                // exact design size render texture for height but not width
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;
                break;

            case SceneResolutionPolicy.FixedHeightPixelPerfect:
                // start with exact design size render texture height. the width may change
                renderTargetHeight = designSize.Y;

                _finalRenderDestinationRect.Width  = Mathf.CeilToInt(designSize.X * resolutionScaleX);
                _finalRenderDestinationRect.Height = Mathf.CeilToInt(designSize.Y * PixelPerfectScale);
                _finalRenderDestinationRect.X      = (screenSize.X - _finalRenderDestinationRect.Width) / 2;
                _finalRenderDestinationRect.Y      = (screenSize.Y - _finalRenderDestinationRect.Height) / 2;
                rectCalculated = true;

                renderTargetWidth = (int)(designSize.X * resolutionScaleX / PixelPerfectScale);
                break;

            case SceneResolutionPolicy.FixedWidth:
                resolutionScaleY = resolutionScaleX;
                designSize.Y     = Mathf.CeilToInt(screenSize.Y / resolutionScaleY);

                // exact design size render texture for width but not height
                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;
                break;

            case SceneResolutionPolicy.FixedWidthPixelPerfect:
                // start with exact design size render texture width. the height may change
                renderTargetWidth = designSize.X;

                _finalRenderDestinationRect.Width  = Mathf.CeilToInt(designSize.X * PixelPerfectScale);
                _finalRenderDestinationRect.Height = Mathf.CeilToInt(designSize.Y * resolutionScaleY);
                _finalRenderDestinationRect.X      = (screenSize.X - _finalRenderDestinationRect.Width) / 2;
                _finalRenderDestinationRect.Y      = (screenSize.Y - _finalRenderDestinationRect.Height) / 2;
                rectCalculated = true;

                renderTargetHeight = (int)(designSize.Y * resolutionScaleY / PixelPerfectScale);

                break;

            case SceneResolutionPolicy.BestFit:
                var safeScaleX = (float)screenSize.X / (designSize.X - _designBleedSize.X);
                var safeScaleY = (float)screenSize.Y / (designSize.Y - _designBleedSize.Y);

                var resolutionScale = MathHelper.Max(resolutionScaleX, resolutionScaleY);
                var safeScale       = MathHelper.Min(safeScaleX, safeScaleY);

                resolutionScaleX = resolutionScaleY = MathHelper.Min(resolutionScale, safeScale);

                renderTargetWidth  = designSize.X;
                renderTargetHeight = designSize.Y;

                break;
            }

            // if we didnt already calculate a rect (None and all pixel perfect variants calculate it themselves) calculate it now
            if (!rectCalculated)
            {
                // calculate the display rect of the RenderTarget
                var renderWidth  = designSize.X * resolutionScaleX;
                var renderHeight = designSize.Y * resolutionScaleY;

                _finalRenderDestinationRect = RectangleExt.FromFloats((screenSize.X - renderWidth) / 2, (screenSize.Y - renderHeight) / 2, renderWidth, renderHeight);
            }


            // set some values in the Input class to translate mouse position to our scaled resolution
            var scaleX = renderTargetWidth / (float)_finalRenderDestinationRect.Width;
            var scaleY = renderTargetHeight / (float)_finalRenderDestinationRect.Height;

            Input._resolutionScale  = new Vector2(scaleX, scaleY);
            Input._resolutionOffset = _finalRenderDestinationRect.Location;

            // resize our RenderTargets
            if (_sceneRenderTarget != null)
            {
                _sceneRenderTarget.Dispose();
            }
            _sceneRenderTarget = RenderTarget.Create(renderTargetWidth, renderTargetHeight);

            // only create the destinationRenderTarget if it already exists, which would indicate we have PostProcessors
            if (_destinationRenderTarget != null)
            {
                _destinationRenderTarget.Dispose();
                _destinationRenderTarget = RenderTarget.Create(renderTargetWidth, renderTargetHeight);
            }

            // notify the Renderers, PostProcessors and FinalRenderDelegate of the change in render texture size
            for (var i = 0; i < _renderers.Length; i++)
            {
                _renderers.Buffer[i].OnSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight);
            }

            for (var i = 0; i < _afterPostProcessorRenderers.Length; i++)
            {
                _afterPostProcessorRenderers.Buffer[i].OnSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight);
            }

            for (var i = 0; i < _postProcessors.Length; i++)
            {
                _postProcessors.Buffer[i].OnSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight);
            }

            if (_finalRenderDelegate != null)
            {
                _finalRenderDelegate.OnSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight);
            }

            Camera.OnSceneRenderTargetSizeChanged(renderTargetWidth, renderTargetHeight);
        }
        public override void Load()
        {
            m_ImGuiDriver = new ImGuiDriver();
            m_ImGuiDriver.Initalise(GraphicsDevice, m_ResourceManager);

            camera = new GameCamera(new Vector3(40, 40, 40), new Vector3(80, 80, 0), 55, -20);

            m_QuadBatch = new QuadBatch();


            var cubeShader    = m_ResourceManager.LoadShaderFromFile("v.cube.glsl", "f.cube.glsl");
            var skyboxShader  = m_ResourceManager.LoadShaderFromFile("v.skybox.glsl", "f.skybox.glsl");
            var terrainShader = m_ResourceManager.LoadShaderFromFile("v.terrain.glsl", "f.terrain.glsl");
            var waterShader   = m_ResourceManager.LoadShaderFromFile("v.water.glsl", "f.water.glsl");


            // Load Textures
            {
                m_AwesomeFace = m_ResourceManager.LoadTexture2d("awesomeface.png");
                m_Texture     = m_ResourceManager.LoadTexture2d("texture1.png");
                //m_Default = m_ResourceManager.LoadTexture2d("default.png");
            }


            // Load Terrain
            {
                var heightMapData = HeightMapData.LoadHeightmapData("Resources/Textures/Heightmaps/1.png");
                var model         = ModelLoader.CreateTerrain(heightMapData);

                var terrainVAO = m_ResourceManager.LoadVAO(model.Verts, model.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets);

                m_TerrainRenderObject = new Terrain(terrainShader.ShaderProgramId, terrainVAO.VaoId, terrainVAO.VertexCount);
            }

            // Create Water
            {
                var model = ModelLoader.CreatePlane(1024, 1024, 12.2f);

                var waterVAO = m_ResourceManager.LoadVAO(model.Verts, model.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets);

                m_WaterRenderObject = new Water(waterShader.ShaderProgramId, waterVAO.VaoId, waterVAO.VertexCount);
            }

            // Create Bunny
            {
                var bunnyVerts = ModelLoader.LoadObj("Resources/Models/bunny.obj");

                var bunnyVAO = m_ResourceManager.LoadVAO(bunnyVerts.Verts, bunnyVerts.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets);

                m_BunnyRenderObject = new Bunny(terrainShader.ShaderProgramId, bunnyVAO.VaoId, bunnyVAO.VertexCount);
            }


            // Create Cube
            {
                Maploader mp = new Maploader();
                mp.Load();

                var verts = Geometry.CreateCube();

                var m_CubeVAO = m_ResourceManager.LoadNonIndexedVAO(verts, VertexPositionColorTexture.Stride, VertexPositionColorTexture.AttributeLengths, VertexPositionColorTexture.AttributeOffsets);

                m_Cube = new Cube[Maploader.width * Maploader.height];
                for (int i = 0; i < Maploader.width * Maploader.height; i++)
                {
                    m_Cube[i]            = new Cube(cubeShader.ShaderProgramId, m_CubeVAO.VaoId, m_CubeVAO.VertexCount);
                    m_Cube[i].i          = i;
                    m_Cube[i].TextureIdA = m_AwesomeFace.TextureId;
                    m_Cube[i].TextureIdB = m_Texture.TextureId;
                }

                int k = 0;
                for (int i = 0; i < Maploader.width; i++)
                {
                    for (int j = 0; j < Maploader.height; j++)
                    {
                        var height = (float)mp.cubes[i, j];

                        height /= 2.0f;

                        if (height < 0)
                        {
                            height = -100; // Temp
                        }
                        height            += 20;
                        m_Cube[k].Position = new Vector3(i, height, j);
                        k++;
                    }
                }
            }

            // Create Skyubox
            {
                var verts     = Geometry.CreateSkyBoxVerticies();
                var skyboxVAO = m_ResourceManager.LoadNonIndexedVAO(verts, VertexPosition.Stride, VertexPosition.AttributeLengths, VertexPosition.AttributeOffsets);


                var cubeMap = m_ResourceManager.LoadCubeMap("Skybox/front.png", "Skybox/back.png", "Skybox/bottom.png", "Skybox/top.png", "Skybox/left.png", "Skybox/right.png");

                m_SkyBoxRenderObject = new SkyBox(skyboxShader.ShaderProgramId, skyboxVAO.VaoId, skyboxVAO.VertexCount, cubeMap.TextureId);
            }

            // Load Font
            {
                m_FontAriel = m_ResourceManager.LoadTextureFont("ariel.fnt");
            }


            renderTarget = RenderTarget.Create(GameWindow.ScreenWidth, GameWindow.ScreenHeight); // TODO This should be the size of the screen

            quad = new ScreenSpaceQuad();
            quad.Create();
        }