Exemple #1
0
        /// <summary>
        /// Applies the filter on a certain display object, rendering the output into the current render
        /// target. This method is called automatically by Sparrow's rendering system for the object the
        /// filter is attached to.
        /// </summary>
        public void RenderObject(DisplayObject obj, RenderSupport support)
        {
            // bottom layer
            if (Mode == FragmentFilterMode.Above)
            {
                obj.Render(support);
            }

            // center layer
            if (_cacheRequested)
            {
                _cacheRequested = false;
                _cache          = RenderPasses(obj, support, true);
                DisposePassTextures();
            }

            if (_cache != null)
            {
                _cache.Render(support);
            }
            else
            {
                RenderPasses(obj, support, false);
            }

            // top layer
            if (Mode == FragmentFilterMode.Below)
            {
                obj.Render(support);
            }
        }
Exemple #2
0
 public BoxDrawNode(DrawInfo drawInfo, Game game, Quad screenSpaceDrawQuad, QuadBatch <Vertex2d> batch)
     : base(drawInfo)
 {
     this.game = game;
     this.screenSpaceDrawQuad = screenSpaceDrawQuad;
     this.batch = batch;
 }
        private void startBatch(bool allowRecycle = false)
        {
            if (hasBegun && !allowRecycle)
            {
                return;
            }

            endBatch();

            int amountQuads = OsuMathHelper.Clamp(SpriteList.Count, 1, 100);

            if (SpriteBatch == null || SpriteBatch.Size < amountQuads)
            {
                for (int i = 0; i < SpriteBatches.Length; i++)
                {
                    SpriteBatches[i] = new QuadBatch <TexturedVertex2d>(amountQuads * 2, 500);
                }
            }

            if (currentBlend == SpriteBlendMode.Additive)
            {
                OsuGlControl.SetBlend(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
            }
            else
            {
                OsuGlControl.SetBlend(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }

            hasBegun = true;
            Current  = this;
            NativeText.ScaleModifier = Scale;
        }
Exemple #4
0
 public BufferedContainerDrawNode(DrawInfo drawInfo, FrameBuffer frameBuffer, Quad screenSpaceDrawQuad, QuadBatch <TexturedVertex2d> batch, List <RenderbufferInternalFormat> formats)
     : base(drawInfo)
 {
     this.frameBuffer         = frameBuffer;
     this.screenSpaceDrawQuad = screenSpaceDrawQuad;
     this.batch   = batch;
     this.formats = new List <RenderbufferInternalFormat>(formats);
 }
Exemple #5
0
 // C O N S T R U C T
 public VelcroChain(World worldSys, QuadBatch qbatch)
 {
     world     = worldSys;
     quadBatch = qbatch;
     bods      = new List <Body>();
     joints    = new List <WeldJoint>();
     vecs      = new List <Vector2>();
 }
        /// <summary>
        /// Clears all vertex and index buffers, releasing the associated memory. Useful in low-memory
        /// situations. Don't call from within a render method!
        /// </summary>
        public void PurgeBuffers()
        {
            _quadBatches.Clear();
            _quadBatchTop = new QuadBatch();
            _quadBatches.Add(_quadBatchTop);

            _quadBatchIndex = 0;
            _quadBatchSize  = 1;
        }
            public override void ApplyState()
            {
                base.ApplyState();

                skeleton = Source.Skeleton;
                drawQuad = Source.ScreenSpaceDrawQuad;

                vertexBatch = new QuadBatch <TexturedVertex2D>(skeleton.BoneCount * 6, 1);
            }
 /// <summary>
 /// Resets the render state stack to the default.
 /// </summary>
 public void NextFrame()
 {
     _clipRectStackSize = 0;
     _stateStackIndex   = 0;
     _quadBatchIndex    = 0;
     _numDrawCalls      = 0;
     _quadBatchTop      = _quadBatches[0];
     _stateStackTop     = _stateStack[0];
 }
Exemple #9
0
        public override void DrawQuad(Quad vertexQuad, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null, Vector2?blendRangeOverride = null)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(ToString(), "Can not draw a quad with a disposed texture.");
            }

            RectangleF texRect         = GetTextureRect(textureRect);
            Vector2    inflationAmount = inflationPercentage.HasValue ? new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height) : Vector2.Zero;
            RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);
            Vector2    blendRange      = blendRangeOverride ?? inflationAmount;

            if (vertexAction == null)
            {
                if (quadBatch == null)
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);
                }
                vertexAction = quadBatch.Add;
            }

            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Bottom),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.BottomRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(inflatedTexRect.Right, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.TopRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(inflatedTexRect.Left, inflatedTexRect.Top),
                TextureRect     = new Vector4(texRect.Left, texRect.Top, texRect.Right, texRect.Bottom),
                BlendRange      = blendRange,
                Colour          = drawColour.TopLeft.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexQuad.ConservativeArea);
        }
            private void updateQuadBatch()
            {
                if (Children == null)
                {
                    return;
                }

                if (quadBatch == null && mayHaveOwnVertexBatch(sourceChildrenCount))
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(100, 1000);
                }
            }
        static TextureGLSingle()
        {
            QuadBatch <TexturedVertex2D> quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);

            default_quad_action = quadBatch.AddAction;

            // We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
            // per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
            // grouping of vertices into primitives.
            LinearBatch <TexturedVertex2D> triangleBatch = new LinearBatch <TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);

            default_triangle_action = triangleBatch.AddAction;
        }
