Пример #1
0
        public SpriteRenderer(SpriteSheet spriteSheet)
        {
            SpriteSheet = spriteSheet;

            m_program = SpriteProgram.Instance;
            m_instances = new List<SpriteInstance>();
            m_vao = new VertexArray();

            GL.BindVertexArray(m_vao);

            m_bufferSprite = new Buffer<SpriteData>();
            m_bufferQuad = new Buffer<Vector3>();

            m_bufferQuad.SetData(new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3(0f, 1f, 0f),
                new Vector3(1f, 1f, 0f),
                new Vector3(1f, 0f, 0f)
            });

            GL.UseProgram(m_program);

            m_program.Position.SetValue(m_bufferQuad.GetView());

            m_program.Transform.SetValue(m_bufferSprite.GetView<Matrix4>("Transform"));
            m_program.Transform.SetDivisor(1);
            m_program.TextureOrigin.SetValue(m_bufferSprite.GetView<Vector2>("TextureOrigin"));
            m_program.TextureOrigin.SetDivisor(1);
            m_program.TextureTarget.SetValue(m_bufferSprite.GetView<Vector2>("TextureTarget"));
            m_program.TextureTarget.SetDivisor(1);

            GL.BindVertexArray(null);

            m_isDirty = true;
        }
Пример #2
0
        public Graphics(int queueCapacity = 1000)
        {
            m_queueCapacity = queueCapacity;
            m_queue = new QuadData[m_queueCapacity];
            m_textureQueue = new Texture2D[TEXTURE_QUEUE_CAPACITY];

            m_transformStack = new Stack<Matrix3x2>();

            m_verticesBuffer = new Buffer<Vector2>();
            m_verticesBuffer.SetData(new Vector2[] {
                new Vector2(0,0),
                new Vector2(0,1),
                new Vector2(1,1),
                new Vector2(1,0)
            });

            m_quadsBuffer = new Buffer<QuadData>();
            m_quadsBuffer.SetData(m_queueCapacity, GL.STREAM_DRAW);

            m_program = QuadProgram.Instance;
            m_vertexArray = new VertexArray();

            GL.UseProgram(m_program);
            GL.BindVertexArray(m_vertexArray);

            m_program.Vertex.SetValue(m_verticesBuffer.GetView());

            m_program.TextureCoordinates0.SetValue(m_quadsBuffer.GetView<Vector2>("TextureCoordinates0"));
            m_program.TextureCoordinates0.SetDivisor(1);

            m_program.TextureCoordinates1.SetValue(m_quadsBuffer.GetView<Vector2>("TextureCoordinates1"));
            m_program.TextureCoordinates1.SetDivisor(1);

            m_program.Transform.SetValue(m_quadsBuffer.GetView<Matrix3x2>("Transform"));
            m_program.Transform.SetDivisor(1);

            m_program.Color.SetValue(m_quadsBuffer.GetView<Color4ub>("Color"));
            m_program.Color.SetDivisor(1);

            m_program.Texture.SetValue(m_quadsBuffer.GetView<int>("Texture"));
            m_program.Texture.SetDivisor(1);

            GL.BindVertexArray(null);

            Clear();
        }
Пример #3
0
        public SpriteRenderer(SpriteSheet spriteSheet)
        {
            SpriteSheet = spriteSheet;
            textureFire = Texture2D.Load(typeof(Particle).Assembly.GetManifestResourceStream("Granite.Particle.Textures.fire_color.png"));

            m_program = SpriteProgram.Instance;
            m_instances = new List<SpriteInstance>();
            m_vao = new VertexArray();

            GL.BindVertexArray(m_vao);

            m_bufferSprite = new Buffer<SpriteData>();
            m_bufferQuad = new Buffer<Vector3>();

            m_bufferQuad.SetData(new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3(0f, 1f, 0f),
                new Vector3(1f, 1f, 0f),
                new Vector3(1f, 0f, 0f)
            });

            GL.UseProgram(m_program);

            m_program.Position.SetValue(m_bufferQuad.GetView());

            //m_program.Color.SetValue(m_bufferSprite.GetView(s => s.Color));
            //m_program.Color.SetDivisor(1);
            m_program.Transform.SetValue(m_bufferSprite.GetView<Matrix4>("Transform"));
            m_program.Transform.SetDivisor(1);
            m_program.TextureOrigin.SetValue(m_bufferSprite.GetView<Vector2>("TextureOrigin"));
            m_program.TextureOrigin.SetDivisor(1);
            m_program.TextureTarget.SetValue(m_bufferSprite.GetView<Vector2>("TextureTarget"));
            m_program.TextureTarget.SetDivisor(1);
            m_program.Progress.SetValue(m_bufferSprite.GetView(s => s.Progress));
            m_program.Progress.SetDivisor(1);

            GL.BindVertexArray(null);

            m_isDirty = true;
        }