Subversion Repositories AndroidProjects

Rev

Rev 789 | Rev 827 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using BauzoidNET.graphics.model;
using BauzoidNET.graphics.renderstates;
using BauzoidNET.graphics.shader;
using BauzoidNET.graphics.sprite;
using BauzoidNET.app;

using Tao.OpenGl;

namespace BauzoidNET.graphics
{
    public class Graphics : BauzoidObject
    {
        private int mWidth = 0;
        private int mHeight = 0;

        public RenderStates renderStates = new RenderStates();

        //public TileBatch mBatch = null;
       
            /** Global sprite shader instance. */
            private SpriteShader mSpriteShader;

        public Graphics(BauzoidApp app) : base(app)
        {
            renderStates.initialize();
        }

        /** Initialize globally available objects. */
            public void init()
            {
            mSpriteShader = new SpriteShader(this);
               
                    //mBatch = new TileBatch(this);
            }
       
            /** Destroy globally available objects. */
            public void exit()
            {
                    /*if (mBatch != null)
                    {
                            mBatch.dispose();
                            mBatch = null;
                    }*/

               
                    if (mSpriteShader != null)
                    {
                            mSpriteShader.dispose();
                            mSpriteShader = null;
                    }
            }
       
            /** Clear render surface (color and depth buffer). */
            public void clear(float r, float g, float b, float a)
            {
                    clear(r, g, b, a, true, true);
            }
       
            /** Same as clear(r, g, b, a, true, clearDepth). */
            public void clear(float r, float g, float b, float a, bool clearDepth)
            {
                    clear(r, g, b, a, true, clearDepth);
            }
       
            /** Clear render surface. */
            public void clear(float r, float g, float b, float a, bool clearColor, bool clearDepth)
            {
                    int bits = 0;
                    if (clearColor)
                            bits |= Gl.GL_COLOR_BUFFER_BIT;
                    if (clearDepth)
                            bits |= Gl.GL_DEPTH_BUFFER_BIT;

                    Gl.glClearColor(r, g, b, a);
                    Gl.glClear(bits);
            }

            public void onSurfaceLost()
            {
                    // destroy resources
            }
       
            public void onSurfaceRecreated()
            {
                    // Update viewport
                    Gl.glViewport(0, 0, mWidth, mHeight);
                       
                    // recreate resources
                    renderStates.initialize();
                    VertexStream.reloadManagedStreams();
                    IndexStream.reloadManagedStreams();
                    ShaderProgram.reloadManagedShaders();
            }
       
            /** Update the GL Surface's dimensions. */
            public void updateSurfaceDimensions(int w, int h)
            {
                    mWidth = w;
                    mHeight = h;
            }
       
            /** Get the GL Surface's width in pixels. */
            public int getWidth()
            {
                    return mWidth;
            }
       
            /** Get the GL Surface's height in pixels. */
            public int getHeight()
            {
                    return mHeight;
            }
       
                    /** Get the aspect ratio. */
            public float getAspect()
            {
                    return ((float)mWidth / (float)mHeight);
            }

        /** Get a reference to the sprite shader. */
        public SpriteShader getSpriteShader()
        {
            return mSpriteShader;
        }

        /*
            public TileBatch getBatch()
            {
                    return mBatch;
            }*/

    }
}