Exemple #12
0
            protected override unsafe void OnLoad(EventArgs e)
            {
                LoadTex();

                var green = new Texture("green.png");
                var red   = new Texture("red.png");

                {
                    batch = new QuadBatch <SpriteProgram, SpriteData, SpriteVertex>(4);
                    batch.Shader.Make(new Vector2(800, 800), new Vector2(338, 338), green, red);

                    batch.AddQuad(new SpriteData(new Rectangle(new Point(0, 0), new Size(200, 200)), new Rectangle(new Point(0, 0), new Size(200, 200))));
                    batch.AddQuad(new SpriteData(new Rectangle(new Point(300, 0), new Size(200, 200)), new Rectangle(new Point(100, 100), new Size(200, 200))));
                    batch.UpdateGpu();
                }
                {
                    batch2 = new QuadBatch <SpriteProgram, SpriteData, SpriteVertex>(4);
                    batch2.Shader.Make(new Vector2(800, 800), new Vector2(338, 338), red, green);

                    batch2.AddQuad(new SpriteData(new Rectangle(new Point(0, 300), new Size(200, 200)), new Rectangle(new Point(0, 0), new Size(200, 200))));
                    batch2.AddQuad(new SpriteData(new Rectangle(new Point(300, 300), new Size(200, 200)), new Rectangle(new Point(100, 100), new Size(200, 200))));
                    batch2.UpdateGpu();
                }

                watch.Start();
                // random final setup
                {
                    //var x = GLFW.SetMouseButtonCallback;

                    VSync = VSyncMode.Adaptive;
                    GL.FrontFace(FrontFaceDirection.Cw);
                    GL.PolygonMode(MaterialFace.Back, PolygonMode.Line); // make draw with lines if drawing backs
                    //GL.ClearColor(0.0f, 0.0f, 1.0f, 0.0f); // set clear color
                }
                int total = 0;

                for (int currentNumber = 1; currentNumber < 1000; currentNumber++)
                {
                    int  iMod3          = currentNumber % 3;
                    int  iMod5          = currentNumber % 5;
                    bool isDivisibleBy3 = iMod3 == 0;
                    bool isDivisibleBy5 = iMod5 == 0;
                    if (isDivisibleBy3 || isDivisibleBy5)
                    {
                        total += currentNumber;
                    }
                }
                base.OnLoad(e);

                transform = Matrix4.CreateTranslation(new Vector3(100, 10, 0));
            }
Exemple #13
0
        // I N I T
        protected override void Initialize()
        {
            gpu         = GraphicsDevice;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            quadBatch   = new QuadBatch(Content, gpu, "QuadEffect", "", null, null); // ( if using a rendertarget for most rendering - change null to its resolution )

            pixel    = new Rectangle(382, 0, 1, 1);     quadBatch.PIXEL = pixel;     // need this for line drawing to work in quadbatch
            gras1    = new Rectangle(12, 144, 28, 82);                               // fixed these since last time
            gras2    = new Rectangle(80, 144, 28, 82);                               // fixed these since last time
            gras3    = new Rectangle(142, 144, 28, 82);                              // fixed these since last time
            BigGrass = new Rectangle(0, 0, 380, 122);

            world = new World(new Vector2(0f, 9.8f)); // world physics sim (provide gravity direction)

            player_body                     = BodyFactory.CreateCircle(world, con.ToSimUnits(8.0f), 1.0f);
            player_body.Position            = con.ToSimUnits(400, 10);
            player_body.BodyType            = BodyType.Dynamic; // moves
            player_body.Mass                = 0.4f;
            player_body.Restitution         = 0.2f;             // bounciness
            player_body.Friction            = 0.4f;             // grip
            player_body.CollisionCategories = Category.Cat1; player_body.CollidesWith = Category.All;
            player_body.FixedRotation       = false;

            // attach collider_body to mouse:
            mouse_joint          = JointFactory.CreateFixedMouseJoint(world, player_body, player_body.Position);
            mouse_joint.MaxForce = 500.0f;


            // 大きな 草
            big_grass_body                     = BodyFactory.CreateRectangle(world, con.ToSimUnits(BigGrass.Width * 0.88f), con.ToSimUnits(BigGrass.Height * 0.6f), 1.0f);
            big_grass_body.Position            = con.ToSimUnits(300 + BigGrass.Width / 2f - 10, 600 + BigGrass.Height / 2f);
            big_grass_body.BodyType            = BodyType.Static;
            big_grass_body.Restitution         = 0.2f; // bounciness
            big_grass_body.Friction            = 0.8f; // surface grip
            big_grass_body.Mass                = 1.0f;
            big_grass_body.CollisionCategories = Category.Cat2;
            big_grass_body.CollidesWith        = Category.Cat1;


            // DYNAMIC GRASS (BOTTOM PART):
            grassChain    = new VelcroChain[3];
            grassChain[0] = new VelcroChain(world, quadBatch);
            grassChain[0].MakeGrass(gras1.Width * 0.5f, gras1.Height, new Vector2(350, 600), num_divisions: 3, baseBody: big_grass_body, noGravity: false);
            grassChain[1] = new VelcroChain(world, quadBatch);
            grassChain[1].MakeGrass(gras1.Width * 0.5f, gras1.Height, new Vector2(380, 600), num_divisions: 3, baseBody: big_grass_body, noGravity: false);
            grassChain[2] = new VelcroChain(world, quadBatch);
            grassChain[2].MakeGrass(gras1.Width * 0.5f, gras1.Height, new Vector2(410, 600), num_divisions: 3, baseBody: big_grass_body, noGravity: false);

            base.Initialize();
        }
Exemple #14
0
        // C O N S T R U C T O R
        public Text(QuadBatch Quad, int ScreenWidth, int ScreenHeight, Input Inp, Rectangle?PixelRect)
        {
            pixel = new Rectangle(0, 0, 1, 1); if (PixelRect.HasValue)
            {
                pixel = PixelRect.Value;
            }
            swidth = ScreenWidth; sheight = ScreenHeight;
            center = new Vector2(swidth / 2, sheight / 2);
            inp    = Inp;
            quad   = Quad;
            color  = reg_color;
            Vector2 font_size = new Vector2(quad.Average_Width, quad.text_v_space);

            last_letter_x = last_letter_y = 0; letter_width = (int)font_size.X; letter_height = (int)font_size.Y;
        }
Exemple #15
0
            private void updateQuadBatch()
            {
                if (Children == null)
                {
                    return;
                }

                // This logic got roughly copied from the old osu! code base. These constants seem to have worked well so far.
                int clampedAmountChildren = MathHelper.Clamp(Children.Count, 1, 1000);

                if (mayHaveOwnVertexBatch(clampedAmountChildren) && (quadBatch == null || quadBatch.Size < clampedAmountChildren))
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(clampedAmountChildren * 2, 500);
                }
            }
Exemple #16
0
        public override void DrawQuad(Quad vertexQuad, RectangleF?textureRect, ColourInfo drawColour, Action <TexturedVertex2D> vertexAction = null, Vector2?inflationPercentage = null)
        {
            Debug.Assert(!isDisposed);

            RectangleF texRect = GetTextureRect(textureRect);

            if (inflationPercentage.HasValue)
            {
                texRect = texRect.Inflate(new Vector2(inflationPercentage.Value.X * texRect.Width, inflationPercentage.Value.Y * texRect.Height));
            }

            if (vertexAction == null)
            {
                if (quadBatch == null)
                {
                    quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);
                }
                vertexAction = quadBatch.Add;
            }

            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Bottom),
                Colour          = drawColour.BottomLeft.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.BottomRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Bottom),
                Colour          = drawColour.BottomRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopRight,
                TexturePosition = new Vector2(texRect.Right, texRect.Top),
                Colour          = drawColour.TopRight.Linear,
            });
            vertexAction(new TexturedVertex2D
            {
                Position        = vertexQuad.TopLeft,
                TexturePosition = new Vector2(texRect.Left, texRect.Top),
                Colour          = drawColour.TopLeft.Linear,
            });

            FrameStatistics.Increment(StatisticsCounterType.KiloPixels, (long)vertexQuad.ConservativeArea);
        }
        /// <summary>
        /// Renders the current quad batch and resets it.
        /// </summary>
        public void FinishQuadBatch()
        {
            if (_quadBatchTop.NumQuads != 0)
            {
                _quadBatchTop.Render(_projectionMatrix);
                _quadBatchTop.Reset();

                if (_quadBatchSize == _quadBatchIndex + 1)
                {
                    _quadBatches.Add(new QuadBatch());
                    _quadBatchSize++;
                }

                _numDrawCalls++;
                _quadBatchTop = _quadBatches[++_quadBatchIndex];
            }
        }
Exemple #18
0
    public void lerpGeometry(int index, int count, QuadBatch target, float factor)
    {
        for (int i = 0; i < count; i++)
        {
            int     vidx = (index + i) * 4;
            Vector3 bl   = vertexBatch.vertices[vidx + 0];
            Vector3 tl   = vertexBatch.vertices[vidx + 1];
            Vector3 tr   = vertexBatch.vertices[vidx + 2];
            Vector3 br   = vertexBatch.vertices[vidx + 3];

            Vector3 tbl = target.vertexBatch.vertices[vidx + 0];
            Vector3 ttl = target.vertexBatch.vertices[vidx + 1];
            Vector3 ttr = target.vertexBatch.vertices[vidx + 2];
            Vector3 tbr = target.vertexBatch.vertices[vidx + 3];

            vertexBatch.vertices[vidx + 0] = Vector3.Lerp(bl, tbl, factor);
            vertexBatch.vertices[vidx + 1] = Vector3.Lerp(tl, ttl, factor);
            vertexBatch.vertices[vidx + 2] = Vector3.Lerp(tr, ttr, factor);
            vertexBatch.vertices[vidx + 3] = Vector3.Lerp(br, tbr, factor);
        }
    }
Exemple #19
0
        public TextField(float width, float height, string text = "", string fontName = "mini", float fontSize = 14, uint color = 0x0)
        {
            _text           = text;
            _fontSize       = fontSize;
            _color          = color;
            _hAlign         = HAlign.Center;
            _vAlign         = VAlign.Center;
            _autoScale      = false;
            _kerning        = true;
            _requiresRedraw = true;
            FontName        = fontName;

            _hitArea       = new Quad(width, height);
            _hitArea.Alpha = 0.0f;
            AddChild(_hitArea);

            _contents           = new QuadBatch();
            _contents.Touchable = false;
            AddChild(_contents);

            //[self addEventListener:@selector(onFlatten:) atObject:self forType:SPEventTypeFlatten];
        }
Exemple #20
0
        //--------
        // I N I T
        //--------
        protected override void Initialize()
        {
            #region // SETUP SPRITEBATCH AND GET TRUE DISPLAY
            spriteBatch = new SpriteBatch(GraphicsDevice); pp = GraphicsDevice.PresentationParameters; SurfaceFormat format = pp.BackBufferFormat;
            MainTarget  = new RenderTarget2D(GraphicsDevice, SCREENWIDTH, SCREENHEIGHT);
            screenW     = MainTarget.Width;   screenH = MainTarget.Height;
            desktopRect = new Rectangle(0, 0, pp.BackBufferWidth, pp.BackBufferHeight);   screenRect = new Rectangle(0, 0, screenW, screenH);
            quadBatch   = new QuadBatch(Content, GraphicsDevice, "QuadEffect", "FontTexture", screenW, screenH); // setup distortable quad class (like spriteBatch)
            pixel       = new Rectangle(0, 0, 1, 1); quadBatch.PIXEL = pixel;
            rnd         = new Random();   inp = new Input(pp, MainTarget);
            text        = new Text(quadBatch, screenW, screenH, inp, pixel); text.Size = 0.5f;
            #endregion

            tailRec = new Rectangle(195, 130, 188, 44);

            // M A K E   B O N E S : : :
            bones = new TailBone[5];
            for (int i = 0; i < bones.Length; i++)
            {
                bones[i] = new TailBone(tail_size);
            }
            base.Initialize();
        }
Exemple #21
0
        public override void Draw()
        {
            if (Texture == null)
            {
                return;
            }

            // For billboarding
            Shader.SetGlobalProperty("g_InverseViewMatrix", InverseViewMatrix);

            // Taken from DrawNode3D, since we don't need the world transform for particle systems
            GLWrapper.SetBlend(Blending);

            Shader.Bind();

            // Force create a separate batch so we can use instanced rendering
            if (particleInstancedBatch == null)
            {
                particleInstancedBatch = new QuadBatch <TexturedVertex2D>(TexturedVertex2D.Stride * 4, 1);
            }

            var colourInfo = new ColourInfo {
                Colour = Color4.White
            };

            Texture.DrawQuad(new Quad(-0.5f, -0.5f, 1.0f, 1.0f), colourInfo, vertexAction: v => particleInstancedBatch.Add(v));

            // Set GPU buffer data
            Buffer.SetData(BufferData);

            Buffer.Bind();

            // Render instanced
            particleInstancedBatch.DrawInstanced(InstanceCount);

            Shader.Unbind();
        }
        public RenderSupport()
        {
            _projectionMatrix = Matrix.Create();
            _mvpMatrix        = Matrix.Create();

            _stateStack = new List <RenderState> {
                new RenderState()
            };
            _stateStackIndex = 0;
            _stateStackSize  = 1;
            _stateStackTop   = _stateStack[0];

            _quadBatches = new List <QuadBatch> {
                new QuadBatch()
            };
            _quadBatchIndex = 0;
            _quadBatchSize  = 1;
            _quadBatchTop   = _quadBatches[0];

            _clipRectStack     = new List <Rectangle>();
            _clipRectStackSize = 0;

            SetupOrthographicProjection(0, 320, 0, 480);
        }
        /// <summary>
        ///  Draws text into a quad batch.
        /// </summary>
        public void FillQuadBatch(QuadBatch quadBatch, float width, float height, string text, float size, uint color, HAlign hAlign, VAlign vAlign, bool autoScale, bool kerning)
        {
            List <CharLocation> charLocations = ArrangeCharsInArea(width, height, text, size, hAlign, vAlign, autoScale, kerning);

            _helperImage.Color = color;

            if (charLocations.Count > MAX_TEXT_CHAR_COUNT)
            {
                throw new InvalidDataException(string.Format("Bitmap font text is limited to {0} characters", MAX_TEXT_CHAR_COUNT));
            }

            CharLocation charLocation;

            for (int i = 0; i < charLocations.Count; i++)
            {
                charLocation         = charLocations[i];
                _helperImage.Texture = charLocation.BitmapChar.Texture;
                _helperImage.X       = charLocation.X;
                _helperImage.Y       = charLocation.Y;
                _helperImage.ScaleX  = _helperImage.ScaleY = charLocation.Scale;
                _helperImage.ReadjustSize();
                quadBatch.AddQuad(_helperImage);
            }
        }
Exemple #24
0
 private void DisposeCache()
 {
     _cache = null;
 }
Exemple #25
0
 public void Set(QuadBatch qb)
 {
     vertexBatch = qb.vertexBatch.Duplicate();
 }
Exemple #26
0
        static TextureGLSingle()
        {
            QuadBatch <TexturedVertex2D> quadBatch = new QuadBatch <TexturedVertex2D>(512, 128);

            default_quad_action = quadBatch.AddAction;
        }
        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();
        }
Exemple #28
0
 public RenderContext()
 {
     QuadBatch      = new QuadBatch();
     PrimitiveBatch = new PrimitiveBatch();
     TextureFill    = new TextureFill();
 }
Exemple #29
0
 //-----------------------------------------------------------------------------
 // Method:	GetQuadDefinition()
 // Desc:	Returns a reference to a QuadDefinition object from the specified
 //            quad batch, or null if none are left
 public BatchedQuadDef GetQuadDefinition( QuadBatch batch )
 {
     return PrimitiveQuadBatch.GetQuadDef( m_quadBatches[(int)batch] );
 }
Exemple #30
0
 public void lerpGeometry(QuadBatch target, float factor)
 {
     lerpGeometry(0, Count, target, factor);
 }
Exemple #31
0
        private QuadBatch RenderPasses(DisplayObject obj, RenderSupport support, bool intoCache)
        {
            Texture cacheTexture = null;
            Stage   stage        = obj.Stage;
            float   scale        = Resolution;

            if (stage == null)
            {
                throw new InvalidOperationException("Filtered object must be on the stage.");
            }
            // the bounds of the object in stage coordinates
            Rectangle boundsPOT;
            Rectangle bounds;

            CalcBounds(obj, stage, scale, !intoCache, out bounds, out boundsPOT);

            if (bounds.IsEmpty())
            {
                DisposePassTextures();
                return(intoCache ? new QuadBatch() : null);
            }

            UpdateBuffers(boundsPOT);
            UpdatePassTextures((int)boundsPOT.Width, (int)boundsPOT.Height, scale);

            support.FinishQuadBatch();
            support.AddDrawCalls(NumPasses);
            support.PushState(Matrix.Create(), 1.0f, BlendMode.AUTO);

            // save original projection matrix and render target
            _projMatrix.CopyFromMatrix(support.ProjectionMatrix);
            Texture previousRenderTarget = support.RenderTarget;

            // use cache?
            if (intoCache)
            {
                cacheTexture = CreateTexture((int)boundsPOT.Width, (int)boundsPOT.Height, scale);
            }

            // draw the original object into a texture
            support.RenderTarget = _passTextures[0];
            SparrowSharpApp.Context.ScissorBox = null; // we want the entire texture cleared
            support.Clear();
            support.BlendMode = BlendMode.NORMAL;
            support.SetupOrthographicProjection(boundsPOT.Left, boundsPOT.Right, boundsPOT.Bottom, boundsPOT.Top);
            obj.Render(support);
            support.FinishQuadBatch();

            // prepare drawing of actual filter passes
            support.ApplyBlendMode(true);
            support.ModelViewMatrix.Identity();
            support.PushClipRect(bounds);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBufferName);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBufferName);

            GL.EnableVertexAttribArray(VertexPosID);
            GL.VertexAttribPointer(VertexPosID, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.POSITION_OFFSET);

            GL.EnableVertexAttribArray(TexCoordsID);
            GL.VertexAttribPointer(TexCoordsID, 2, VertexAttribPointerType.Float, false, Vertex.SIZE, (IntPtr)Vertex.TEXTURE_OFFSET);

            // draw all passes
            for (int i = 0; i < NumPasses; ++i)
            {
                if (i < NumPasses - 1)
                { // intermediate pass
                    // draw into pass texture
                    support.RenderTarget = PassTextureForPass(i + 1);
                    support.Clear();
                }
                else
                { // final pass
                    if (intoCache)
                    {
                        // draw into cache texture
                        support.RenderTarget = cacheTexture;
                        support.Clear();
                    }
                    else
                    {
                        // draw into back buffer, at original (stage) coordinates
                        support.RenderTarget     = previousRenderTarget;
                        support.ProjectionMatrix = _projMatrix;
                        support.ModelViewMatrix.Translate(OffsetX, OffsetY);
                        support.BlendMode = obj.BlendMode;
                        support.ApplyBlendMode(true);
                    }
                }

                Texture passTexture = PassTextureForPass(i);

                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, passTexture.Name);

                ActivateWithPass(i, passTexture, support.MvpMatrix);
                GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, IntPtr.Zero);

                DeactivateWithPass(i, passTexture);
            }

            GL.DisableVertexAttribArray(VertexPosID);
            GL.DisableVertexAttribArray(TexCoordsID);

            support.PopState();
            support.PopClipRect();

            QuadBatch cache = null;

            if (intoCache)
            {
                // restore support settings
                support.RenderTarget     = previousRenderTarget;
                support.ProjectionMatrix = _projMatrix;

                // Create an image containing the cache. To have a display object that contains
                // the filter output in object coordinates, we wrap it in a QuadBatch: that way,
                // we can modify it with a transformation matrix.
                cache = new QuadBatch();
                Image image = new Image(cacheTexture);

                Matrix matrix = stage.TransformationMatrixToSpace(obj);
                // Note: the next line was originally:
                // matrix.Translate (bounds.X + OffsetX, bounds.Y + OffsetY);
                // this seems like a sparrow-s bug; fix is from Starling
                matrix.PrependTranslation(bounds.X + OffsetX, bounds.Top + OffsetY);
                cache.AddQuad(image, 1.0f, BlendMode.AUTO, matrix);
            }

            return(cache);
        }